Change to ur prototype scheme

This commit is contained in:
John Alanbrook 2023-09-08 06:26:36 +00:00
parent 3b67b08683
commit 22fb3de804
3 changed files with 21 additions and 22 deletions

View file

@ -3,7 +3,7 @@ var score = 0;
var highscore = 0;
var lives = 3;
var brick = World.spawn(gameobjects['brick']);
var brick = World.spawn(prototypes.get_ur('brick'));
var brickbb = brick.char.boundingbox;
var bwidth = brickbb.r - brickbb.l;
var bheight = brickbb.t-brickbb.b;
@ -17,7 +17,7 @@ var lvlheight = 600;
//var frameworld = World
var f = World.spawn(gameobjects['edge2d']);
var f = World.spawn(prototypes.get_ur('edge2d'));
f.edge2d.thickness = 10;
f.edge2d.cpoints = Geometry.box(lvlwidth+f.edge2d.thickness*2,lvlheight);
f.draw = function() {
@ -83,7 +83,7 @@ for (var row = 0; row < rows; row++) {
if (lvl.bricks[row][col] === 0)
continue;
var brick = World.spawn(gameobjects['brick']);
var brick = World.spawn(prototypes.get_ur('brick'));
brick.powerup = function() {
if (Math.random() < 0.1)
spawn_random_powerup(this.pos);
@ -101,23 +101,24 @@ for (var row = 0; row < rows; row++) {
}
var flashtimer = timer.make(function() {
if (gameobjects['brick'].instances.length === 0) {
if (prototypes.get_ur('brick').instances.length === 0) {
flashtimer.kill();
return;
}
var idx = Math.randomint(gameobjects['brick'].instances.length);
gameobjects['brick'].instances[idx].flash();
var idx = Math.randomint(prototypes.get_ur('brick').instances.length);
prototypes.get_ur('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(prototypes.get_ur('paddle'));
paddle.extents = lvlwidth/2 - f.edge2d.thickness;
paddle.pos = [0,-lvlheight/2+paddle.height*4];
paddle.setgrow(3);
paddle.lasership();
Player.players[0].control(paddle);
Gamestate.spawnball = function() {
var bb = World.spawn(gameobjects['ball']);
var bb = World.spawn(prototypes.get_ur('ball'));
bb.pos = bb.pos.add([0,-200]);
bb.velocity = [30,200];
bb.draw_layer = 3;
@ -144,7 +145,7 @@ powerups.catch = mk_pup(Color.Arkanoid.Powerups.green, function() {
});
powerups.slow = mk_pup(Color.Arkanoid.Powerups.orange, function() {
/* Slow all balls */
gameobjects['ball'].instances.forEach(function(x) {
prototypes.get_ur('ball').instances.forEach(function(x) {
x.velocity = x.velocity.scale(0.5);
});
});
@ -152,7 +153,7 @@ 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];
var ball = prototypes.get_ur('ball').instances[0];
if (!ball) return;
ball.instandup();
@ -206,8 +207,8 @@ var last_powerup = {};
function spawn_random_powerup(pos)
{
if (gameobjects['upgrade_drop'].instances.length !== 0) return;
var p = World.spawn(gameobjects['upgrade_drop']);
if (prototypes.get_ur('upgrade_drop').instances.length !== 0) return;
var p = World.spawn(prototypes.get_ur('upgrade_drop'));
p.pos = pos;
var power = select_weighted(powerups.array());
@ -221,7 +222,7 @@ function spawn_random_powerup(pos)
}
function spawn_powerup(pos, fn) {
var p = World.spawn(gameobjects['upgrade_drop']);
var p = World.spawn(prototypes.get_ur('upgrade_drop'));
p.pos = pos;
p.upgrade = fn;
return p;
@ -234,7 +235,7 @@ function multiball(n) {
function lostball()
{
if (gameobjects['ball'].instances.length === 0)
if (prototypes.get_ur('ball').instances.length === 0)
lostlife();
};
@ -254,7 +255,7 @@ function lostlife() {
};
Gamestate.spawnball();
var killbox = World.spawn(gameobjects['polygon2d']);
var killbox = World.spawn(prototypes.get_ur('polygon2d'));
killbox.polygon2d.points = Geometry.box(lvlwidth,30);
killbox.pos = [0,-lvlheight/2];
@ -309,7 +310,7 @@ var gamepawn =
}
function clear_level() {
var bricks = gameobjects['brick'].instances.slice();
var bricks = prototypes.get_ur('brick').instances.slice();
bricks.forEach(function(x) { x.kill(); });
};
@ -320,8 +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(`BRICKS: ${prototypes.get_ur('brick').instances.length}`),
GUI.text_fn(`BALLS IN PLAY: ${prototypes.get_ur('ball').instances.length}`),
GUI.text_fn(`LIVES: ${lives}`),
GUI.text_fn("YARKANOID", {color: [5,120,240,255]}),
@ -343,3 +344,4 @@ let backtomain = function()
Register.gui.unregister(gamegui);
Player.players[0].uncontrol(gamepawn);
}

View file

@ -1,6 +1,2 @@
//var b = prototypes.from_file("ball.js");
//var ball1 = b.make();
//Log.warn(ball1.from);
//var ball2 = ball1.dup({pos:[100,100]});
Window.icon("powerup.png");
World.load("startmenu");

View file

@ -105,6 +105,7 @@ Object.assign(self, {
self.inputs = {};
self.inputs.space = function() {
Log.warn("PADDLE SPACE");
if (this.sticky && this.stickball) {
this.stickball.velocity = this.stored_vel;
this.stickball = {};