Skip to content

Commit f5c7830

Browse files
author
Thomas
committed
changed a function name
1 parent 7b64c9e commit f5c7830

3 files changed

Lines changed: 71 additions & 6 deletions

File tree

2-flappy_bird/flappy_bird.zip

958 Bytes
Binary file not shown.

2-flappy_bird/flappy_bird/main.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ game_state.main.prototype = {
2626
// Add gravity to the bird to make it fall
2727
this.bird.body.gravity.y = 1000;
2828

29-
// Call the 'flap' function when the spacekey is hit
29+
// Call the 'jump' function when the spacekey is hit
3030
var space_key = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);
31-
space_key.onDown.add(this.flap, this);
31+
space_key.onDown.add(this.jump, this);
3232

3333
// Create a group of 20 pipes
3434
this.pipes = game.add.group();
3535
this.pipes.createMultiple(20, 'pipe');
3636

37-
// Timer that calls 'add_row_pipes' ever 1.5 seconds
38-
this.timer = this.game.time.events.loop(1500, this.add_row_pipes, this);
37+
// Timer that calls 'add_row_of_pipes' ever 1.5 seconds
38+
this.timer = this.game.time.events.loop(1500, this.add_row_of_pipes, this);
3939

4040
// Add a score label on the top left of the screen
4141
this.score = 0;
@@ -54,7 +54,7 @@ game_state.main.prototype = {
5454
},
5555

5656
// Make the bird jump
57-
flap: function() {
57+
jump: function() {
5858
// Add a vertical velocity to the bird
5959
this.bird.body.velocity.y = -350;
6060
},
@@ -84,7 +84,7 @@ game_state.main.prototype = {
8484
},
8585

8686
// Add a row of 6 pipes with a hole somewhere in the middle
87-
add_row_pipes: function() {
87+
add_row_of_pipes: function() {
8888
var hole = Math.floor(Math.random()*5)+1;
8989

9090
for (var i = 0; i < 8; i++)
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
var game = new Phaser.Game(400, 490, Phaser.AUTO, 'game_div');
2+
var game_state = {};
3+
4+
game_state.main = function() { };
5+
game_state.main.prototype = {
6+
7+
preload: function() {
8+
this.game.stage.backgroundColor = '#71c5cf';
9+
this.game.load.image('bird', 'assets/bird.png');
10+
this.game.load.image('pipe', 'assets/pipe.png');
11+
},
12+
13+
create: function() {
14+
this.bird = this.game.add.sprite(100, 245, 'bird');
15+
this.bird.body.gravity.y = 1000;
16+
17+
var space_key = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);
18+
space_key.onDown.add(this.jump, this);
19+
20+
this.pipes = game.add.group();
21+
this.pipes.createMultiple(20, 'pipe');
22+
this.timer = this.game.time.events.loop(1500, this.add_row_of_pipes, this);
23+
24+
this.score = 0;
25+
var style = { font: "30px Arial", fill: "#ffffff" };
26+
this.label_score = this.game.add.text(20, 20, "0", style);
27+
},
28+
29+
update: function() {
30+
if (this.bird.inWorld == false)
31+
this.restart_game();
32+
33+
this.game.physics.overlap(this.bird, this.pipes, this.restart_game, null, this);
34+
},
35+
36+
jump: function() {
37+
this.bird.body.velocity.y = -350;
38+
},
39+
40+
restart_game: function(bird, pipe) {
41+
this.game.time.events.remove(this.timer);
42+
this.game.state.start('main');
43+
},
44+
45+
add_one_pipe: function(x, y) {
46+
var pipe = this.pipes.getFirstDead();
47+
pipe.reset(x, y);
48+
pipe.body.velocity.x = -200;
49+
pipe.outOfBoundsKill = true;
50+
},
51+
52+
add_row_of_pipes: function() {
53+
var hole = Math.floor(Math.random()*5)+1;
54+
55+
for (var i = 0; i < 8; i++)
56+
if (i != hole && i != hole +1)
57+
this.add_one_pipe(400, i*60+10);
58+
59+
this.score += 1;
60+
this.label_score.content = this.score;
61+
},
62+
};
63+
64+
game.state.add('main', game_state.main);
65+
game.state.start('main');

0 commit comments

Comments
 (0)