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