Merge pull request #2983 from hughbarney/master
Asteroids - increased ship, asteroids and font sizemaster
commit
0b96c2f063
|
|
@ -1,2 +1,5 @@
|
||||||
0.02: Add "ram" keyword to allow 2v06 Espruino builds to cache function that needs to be fast
|
0.02: Add "ram" keyword to allow 2v06 Espruino builds to cache function that needs to be fast
|
||||||
0.03: Bangle 2 support
|
0.03: Bangle 2 support
|
||||||
|
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
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,22 @@ if (process.env.HWVERSION==2) {
|
||||||
}
|
}
|
||||||
var W = g.getWidth();
|
var W = g.getWidth();
|
||||||
var H = g.getHeight();
|
var H = g.getHeight();
|
||||||
|
var SS = W/11; // ship back length
|
||||||
|
var SL = W/15; // ship side length
|
||||||
|
var AS = W/18; // asteroid radius
|
||||||
|
// radius of ship, assumed a circle inside equilateral traingle of side SS
|
||||||
|
// r = a / root 3 where a is length of equilateral triangle
|
||||||
|
var SR = SS / Math.sqrt(3);
|
||||||
|
var AST = [ // asteroid polygon as X/Y pairs
|
||||||
|
0 ,-1.5,
|
||||||
|
1 , 0,
|
||||||
|
0.5, 0,
|
||||||
|
0.5, 0.5,
|
||||||
|
0 , 1,
|
||||||
|
-1 , 0,
|
||||||
|
-1 , -1
|
||||||
|
];
|
||||||
|
|
||||||
g.clear().setFontAlign(0,-1);
|
g.clear().setFontAlign(0,-1);
|
||||||
|
|
||||||
function newAst(x,y) {
|
function newAst(x,y) {
|
||||||
|
|
@ -25,7 +41,7 @@ function newAst(x,y) {
|
||||||
x:x,y:y,
|
x:x,y:y,
|
||||||
vx:Math.random()-0.5,
|
vx:Math.random()-0.5,
|
||||||
vy:Math.random()-0.5,
|
vy:Math.random()-0.5,
|
||||||
rad:3+Math.random()*5
|
rad:3+Math.random()*AS
|
||||||
};
|
};
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
@ -41,8 +57,9 @@ var lastFrame;
|
||||||
|
|
||||||
function gameStop() {
|
function gameStop() {
|
||||||
running = false;
|
running = false;
|
||||||
g.clear();
|
g.setFont('Vector', W/7);
|
||||||
g.drawString("Game Over!",120,(H-6)/2);
|
g.setFontAlign(0,0);
|
||||||
|
g.drawString("Game Over", W/2, H/2);
|
||||||
g.flip();
|
g.flip();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -104,12 +121,13 @@ function onFrame() {
|
||||||
}
|
}
|
||||||
|
|
||||||
g.clear();
|
g.clear();
|
||||||
g.drawString(score,W-20,0);
|
g.setFont('Vector', 16);
|
||||||
|
g.drawString(score,W-20,16);
|
||||||
var rs = Math.PI*0.8;
|
var rs = Math.PI*0.8;
|
||||||
g.drawPoly([
|
g.fillPoly([
|
||||||
ship.x+Math.cos(ship.r)*4, ship.y+Math.sin(ship.r)*4,
|
ship.x+Math.cos(ship.r)*SS, ship.y+Math.sin(ship.r)*SS,
|
||||||
ship.x+Math.cos(ship.r+rs)*3, ship.y+Math.sin(ship.r+rs)*3,
|
ship.x+Math.cos(ship.r+rs)*SL, ship.y+Math.sin(ship.r+rs)*SL,
|
||||||
ship.x+Math.cos(ship.r-rs)*3, ship.y+Math.sin(ship.r-rs)*3,
|
ship.x+Math.cos(ship.r-rs)*SL, ship.y+Math.sin(ship.r-rs)*SL,
|
||||||
],true);
|
],true);
|
||||||
var na = [];
|
var na = [];
|
||||||
ammo.forEach(function(a) {
|
ammo.forEach(function(a) {
|
||||||
|
|
@ -137,7 +155,10 @@ function onFrame() {
|
||||||
ast.forEach(function(a) {
|
ast.forEach(function(a) {
|
||||||
a.x += a.vx*d;
|
a.x += a.vx*d;
|
||||||
a.y += a.vy*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(g.transformVertices(AST,{x:a.x,y:a.y,scale:a.rad,rotate:t}),true);
|
||||||
|
|
||||||
if (a.x<0) a.x+=W;
|
if (a.x<0) a.x+=W;
|
||||||
if (a.y<0) a.y+=H;
|
if (a.y<0) a.y+=H;
|
||||||
if (a.x>=W) a.x-=W;
|
if (a.x>=W) a.x-=W;
|
||||||
|
|
@ -165,7 +186,7 @@ function onFrame() {
|
||||||
var dx = a.x-ship.x;
|
var dx = a.x-ship.x;
|
||||||
var dy = a.y-ship.y;
|
var dy = a.y-ship.y;
|
||||||
var d = Math.sqrt(dx*dx+dy*dy);
|
var d = Math.sqrt(dx*dx+dy*dy);
|
||||||
if (d < a.rad) crashed = true;
|
if (d < a.rad + SR) crashed = true;
|
||||||
});
|
});
|
||||||
ast=na;
|
ast=na;
|
||||||
if (!ast.length) {
|
if (!ast.length) {
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
{
|
{
|
||||||
"id": "astroid",
|
"id": "astroid",
|
||||||
"name": "Asteroids!",
|
"name": "Asteroids!",
|
||||||
"version": "0.03",
|
"version": "0.06",
|
||||||
"description": "Retro asteroids game",
|
"description": "Retro asteroids game",
|
||||||
"icon": "asteroids.png",
|
"icon": "asteroids.png",
|
||||||
"screenshots": [{"url":"screenshot_asteroids.png"}],
|
"screenshots": [{"url":"screenshot.png"}],
|
||||||
"tags": "game",
|
"tags": "game",
|
||||||
"supports": ["BANGLEJS","BANGLEJS2"],
|
"supports": ["BANGLEJS","BANGLEJS2"],
|
||||||
"allow_emulator": true,
|
"allow_emulator": true,
|
||||||
|
|
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 2.1 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.5 KiB |
Loading…
Reference in New Issue