arkanoid powerups
This commit is contained in:
parent
c83de00f1c
commit
f02b76d301
96
breakout.js
96
breakout.js
|
@ -1,10 +1,9 @@
|
||||||
/* Arkanoid level is 10x10 */
|
/* Arkanoid level is 10x10 */
|
||||||
|
|
||||||
var score = 0;
|
var score = 0;
|
||||||
var highscore = 0;
|
var highscore = 0;
|
||||||
var lives = 3;
|
var lives = 3;
|
||||||
var balls = 0;
|
|
||||||
|
|
||||||
|
Log.warn(gameobjects['brick'].boundingbox);
|
||||||
var brick = World.spawn(gameobjects['brick']);
|
var brick = World.spawn(gameobjects['brick']);
|
||||||
var brickbb = brick.char.boundingbox;
|
var brickbb = brick.char.boundingbox;
|
||||||
var bwidth = brickbb.r - brickbb.l;
|
var bwidth = brickbb.r - brickbb.l;
|
||||||
|
@ -17,10 +16,6 @@ var cols = 13;
|
||||||
var lvlwidth = bwidth*cols;
|
var lvlwidth = bwidth*cols;
|
||||||
var lvlheight = 600;
|
var lvlheight = 600;
|
||||||
|
|
||||||
let bricks = 0;
|
|
||||||
let allbricks = [];
|
|
||||||
|
|
||||||
|
|
||||||
//var frameworld = World
|
//var frameworld = World
|
||||||
|
|
||||||
var f = World.spawn(gameobjects['edge2d']);
|
var f = World.spawn(gameobjects['edge2d']);
|
||||||
|
@ -32,8 +27,6 @@ f.draw = function() {
|
||||||
|
|
||||||
register_draw(f.draw,f);
|
register_draw(f.draw,f);
|
||||||
|
|
||||||
Debug.draw_phys(true);
|
|
||||||
|
|
||||||
var fitbricks = Math.floor(lvlwidth/bwidth);
|
var fitbricks = Math.floor(lvlwidth/bwidth);
|
||||||
|
|
||||||
var wingame = function() {
|
var wingame = function() {
|
||||||
|
@ -46,13 +39,6 @@ var wingame = function() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var killbrick = function() {
|
|
||||||
bricks--;
|
|
||||||
|
|
||||||
if (bricks <= 0)
|
|
||||||
wingame();
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Spawn bricks */
|
/* Spawn bricks */
|
||||||
if (!IO.exists('lvl1.json')) {
|
if (!IO.exists('lvl1.json')) {
|
||||||
var lvl1 = {};
|
var lvl1 = {};
|
||||||
|
@ -91,7 +77,7 @@ Color.Arkanoid.Powerups = {
|
||||||
gray: [143,143,143] /* 1up */
|
gray: [143,143,143] /* 1up */
|
||||||
};
|
};
|
||||||
|
|
||||||
var lvl = JSON.parse(IO.slurp("lvl1.json"));
|
var lvl = JSON.parse(IO.slurp("lvlsparse.json"));
|
||||||
|
|
||||||
for (var row = 0; row < rows; row++) {
|
for (var row = 0; row < rows; row++) {
|
||||||
for (var col = 0; col < cols; col++) {
|
for (var col = 0; col < cols; col++) {
|
||||||
|
@ -99,16 +85,14 @@ for (var row = 0; row < rows; row++) {
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var brick = World.spawn(gameobjects['brick']);
|
var brick = World.spawn(gameobjects['brick']);
|
||||||
allbricks.push(brick);
|
|
||||||
brick.powerup = function() {
|
brick.powerup = function() {
|
||||||
if (Math.random() < 0.1)
|
if (Math.random() < 0.1)
|
||||||
spawn_random_powerup(this.pos);
|
spawn_random_powerup(this.pos);
|
||||||
|
|
||||||
killbrick();
|
if (this.instances === 1)
|
||||||
|
wingame();
|
||||||
};
|
};
|
||||||
|
|
||||||
bricks++;
|
|
||||||
|
|
||||||
// brick.char.color = bcolor;
|
// brick.char.color = bcolor;
|
||||||
var startrow = lvlheight/2-bheight*2; // one brick gap between top and brick start
|
var startrow = lvlheight/2-bheight*2; // one brick gap between top and brick start
|
||||||
var x = -(cols/2) * bwidth;
|
var x = -(cols/2) * bwidth;
|
||||||
|
@ -117,21 +101,28 @@ for (var row = 0; row < rows; row++) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var flashtimer = timer.make(function() {
|
||||||
|
if (gameobjects['brick'].instances.length === 0) {
|
||||||
|
flashtimer.kill();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var idx = Math.randomint(gameobjects['brick'].instances.length);
|
||||||
|
gameobjects['brick'].instances[idx].flash();
|
||||||
|
flashtimer.time = Math.random_range(1,3);
|
||||||
|
}, Math.random_range(1,3));
|
||||||
|
|
||||||
var paddle = World.spawn(gameobjects['paddle']);
|
var paddle = World.spawn(gameobjects['paddle']);
|
||||||
paddle.extents = lvlwidth/2 - f.edge2d.thickness;
|
paddle.extents = lvlwidth/2 - f.edge2d.thickness;
|
||||||
|
paddle.lasership();
|
||||||
paddle.pos = [0,-lvlheight/2+paddle.height*4];
|
paddle.pos = [0,-lvlheight/2+paddle.height*4];
|
||||||
paddle.setgrow(1);
|
paddle.setgrow(3);
|
||||||
|
|
||||||
let allballs = [];
|
|
||||||
|
|
||||||
Gamestate.spawnball = function() {
|
Gamestate.spawnball = function() {
|
||||||
var bb = World.spawn(gameobjects['ball']);
|
var bb = World.spawn(gameobjects['ball']);
|
||||||
bb.pos = bb.pos.add([0,-200]);
|
bb.pos = bb.pos.add([0,-200]);
|
||||||
bb.velocity = [30,300];
|
bb.velocity = [30,200];
|
||||||
bb.draw_layer = 3;
|
bb.draw_layer = 3;
|
||||||
bb.tag = 'ball';
|
bb.tag = 'ball';
|
||||||
balls++;
|
|
||||||
allballs.push(bb);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var powerups = {};
|
var powerups = {};
|
||||||
|
@ -145,13 +136,32 @@ function mk_pup(color, fn, weight) {
|
||||||
return o;
|
return o;
|
||||||
};
|
};
|
||||||
|
|
||||||
powerups.laser = mk_pup(Color.Arkanoid.Powerups.red, null);
|
powerups.laser = mk_pup(Color.Arkanoid.Powerups.red, function() {
|
||||||
powerups.enlarge = mk_pup(Color.Arkanoid.Powerups.blue, null);
|
paddle.lasership();
|
||||||
powerups.catch = mk_pup(Color.Arkanoid.Powerups.green, null);
|
});
|
||||||
powerups.slow = mk_pup(Color.Arkanoid.Powerups.orange, null);
|
powerups.enlarge = mk_pup(Color.Arkanoid.Powerups.blue, function() { paddle.grow(); });
|
||||||
powerups.break = mk_pup(Color.Arkanoid.Powerups.purple, null, 0.5);
|
powerups.catch = mk_pup(Color.Arkanoid.Powerups.green, function() {
|
||||||
powerups.disruption = mk_pup(Color.Arkanoid.Powerups.cyan, null);
|
paddle.sticky = true;
|
||||||
powerups.player = mk_pup(Color.Arkanoid.Powerups.gray, null, 0.5);
|
});
|
||||||
|
powerups.slow = mk_pup(Color.Arkanoid.Powerups.orange, function() {
|
||||||
|
/* Slow all balls */
|
||||||
|
gameobjects['ball'].instances.forEach(function(x) {
|
||||||
|
x.velocity = x.velocity.scale(0.5);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
powerups.break = mk_pup(Color.Arkanoid.Powerups.purple, function() {
|
||||||
|
clear_level();
|
||||||
|
}, 0.5);
|
||||||
|
powerups.disruption = mk_pup(Color.Arkanoid.Powerups.cyan, function() {
|
||||||
|
var ball = gameobjects['ball'].instances[0];
|
||||||
|
if (!ball) return;
|
||||||
|
|
||||||
|
ball.instandup();
|
||||||
|
ball.instandup();
|
||||||
|
});
|
||||||
|
powerups.player = mk_pup(Color.Arkanoid.Powerups.gray, function() {
|
||||||
|
lives += 1;
|
||||||
|
}, 0.5);
|
||||||
|
|
||||||
function select_weighted(objs)
|
function select_weighted(objs)
|
||||||
{
|
{
|
||||||
|
@ -197,12 +207,15 @@ var last_powerup = {};
|
||||||
|
|
||||||
function spawn_random_powerup(pos)
|
function spawn_random_powerup(pos)
|
||||||
{
|
{
|
||||||
|
if (gameobjects['upgrade_drop'].instances.length !== 0) return;
|
||||||
var p = World.spawn(gameobjects['upgrade_drop']);
|
var p = World.spawn(gameobjects['upgrade_drop']);
|
||||||
p.pos = pos;
|
p.pos = pos;
|
||||||
|
|
||||||
var power = select_weighted(powerups.array());
|
var power = select_weighted(powerups.array());
|
||||||
if (last_powerup === power)
|
if (last_powerup === power)
|
||||||
power = powerups.disruption;
|
power = powerups.disruption;
|
||||||
|
|
||||||
|
last_powerup = power;
|
||||||
|
|
||||||
p.color = power.color;
|
p.color = power.color;
|
||||||
p.upgrade = power.fn;
|
p.upgrade = power.fn;
|
||||||
|
@ -222,8 +235,7 @@ function multiball(n) {
|
||||||
|
|
||||||
function lostball()
|
function lostball()
|
||||||
{
|
{
|
||||||
balls--;
|
if (gameobjects['ball'].instances.length === 0)
|
||||||
if (balls === 0)
|
|
||||||
lostlife();
|
lostlife();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -293,11 +305,15 @@ var gamepawn =
|
||||||
},
|
},
|
||||||
|
|
||||||
input_o_pressed() {
|
input_o_pressed() {
|
||||||
/* Get all bricks and kill */
|
clear_level();
|
||||||
allbricks.forEach(x => x.kill());
|
},
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function clear_level() {
|
||||||
|
var bricks = gameobjects['brick'].instances.slice();
|
||||||
|
bricks.forEach(function(x) { x.kill(); });
|
||||||
|
};
|
||||||
|
|
||||||
function gamegui() {
|
function gamegui() {
|
||||||
GUI.column({
|
GUI.column({
|
||||||
items: [
|
items: [
|
||||||
|
@ -305,6 +321,8 @@ function gamegui() {
|
||||||
GUI.text_fn(`${score}`),
|
GUI.text_fn(`${score}`),
|
||||||
GUI.text_fn("HIGH SCORE", {color: Color.red}),
|
GUI.text_fn("HIGH SCORE", {color: Color.red}),
|
||||||
GUI.text_fn(`${highscore}`),
|
GUI.text_fn(`${highscore}`),
|
||||||
|
GUI.text_fn(`BRICKS: ${gameobjects['brick'].instances.length}`),
|
||||||
|
GUI.text_fn(`BALLS IN PLAY: ${gameobjects['ball'].instances.length}`),
|
||||||
|
|
||||||
GUI.text_fn(`LIVES: ${lives}`),
|
GUI.text_fn(`LIVES: ${lives}`),
|
||||||
GUI.text_fn("YARKANOID", {color: [5,120,240,255]}),
|
GUI.text_fn("YARKANOID", {color: [5,120,240,255]}),
|
||||||
|
@ -312,7 +330,7 @@ function gamegui() {
|
||||||
GUI.text_fn("ODPLOT GAMES"),
|
GUI.text_fn("ODPLOT GAMES"),
|
||||||
GUI.text_fn("[C] 2023"),
|
GUI.text_fn("[C] 2023"),
|
||||||
]
|
]
|
||||||
}).draw(Window.dimensions.scale([0.9,0.8]));
|
}).draw(Window.dimensions.scale([0.8,0.8]));
|
||||||
}
|
}
|
||||||
|
|
||||||
register_gui(gamegui);
|
register_gui(gamegui);
|
||||||
|
|
66
config.js
66
config.js
|
@ -10,19 +10,6 @@ gameobject.clone("ball", {
|
||||||
collide(hit) {
|
collide(hit) {
|
||||||
Sound.play("bump.wav");
|
Sound.play("bump.wav");
|
||||||
},
|
},
|
||||||
|
|
||||||
start() {
|
|
||||||
this.velocity = [-10,-300];
|
|
||||||
Player.players[0].control(this);
|
|
||||||
},
|
|
||||||
|
|
||||||
input_left_down() {
|
|
||||||
/* Slow down */
|
|
||||||
},
|
|
||||||
|
|
||||||
input_right_down() {
|
|
||||||
/* Speed up */
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Color.Gameboy = {
|
Color.Gameboy = {
|
||||||
|
@ -47,14 +34,11 @@ gameobject.clone("brick", {
|
||||||
flash:Resources.load("brick.png"),
|
flash:Resources.load("brick.png"),
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
points: 50,
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
this.char.stop();
|
this.char.stop();
|
||||||
this.flash();
|
this.flash();
|
||||||
this.timer = timer.make(() => {
|
|
||||||
this.flash();
|
|
||||||
this.timer.time = Math.random_range(2,10);
|
|
||||||
}, Math.random_range(2,10));
|
|
||||||
|
|
||||||
this.char.color = Color.Rainbow.red;
|
this.char.color = Color.Rainbow.red;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -67,7 +51,6 @@ gameobject.clone("brick", {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this.powerup?.();
|
this.powerup?.();
|
||||||
this.timer.kill();
|
|
||||||
this.kill();
|
this.kill();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -110,6 +93,9 @@ var paddle = gameobject.clone("paddle", {
|
||||||
fpos.x = Math.clamp(fpos.x,-this.max_x,this.max_x);
|
fpos.x = Math.clamp(fpos.x,-this.max_x,this.max_x);
|
||||||
this.pos = fpos;
|
this.pos = fpos;
|
||||||
this.frame_vel = [0,0];
|
this.frame_vel = [0,0];
|
||||||
|
|
||||||
|
if (this.stickball)
|
||||||
|
this.stickball.pos = this.pos.add(this.stickpos);
|
||||||
},
|
},
|
||||||
|
|
||||||
physupdate(dt) { this.velocity = [0,0]; },
|
physupdate(dt) { this.velocity = [0,0]; },
|
||||||
|
@ -124,9 +110,6 @@ var paddle = gameobject.clone("paddle", {
|
||||||
this.length = this.lengths[0];
|
this.length = this.lengths[0];
|
||||||
},
|
},
|
||||||
|
|
||||||
input_p_pressed() { this.grow(); },
|
|
||||||
input_l_pressed() { Gamestate.spawnball(); },
|
|
||||||
|
|
||||||
grow() {
|
grow() {
|
||||||
this.setgrow(this.growlvl + 1);
|
this.setgrow(this.growlvl + 1);
|
||||||
},
|
},
|
||||||
|
@ -143,13 +126,48 @@ var paddle = gameobject.clone("paddle", {
|
||||||
this.max_x = this.extents - (d.x*this.scale)/2;
|
this.max_x = this.extents - (d.x*this.scale)/2;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
lasership() {
|
||||||
|
this.laser = true;
|
||||||
|
},
|
||||||
|
|
||||||
|
shoot() {
|
||||||
|
Log.warn("SHOOTING MISSILES");
|
||||||
|
},
|
||||||
|
|
||||||
|
sticky: false,
|
||||||
|
stored_vel: [0,0],
|
||||||
|
stickball: {},
|
||||||
|
stickpos: [0,0],
|
||||||
|
|
||||||
|
input_space_pressed() {
|
||||||
|
if (this.sticky && this.stickball) {
|
||||||
|
this.stickball.velocity = this.stored_vel;
|
||||||
|
this.stickball = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.laser) {
|
||||||
|
this.shoot();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
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;
|
var hitangle = xdiff/this.length - 0.5;
|
||||||
|
var speed = Vector.length(hit.obj.velocity);
|
||||||
|
hit.obj.velocity = [Math.cos(hitangle)*speed, Math.sin(hitangle)*speed];
|
||||||
|
hit.obj.velocity = hit.obj.velocity.scale(-1);
|
||||||
var oldvel = hit.obj.velocity;
|
var oldvel = hit.obj.velocity;
|
||||||
var scaler = Math.max(Math.abs(xdiff)/30, 1.05);
|
var scaler = Math.max(Math.abs(xdiff)/30, 1.01);
|
||||||
hit.obj.velocity = hit.obj.velocity.scale(scaler);
|
hit.obj.velocity = hit.obj.velocity.scale(scaler);
|
||||||
|
|
||||||
|
if (this.sticky) {
|
||||||
|
this.stored_vel = hit.obj.velocity;
|
||||||
|
hit.obj.velocity = [0,0];
|
||||||
|
this.stickball = hit.obj;
|
||||||
|
this.stickpos = hit.obj.pos.sub(this.pos);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
],
|
],
|
||||||
"path": "ball.png"
|
"path": "ball.png"
|
||||||
},
|
},
|
||||||
"scale": 2.919193983078003,
|
"scale": 1.5,
|
||||||
"from": "gameobject"
|
"from": "gameobject"
|
||||||
},
|
},
|
||||||
"paddle": {
|
"paddle": {
|
||||||
|
@ -60,7 +60,7 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"from": "gameobject",
|
"from": "gameobject",
|
||||||
"scale": 2.9100000858306885
|
"scale": 1.5
|
||||||
},
|
},
|
||||||
"breakoutfield": {
|
"breakoutfield": {
|
||||||
"from": "edge2d",
|
"from": "edge2d",
|
||||||
|
|
Loading…
Reference in a new issue