From 67b9e98a6d9cf8ef3830629085a7e4810b3ea39e Mon Sep 17 00:00:00 2001 From: Bye <bye@byecorps.com> Date: Sat, 19 Aug 2023 18:14:39 +0100 Subject: [PATCH] remove old editor and shrink font --- assets/tilemap.ase | Bin 3185 -> 3017 bytes src/img/hampsterfont.webp | Bin 380 -> 200 bytes src/img/t.webp | Bin 264 -> 296 bytes src/index.html | 7 +- src/js/canvas.js | 2 - src/js/config.js | 3 - src/js/game.js | 136 +++++--------------------------------- src/js/objects.js | 2 + src/js/text.js | 9 ++- src/js/utils.js | 32 +-------- 10 files changed, 28 insertions(+), 163 deletions(-) diff --git a/assets/tilemap.ase b/assets/tilemap.ase index e545cf9a93ce4fedf02adda9e6c9a90f6b484759..bfdc857bcbadc9022c2e857a1314f74fee583435 100644 GIT binary patch literal 3017 zcmX@f&A{+rsVIX0g8+j910w?iLka^jP+(vL34-O3#i_+!!N|by>mw`JR#pZE1~CQ( z26hFol}J|HVqjp9R8WA5$U|v3^`C)3Nx|el1B0uE&3^`lG)u$(3=I8Y*8dq8?iZ^4 zXJELwAniW`!@I+?{xdNA{$%!_fnny;fd32(S^EtBGccG>$@|a1;GL=epMfFBTjf6k zgOQEpe+CA7`;z|*3<e2J{}~vf^B(?ZU`U?*|33pm{Mje}85mCA{_~%K;s1Y-$n3S- z|1&VO)V2R-V93nM`p>`+85Z=PfuYQ)>pug-8Y3f+8^V+SGca7Q-UV{obg%ym3|;vK z|Fakv7+65z4)UCmf{Ck!O`4@)f0*_CLbaO<(%v1O_4||A%%=fa`wYyd<auZ62YIU) z*;v}!mlz~8Mdv+Cp8Y@m>=Te%{{Nr7c6&=*duCQvWLQv{Q`Z_JqnqK$*Q<B+PxtD| zHvokiivlw|&=?s0gTk7@C$TcMNWlodwBd9HP&_e#<B5rZfkBUffq@m|W(Ed^{~!Ud zxu8^3F{hh{`<J|Bm-|Nzxrq`Co(v4~kzm!3SVdQzoN$2OX!E9j!U0B0zBWJ6JoseS zbfLdHz6dRrpC9M+i}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l2^{hp4@QflDKMK^mSr4<KHd5j%5^C4JzDN!L<ykS3y=o(ksHNp4KO_UM}Tl z2yFFrtf$CUM;smoMJa9%2hKY8Vktkv>#uf4sT04bnG`vG)!^}akl~A2^xi6pylVsX zE~s2Yk6%zAgEFa0P_(Cd?THx?wL9L(T{YkIWnwd9VZN_p1w}Sn!EMGBy-=TCb?=EP zx+J+Ns^}{t!%;(D#|Db*b%NWATrBZ1fFc-&k5}<e2f4uX6Enl>gLX#?DYD-fYCmcY z7C_3ujA;_AixU_aRWrp~7(qowBSjWE!!1PiumE}%&dEA?l|SjQf#xsItHxYzjJga( zQ7Y`r3~#ILj*?UXV^lnd3K%)2Ar1hAc)Taf$CjCbv*m)m3M;$y)G@rWwmaHHk<VRl z_#70~NO>94=UXqmcX(>gut>nbvxXEGV6;8#;4VOJd+;-`FjUM*PDn_I*phLvo=wF; zN8TkoEbO0pyMJd~(4CHR><qi)BTkYO>=<^#f}M>4Io??q_>t`vNNd=nt*w1fB9iCW LF}AizbzqADNUCaD diff --git a/src/img/hampsterfont.webp b/src/img/hampsterfont.webp index a8eddc36fba2ac0e66216ed0d11b68c0bdb77315..e90999eb673f6ae56434899a04c48a89ba5cb4a7 100644 GIT binary patch literal 200 zcmWIYbaOkvz`zjh>J$(bVBxccfq_B)DFdSbzrp{{_WwW2e`tu#y}gO8yu3W(K&<+P zX<e7*c74`wDC5(WwXO(q6!rHi|Gp>N<%|7;_e{q&RPJhE|8Oi@|4z3pL(7ZJD+`5# z7Usp5a$LS}SmB_-G5;NZ&+XHwKKEs1z>*aluj12{4_UD6HxEr-YLd48Tb<v(7k1KJ zEuTfCzFl3Pc<SGTyFYq2Ue;axRyH-=hsVqHP-onOB-^&$Pfnc*`n!D_+TWf}4v<h- IS*Rie02B&dGynhq literal 380 zcmWIYbaN|VWMBw)bqWXzu<*%XWMI&DY-AJ=H~9bA{{LtB26hj=1KV<MDE?LWY&zHO zbc05Nl{@Q_>lV&uEZSL@q`MW}6S!E<ns-}c?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L>l)Uk0r%mbH%&)Q+>)G<8HNBP` zO@6ia;fyVwbA2{jntK1*|9HdH_sMB?ix%x@T9_ghn0e(O>%YP)FD<lcWj;6hg#5P< zyL9}aNc5TOsmbh}_YeO1A+)`@f6G=GUj-&R4V8|hWC??kue+KaY+b0*^?S=g^E?fv zQ^wQ&8L%+~PK{X5U9B?1?<8Nwy>yA13C)U$Zh{$%92-t$D{bFf^R0OH2^iz_>q*km R|1;;geEfX;sp!UsnE*Zpd(Hp= diff --git a/src/index.html b/src/index.html index 18edcf3..83a0e4d 100644 --- a/src/index.html +++ b/src/index.html @@ -2,7 +2,7 @@ <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1"> <style> - :root { color-scheme: dark; } + :root { color-scheme: light dark; } body { display: flex; justify-content: center; align-items: center; height: 100vh;} canvas, body { margin: 0; @@ -10,8 +10,8 @@ user-select: none; } canvas { - width: 768px; - height: 768px; + width: 100%; + max-height: 100vh; object-fit: contain; image-rendering: pixelated; margin: auto; @@ -19,6 +19,5 @@ </style> <body> <canvas id=c></canvas> - <script src="lzs.js"></script> <script type="module" src=game.js></script> </body> \ No newline at end of file diff --git a/src/js/canvas.js b/src/js/canvas.js index e688f02..6cb40fc 100644 --- a/src/js/canvas.js +++ b/src/js/canvas.js @@ -1,7 +1,5 @@ // Holds canvas, context and adds endpoints for graphics - -import { pi } from "./utils.js" class Canvas { constructor(id="c", w=128, h=128) { this.canvas = document.getElementById(id); diff --git a/src/js/config.js b/src/js/config.js index ddaf861..40a6ff3 100644 --- a/src/js/config.js +++ b/src/js/config.js @@ -4,6 +4,3 @@ export const GAME_TITLE = "Untitled JS13K23 Game." export const WIDTH = 256; // pixels export const HEIGHT = 240; // pixels - -export const SCALE = 2<<4; - diff --git a/src/js/game.js b/src/js/game.js index ec2c1f1..3ebfd40 100644 --- a/src/js/game.js +++ b/src/js/game.js @@ -1,31 +1,17 @@ -import { WIDTH, HEIGHT, GAME_TITLE, SCALE } from "./config.js"; +import { WIDTH, HEIGHT, GAME_TITLE } from "./config.js"; import { Canvas } from "./canvas.js"; import { TextRenderer } from "./text.js"; import { Room, Object } from "./objects.js"; -import { whichKeyDown } from "./keyboard.js"; -import { convertTileToScreen, getParameter, hash } from "./utils.js"; +import { isKeyUp, whichKeyDown } from "./keyboard.js"; +import { getParameter } from "./utils.js"; let assets = { images: { splash: "../img/splash1.webp", font: "../img/hampsterfont.webp", - tiles: "../img/t.webp", selector: "../img/selector.webp", }, - spritesheets: { - player: [ - {x: 0}, // looking up - {x: 16}, // looking right - {x: 32}, // looking down - {x: 48} // looking left - ] - } -} - -const tileTypes = { - 1: 1, // floor - 2: 2, // wall } let running = 1; @@ -90,6 +76,7 @@ let searchForRoom = (name) => { const changeRoom = (index) => { currentRoom = rooms[index]; roomIndex = index; + currentRoom.init(); } const loadingRoom = new Room("loading"); @@ -101,20 +88,21 @@ loadingRoom.updateStatus = (status) => { } const debugRoom = new Room("debug"); +debugRoom.init = () => { + if (!debug) changeRoom(searchForRoom("menu")); +} debugRoom.draw = () => { canvas.fill("black"); } debugRoom.drawGUI = () => { debugStatuses.push("Current Frame:"+currentFrame+`(~${Math.round((currentFrame/targetFrames)*100)/100} sec)`); } -debugRoom.keyDown = (key) => { - if (key == "Escape") changeRoom(searchForRoom("menu")); -} const menuRoom = new Room("menu"); menuRoom.options = [ {"label": "Start Game", "action": _ => {changeRoom(searchForRoom("game"))}}, ]; +if (debug) menuRoom.options.push({"label": "Debug Room", "action": _ => {changeRoom(searchForRoom("debug"))}}); menuRoom.index = 0; menuRoom.draw = () => { @@ -143,105 +131,8 @@ menuRoom.keyDown = (key) => { if (menuRoom.index >= menuRoom.options.length) menuRoom.index = 0; if (menuRoom.index < 0) menuRoom.index = menuRoom.options.length-1; } - -const getTileType = (x, y, data) => { - for (let i = 0; i < data.tiles.length; i++) { - let tile = data.tiles[i]; - if (tile.x == x && tile.y == y) return tileTypes[tile.id]; - } - return 0; -} - - -const renderTiles = (data) => { - for (let i = 0; i < data.tiles.length; i++) { - let tile = data.tiles[i]; - let tileLocation = convertTileToScreen(tile.x, tile.y); - let tId = tile.id; - - if (tile.id == 2) { - tId = 3; - // connect walls to each other. - // check the tile above, below, left, and right of this one. if it is also id 2, then set the corresponding variable to 1 - getTileType(tile.x, tile.y-1, data) == 2 ? tId += 1 : tId += 0; - getTileType(tile.x, tile.y+1, data) == 2 ? tId += 2 : tId += 0; - getTileType(tile.x-1, tile.y, data) == 2 ? tId += 4 : tId += 0; - getTileType(tile.x+1, tile.y, data) == 2 ? tId += 8 : tId += 0; - } - - canvas.sliceImage(assets.images.tiles, tileLocation.x, tileLocation.y, SCALE, SCALE, tId*16, 0, 16, 16); - } -} - -const gameRoom = new Room("game"); -gameRoom.data = { tiles: [ ] }; -gameRoom.draw = () => { - canvas.fill("black"); - - renderTiles(gameRoom.data); -} - -const levelEditor = new Room("editor"); -levelEditor.currentTile = { x: 0, y: 0, id: 0 }; -levelEditor.data = { tiles : [] }; -levelEditor.step = _ => { - - // place the camera at the center of the current tile if it is outside the screen - let tileLocation = convertTileToScreen(levelEditor.currentTile.x, levelEditor.currentTile.y); - if (tileLocation.x < canvas.cX) canvas.cX = tileLocation.x; - if (tileLocation.x >= canvas.cX+256) canvas.cX = tileLocation.x-canvas.width; - if (tileLocation.y < canvas.cY) canvas.cY = tileLocation.y; - if (tileLocation.y > canvas.cY+224) canvas.cY = tileLocation.y-canvas.height; - - - debugStatuses.push("Current tile:"+levelEditor.currentTile.x+","+levelEditor.currentTile.y); - debugStatuses.push("Current tile ID:"+levelEditor.currentTile.id); - debugStatuses.push("Camera:"+canvas.cX+","+canvas.cY); -} -levelEditor.keyDown = (key) => { - if (pressedLastFrame.includes(key)) return; - - const { currentTile, data } = levelEditor; - const { x, y, id } = currentTile; - - const keyActions = { - ArrowUp: () => currentTile.y--, - ArrowDown: () => currentTile.y++, - ArrowLeft: () => currentTile.x--, - ArrowRight: () => currentTile.x++, - PageUp: () => currentTile.id++, - PageDown: () => currentTile.id--, - KeyP: () => console.log(data), - Enter: () => { - data.tiles = data.tiles.filter(tile => tile.x !== x || tile.y !== y); - data.tiles.push({ id, x, y }); - }, - }; - - const action = keyActions[key]; - if (action) action(); -}; - -levelEditor.draw = () => { - canvas.fill("#010101"); - - renderTiles(levelEditor.data); - - canvas.drawLine(-canvas.width*100, 0, canvas.width*100, 0, "white"); - canvas.drawLine(0, -canvas.height*100, 0, canvas.height*100, "white"); - text.render("(0,0)", 1-canvas.cX, 1-canvas.cY) - - let tileLocation = convertTileToScreen(levelEditor.currentTile.x, levelEditor.currentTile.y); - canvas.ctx.globalAlpha = 0.5; - canvas.sliceImage(assets.images.tiles, tileLocation.x, tileLocation.y, SCALE, SCALE, levelEditor.currentTile.id*16, 0, 16, 16); - canvas.ctx.globalAlpha = 1; - canvas.drawImage(assets.images.selector, tileLocation.x, tileLocation.y, SCALE, SCALE); -} - rooms.push(loadingRoom); rooms.push(menuRoom); -rooms.push(gameRoom); -rooms.push(levelEditor); rooms.push(debugRoom); currentRoom = rooms[roomIndex]; @@ -264,6 +155,7 @@ let main = () => { // main game loop let currentKeys = whichKeyDown(); for (let i = 0; i < currentKeys.length; i++) { + if (isKeyUp(currentKeys[i]) && pressedLastFrame.includes(currentKeys[i])) continue; if (debug) debugStatuses.push(currentKeys[i]); currentRoom.keyDown(currentKeys[i]); } @@ -272,7 +164,7 @@ let main = () => { // main game loop if (debug) { text.render("FPS:" + Math.round(1000 / delta), 0, 0); - text.render(currentRoom.name, canvas.width-8*(currentRoom.name.length), 0); + text.render(currentRoom.name, canvas.width-(text.charWidth*(currentRoom.name.length)), 0); debugStatuses.push("Debug mode"); if (currentFrame <= 60*5) { @@ -282,7 +174,10 @@ let main = () => { // main game loop } for (let i = 0; i < debugStatuses.length; i++) { - text.render(debugStatuses[i], 0, canvas.height-7*(debugStatuses.length-i)); + // console.debug(debugStatuses[i]); + if (typeof(debugStatuses[i]) == "string") text.render(debugStatuses[i], 0, canvas.height-text.charHeight*(debugStatuses.length-i)); + if (typeof(debugStatuses[i]) == "object") {text.render(debugStatuses[i].msg, 0, canvas.height-text.charHeight*(debugStatuses.length-i)); debugStatuses[i].ttl--;} + } lastFrameTime = now; @@ -302,8 +197,7 @@ let init = () => { console.log("Images loaded.") currentRoom.updateStatus("Loading complete!"); setTimeout(() => { - let rm = getParameter("room") - (rm ? changeRoom(searchForRoom(rm)) : changeRoom(searchForRoom("menu"))); + (getParameter("room") ? changeRoom(searchForRoom(getParameter("room"))) : changeRoom(searchForRoom("menu"))); main(); }, 1000); } diff --git a/src/js/objects.js b/src/js/objects.js index 9113a0b..f194109 100644 --- a/src/js/objects.js +++ b/src/js/objects.js @@ -11,6 +11,8 @@ class Room extends Object { this.name = name; // needs to be unique, otherwise the searching code will just use the first one it finds. } + init(){} + draw() { for (let i = 0; i < this.objects.length; i++) { this.objects[i].draw(); diff --git a/src/js/text.js b/src/js/text.js index cbe816d..9fd464c 100644 --- a/src/js/text.js +++ b/src/js/text.js @@ -3,8 +3,11 @@ class TextRenderer { constructor(canvas, fontimg) { this.fontimg = fontimg; // MUST BE AN IMAGE OBJECT - this.fontWidth = 7; - this.fontHeight = 7; + this.fontWidth = 5; + this.fontHeight = 5; + this.spacing = 1; + this.charWidth = this.fontWidth + this.spacing; + this.charHeight = this.fontHeight + this.spacing; this.fontChars = "abcdefghijklmnopqrstuvwxyz1234567890.,!?:;)(~>"; this.canvas = canvas; } @@ -39,7 +42,7 @@ class TextRenderer { xOffset = 0; continue; } - this.drawLetter(text[i], x + (xOffset * this.fontWidth), y + (heightOffset * this.fontHeight)); + this.drawLetter(text[i], (x + (xOffset * (this.fontWidth + this.spacing))), y + (heightOffset * this.fontHeight)); xOffset++; } } diff --git a/src/js/utils.js b/src/js/utils.js index 15051af..9f6bcc2 100644 --- a/src/js/utils.js +++ b/src/js/utils.js @@ -1,36 +1,8 @@ // random shit -import { SCALE } from "./config"; - const params = new URLSearchParams(location.search); export const pi = Math.PI; -export const convertTileToScreen = (x, y) => ({x: x*SCALE, y: y*SCALE}); export const getParameter = key => key ? params.get(key) : 0; -export const hash = window.location.hash.split("?")[0].slice(1); - -// The following code is responsible for building levels. -const lineToCoords=(x0,y0,x1,y1,id=2)=>{const c=[];let dx=Math.abs(x1-x0),dy=Math.abs(y1-y0),sx=(x0<x1)?1:-1,sy=(y0<y1)?1:-1,err=dx-dy;while(true){c.push({x:x0,y:y0,id:id});if(x0===x1&&y0===y1)break;const e2=2*err;if(e2>-dy){err-=dy;x0+=sx}if(e2<dx){err+=dx;y0+=sy}}return c}; - -const generateBox = (x, y, width, height, fillTileId=1) => { - const box = []; - - for (let y = y; y < height; y++) { - for (let x = x; x < width; x++) { - box.push({ x, y, id: fillTileId }); - } - } - - return box; -} - -export const generateRoom = (x,y,width,height,lineId=2,fillId=1) => { - let top = lineToCoords(x, y, x+width, y, lineId); - let bottom = lineToCoords(x, y+height, x+width, y+height, lineId); - let left = lineToCoords(x, y, x, y+height, lineId); - let right = lineToCoords(x+width, y, x+width, y+height, lineId); - - let fill = generateBox(x+1, y+1, x+width-1, y+height-1, fillId); - - return [...top, ...bottom, ...left, ...right, ...fill]; -} +export const hash = _ => window.location.hash; +export const setHash = string => window.location.hash = string; -- GitLab