-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.js
84 lines (73 loc) · 2.62 KB
/
Game.js
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
GoosePatrol.Game = function (game) {
this.amtOfGoose;
this.amtOfCurrGoose;
this.amtOfGooseSpawned;
this.gooseGroup;
this.t;
this.score;
};
GoosePatrol.Game.prototype = {
//Initializes all game variables and sprites
create: function() {
this.amtOfGoose = 100;
this.amtOfCurrGoose = 0;
this.amtOfGooseSpawned = 0;
this.buildWorld();
this.score = 0;
var style = {font: "20px Arial", fill: "#000000"};
this.t = this.add.text(10, 10, "Score: " + this.score , style);
},
buildWorld: function() {
this.add.image(0, 0, 'sky');
this.add.image(0, 0, 'scenery');
this.createGoose();
},
//Creates a goose and adds it to the gooseGroup
createGoose: function() {
this.gooseGroup = this.add.group();
this.gooseGroup.enableBody = true;
for(var i = 0; i < (this.amtOfGoose); i++){
if(this.amtOfCurrGoose <= 10) {
this.amtOfGooseSpawned++;
var r = this.rnd.integerInRange(1, 2);
if (r == 1)
var g = this.spawnGoose(this.rnd.integerInRange(-500, -100), this.rnd.integerInRange(100, 150), 200);
else if (r == 2)
var g = this.spawnGoose(this.rnd.integerInRange(900, 1400), this.rnd.integerInRange(100, 150), -200);
}
}
},
spawnGoose: function(x, y, velocity) {
var goose = this.gooseGroup.create(x, y, 'goose');
goose.anchor.setTo(0.5);
goose.enableBody = true;
goose.inputEnabled = true;
goose.body.velocity.x = velocity;
goose.events.onInputDown.add(this.killGoose, this);
this.amtOfCurrGoose++;
//goose.animations.add('fly', [0,1], 20, true);
//goose.animations.play('fly');
//this.player.body.collideWorldBounds = true;
},
killGoose: function(goose, pointer){
goose.kill();
this.addScore();
this.amtOfCurrGoose--;
},
addScore: function(){
this.score++;
this.t.setText("Score: " + this.score);
},
update: function() {
for(var i = 0; i < (this.amtOfGoose); i++){
if(this.amtOfCurrGoose <= 10) {
this.amtOfGooseSpawned++;
var r = this.rnd.integerInRange(1, 2);
if (r == 1)
var g = this.spawnGoose(this.rnd.integerInRange(-500, -100), this.rnd.integerInRange(100, 150), 200);
else if (r == 2)
var g = this.spawnGoose(this.rnd.integerInRange(900, 1400), this.rnd.integerInRange(100, 150), -200);
}
}
}
};