-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpart1.html
112 lines (98 loc) · 3.18 KB
/
part1.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Phaser - Making your first game, part 1</title>
<script type="text/javascript" src="js/phaser.min.js"></script>
<style type="text/css">
body {
margin: 0;
}
</style>
</head>
<body>
<script type="text/javascript">
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update });
function preload() {
game.load.image('sky', 'assets/sky.png');
game.load.image('ground', 'assets/platform.png');
game.load.image('star', 'assets/star.png');
game.load.image('arrow', 'assets/arrow.png');
game.load.spritesheet('dude', 'assets/dude.png', 32, 48);
}
var platforms;
var ground;
var player;
var cursors;
var arrow;
function create() {
game.physics.startSystem(Phaser.Physics.ARCADE);
game.add.sprite(0,0,'sky');
platforms = game.add.group();
platforms.enableBody = true;
var ground = platforms.create(0,game.world.height-32,'ground');
ground.scale.setTo(2,1);
ground.body.immovable = true;
var ledge = platforms.create(32,0,'ground');
ledge.body.immovable = true;
ledge.scale.setTo(2,1);
ledge.angle = 90;
var ledge = platforms.create(game.world.width,0,'ground');
ledge.body.immovable = true;
ledge.scale.setTo(2,1);
ledge.angle = 90;
var ledge = platforms.create(0,0,'ground');
ledge.body.immovable = true;
ledge.scale.setTo(2,1);
//create player
player = game.add.sprite(32,game.world.height-150,'dude');
game.physics.arcade.enable(player);
player.body.bounce.y = 0.2;
player.body.gravity.y = 300;
player.body.collideWorldBounds = true;
player.animations.add('left',[0,1,2,3],10,true);
player.animations.add('right',[5,6,7,8],10,true);
cursors = game.input.keyboard.createCursorKeys();
arrow = game.add.sprite(300,300,'arrow');
game.physics.enable(arrow,Phaser.Physics.ARCADE);
arrow.body.maxAngular = 500;
arrow.body.angularDrag = 100;
arrow.anchor.setTo(0.5, 0.5);
arrow.body.collideWorldBounds = true;
}
function update() {
game.physics.arcade.collide(player,platforms);
player.body.velocity.x = 0;
arrow.body.angularAcceleration = 0;
var turning = false;
if(cursors.left.isDown) {
// player.body.velocity.x = -150;
// player.animations.play('left');
arrow.body.angularAcceleration -= 200;
turning = true;
// game.physics.arcade.accelerationFromRotation(arrow.rotation, 200, arrow.body.acceleration);
} else if(cursors.right.isDown) {
// player.body.velocity.x = 150;
// player.animations.play('right');
arrow.body.angularAcceleration += 200;
turning = true;
// game.physics.arcade.accelerationFromRotation(arrow.rotation, 200, arrow.body.acceleration);
} else {
// player.animations.stop();
// player.frame = 4;
arrow.body.acceleration.set(0);
}
if(cursors.up.isDown && turning) {
game.physics.arcade.accelerationFromRotation(arrow.rotation, 200, arrow.body.acceleration);
} else {
arrow.body.acceleration.set(0);
}
if(cursors.up.isDown && player.body.touching.down) {
player.body.velocity.y = -350;
} else if(cursors.up.isDown) {
player.body.velocity.y -= 10;
}
}
</script>
</body>
</html>