Asteroids, switched to 7 point astroid polygon

pull/2983/head
Hugh Barney 2023-08-20 16:15:34 +01:00
parent 2e3ee8cbc3
commit 648cc11fdc
5 changed files with 18 additions and 7 deletions

View File

@ -1,4 +1,5 @@
0.02: Add "ram" keyword to allow 2v06 Espruino builds to cache function that needs to be fast
0.03: Bangle 2 support
0.04: Increase size if ship, asteroids and fonts for better readability
0.04: Increase size of ship, asteroids and fonts for better readability
0.05: improve collision detect for larger ship v astroid
0.06: added, 7 point asteroid ploygon, made ship solid, rather than outline

View File

@ -48,10 +48,9 @@ var lastFrame;
function gameStop() {
running = false;
//g.clear();
g.setFont('Vector', W/7);
g.setFontAlign(0,0);
g.drawString("Game Over!", W/2, H/2);
g.drawString("Game Over", W/2, H/2);
g.flip();
}
@ -116,7 +115,7 @@ function onFrame() {
g.setFont('Vector', 16);
g.drawString(score,W-20,16);
var rs = Math.PI*0.8;
g.drawPoly([
g.fillPoly([
ship.x+Math.cos(ship.r)*SS, ship.y+Math.sin(ship.r)*SS,
ship.x+Math.cos(ship.r+rs)*SL, ship.y+Math.sin(ship.r+rs)*SL,
ship.x+Math.cos(ship.r-rs)*SL, ship.y+Math.sin(ship.r-rs)*SL,
@ -147,7 +146,18 @@ function onFrame() {
ast.forEach(function(a) {
a.x += a.vx*d;
a.y += a.vy*d;
g.drawCircle(a.x, a.y, a.rad);
//g.drawCircle(a.x, a.y, a.rad);
// a 7 point asteroid with rough circle radius of scale 2
g.drawPoly([
a.x , a.y - 1.5 * a.rad,
a.x + a.rad , a.y ,
a.x + a.rad/2 , a.y ,
a.x + a.rad/2 , a.y + a.rad/2 ,
a.x , a.y + a.rad ,
a.x - a.rad , a.y ,
a.x - a.rad , a.y - a.rad
],true);
if (a.x<0) a.x+=W;
if (a.y<0) a.y+=H;
if (a.x>=W) a.x-=W;

View File

@ -1,10 +1,10 @@
{
"id": "astroid",
"name": "Asteroids!",
"version": "0.05",
"version": "0.06",
"description": "Retro asteroids game",
"icon": "asteroids.png",
"screenshots": [{"url":"screenshot_asteroids.png"}],
"screenshots": [{"url":"screenshot.png"}],
"tags": "game",
"supports": ["BANGLEJS","BANGLEJS2"],
"allow_emulator": true,

BIN
apps/astroid/screenshot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB