-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
237 lines (181 loc) · 6.53 KB
/
app.js
File metadata and controls
237 lines (181 loc) · 6.53 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
// mods by Patrick OReilly
// Twitter: @pato_reilly Web: http://patricko.byethost9.com
var DEBUG=0;
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'pang-example', { preload: preload, create: create, update: update, render: render });
function preload() {
game.load.image('sky', 'assets/sky.jpg');
game.load.image('dude', 'assets/sprites/pang-dude.png');
game.load.spritesheet('ball', 'assets/pang.png',98,98);
game.load.image('lace', 'assets/lace2.png');
// game.load.image('ground', 'assets/platform.png');
game.load.spritesheet('bam', 'assets/bam.png', 98,98);
game.load.tilemap('map', 'assets/tilemaps/maps/features_test.json', null, Phaser.Tilemap.TILED_JSON);
game.load.image('ground_1x1', 'assets/tilemaps/tiles/ground_1x1.png');
game.load.image('walls_1x2', 'assets/tilemaps/tiles/walls_1x2.png');
game.load.image('tiles2', 'assets/tilemaps/tiles/tiles2.png');
game.load.image('phaser', 'assets/sprites/arrow.png');
game.load.spritesheet('coin', 'assets/sprites/coin.png', 32, 32);
}
var image;
var timerEvent=0;
var timerStart;var jumpTimer = 0;
var explosions;
var explosionAnimation;
var map;
var layer;
function create() {
map = game.add.tilemap('map');
map.addTilesetImage('ground_1x1');
map.addTilesetImage('walls_1x2');
map.addTilesetImage('tiles2');
map.setCollisionBetween(1, 12);
layer = map.createLayer('Tile Layer 1');
layer.debug = true;
layer.resizeWorld();
game.physics.gravity.y =450;
game.physics.setBoundsToWorld();
// Here we create our coins group
coins = game.add.group();
cursors = game.input.keyboard.createCursorKeys();
lineButton = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);
balls = game.add.group();
laces =game.add.group();
ball = balls.create(
400,
200,
'ball',
1
);
knocker = game.add.sprite(120,120, 'dude');
ball.scale.setTo(1,1);
knocker.scale.setTo(1,1);
knocker.body.velocity.y = 190;
knocker.body.minVelocity.y = 5;
// This gets it moving
knocker.body.bounce.setTo(0, 0.2);
// This makes the game world bounce-able
ball.body.collideWorldBounds = true;
// lace.body.collideWorldBounds = true;
knocker.body.collideWorldBounds=true;
// cop = platforms.create(120, 230, 'ground');
//cop.body.immovable = true;
console.log(knocker);
// This sets the image bounce energy for the horizontal
// and vertical vectors (as an x,y point). "1" is 100% energy return
ball.body.bounce.setTo(0.98, 0.97);
//ball.body.velocity.setTo(100, 100);
// This sets the gravity the sprite responds to in the world, as a point
// Here we leave x=0 and set y=80 to simulate falling
// ball.body.gravity.setTo(0, 680);
//knocker.body.gravity.setTo(0, 15600);
//knocker.scale.setTo(1,1);
game.camera.follow(knocker);
lace = laces.create(
knocker.x,
knocker.y,
'lace',
1
);
//pang
explosions = game.add.group();
var explosionAnimation = explosions.create(-100, -100, 'bam', false);
// explosionAnimation.anchor.setTo(0.5, 0.5);
explosionAnimation.animations.add('bam',[0,1,2,3],4,true);
}
// Move the knocker with the arrow keys
function update () {
knocker.body.velocity.x = 0;
// Enable physics between the knocker and the ball
game.physics.collide(layer, balls);
game.physics.collide(knocker,layer);
//game.physics.collide(laces,layer);
game.physics.overlap(laces, layer,killit,null,this);
game.physics.overlap(knocker, balls,function(){});
game.physics.overlap(laces, balls,dostuff,null,this);
if (cursors.up.isDown && knocker.body.onFloor() && game.time.now > jumpTimer)
{
knocker.body.velocity.y = -350;
jumpTimer = game.time.now + 250;
}
else if (cursors.left.isDown)
{
knocker.body.velocity.x = -100;
}
else if (cursors.right.isDown)
{
knocker.body.velocity.x = 100;
}
else
{
// knocker.body.velocity.setTo(0, 0);
}
if (lineButton.isDown){
if(timerEvent==0){
lace.reset(knocker.x+10,knocker.y);
countTime();
lace.body.velocity.setTo(0, -400);lace.body.gravity.setTo(0, -180);
}
}
}
function countTime(){
timerEvent++;
}
function killit(lace, layer) {
lace.kill();
timerEvent=0;
//timerStart.remove();
}
function dostuff(lace, ball) {
var lacex=lace.x;
var lacey=lace.y;
var x=ball.x;
var y=ball.y;
var scalex=ball.scale.x;
var scaley=ball.scale.y;
var velox=Math.abs(ball.body.velocity.x);
var veloy=Math.abs(ball.body.velocity.y);
var explosionAnimation= explosions.getFirstAlive();
explosionAnimation.scale.x=ball.scale.x;
explosionAnimation.scale.y=ball.scale.y;
explosionAnimation.reset(lacex,y);
explosionAnimation.play('bam',20, false,true);
if(ball.scale.x==0.125){
ball.kill();
// ball.animations.onComplete(function(){);
lace.kill();
}else{
//ball.animations.onComplete(function(){ball.kill()});
lace.kill();
ball.kill();
for (var i = 0; i <=2; i++) {
// Create a star inside of the 'stars' group
if(i==1){
ball = balls.create((lacex+20),y, 'ball');ball.body.velocity.setTo(10+velox, 110-veloy);
}else if(i==2){
ball = balls.create(lacex-20,y, 'ball');ball.body.velocity.setTo(-20-velox, 110-veloy);
}
/**/
// This just gives each star a slightly random bounce value
ball.body.bounce.setTo(0.99, 0.98);
ball.scale.setTo(scalex/2, scaley/2); // ball.body.gravity.setTo(0,680);
// This sets the gravity the sprite responds to in the world, as a point
// Here we leave x=0 and set y=80 to simulate falling
ball.body.collideWorldBounds = true;
}
} var explosionAnimation = explosions.create(-100, -100, 'bam', false);
// explosionAnimation.anchor.setTo(0.5, 0.5);
explosionAnimation.animations.add('bam',[0,1,2,3],60,true);
timerEvent=0;
//timerStart.remove();
}
function render () {
if(DEBUG==true){
//debug helper
game.debug.renderSpriteInfo(ball, 32, 32);
game.debug.renderPhysicsBody(ball.body)
balls.forEachAlive(function(ball) {
game.debug.renderPhysicsBody(ball.body);
game.debug.renderSpriteBody(ball);
});
}
}