0.06: Bangle.js 2 enhancements - remove offscreen buffer and render direct

pull/2037/head
Gordon Williams 2022-07-07 11:00:18 +01:00
parent 970de6bf9b
commit 789e3a7ec5
3 changed files with 25 additions and 39 deletions

View File

@ -2,3 +2,4 @@
0.03: A few tweaks to improve rendering speed
0.04: Add "ram" keyword to allow 2v06 Espruino builds to cache function that needs to be fast
0.05: Don't use Bangle.setLCDMode, just use offscreen buffer (allows widgets)
0.06: Bangle.js 2 enhancements - remove offscreen buffer and render direct

View File

@ -1,19 +1,20 @@
b = Graphics.createArrayBuffer(120,120,8);
var gimg = {
width:120,
height:104,
bpp:8,
buffer:b.buffer
};
var Y;
if (process.env.HWVERSION==2) {
b.flip = function() {
g.drawImage(gimg,28,50);
};
// we have offscreen graphics, so just go direct
b = g;
Y = 24; // widgets
} else {
b = Graphics.createArrayBuffer(120,120,8);
var gimg = {
width:120,
height:104,
bpp:8,
buffer:b.buffer
};
b.flip = function() {
g.drawImage(gimg,0,24,{scale:2});
};
Y = 0; // we offset for widgets anyway
}
var BIRDIMG = E.toArrayBuffer(atob("EQyI/v7+/v7+/gAAAAAAAP7+/v7+/v7+/gYG0tLS0gDXAP7+/v7+/v4A0tLS0tIA19fXAP7+/v4AAAAA0tLS0gDX1wDXAP7+ANfX19cA0tLSANfXANcA/v4A19fX19cA0tLSANfX1wD+/gDS19fX0gDS0tLSAAAAAAD+/gDS0tIA0tLS0gDAwMDAwAD+/gAAAM3Nzc0AwAAAAAAA/v7+/v4Azc3Nzc0AwMDAwAD+/v7+/v4AAM3Nzc0AAAAAAP7+/v7+/v7+AAAAAP7+/v7+/g=="))
@ -30,14 +31,14 @@ function newBarrier(x) {
barriers.push({
x1 : x-7,
x2 : x+7,
y : 20+Math.random()*38,
y : Y+20+Math.random()*38,
gap : 12+Math.random()*15
});
}
function gameStart() {
running = true;
birdy = 48/2;
birdy = Y + 48/2;
birdvy = 0;
barriers = [];
for (var i=38;i<g.getWidth();i+=38)
@ -52,8 +53,7 @@ function gameStop() {
function draw() {
"ram"
var H = b.getHeight()-24;
b.setColor("#71c6cf");
b.fillRect(0,0,b.getWidth(),H-1);
b.setColor("#71c6cf").fillRect(0,Y,b.getWidth(),H-1);
floorpos++;
for (var x=-(floorpos&15);x<b.getWidth();x+=16)
b.drawImage(FLOORIMG,x,H);
@ -63,13 +63,9 @@ function draw() {
var x = b.getWidth()/2;
b.setColor("#000000");
b.setFontAlign(0,0);
b.setFont("4x6",2);
b.drawString("GAME OVER!",x,20);
b.setFont("6x8",1);
b.drawString("Score",x,40);
b.drawString(score,x,56);
b.drawString("Tap screen to",x,76);
b.drawString("restart and flap",x,84);
b.setFont("4x6",2).drawString("GAME OVER!",x,20+Y);
b.setFont("6x8",1).drawString("Score",x,40+Y).drawString(score,x,56+Y);
b.drawString("Tap screen to",x,76+Y).drawString("restart and flap",x,84+Y);
b.flip();
return;
}
@ -88,22 +84,11 @@ function draw() {
r.x2--;
var btop = r.y-r.gap;
var bbot = r.y+r.gap;
b.setColor("#73bf2f"); // middle
b.fillRect(r.x1+4, 0, r.x2-4, btop-1);
b.fillRect(r.x1+4, bbot, r.x2-4, H-1);
b.setColor("#c0f181"); // left
b.fillRect(r.x1+1, 0, r.x1+3, btop-1);
b.fillRect(r.x1+1, bbot, r.x1+3, H-1);
b.setColor("#538917"); // right
b.fillRect(r.x2-3, 0, r.x2-1, btop-1);
b.fillRect(r.x2-3, bbot, r.x2-1, H-1);
b.setColor("#808080"); // outlines
b.drawRect(r.x1, btop-5, r.x2, btop); // top
b.drawLine(r.x1+1, 0, r.x1+1, btop-6);
b.drawLine(r.x2-2, 0, r.x2-2, btop-6);
b.drawRect(r.x1, bbot, r.x2, bbot+5); // bottom
b.drawLine(r.x1+1, bbot+6, r.x1+1, H-1);
b.drawLine(r.x2-1, bbot+6, r.x2-1, H-1);
b.setColor("#73bf2f").fillRect(r.x1+4, Y, r.x2-4, btop-1).fillRect(r.x1+4, bbot, r.x2-4, H-1); // middle
b.setColor("#c0f181").fillRect(r.x1+1, Y, r.x1+3, btop-1).fillRect(r.x1+1, bbot, r.x1+3, H-1); // left
b.setColor("#538917").fillRect(r.x2-3, Y, r.x2-1, btop-1).fillRect(r.x2-3, bbot, r.x2-1, H-1); // right
b.setColor("#808080").drawRect(r.x1, btop-5, r.x2, btop).drawLine(r.x1+1, Y, r.x1+1, btop-6).drawLine(r.x2-2, Y, r.x2-2, btop-6); // top
b.drawRect(r.x1, bbot, r.x2, bbot+5).drawLine(r.x1+1, bbot+6, r.x1+1, H-1).drawLine(r.x2-1, bbot+6, r.x2-1, H-1); // bottom
if (r.x1<6 && (birdy-3<btop || birdy+3>bbot))
gameStop();
});

View File

@ -1,7 +1,7 @@
{
"id": "flappy",
"name": "Flappy Bird",
"version": "0.05",
"version": "0.06",
"description": "A Flappy Bird game clone",
"icon": "app.png",
"screenshots": [{"url":"screenshot1_flappy.png"},{"url":"screenshot2_flappy.png"}],