mirror of https://github.com/espruino/BangleApps
commit
c521dad7a3
13
apps.json
13
apps.json
|
@ -973,5 +973,18 @@
|
|||
"storage": [
|
||||
{"name":"widhwt.wid.js","url":"widget.js"}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "balltastic",
|
||||
"name": "Balltastic",
|
||||
"icon": "app.png",
|
||||
"version": "0.01",
|
||||
"description": "Simple but fun ball eats dots game.",
|
||||
"tags": "game,fun",
|
||||
"type": "app",
|
||||
"storage": [
|
||||
{"name":"balltastic.app.js","url":"app.js"},
|
||||
{"name":"balltastic.img","url":"app-icon.js","evaluate":true}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
0.01: Initial version of Balltastic released! Happy!
|
|
@ -0,0 +1 @@
|
|||
require("heatshrink").decompress(atob("mEwwkEogAIkUzmciBpIVIkYWBAAUyCx0hiIXFAAMkCxhUBC4fzDAYWLiAXFAAP//5KKoMRC4UTC4k/DAPzJJERiKcCC5H/GA4uBWwp6DC4YwHCwMBDI0SMAYwHoIWBiXxdIwYCMJCjBiM/C46VDC4M/GAkRgMf//ySAQAEgKrDC4lBgMCHIQXHSwxICIwIuBAAIXIGAYABiQXBkEBTYcgC473FkQXBiETTQZ4IgECC4cholCiJGDMAIXIWgIXCmMkC4JGDJBbEDC4UACwn/mAtGSYsxilCgIXFSAqDBkMRiIFBkcxiUiC4sxXowIBC4QGBkIXBiJ2EFwsDBIPyC4ILBgMRiUyiCmJgSCC+YXDgAXDR4YuEcAn/MAIXEmcgBoXyFwjIEMAQXFkIOCUgoXF+J3CC4cxBwR1IQQx3BkUzmUSBQKkFC5IuBkVDJAJeGRwLhHFwUkC4Mxl6lFC48gFwYXCmcTOwomBC4swYIMikU0C4UxkJ3FC40xFoIXCogXBmaxDC5MyCwUiogXDmIXTJASSBC4kRU4oXDkgXFmQwDNwIWEBoIXFJAYKBZggWFC4YWCC4g7BkIWBkYWBBYYXCkYXDJAYjDkQUEEYZGEGA4XIIwwwGDAQuOGAomCFo4uGGARoBE4ZOGFxAABBwgAICxAABCyxJBGJJFJJRgVNPggsMA="))
|
|
@ -0,0 +1,186 @@
|
|||
Bangle.setLCDBrightness(1);
|
||||
Bangle.setLCDMode("doublebuffered");
|
||||
|
||||
let points = 0;
|
||||
let level = 1;
|
||||
let levelSpeedStart = 0.8;
|
||||
let nextLevelPoints = 20;
|
||||
let levelSpeedFactor = 0.2;
|
||||
let counterWidth = 10;
|
||||
let gWidth = g.getWidth() - counterWidth;
|
||||
let gHeight = g.getHeight();
|
||||
let counter = 160;
|
||||
let counterMax = 160;
|
||||
let ballDims = 20;
|
||||
let ballx = g.getWidth() / 2 - ballDims;
|
||||
let bally = g.getHeight() / 2 - ballDims;
|
||||
let dotx = g.getWidth() / 2;
|
||||
let doty = g.getWidth() / 2;
|
||||
let ballBuzzTime = 5;
|
||||
let ballSpeedFactor = 40;
|
||||
let redrawspeed = 5;
|
||||
let dotwidth = 5;
|
||||
let running = false;
|
||||
let drawInterval;
|
||||
let xBuzzed = false;
|
||||
let yBuzzed = false;
|
||||
|
||||
let BALL = require("heatshrink").decompress(
|
||||
atob(
|
||||
"ikUyAROvkQ3v4405AIYHBGq9KpMhktz1/W7feAJAtBEZ9jhkhs0ZgkQ8lKxW+jAdB516627E4X8AIPWzelmolKlpJBjMFEYIpC4kQ0YBBqWKynTFYPe7gpE3ec6gnHkNFrXL7372u2E4WjhGCAIliqWrUIPeKoIpB7h9HoUoqWq999///FIJ3BhGDEIIBBgFBAoWCoUI3vY62aQIW7ymSJooLBEoIADwkQEYVhEoInEGIOjR4O1y/OrIrBUYdr198iH/74nF88cE4gpCA4MY8k59CzBAINrx2164nBtduufPWYIlF++/xkxNoMAAIJPBoSdB52a30ZkNGE4IvBoUpwkxLIOMyWEmAmE7+MqKbEsLLBH4P3zw1BAYJFBFIMY8sQ4cx44nB0tVHYITBEoO967lDgDDC1tVQ4QBD37xBjMmJ4I3BE4IxBPoOMuSrBHYL1BJYbrDvfPLoYBD889jMlEoMhkpJBwkRE4O+jB7B405LoJPEYYUx0xPG7/3vxvBmOnrXsdIOc6jxBE4JfBvfwHIafDFoMRgh3H99+zsUDIOMqWU2YlBAAO1/AnBToN76EhgpTBFYKPBGIIhBEovOrWliuc2YlBE4oABE4etu2UyVrpqJBMoKvBEIPnjvWze97ATBE4YPBEopRC64BC27nBzn0znTAIOlimtq21y4BCEoM1HYOMqIVBE44AB0tVCYIBEigVBE4U1GYIFBymywkwEoJzHABIRBMIIXBWoIDCqOEmOEiABCmIjPAA51BFoVSEoUwAIIZNA"
|
||||
)
|
||||
);
|
||||
|
||||
function reset() {
|
||||
g.clear();
|
||||
level = 1;
|
||||
points = 0;
|
||||
ballx = g.getWidth() / 2 - ballDims;
|
||||
bally = g.getHeight() / 2 - ballDims;
|
||||
counter = counterMax;
|
||||
createRandomDot();
|
||||
drawInterval = setInterval(play, redrawspeed);
|
||||
running = true;
|
||||
}
|
||||
|
||||
function collide() {
|
||||
try {
|
||||
Bangle.buzz(ballBuzzTime, 0.8);
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
function createRandomDot() {
|
||||
dotx = Math.floor(
|
||||
Math.random() * Math.floor(gWidth - dotwidth / 2) + dotwidth / 2
|
||||
);
|
||||
doty = Math.floor(
|
||||
Math.random() * Math.floor(gHeight - dotwidth / 2) + dotwidth / 2
|
||||
);
|
||||
}
|
||||
|
||||
function checkIfDotEaten() {
|
||||
if (
|
||||
ballx + ballDims > dotx &&
|
||||
ballx <= dotx + dotwidth &&
|
||||
bally + ballDims > doty &&
|
||||
bally <= doty + dotwidth
|
||||
) {
|
||||
collide();
|
||||
createRandomDot();
|
||||
counter = counterMax;
|
||||
points++;
|
||||
|
||||
if (points % nextLevelPoints == 0) {
|
||||
level++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function drawLevelText() {
|
||||
g.setColor("#26b6c7");
|
||||
g.setFontAlign(0, 0);
|
||||
g.setFont("4x6", 5);
|
||||
g.drawString("Level " + level, 120, 80);
|
||||
}
|
||||
|
||||
function draw() {
|
||||
//bg
|
||||
g.setColor("#71c6cf");
|
||||
g.fillRect(0, 0, g.getWidth(), g.getHeight());
|
||||
|
||||
//counter
|
||||
drawCounter();
|
||||
|
||||
//draw level
|
||||
drawLevelText();
|
||||
|
||||
//dot
|
||||
g.setColor("#ff0000");
|
||||
g.fillCircle(dotx, doty, dotwidth);
|
||||
|
||||
//ball
|
||||
g.drawImage(BALL, ballx, bally);
|
||||
|
||||
g.flip();
|
||||
}
|
||||
|
||||
function drawCounter() {
|
||||
g.setColor("#000000");
|
||||
g.fillRect(g.getWidth() - counterWidth, 0, g.getWidth(), gHeight);
|
||||
|
||||
if(counter < 40 ) g.setColor("#fc0303");
|
||||
else if (counter < 80 ) g.setColor("#fc9803");
|
||||
else g.setColor("#0318fc");
|
||||
|
||||
g.fillRect(
|
||||
g.getWidth() - counterWidth,
|
||||
gHeight,
|
||||
g.getWidth(),
|
||||
gHeight - counter
|
||||
);
|
||||
}
|
||||
|
||||
function checkCollision() {
|
||||
if (ballx < 0) {
|
||||
ballx = 0;
|
||||
if (!xBuzzed) collide();
|
||||
xBuzzed = true;
|
||||
} else if (ballx > gWidth - ballDims) {
|
||||
ballx = gWidth - ballDims;
|
||||
if (!xBuzzed) collide();
|
||||
xBuzzed = true;
|
||||
} else {
|
||||
xBuzzed = false;
|
||||
}
|
||||
|
||||
if (bally < 0) {
|
||||
bally = 0;
|
||||
if (!yBuzzed) collide();
|
||||
yBuzzed = true;
|
||||
} else if (bally > gHeight - ballDims) {
|
||||
bally = gHeight - ballDims;
|
||||
if (!yBuzzed) collide();
|
||||
yBuzzed = true;
|
||||
} else {
|
||||
yBuzzed = false;
|
||||
}
|
||||
}
|
||||
|
||||
function count() {
|
||||
counter -= levelSpeedStart + level * levelSpeedFactor;
|
||||
if (counter <= 0) {
|
||||
running = false;
|
||||
clearInterval(drawInterval);
|
||||
setTimeout(function(){ E.showMessage("Press Button 1\nto restart.", "Gameover!");},50);
|
||||
}
|
||||
}
|
||||
|
||||
function accel(values) {
|
||||
ballx -= values.x * ballSpeedFactor;
|
||||
bally -= values.y * ballSpeedFactor;
|
||||
}
|
||||
|
||||
function play() {
|
||||
if (running) {
|
||||
accel(Bangle.getAccel());
|
||||
checkCollision();
|
||||
checkIfDotEaten();
|
||||
count();
|
||||
draw();
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
reset();
|
||||
drawInterval = setInterval(play, redrawspeed);
|
||||
|
||||
setWatch(
|
||||
() => {
|
||||
if(!running) reset();
|
||||
},
|
||||
BTN1,
|
||||
{ repeat: true }
|
||||
);
|
||||
|
||||
running = true;
|
||||
}, 10);
|
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
Loading…
Reference in New Issue