powerup multiball
This commit is contained in:
parent
42f5a514ae
commit
0cad186c56
|
@ -140,7 +140,7 @@ var paddle = gameobject.clone("paddle", {
|
|||
},
|
||||
|
||||
collide(hit) {
|
||||
if (!hit.obj.from === 'ball') return;
|
||||
if (!(hit.obj.from === 'ball')) return;
|
||||
var xdiff = hit.pos.x - this.pos.x;
|
||||
if (Math.sign(xdiff) === Math.sign(hit.obj.velocity)) return;
|
||||
var oldvel = hit.obj.velocity;
|
||||
|
@ -159,10 +159,11 @@ gameobject.clone("upgrade_drop", {
|
|||
|
||||
start() {
|
||||
this.collider.radius = 15;
|
||||
this.collider.sensor = true;
|
||||
},
|
||||
|
||||
draw() {
|
||||
Debug.box(this.pos, [this.size,this.size], Color.white);
|
||||
Shape.circle(this.pos,this.size/3,Color.white);
|
||||
},
|
||||
|
||||
collide(hit) {
|
||||
|
@ -170,7 +171,7 @@ gameobject.clone("upgrade_drop", {
|
|||
return;
|
||||
|
||||
this.upgrade();
|
||||
Register.postphys_cbs.push(() => { this.kill(); });
|
||||
this.kill();
|
||||
},
|
||||
|
||||
update(dt) {
|
||||
|
|
34
game.js
34
game.js
|
@ -6,11 +6,11 @@ sim_start();
|
|||
World.loadfile("lvl1.lvl");
|
||||
|
||||
function spawnball() {
|
||||
var bb = World.spawn(gameobjects['ball']);
|
||||
bb.pos = bb.pos.add([50,0]);
|
||||
bb.pos.y += 200;
|
||||
bb.draw_layer = 3;
|
||||
bb.tag = 'ball';
|
||||
var bb = World.spawn(gameobjects['ball']);
|
||||
bb.pos = bb.pos.add([50,0]);
|
||||
bb.pos.y += 200;
|
||||
bb.draw_layer = 3;
|
||||
bb.tag = 'ball';
|
||||
}
|
||||
|
||||
function spawn_powerup(pos, fn) {
|
||||
|
@ -20,15 +20,10 @@ function spawn_powerup(pos, fn) {
|
|||
p.upgrade = fn;
|
||||
}
|
||||
|
||||
var Game = {
|
||||
grow() {
|
||||
|
||||
},
|
||||
};
|
||||
|
||||
spawn_powerup([0,300], () => {
|
||||
var up = World.spawn(gameobjects['upgrade_drop']);
|
||||
up.pos = [0,300];
|
||||
for (var i = 0; i < 10; i++)
|
||||
spawnball();
|
||||
});
|
||||
|
||||
function lostlife() {
|
||||
lives--;
|
||||
|
@ -37,11 +32,11 @@ function lostlife() {
|
|||
|
||||
spawnball();
|
||||
|
||||
|
||||
var f = World.spawn(gameobjects['edge2d']);
|
||||
f.edge2d.cpoints = Geometry.box(lvlwidth,lvlheight);
|
||||
f.edge2d.thickness = 10;
|
||||
f.mass = 50;
|
||||
//f.phys = 0;
|
||||
|
||||
var killbox = World.spawn(gameobjects['polygon2d']);
|
||||
|
||||
|
@ -49,12 +44,11 @@ killbox.polygon2d.points = Geometry.box(lvlwidth,30);
|
|||
killbox.pos = [0,-lvlheight/2];
|
||||
killbox.polygon2d.sensor = true;
|
||||
killbox.register_hit(hit => {
|
||||
if (hit.obj.tag === 'ball') {
|
||||
Register.postphys_cbs.push(() => {
|
||||
hit.obj.kill();
|
||||
lostlife();
|
||||
});
|
||||
}
|
||||
if (hit.obj.tag !== 'ball')
|
||||
return;
|
||||
|
||||
hit.obj.kill();
|
||||
lostlife();
|
||||
}, this);
|
||||
|
||||
//Sound.play("start.wav");
|
||||
|
|
Loading…
Reference in a new issue