powerup multiball

This commit is contained in:
John Alanbrook 2023-05-27 15:13:08 +00:00
parent 42f5a514ae
commit 0cad186c56
2 changed files with 18 additions and 23 deletions

View file

@ -140,7 +140,7 @@ var paddle = gameobject.clone("paddle", {
}, },
collide(hit) { collide(hit) {
if (!hit.obj.from === 'ball') return; if (!(hit.obj.from === 'ball')) return;
var xdiff = hit.pos.x - this.pos.x; var xdiff = hit.pos.x - this.pos.x;
if (Math.sign(xdiff) === Math.sign(hit.obj.velocity)) return; if (Math.sign(xdiff) === Math.sign(hit.obj.velocity)) return;
var oldvel = hit.obj.velocity; var oldvel = hit.obj.velocity;
@ -159,10 +159,11 @@ gameobject.clone("upgrade_drop", {
start() { start() {
this.collider.radius = 15; this.collider.radius = 15;
this.collider.sensor = true;
}, },
draw() { draw() {
Debug.box(this.pos, [this.size,this.size], Color.white); Shape.circle(this.pos,this.size/3,Color.white);
}, },
collide(hit) { collide(hit) {
@ -170,7 +171,7 @@ gameobject.clone("upgrade_drop", {
return; return;
this.upgrade(); this.upgrade();
Register.postphys_cbs.push(() => { this.kill(); }); this.kill();
}, },
update(dt) { update(dt) {

30
game.js
View file

@ -6,11 +6,11 @@ sim_start();
World.loadfile("lvl1.lvl"); World.loadfile("lvl1.lvl");
function spawnball() { function spawnball() {
var bb = World.spawn(gameobjects['ball']); var bb = World.spawn(gameobjects['ball']);
bb.pos = bb.pos.add([50,0]); bb.pos = bb.pos.add([50,0]);
bb.pos.y += 200; bb.pos.y += 200;
bb.draw_layer = 3; bb.draw_layer = 3;
bb.tag = 'ball'; bb.tag = 'ball';
} }
function spawn_powerup(pos, fn) { function spawn_powerup(pos, fn) {
@ -20,15 +20,10 @@ function spawn_powerup(pos, fn) {
p.upgrade = fn; p.upgrade = fn;
} }
var Game = {
grow() {
},
};
spawn_powerup([0,300], () => { spawn_powerup([0,300], () => {
var up = World.spawn(gameobjects['upgrade_drop']); for (var i = 0; i < 10; i++)
up.pos = [0,300]; spawnball();
});
function lostlife() { function lostlife() {
lives--; lives--;
@ -37,11 +32,11 @@ function lostlife() {
spawnball(); spawnball();
var f = World.spawn(gameobjects['edge2d']); var f = World.spawn(gameobjects['edge2d']);
f.edge2d.cpoints = Geometry.box(lvlwidth,lvlheight); f.edge2d.cpoints = Geometry.box(lvlwidth,lvlheight);
f.edge2d.thickness = 10; f.edge2d.thickness = 10;
f.mass = 50; f.mass = 50;
//f.phys = 0;
var killbox = World.spawn(gameobjects['polygon2d']); var killbox = World.spawn(gameobjects['polygon2d']);
@ -49,12 +44,11 @@ killbox.polygon2d.points = Geometry.box(lvlwidth,30);
killbox.pos = [0,-lvlheight/2]; killbox.pos = [0,-lvlheight/2];
killbox.polygon2d.sensor = true; killbox.polygon2d.sensor = true;
killbox.register_hit(hit => { killbox.register_hit(hit => {
if (hit.obj.tag === 'ball') { if (hit.obj.tag !== 'ball')
Register.postphys_cbs.push(() => { return;
hit.obj.kill(); hit.obj.kill();
lostlife(); lostlife();
});
}
}, this); }, this);
//Sound.play("start.wav"); //Sound.play("start.wav");