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

master
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.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.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.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 Y;
var gimg = { if (process.env.HWVERSION==2) {
// we have offscreen graphics, so just go direct
b = g;
Y = 24; // widgets
} else {
b = Graphics.createArrayBuffer(120,120,8);
var gimg = {
width:120, width:120,
height:104, height:104,
bpp:8, bpp:8,
buffer:b.buffer buffer:b.buffer
}; };
if (process.env.HWVERSION==2) {
b.flip = function() {
g.drawImage(gimg,28,50);
};
} else {
b.flip = function() { b.flip = function() {
g.drawImage(gimg,0,24,{scale:2}); 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==")) 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({ barriers.push({
x1 : x-7, x1 : x-7,
x2 : x+7, x2 : x+7,
y : 20+Math.random()*38, y : Y+20+Math.random()*38,
gap : 12+Math.random()*15 gap : 12+Math.random()*15
}); });
} }
function gameStart() { function gameStart() {
running = true; running = true;
birdy = 48/2; birdy = Y + 48/2;
birdvy = 0; birdvy = 0;
barriers = []; barriers = [];
for (var i=38;i<g.getWidth();i+=38) for (var i=38;i<g.getWidth();i+=38)
@ -52,8 +53,7 @@ function gameStop() {
function draw() { function draw() {
"ram" "ram"
var H = b.getHeight()-24; var H = b.getHeight()-24;
b.setColor("#71c6cf"); b.setColor("#71c6cf").fillRect(0,Y,b.getWidth(),H-1);
b.fillRect(0,0,b.getWidth(),H-1);
floorpos++; floorpos++;
for (var x=-(floorpos&15);x<b.getWidth();x+=16) for (var x=-(floorpos&15);x<b.getWidth();x+=16)
b.drawImage(FLOORIMG,x,H); b.drawImage(FLOORIMG,x,H);
@ -63,13 +63,9 @@ function draw() {
var x = b.getWidth()/2; var x = b.getWidth()/2;
b.setColor("#000000"); b.setColor("#000000");
b.setFontAlign(0,0); b.setFontAlign(0,0);
b.setFont("4x6",2); b.setFont("4x6",2).drawString("GAME OVER!",x,20+Y);
b.drawString("GAME OVER!",x,20); b.setFont("6x8",1).drawString("Score",x,40+Y).drawString(score,x,56+Y);
b.setFont("6x8",1); b.drawString("Tap screen to",x,76+Y).drawString("restart and flap",x,84+Y);
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.flip(); b.flip();
return; return;
} }
@ -88,22 +84,11 @@ function draw() {
r.x2--; r.x2--;
var btop = r.y-r.gap; var btop = r.y-r.gap;
var bbot = r.y+r.gap; var bbot = r.y+r.gap;
b.setColor("#73bf2f"); // middle 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.fillRect(r.x1+4, 0, r.x2-4, btop-1); 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.fillRect(r.x1+4, bbot, r.x2-4, H-1); 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("#c0f181"); // left 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.fillRect(r.x1+1, 0, r.x1+3, btop-1); 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
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);
if (r.x1<6 && (birdy-3<btop || birdy+3>bbot)) if (r.x1<6 && (birdy-3<btop || birdy+3>bbot))
gameStop(); gameStop();
}); });

View File

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