flappybat/game.js
John Alanbrook 9f49fc4cb8 initial add
2024-03-03 17:45:08 -06:00

61 lines
1.1 KiB
JavaScript

physics.gravity.strength = 1500;
physics.gravity.mask = [true];
var bird = world.spawn(ur.bird);
bird.pos = [0,0];
world.spawn(ur.watcher);
world.spawn(ur.gui);
var game = {};
var ready;
var savefile = json.decode(io.slurp("@save.json"));
if (savefile) game.save = savefile;
else
game.save = {high:0};
game.prepare = function()
{
game.score = 0;
game.time = 3;
ready = world.spawn(ur.getready);
ready.pos = [-ready.width()/2, -ready.height()/2];
player[0].control(ready);
bird.hide();
bird.pos = [0,-50];
bird.velocity = [0,0];
bird.warp_layer = [false];
}
game.start = function()
{
ready.kill();
bird.warp_layer = [true];
player[0].control(bird);
bird.show();
bird.inputs.space.call(bird);
bird.pulse([100,0]);
bird.circle2d.enabled = true;
}
game.gameover = function()
{
if (game.score > game.save.high) {
game.save.high = game.score;
io.slurpwrite("@save.json", json.encode(game.save));
}
player[0].control(world.spawn(ur.endgui));
}
game.inputs = {};
game.inputs.space = function()
{
game.prepare();
player[0].uncontrol(game);
}
game.prepare();
return {game};