85 lines
1.6 KiB
JavaScript
85 lines
1.6 KiB
JavaScript
var lvlwidth = 300;
|
|
var lvlheight = 500;
|
|
|
|
Debug.draw_phys(true);
|
|
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';
|
|
}
|
|
|
|
function spawn_powerup(pos, fn) {
|
|
var p = World.spawn(gameobjects['upgrade_drop']);
|
|
|
|
p.pos = pos;
|
|
p.upgrade = fn;
|
|
}
|
|
|
|
spawn_powerup([0,300], () => {
|
|
for (var i = 0; i < 10; i++)
|
|
spawnball();
|
|
});
|
|
|
|
function lostlife() {
|
|
lives--;
|
|
spawnball();
|
|
}
|
|
|
|
spawnball();
|
|
|
|
|
|
var f = World.spawn(gameobjects['edge2d']);
|
|
f.edge2d.cpoints = Geometry.box(lvlwidth,lvlheight);
|
|
f.edge2d.thickness = 10;
|
|
f.mass = 50;
|
|
|
|
var killbox = World.spawn(gameobjects['polygon2d']);
|
|
|
|
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')
|
|
return;
|
|
|
|
hit.obj.kill();
|
|
lostlife();
|
|
}, this);
|
|
|
|
//Sound.play("start.wav");
|
|
|
|
var score = 0;
|
|
var highscore = 0;
|
|
var lives = 3;
|
|
|
|
function gamegui() {
|
|
var xpos = 1000;
|
|
|
|
GUI.text("SCORE", [xpos,500],1,Color.red);
|
|
GUI.text(`${score}`, [xpos,480],1);
|
|
|
|
GUI.text("HIGH SCORE", [xpos,450],1, Color.red);
|
|
GUI.text(`${highscore}`, [xpos,430],1);
|
|
|
|
GUI.text(`LIVES: ${lives}`, [xpos, 400], 1, Color.white);
|
|
|
|
GUI.text("YARKANOID", [xpos,300], 1,[5,120,240]);
|
|
|
|
GUI.text("ODPLOT GAMES", [xpos,250],1);
|
|
GUI.text("[C] 2023", [xpos,230]);
|
|
}
|
|
|
|
function startmenu() {
|
|
GUI.text("Press ENTER to start", Window.dimensions.scale(0.5));
|
|
GUI.text("Press ESCAPE to exit", Window.dimensions.scale(0.5).add([0,-100]));
|
|
}
|
|
|
|
register_gui(gamegui);
|
|
|
|
register_gui(startmenu);
|