From d03e867e7af3e4b8f47381bbf1c44086d96fe118 Mon Sep 17 00:00:00 2001 From: Erico Vieira Porto Date: Sat, 29 Oct 2016 18:00:12 -0200 Subject: [PATCH] adding a textbuffer, this makes drawing text to the screen way faster --- src/engine.js | 6 +- src/img/printer.png | Bin 3313 -> 4080 bytes src/index.html | 1 + src/menu.js | 19 ++-- src/printer.js | 2 +- src/screen.js | 210 +++++++++++++++++--------------------------- src/textbuffer.js | 30 +++++++ 7 files changed, 125 insertions(+), 143 deletions(-) create mode 100644 src/textbuffer.js diff --git a/src/engine.js b/src/engine.js index 3eefcc1..9104a5f 100644 --- a/src/engine.js +++ b/src/engine.js @@ -145,7 +145,7 @@ engine.menuSetup = function() { action: 'exit', index: 3 } - }); + },null, false, null, 2); menus.setParent(engine.mapMenu); } @@ -871,7 +871,7 @@ player.setup = function() { if (charFacing) { if (eventInChar(charFacing, [1, 0], [py - 1, px])) { HID.inputs["accept"].active = false - engine.waitTime(400); + engine.waitTime(300); } else { player.waits = 16 } @@ -880,7 +880,7 @@ player.setup = function() { var fpos = player.facingPosition() if (eventInMap(engine.currentLevel["Level"], [1, 0], fpos)) { HID.inputs["accept"].active = false - engine.waitTime(400); + engine.waitTime(300); } } diff --git a/src/img/printer.png b/src/img/printer.png index 9812207e270a49dbe112f32e6d6afcb17499813f..37d6e2c1452824e070e7e1e71147e6591c0fb840 100755 GIT binary patch literal 4080 zcmbtXc_5VA`#;0T64%moU0KVdE=iVBwwYTJ*~?lOS(0TUg=8B_+!i!q6r#vBHI$g_ zBw=jXHDe27UuSG%7~h$>_pjf-zxR*#J@0v*_nhZ^p3nK5=l#dh{GyP+K>+}Okg<`$ zWdI>VDCxu$C$_+XO zkk%8VcEjSFj~aiIQv)t{15W{Y zkyQQh2=gGBPNqD>6kmNdZ-C4nqkTMq(Qq9gD37=zK_F!s0w(X&*|9fm5%GC4Zfg79H~?g8vo^!&Dn&|gwI?+fAOhe)bNKU06PjP z*zs;8;Bx3Cb7 z$SvXs$QgV8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..0dd2975 100644 --- a/src/index.html +++ b/src/index.html @@ -20,6 +20,7 @@ + diff --git a/src/menu.js b/src/menu.js index 6f925ae..d29fbff 100644 --- a/src/menu.js +++ b/src/menu.js @@ -62,17 +62,18 @@ var menus = { } }; -function menu(_items, _index, _noexit, _icon) { +function menu(_items, _index, _noexit, _icon, _scale) { var tempArray = []; _index = (typeof _index === "undefined") ? null : _index; - _icon = (typeof _icon === "undefined") ? null : _icon; _noexit = (typeof _noexit === "undefined") ? false : _noexit; + _icon = (typeof _icon === "undefined") ? null : _icon; + _scale = (typeof _scale === "undefined") ? 2 : _scale; this.items = _items; this.noexit = _noexit; - this.menuScale = 1; + this.menuScale = _scale; this.maxOnScreen = 5; this.parent = null; this.index = _index; @@ -150,7 +151,7 @@ function menu(_items, _index, _noexit, _icon) { if (this.parent != null) { this.parent.wait = false; - this.parent.menuKeyWasPressed = 32 + this.parent.menuKeyWasPressed = 16 } else { engine.atomStack.push(engine.atomStack.push([function() { engine.atomStack = menus.holdAtomStack @@ -179,7 +180,7 @@ function menu(_items, _index, _noexit, _icon) { this.selectedItem = this.items[this.selectedItem.previous] this.selectedItem.selected = true HID.inputs["up"].active = false - this.menuKeyWasPressed = 32 + this.menuKeyWasPressed = 16 } else if (HID.inputs["left"].active) { @@ -191,7 +192,7 @@ function menu(_items, _index, _noexit, _icon) { this.selectedItem = this.items[this.selectedItem.next] this.selectedItem.selected = true HID.inputs["down"].active = false - this.menuKeyWasPressed = 32 + this.menuKeyWasPressed = 16 } else if (HID.inputs["accept"].active) { HID.inputs["accept"].active = false @@ -217,17 +218,17 @@ function menu(_items, _index, _noexit, _icon) { if (typeof this.selectedItem.isMenu === "undefined") { this.selectedItem.action(); } else { - this.selectedItem.menuKeyWasPressed = 32 + this.selectedItem.menuKeyWasPressed = 16 this.selectedItem.action(); } } - this.menuKeyWasPressed = 32 + this.menuKeyWasPressed = 16 } else if (HID.inputs["cancel"].active) { if (this._counter >= 20 && this.noexit == false) { HID.inputs["cancel"].active = false this.exit() engine.waitTime(200) - this.menuKeyWasPressed = 32 + this.menuKeyWasPressed = 16 } } } diff --git a/src/printer.js b/src/printer.js index 6047d0f..d063d0d 100644 --- a/src/printer.js +++ b/src/printer.js @@ -38,7 +38,7 @@ printer.showText = function(_text) { for (var nboxes = 0; nboxes < total_boxes; nboxes++) { engine.atomStack.unshift([function() { printer.nextBox(); - engine.waitTime(400); + engine.waitTime(300); }, '']); engine.atomStack.unshift(["block", null]); engine.atomStack.unshift([engine.waitForKey, true]); diff --git a/src/screen.js b/src/screen.js index 4abba62..b246d84 100644 --- a/src/screen.js +++ b/src/screen.js @@ -193,14 +193,9 @@ screen.drawChara = function(charaset, animation, frameNumber, position) { 32, 64); } -screen.drawText = function(text, posx, posy) { - png_font.ctx = screen.ctx - png_font.drawText(text,[ screen.GSTARTX + posx,screen.GSTARTY +posy-28],'#FFFFFF',size,'#221100'); -} - -screen.drawTextSize = function(text, posx, posy, size) { - png_font.ctx = screen.ctx - png_font.drawText(text,[ screen.GSTARTX + posx,screen.GSTARTY +posy-28],'#FFFFFF',size,'#221100'); +screen.drawText = function(text, posx, posy, size) { + size = (typeof size === "undefined") ? 2 : size; + textBuffer.drawText(text, posx, posy, size); } screen.drawTile = function(tileset, tile, position) { @@ -477,84 +472,34 @@ screen.printBox = { }, printSet: { - background: { - x: 0, - y: 0, - sizex: 64, - sizey: 64 - }, - topLeftBox: { - x: 64, - y: 0, - sizex: 16, - sizey: 16 - }, - topRightBox: { - x: 112, - y: 0, - sizex: 16, - sizey: 16 - }, - bottomLeftBox: { - x: 64, - y: 48, - sizex: 16, - sizey: 16 - }, - bottomRightBox: { - x: 112, - y: 48, - sizex: 16, - sizey: 16 - }, - LeftBox: { - x: 64, - y: 16, - sizex: 16, - sizey: 32 - }, - RightBox: { - x: 112, - y: 16, - sizex: 16, - sizey: 32 - }, - TopBox: { - x: 80, - y: 0, - sizex: 32, - sizey: 16 - }, - BottomBox: { - x: 80, - y: 48, - sizex: 32, - sizey: 16 - }, - acceptUp: { - x: 0, - y: 64, - sizex: 16, - sizey: 16 - }, - acceptDown: { - x: 16, - y: 64, - sizex: 16, - sizey: 16 - }, - upArrow: { - x: 64, - y: 64, - sizex: 32, - sizey: 16 - }, - downArrow: { - x: 64, - y: 80, - sizex: 32, - sizey: 16 - } + background: { x: 0, y: 0, sizex: 64, sizey: 64 }, + topLeftBox: { x: 64, y: 0, sizex: 16, sizey: 16 }, + topRightBox: { x: 112, y: 0, sizex: 16, sizey: 16 }, + bottomLeftBox: { x: 64, y: 48, sizex: 16, sizey: 16 }, + bottomRightBox: { x: 112, y: 48, sizex: 16, sizey: 16 }, + LeftBox: { x: 64, y: 16, sizex: 16, sizey: 32 }, + RightBox: { x: 112, y: 16, sizex: 16, sizey: 32 }, + TopBox: { x: 80, y: 0, sizex: 32, sizey: 16 }, + BottomBox: { x: 80, y: 48, sizex: 32, sizey: 16 }, + acceptUp: { x: 0, y: 64, sizex: 16, sizey: 16 }, + acceptDown: { x: 16, y: 64, sizex: 16, sizey: 16 }, + upArrow: { x: 64, y: 64, sizex: 32, sizey: 16 }, + downArrow: { x: 64, y: 80, sizex: 32, sizey: 16 } + }, + printSet_05: { + background: { x: 0, y: 0, sizex: 64, sizey: 64 }, + topLeftBox: { x: 160, y: 64, sizex: 8, sizey: 8 }, + topRightBox: { x: 184, y: 64, sizex: 8, sizey: 8 }, + bottomLeftBox: { x: 160, y: 88, sizex: 8, sizey: 8 }, + bottomRightBox: { x: 184, y: 88, sizex: 8, sizey: 8 }, + LeftBox: { x: 160, y: 72, sizex: 8, sizey: 16 }, + RightBox: { x: 184, y: 72, sizex: 8, sizey: 16 }, + TopBox: { x: 168, y: 64, sizex: 16, sizey: 8 }, + BottomBox: { x: 168, y: 88, sizex: 16, sizey: 8 }, + acceptUp: { x: 0, y: 64, sizex: 16, sizey: 16 }, + acceptDown: { x: 16, y: 64, sizex: 16, sizey: 16 }, + upArrow: { x: 64, y: 64, sizex: 32, sizey: 16 }, + downArrow: { x: 64, y: 80, sizex: 32, sizey: 16} }, getIcon: function(i) { @@ -577,10 +522,12 @@ screen.printBox = { screen.GSTARTX + screen.GWIDTH - 32, screen.GSTARTY + screen.GHEIGHT - 32, accept['sizex'], accept['sizey']) }, - drawElement: function(element, x, y, sizex, sizey, imgPrintSet, select) { + drawElement: function(element, x, y, sizex, sizey, imgPrintSet, select, size, ctx) { + size = (typeof size === "undefined") ? 2 : size; select = (typeof select === "undefined") ? 0 : select; - screen.ctx.drawImage(imgPrintSet, - element['x'] + select * 64, element['y'], + ctx = (typeof ctx === "undefined") ? screen.ctx : ctx; + ctx.drawImage(imgPrintSet, + element['x'] + select * 32 * size, element['y'], element['sizex'], element['sizey'], screen.GSTARTX + x, screen.GSTARTY + y, sizex, sizey); }, @@ -626,49 +573,54 @@ screen.printBox = { screen.printBox.drawElement(arrow, x, y, arrow.sizex, arrow.sizey, imgPrintSet) }, - drawBox: function(x, y, sizex, sizey, select) { - + drawBox: function(x, y, sizex, sizey, select,size, ctx) { select = (typeof select === "undefined") ? 0 : select; - + size = (typeof size === "undefined") ? 2 : size; + ctx = (typeof ctx === "undefined") ? screen.ctx : ctx; imgPrintSet = screen.printBox.imgPrintSet; - s = screen['printBox']['printSet'] + + if(size==2){ + var s = screen['printBox']['printSet'] + } else { + var s = screen['printBox']['printSet_05'] + } if (select == 0) { - screen.printBox.drawElement(s['background'], x, y, sizex, sizey, imgPrintSet); + screen.printBox.drawElement(s['background'], x, y, sizex, sizey, imgPrintSet,0,2,ctx); } - screen.printBox.drawElement(s['topLeftBox'], x, y, s['topLeftBox']['sizex'], s['topLeftBox']['sizey'], imgPrintSet, select); + screen.printBox.drawElement(s['topLeftBox'], x, y, s['topLeftBox']['sizex'], s['topLeftBox']['sizey'], imgPrintSet, select, size,ctx); screen.printBox.drawElement(s['TopBox'], x + s['topLeftBox']['sizex'], y, sizex - s['topLeftBox']['sizex'] - s['topRightBox']['sizex'], s['TopBox']['sizey'], - imgPrintSet, select); + imgPrintSet, select, size,ctx); screen.printBox.drawElement(s['topRightBox'], x + sizex - s['topRightBox']['sizex'], y, s['topRightBox']['sizex'], s['topRightBox']['sizey'], - imgPrintSet, select); + imgPrintSet, select, size,ctx); screen.printBox.drawElement(s['LeftBox'], x, y + s['topLeftBox']['sizey'], s['LeftBox']['sizex'], sizey - s['topLeftBox']['sizey'] - s['bottomLeftBox']['sizey'], - imgPrintSet, select); + imgPrintSet, select, size,ctx); screen.printBox.drawElement(s['RightBox'], x + sizex - s['topRightBox']['sizex'], y + s['topRightBox']['sizey'], s['RightBox']['sizex'], sizey - s['topRightBox']['sizey'] - s['bottomRightBox']['sizey'], - imgPrintSet, select); + imgPrintSet, select, size,ctx); screen.printBox.drawElement(s['bottomLeftBox'], x, y + sizey - s['bottomLeftBox']['sizey'], s['bottomLeftBox']['sizex'], s['bottomLeftBox']['sizey'], - imgPrintSet, select); + imgPrintSet, select, size,ctx); screen.printBox.drawElement(s['BottomBox'], x + s['bottomLeftBox']['sizex'], y + sizey - s['bottomRightBox']['sizey'], sizex - s['bottomLeftBox']['sizex'] - s['bottomRightBox']['sizex'], s['BottomBox']['sizey'], - imgPrintSet, select); + imgPrintSet, select, size,ctx); screen.printBox.drawElement(s['bottomRightBox'], x + sizex - s['bottomRightBox']['sizex'], y + sizey - s['bottomRightBox']['sizey'], s['bottomRightBox']['sizex'], s['bottomRightBox']['sizey'], - imgPrintSet, select); + imgPrintSet, select, size,ctx); } @@ -936,17 +888,17 @@ screen.drawMenu = function(menu) { for (var i = menu.firstItem; i < menu.finalItem; i += 1) { if (menu.items[Object.keys(menu.items)[i]].selected) { if (menu.wait) { - screen.printBox.drawBox(menu['drawx'] + 8, + screen.printBox.drawBox(menu['drawx'] + 4*menu.menuScale, menu['drawy'] + 8 + menu.fontHeight * k, - menu['width'] - 16, - 32, + menu['width'] - 8*menu.menuScale, + 16*menu.menuScale, 1, menu.menuScale); } else { - screen.printBox.drawBox(menu['drawx'] + 8, + screen.printBox.drawBox(menu['drawx'] + 4*menu.menuScale, menu['drawy'] + 8 + menu.fontHeight * k, - menu['width'] - 16, - 32, + menu['width'] - 8*menu.menuScale, + 16*menu.menuScale, 1 + Math.floor(screen.frameCount / 4) % 2, menu.menuScale); } @@ -959,12 +911,12 @@ screen.drawMenu = function(menu) { menu['drawy'], icon.sizex + 16, icon.sizey + 16, - menu.menuScale); - screen.printBox.drawElement(icon, menu['drawx'] + menu['width'] + 8, menu['drawy'] + 8, icon.sizex, icon.sizey, imgPrintSet, menu.menuScale) + 0); + screen.printBox.drawElement(icon, menu['drawx'] + menu['width'] + 8, menu['drawy'] + 8, icon.sizex, icon.sizey, imgPrintSet, 0) } } - screen.drawTextSize(Object.keys(menu.items)[i], +menu['drawx'] + 16, menu['drawy'] + 32+k*menu.fontHeight, menu.menuScale); + screen.drawText(Object.keys(menu.items)[i], menu['drawx'] + 16, menu['drawy'] + 32+k*menu.fontHeight, menu.menuScale); k+=1; } @@ -972,41 +924,39 @@ screen.drawMenu = function(menu) { screen.drawStatus = function(heroch) { var hero = heroch - var statw = screen.GWIDTH - 32 - 96 + var statx = engine.mapMenu.drawx + engine.mapMenu.width; + var staty = engine.mapMenu.drawy ; + var statw = screen.GWIDTH - 8 -(engine.mapMenu.drawx + engine.mapMenu.width); var stath = screen.GHEIGHT - 16 - var statx = 16 + 96 + 8 - var staty = 8 - - screen.printBox.drawBox(statx, - staty, - statw, - stath); screen.printBox.drawBox(statx, staty, statw, stath, - 0); + 0, + 2); + screen.drawFace(resources.faceset, heroch.face, [statx + 112, staty + 16]) - var keys = ["name", "st", "dx", "iq", "level", "xp"] - // heroch.name, - // heroch.st, heroch.dx, heroch.iq, heroch.level, heroch.xp, - // heroch.xpnextlevel heroch.hp, heroch.hpmax + var keys = ["name", "st", "dx", "iq"] + + var stats = "" for (var i = 0; i < keys.length; i++) { var atr = keys[i] var atrval = heroch[atr] if (atr != "name") { - screen.drawText(atr + ": " + atrval, statx + 16, staty + 32 * (1 + i)); + stats = stats.concat(atr + ": " + atrval +"\n"); } else { - screen.drawText(atrval, statx + 16, staty + 32 * (1 + i)); + stats = stats.concat(atrval + "\n"); } } - screen.drawText("xp to next level: " + heroch.xpnextlevel, statx + 16, staty + 32 * (1 + i)); - screen.drawText("hp: " + heroch.hp + "/" + heroch.hpmax, statx + 144, staty + 32 * i); - //screen.ctx.fillText(" "+heroch.hpmax, screen.GSTARTX+32+screen.GWIDTH/2,screen.GSTARTY+32*5+16); + + stats = stats.concat("hp: " + heroch.hp + "/" + heroch.hpmax + "\n") + stats = stats.concat("level: " + heroch.level + "\n") + stats = stats.concat("xp:"+heroch.xp+ "/" + heroch.xpnextlevel+"\n"); + screen.drawText(stats,statx+8,staty+8+24,2) + //screen.ctx.fillText(" "+heroch.hpmax, screen.GSTARTX+32+screen.GWIDTH/2,screen.GSTARTY+32*5+16); //screen.ctx.fillText(heroch.name, statx+statw/2-48,staty+32); - screen.drawFace(resources.faceset, heroch.face, [statx + 144, staty + 16]) screen.printBox.drawButtonAccept() } diff --git a/src/textbuffer.js b/src/textbuffer.js new file mode 100644 index 0000000..d035be7 --- /dev/null +++ b/src/textbuffer.js @@ -0,0 +1,30 @@ +textBuffer = { + buffer: [], + drawText: function(text, posx, posy, size) { + for(var i=0; i29){ + this.buffer.shift() + } + + var newcanvas = document.createElement('canvas') + newcanvas.width = screen.GWIDTH-posx + newcanvas.height = screen.GHEIGHT-posy + png_font.ctx =newcanvas.getContext('2d') + png_font.drawText(text,[ 0,0],'#FFFFFF',size,'#221100'); + this.buffer.push({text: text, + posx: posx, + posy: posy, + size: size, + canvas: newcanvas}); + } +}