-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlavaEdit.html
More file actions
281 lines (206 loc) · 6.88 KB
/
lavaEdit.html
File metadata and controls
281 lines (206 loc) · 6.88 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Phaser - Making your first game, part 9</title>
<script src="//cdn.jsdelivr.net/phaser/2.2.2/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.CANVAS, '', { 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('pink', 'assets/pink.png');
game.load.image('lava', 'assets/lava.png');
game.load.spritesheet('dude', 'assets/dude.png', 32, 48);
}
var player;
var platforms;
var h1 = 300;//heights of ledges
var h2 = 350;
var wormHole;
var cursors;
var deathZone;
var stars;
var score = 0;
var scoreText;
var scoreString;
var lives;
var livesText;
var livesString;
function create() {
game.world.setBounds(0, 0, 1500, 600);
game.physics.startSystem(Phaser.Physics.ARCADE);
// A simple background
game.add.sprite(0, 0, 'sky');
// the platforms group contains the ground and the 2 ledges
platforms = game.add.group();
// We will enable physics for any object that is created in this group
platforms.enableBody = true;
// Here we create the ground.
var ground = platforms.create(0, game.world.height - 64, 'ground');
// Scale it to fit the width of the game (the original sprite is 400x32 in size)
ground.scale.setTo(2, 2);
// This stops it from falling away when you jump on it
ground.body.immovable = true;
// Ledges
var ledge = platforms.create(400, h1, 'ground');
ledge.body.immovable = true;
ledge = platforms.create(-150, h2, 'ground');
ledge.body.immovable = true;
ledge = platforms.create(1100, game.world.height - 64, 'ground');
ledge.body.immovable = true;
ledge.scale.setTo(1,2);
// Death Zone
deathZone = game.add.group();
deathZone.enableBody = true;
lava = deathZone.create(800, game.world.height - 32, 'lava');
lava.scale.setTo(.47,.1);
// WORM HOLE
wormHole = game.add.group();
wormHole.enableBody = true;
hole = wormHole.create(-150, h2+30, 'pink');
hole.scale.setTo(1, 3.5);
hole2 = wormHole.create(400, h1+30, 'pink');
hole2.scale.setTo(1, 3.5);
// The player and its settings
player = game.add.sprite(232, game.world.height - 150, 'dude');
player.anchor.x = 0.5;
player.anchor.y = 0.5;
// We need to enable physics on the player
game.physics.arcade.enable(player);
// Player physics properties. Give the little guy a slight bounce.
player.body.bounce.y = 0.2;
player.body.gravity.y = 300;
player.body.collideWorldBounds = true;
// Our two animations, walking left and right.
player.animations.add('left', [0, 1, 2, 3], 10, true);
player.animations.add('right', [5, 6, 7, 8], 10, true);
//game.camera.fallow(player);
// Finally some stars to collect
stars = game.add.group();
// We will enable physics for any star that is created in this group
stars.enableBody = true;
// Here we'll create 12 of them evenly spaced apart
for (var i = 0; i < 12; i++)
{
// Create a star inside of the 'stars' group
var star = stars.create(i * 70, 0, 'star');
// Let gravity do its thing
star.body.gravity.y = 300;
// This just gives each star a slightly random bounce value
star.body.bounce.y = 0.7 + Math.random() * 0.2;
}
// The score
score= 0;
scoreString = 'Score : ';
scoreText = game.add.text(16, 16, scoreString + score, { fontSize: '32px', fill: '#000' });
//lives
lives = 3;
livesString = 'Lives : '
livesText = game.add.text(300,16, livesString + lives, { fontSize: '32px', fill: '#000'});
// Our controls.
cursors = game.input.keyboard.createCursorKeys();
game.camera.follow(player);
}
function update() {
// Collide the player and the stars with the platforms
var hitPlatform = game.physics.arcade.collide(player, platforms);
game.physics.arcade.collide(stars, platforms);
// Checks if the player overlaps with any of the stars, call collectStar function
game.physics.arcade.overlap(player, stars, collectStar, null, this);
// Reset the players velocity (movement)
player.body.velocity.x = 0;
if(game.physics.arcade.overlap(player, lava))
{
if(lives<1){
gameOver(score);
}
else{ lifeLost(player); }
}
if(game.physics.arcade.overlap(player, wormHole))
{
flipgravity(player, wormHole);
}
else{
player.angle = 0;
player.body.gravity.y = 300;
if (cursors.left.isDown)
{
// Move to the left
player.body.velocity.x = -150;
player.animations.play('left');
}
else if (cursors.right.isDown)
{
// Move to the right
player.body.velocity.x = 150;
player.animations.play('right');
}
else
{
// Stand still
player.animations.stop();
player.frame = 4;
}
}
// Allow the player to jump if they are touching the ground.
if (cursors.up.isDown && player.body.touching.down && hitPlatform)
{
player.body.velocity.y = -350;
}
}
function flipgravity (player, wormHole){
player.body.gravity.y = -300;
//player.body.velocity.y = -300;
player.angle = 180;
if (cursors.left.isDown)
{
// Move to the left
player.body.velocity.x = -150;
player.animations.play('right');
}
else if (cursors.right.isDown)
{
// Move to the right
player.body.velocity.x = 150;
player.animations.play('left');
}
else
{
// Stand still
player.animations.stop();
player.frame = 4;
}
if (cursors.up.isDown)// && player.body.touching.down)// && hitPlatform)
{
player.body.velocity.y = 350;
}
} // end of fliped gravity
function collectStar (player, star) {
// Removes the star from the screen
star.kill();
// Add and update the score
score += 10;
scoreText.text = 'Score: ' + score;
}
function lifeLost(player) {
player.position.x = 300;
player.position.y = game.world.height - 100;
lives -= 1;
livesText.text = 'Lives: ' + lives;
}
function gameOver(score) {
var gameOverText = game.add.text(200,200, 'GAME OVER', { fontSize: '256px', fill: '#000'});
player.kill();
}
</script>
</body>
</html>