From 69a25b9f98c606ec7ebe07e3248c4caf13899b01 Mon Sep 17 00:00:00 2001 From: bye <bye@byecorps.com> Date: Thu, 22 Aug 2024 19:12:31 +0100 Subject: [PATCH] I am about to do something very drastic --- assets/font.aseprite | Bin 2788 -> 3128 bytes src/img/font.json | 346 ------------------------------------- src/img/font.webp | Bin 254 -> 246 bytes src/index.html | 23 ++- src/js/main.js | 28 +-- src/js/objects.js | 42 ++--- src/js/objects/player.js | 8 + src/js/rooms/debug_text.js | 4 +- src/js/rooms/game.js | 73 ++++++-- src/js/rooms/mainMenu.js | 6 +- 10 files changed, 121 insertions(+), 409 deletions(-) delete mode 100644 src/img/font.json create mode 100644 src/js/objects/player.js diff --git a/assets/font.aseprite b/assets/font.aseprite index cd7b4971ae6bd3bb043bb04813d1e54bf6af7dca..03036e2d1b5b702f8551d6fc5432286d3efd38cb 100644 GIT binary patch literal 3128 zcmcEEVPJT$RE>d+frCMTfsuiMA%y`MC^9gD1Q`Sv1dxTP#!h5pVEFZs1#Bw|0|SE? z0|NuQ0@z9<J037FFi0vWLPZpyG%{sp>h_<3p~}GZKLbOyUFm-Y2JX1j{|pQsUgiH8 z7?MIk>=)M7{}~wOxmx~bVECOa`=5c~Y=-TB28L#t*#8U+hgCxUGcZic$@$N~@WH?0 zKLdl@p5p%u46CP9fz<B=$xghT`JaKoH+9Q@28Ic7D?zq&_5WvJFnG8VBtHAue+Gtc zjg9{q82&7u@SlO<@rh|5z5m<(Gcc@Z`TU=O;nmu={}~wiFaHOTKOX&OVEF(4|9^P~ z1_l-dW+V^&2ZaNJPhw?ik%FNO0|Nsq)Yt!+V5&e-Rxu|zp@G3Vc>8~aGYu>gj!wvo zdG(?5@u4NNn)Ub?R9bX4x-ozPm=PSnpkOt_W7cNl(%<>*ZITTPGkeddhtG+6ws<uo z!_oj7O&2s%Oz@bJoRE;P!MOByKezFM#zrCcY0k$OR@bRsbVf777>^k!E|JeDEHPzZ z;j=0v#TgJI*o_x379G8Kc1fG10uRI9P`yk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Kk>`hpn*jp@V<dxsE1C(WcuinoVsm3t zNNAa0z;woy!_c6Kk%93&g9u6a5t<qkS|;!W2sz8F5n^BxAhk$fV05!M$)S9ZA(YRB ziGguGg8)e(k;1~vCg7m>a1oEdEJ2+k3=B-33}U2(L_!LvCRWm5RCZ+0;+e|Q&A`BT zfkA|{8VOu7D_rC-;ACJt&%j4gazF}338fQ{7?=VX#68d=(}K9j<mpLJ<dF6=YI@Sh z!oXzAAmWW?4ydHS-6nx1iWC-Mhe;C|m5y<UGM$E$lQj&IASe9#h-jN=K%K<Qz{r4T m-Y_w+F;vV+PDx2=aB^c{aAM%ZrH>K2z6K{ZHwFef22KEV8_>!C diff --git a/src/img/font.json b/src/img/font.json deleted file mode 100644 index 063b441..0000000 --- a/src/img/font.json +++ /dev/null @@ -1,346 +0,0 @@ -{ "frames": [ - { - "filename": "0", - "frame": { "x": 0, "y": 0, "w": 6, "h": 8 }, - "rotated": false, - "trimmed": false, - "spriteSourceSize": { "x": 0, "y": 0, "w": 6, "h": 8 }, - "sourceSize": { "w": 6, "h": 8 }, - "duration": 100 - }, - { - "filename": "1", - "frame": { "x": 6, "y": 0, "w": 6, "h": 8 }, - "rotated": false, - "trimmed": false, - "spriteSourceSize": { "x": 0, "y": 0, "w": 6, "h": 8 }, - "sourceSize": { "w": 6, "h": 8 }, - "duration": 100 - }, - { - "filename": "2", - "frame": { "x": 12, "y": 0, "w": 6, "h": 8 }, - "rotated": false, - "trimmed": false, - "spriteSourceSize": { "x": 0, "y": 0, "w": 6, "h": 8 }, - "sourceSize": { "w": 6, "h": 8 }, - "duration": 100 - }, - { - "filename": "3", - "frame": { "x": 18, "y": 0, "w": 6, "h": 8 }, - "rotated": false, - "trimmed": false, - "spriteSourceSize": { "x": 0, "y": 0, "w": 6, "h": 8 }, - "sourceSize": { "w": 6, "h": 8 }, - "duration": 100 - }, - { - "filename": "4", - "frame": { "x": 24, "y": 0, "w": 6, "h": 8 }, - "rotated": false, - "trimmed": false, - "spriteSourceSize": { "x": 0, "y": 0, "w": 6, "h": 8 }, - "sourceSize": { "w": 6, "h": 8 }, - "duration": 100 - }, - { - "filename": "5", - "frame": { "x": 30, "y": 0, "w": 6, "h": 8 }, - "rotated": false, - "trimmed": false, - "spriteSourceSize": { "x": 0, "y": 0, "w": 6, "h": 8 }, - "sourceSize": { "w": 6, "h": 8 }, - "duration": 100 - }, - { - "filename": "6", - "frame": { "x": 36, "y": 0, "w": 6, "h": 8 }, - "rotated": false, - "trimmed": false, - "spriteSourceSize": { "x": 0, "y": 0, "w": 6, "h": 8 }, - "sourceSize": { "w": 6, "h": 8 }, - "duration": 100 - }, - { - "filename": "7", - "frame": { "x": 0, "y": 8, "w": 6, "h": 8 }, - "rotated": false, - "trimmed": false, - "spriteSourceSize": { "x": 0, "y": 0, "w": 6, "h": 8 }, - "sourceSize": { "w": 6, "h": 8 }, - "duration": 100 - }, - { - "filename": "8", - "frame": { "x": 6, "y": 8, "w": 6, "h": 8 }, - "rotated": false, - "trimmed": false, - "spriteSourceSize": { "x": 0, "y": 0, "w": 6, "h": 8 }, - "sourceSize": { "w": 6, "h": 8 }, - "duration": 100 - }, - { - "filename": "9", - "frame": { "x": 12, "y": 8, "w": 6, "h": 8 }, - "rotated": false, - "trimmed": false, - "spriteSourceSize": { "x": 0, "y": 0, "w": 6, "h": 8 }, - "sourceSize": { "w": 6, "h": 8 }, - "duration": 100 - }, - { - "filename": "10", - "frame": { "x": 18, "y": 8, "w": 6, "h": 8 }, - "rotated": false, - "trimmed": false, - "spriteSourceSize": { "x": 0, "y": 0, "w": 6, "h": 8 }, - "sourceSize": { "w": 6, "h": 8 }, - "duration": 100 - }, - { - "filename": "11", - "frame": { "x": 24, "y": 8, "w": 6, "h": 8 }, - "rotated": false, - "trimmed": false, - "spriteSourceSize": { "x": 0, "y": 0, "w": 6, "h": 8 }, - "sourceSize": { "w": 6, "h": 8 }, - "duration": 100 - }, - { - "filename": "12", - "frame": { "x": 30, "y": 8, "w": 6, "h": 8 }, - "rotated": false, - "trimmed": false, - "spriteSourceSize": { "x": 0, "y": 0, "w": 6, "h": 8 }, - "sourceSize": { "w": 6, "h": 8 }, - "duration": 100 - }, - { - "filename": "13", - "frame": { "x": 36, "y": 8, "w": 6, "h": 8 }, - "rotated": false, - "trimmed": false, - "spriteSourceSize": { "x": 0, "y": 0, "w": 6, "h": 8 }, - "sourceSize": { "w": 6, "h": 8 }, - "duration": 100 - }, - { - "filename": "14", - "frame": { "x": 0, "y": 16, "w": 6, "h": 8 }, - "rotated": false, - "trimmed": false, - "spriteSourceSize": { "x": 0, "y": 0, "w": 6, "h": 8 }, - "sourceSize": { "w": 6, "h": 8 }, - "duration": 100 - }, - { - "filename": "15", - "frame": { "x": 6, "y": 16, "w": 6, "h": 8 }, - "rotated": false, - "trimmed": false, - "spriteSourceSize": { "x": 0, "y": 0, "w": 6, "h": 8 }, - "sourceSize": { "w": 6, "h": 8 }, - "duration": 100 - }, - { - "filename": "16", - "frame": { "x": 12, "y": 16, "w": 6, "h": 8 }, - "rotated": false, - "trimmed": false, - "spriteSourceSize": { "x": 0, "y": 0, "w": 6, "h": 8 }, - "sourceSize": { "w": 6, "h": 8 }, - "duration": 100 - }, - { - "filename": "17", - "frame": { "x": 18, "y": 16, "w": 6, "h": 8 }, - "rotated": false, - "trimmed": false, - "spriteSourceSize": { "x": 0, "y": 0, "w": 6, "h": 8 }, - "sourceSize": { "w": 6, "h": 8 }, - "duration": 100 - }, - { - "filename": "18", - "frame": { "x": 24, "y": 16, "w": 6, "h": 8 }, - "rotated": false, - "trimmed": false, - "spriteSourceSize": { "x": 0, "y": 0, "w": 6, "h": 8 }, - "sourceSize": { "w": 6, "h": 8 }, - "duration": 100 - }, - { - "filename": "19", - "frame": { "x": 30, "y": 16, "w": 6, "h": 8 }, - "rotated": false, - "trimmed": false, - "spriteSourceSize": { "x": 0, "y": 0, "w": 6, "h": 8 }, - "sourceSize": { "w": 6, "h": 8 }, - "duration": 100 - }, - { - "filename": "20", - "frame": { "x": 36, "y": 16, "w": 6, "h": 8 }, - "rotated": false, - "trimmed": false, - "spriteSourceSize": { "x": 0, "y": 0, "w": 6, "h": 8 }, - "sourceSize": { "w": 6, "h": 8 }, - "duration": 100 - }, - { - "filename": "21", - "frame": { "x": 0, "y": 24, "w": 6, "h": 8 }, - "rotated": false, - "trimmed": false, - "spriteSourceSize": { "x": 0, "y": 0, "w": 6, "h": 8 }, - "sourceSize": { "w": 6, "h": 8 }, - "duration": 100 - }, - { - "filename": "22", - "frame": { "x": 6, "y": 24, "w": 6, "h": 8 }, - "rotated": false, - "trimmed": false, - "spriteSourceSize": { "x": 0, "y": 0, "w": 6, "h": 8 }, - "sourceSize": { "w": 6, "h": 8 }, - "duration": 100 - }, - { - "filename": "23", - "frame": { "x": 12, "y": 24, "w": 6, "h": 8 }, - "rotated": false, - "trimmed": false, - "spriteSourceSize": { "x": 0, "y": 0, "w": 6, "h": 8 }, - "sourceSize": { "w": 6, "h": 8 }, - "duration": 100 - }, - { - "filename": "24", - "frame": { "x": 18, "y": 24, "w": 6, "h": 8 }, - "rotated": false, - "trimmed": false, - "spriteSourceSize": { "x": 0, "y": 0, "w": 6, "h": 8 }, - "sourceSize": { "w": 6, "h": 8 }, - "duration": 100 - }, - { - "filename": "25", - "frame": { "x": 24, "y": 24, "w": 6, "h": 8 }, - "rotated": false, - "trimmed": false, - "spriteSourceSize": { "x": 0, "y": 0, "w": 6, "h": 8 }, - "sourceSize": { "w": 6, "h": 8 }, - "duration": 100 - }, - { - "filename": "26", - "frame": { "x": 30, "y": 24, "w": 6, "h": 8 }, - "rotated": false, - "trimmed": false, - "spriteSourceSize": { "x": 0, "y": 0, "w": 6, "h": 8 }, - "sourceSize": { "w": 6, "h": 8 }, - "duration": 100 - }, - { - "filename": "27", - "frame": { "x": 36, "y": 24, "w": 6, "h": 8 }, - "rotated": false, - "trimmed": false, - "spriteSourceSize": { "x": 0, "y": 0, "w": 6, "h": 8 }, - "sourceSize": { "w": 6, "h": 8 }, - "duration": 100 - }, - { - "filename": "28", - "frame": { "x": 0, "y": 32, "w": 6, "h": 8 }, - "rotated": false, - "trimmed": false, - "spriteSourceSize": { "x": 0, "y": 0, "w": 6, "h": 8 }, - "sourceSize": { "w": 6, "h": 8 }, - "duration": 100 - }, - { - "filename": "29", - "frame": { "x": 6, "y": 32, "w": 6, "h": 8 }, - "rotated": false, - "trimmed": false, - "spriteSourceSize": { "x": 0, "y": 0, "w": 6, "h": 8 }, - "sourceSize": { "w": 6, "h": 8 }, - "duration": 100 - }, - { - "filename": "30", - "frame": { "x": 12, "y": 32, "w": 6, "h": 8 }, - "rotated": false, - "trimmed": false, - "spriteSourceSize": { "x": 0, "y": 0, "w": 6, "h": 8 }, - "sourceSize": { "w": 6, "h": 8 }, - "duration": 100 - }, - { - "filename": "31", - "frame": { "x": 18, "y": 32, "w": 6, "h": 8 }, - "rotated": false, - "trimmed": false, - "spriteSourceSize": { "x": 0, "y": 0, "w": 6, "h": 8 }, - "sourceSize": { "w": 6, "h": 8 }, - "duration": 100 - }, - { - "filename": "32", - "frame": { "x": 24, "y": 32, "w": 6, "h": 8 }, - "rotated": false, - "trimmed": false, - "spriteSourceSize": { "x": 0, "y": 0, "w": 6, "h": 8 }, - "sourceSize": { "w": 6, "h": 8 }, - "duration": 100 - }, - { - "filename": "33", - "frame": { "x": 30, "y": 32, "w": 6, "h": 8 }, - "rotated": false, - "trimmed": false, - "spriteSourceSize": { "x": 0, "y": 0, "w": 6, "h": 8 }, - "sourceSize": { "w": 6, "h": 8 }, - "duration": 100 - }, - { - "filename": "34", - "frame": { "x": 36, "y": 32, "w": 6, "h": 8 }, - "rotated": false, - "trimmed": false, - "spriteSourceSize": { "x": 0, "y": 0, "w": 6, "h": 8 }, - "sourceSize": { "w": 6, "h": 8 }, - "duration": 100 - }, - { - "filename": "35", - "frame": { "x": 0, "y": 40, "w": 6, "h": 8 }, - "rotated": false, - "trimmed": false, - "spriteSourceSize": { "x": 0, "y": 0, "w": 6, "h": 8 }, - "sourceSize": { "w": 6, "h": 8 }, - "duration": 100 - }, - { - "filename": "36", - "frame": { "x": 6, "y": 40, "w": 6, "h": 8 }, - "rotated": false, - "trimmed": false, - "spriteSourceSize": { "x": 0, "y": 0, "w": 6, "h": 8 }, - "sourceSize": { "w": 6, "h": 8 }, - "duration": 100 - } - ], - "meta": { - "app": "https://www.aseprite.org/", - "version": "1.3.7-arm64", - "image": "font.webp", - "format": "I8", - "size": { "w": 42, "h": 48 }, - "scale": "1", - "slices": [ - ] - } -} diff --git a/src/img/font.webp b/src/img/font.webp index fad7b19026b5af571b749beb30d8c48767a8c388..2651a7a87011292037e183666590e68581b3725b 100644 GIT binary patch literal 246 zcmWIYbaQ*hz`zjh>J$(bVBzzSfq_B)@c~8wego6T#%`bGKQtug-hP;)wk`Cf_w=l1 zM~(@lu}8MNofNt%=TL0jmbBE{&&1a&F8a?k*(~9WMcPXxR{5}nv+Ijy-q`=6dgGKh zxeslB%D*c%DOmR{b<OEaepnw7?l1Gpu=U*f1rtP$T2&dXJib@*u-g}*w*sQFNj|@y z%(>B)_fgR)p1En_>Gg^kaaJ#!{3=vRov!mUiZfcsYfe?ME?xb&_(Q(Mujz7)4-Xta zk>O&j^L2;vY`$9KfVw~i{lyCef4zEf(v?e2@B7&gPbO8@cWZxL`nP?*o$Vr<O-dXL E0CCQ7jsO4v literal 254 zcmWIYbaVU0z`zjh>J$(bVBzzMfq_9^^8mL1m*+$k&q*y=KbpH&tVvG$zE&-0zSP%x zrXQVZvace7Jr_1Pv9hwZ{+s7qu61@Pm*_6$)}!lJya<@?Jaw^i$cB)N#c#G>s!<I8 z<mboJTdD5<aGKnO-dz{CcWXIc4-ZPcxagE{E0-wOq6+V8{wvD0d^d+LxNyO|%Ar#$ zeO1n?0FkI$WuY1&wk=I6P4gOh9?6|_bkj>)*YYgX?^K3Lc1w|va_EYs0e+hvI!z4= zwF*<+Jk@LUL4lIQv!#xX>akBW^;a(PTpD~<)iKR+!d8VRt$9y$R^_Z(v1#R^PhS_= MG5vSH=x)ai09p@l2LJ#7 diff --git a/src/index.html b/src/index.html index 70a38e3..e70b4a8 100644 --- a/src/index.html +++ b/src/index.html @@ -4,11 +4,24 @@ background: #1a1a1a; } canvas { - width: 100vw; - height: 100vh; - object-fit: contain; + width: 256px; + height: 240px; + position:fixed;top:50%;left:50%;translate:-50% -50%; image-rendering: pixelated; } </style> -<canvas id="canvas"></canvas> -<script src="./main.js"></script> \ No newline at end of file +<canvas id="c"></canvas> +<script src="./main.js"></script> +<script> + fl = Math.floor; + u = _=>{ + w = innerWidth; + h = innerHeight; + wS = fl(w/256); + hS = fl(h/256); + s=Math.min(wS,hS); + c.style.width = 256*s; + c.style.height= 240*s; + } + u();addEventListener('resize', u, !0); +</script> \ No newline at end of file diff --git a/src/js/main.js b/src/js/main.js index c97615e..1e064f5 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -1,6 +1,7 @@ import Canvas from "../../hampsterengine/src/canvas.js"; import Engine from "../../hampsterengine/src/engine.js"; +import {FontRenderer} from "./objects"; import SoundBox from "./sb-player-small"; // import {mus_DEMOSONG} from "./songs/DEMOSONGDONOTCOMMIT"; @@ -20,13 +21,12 @@ import {rm_DEBUG_music} from "./rooms/debug_music"; import {rm_DEBUG_INCURSION} from "./rooms/debug_incursion"; import {rm_DEBUG_text} from "./rooms/debug_text"; import Mouse from "../../hampsterengine/src/mouse"; -import {FontRenderer} from "./objects"; // Music // There is none // Init the engine and canvas -const canvas = new Canvas('canvas'); +const canvas = new Canvas('c'); const engine = new Engine(canvas); const assets = engine.assetStore; assets.addImage('font', font); @@ -36,9 +36,9 @@ window.fR = fontRenderer // const mouse = new Mouse(engine); // window.mouse = mouse; -canvas.width = 256*4; -canvas.height = 240*4; -canvas.pixelRatio = 4; +canvas.width = 256 * 2; +canvas.height = 240 * 2; +canvas.pixelRatio = 2; canvas.ctx.setTransform(canvas.pixelRatio, 0, 0, canvas.pixelRatio, 0, 0); canvas.ctx.imageSmoothingEnabled = false; @@ -61,13 +61,16 @@ engine.registerRoom(rm_DEBUG_text, 'debug_text'); // stats.showPanel(0); // document.body.appendChild( stats.dom ); +let physicsFrame=0; + function main() { + // Draw things. no user interaction or physics here. + try { // stats.begin(); engine.frames++; canvas.fill(engine.room.bgColor ?? 'black'); - engine.step(); engine.draw(); engine.drawGui(); @@ -75,6 +78,10 @@ function main() { // stats.end(); + if (query.get('debug')) { + + } + // Ask to run at the next frame requestAnimationFrame(main); } catch (e) { @@ -98,11 +105,10 @@ function main() { } function physicsTick() { - if (!engine.running) return; // Paused - // Tell every object to process physics - for (let thing of engine.room.entities) { - thing.physicsTick(); - } + // Runs 60 times a second regardless of frame rate. + physicsFrame++; + + if (engine.running) engine.room.step(); } console.debug(engine.rooms); diff --git a/src/js/objects.js b/src/js/objects.js index ddaa16d..7648691 100644 --- a/src/js/objects.js +++ b/src/js/objects.js @@ -1,5 +1,6 @@ -import {Entity} from "../../hampsterengine/src/things"; +import {Entity, PhysicsEntity} from "../../hampsterengine/src/things"; import ButtonBorder from "../img/button.webp"; +import {rm_game} from "./rooms/game"; // Private @@ -146,22 +147,23 @@ export class FontRenderer { const code = char.charCodeAt(); let slice; if (code < 90 && code > 64) slice = code - 65; // Starts at 0 (LETTER) - else if (code < 58 && code > 48) slice = 25 + (code - 59) // Starts at 25 - else if (code === 91) slice = 35; - else if (code === 93) slice = 36; - else slice = 37; + else if (code < 58 && code >= 48) slice = 25 + (code - 47) // Starts at 25 + else if (code === 91) slice = 36; + else if (code === 93) slice = 37; + else slice = 38; + if (slice < 0) { canvas.setFillColor('red'); // debugger } - else canvas.setFillColor('black'); - // canvas.drawText(`${Math.round(slice)}`, x+(i*(this.w+1)), y, {}) + else canvas.setFillColor('green'); + // canvas.drawText(`${slice}`, x+(i*(this.w+1)), y, {}) canvas.sliceImage( this.font, x+(i*(this.w+1)), y, this.w, this.h, - this.w * (slice % 7), this.h * Math.round(slice / 7), this.w, this.h); + this.w * slice, 0, this.w, this.h); } } @@ -172,27 +174,3 @@ export class FontRenderer { } } } - -// ENTITIES - -export class Player extends Entity { - constructor() { - super(); - this.height=16; - this.width=10; - this.velocity = { - x:0, y:0 - }; - } - - draw() { - canvas.setFillColor('red'); - canvas.fillRect(this.x,this.y,this.width,this.height); - } - - physicsTick() { - // Physics update 60 times a second - this.y += this.velocity.y/60; - this.x += this.velocity.x/60; - } -} diff --git a/src/js/objects/player.js b/src/js/objects/player.js new file mode 100644 index 0000000..fdffe1a --- /dev/null +++ b/src/js/objects/player.js @@ -0,0 +1,8 @@ +import {Entity, PhysicsEntity} from "../../../hampsterengine/src/things"; + +export default class Player extends PhysicsEntity { + draw() { + canvas.setFillColor('red'); + canvas.fillRect(this.x,this.y,10,16); + } +} diff --git a/src/js/rooms/debug_text.js b/src/js/rooms/debug_text.js index 2f0e3f6..96dfeb0 100644 --- a/src/js/rooms/debug_text.js +++ b/src/js/rooms/debug_text.js @@ -7,8 +7,8 @@ const sample_text = `haiiiiiii this is the text test room if you're here, welcome! why are you looking at the debug rooms??? they're boring!! im not hiding any cut content here. i dont have time for that - -here is the same message with a pixel art font:` +here is the same message with a pixel art font: +ze fucking font isnt working` rm_DEBUG_text.drawGui = _=>{ canvas.setFillColor('black'); diff --git a/src/js/rooms/game.js b/src/js/rooms/game.js index 02ded7a..6f9d1ea 100644 --- a/src/js/rooms/game.js +++ b/src/js/rooms/game.js @@ -1,26 +1,79 @@ -import {Room} from "../../../hampsterengine/src/things"; -import {Player} from "../objects"; +import {collideRect, Entity, PhysicsEntity, resolveElastic, Room} from "../../../hampsterengine/src/things"; +import Player from "../objects/player"; import {GRAVITY} from "../extras"; export const rm_game = new Room(); +const GRAVITY_X = 0; +const GRAVITY_Y = 0.0003; + rm_game.start = _=>{ - canvas.pixelRatio = 3; - canvas.ctx.setTransform(canvas.pixelRatio, 0, 0, canvas.pixelRatio, 0, 0); - canvas.canvas.style.cursor = 'none'; engine.running = true; } + rm_game.stop = _=>{ - canvas.canvas.style.cursor = 'auto'; engine.running = false; - } + rm_game.step = _=>{ + const elapsed = (1000/60); // runs 60 times a second + const gx = GRAVITY_X*elapsed; + const gy = GRAVITY_Y*elapsed; + const entities = rm_game.entities; + + for (let i = 0; i < entities.length; i++) { + let entity = entities[i]; + entity.updateBounds(); + + switch (entity.type) { + case PhysicsEntity.DYNAMIC: + entity.vx += entity.ax * elapsed + gx; + entity.vy += entity.ay * elapsed + gy; + entity.x += entity.vx * elapsed; + entity.y += entity.vy * elapsed; + break; + case PhysicsEntity.KINEMATIC: + entity.vx += entity.ax * elapsed; + entity.vy += entity.ay * elapsed; + entity.x += entity.vx * elapsed; + entity.y += entity.vy * elapsed; + break; + } + + // Check if the entity is colliding with another entity + for (let k = 0; k < entities.length; k++) { + if (k === i) { + // console.debug('SAME') + continue; + } + if (collideRect(entities[i], entities[k])) { + console.debug('COLLIDE'); + resolveElastic(entities[i], entities[k]); + } + } + } +} + +rm_game.drawGui = _ => { + // Draw the player's position + canvas.setFillColor('black'); + canvas.drawText(`(${player.x},${player.y})`, 10, canvas.height-10, { + maxWidth: canvas.width-20 + }); } const player = new Player(); -player.velocity.x = 0; -player.velocity.y = 0; -player.direction = 0;// Radians +// player.ay = 0.1; +player.x = 40; rm_game.entities.push(player); + +const floor = new PhysicsEntity(); +floor.type = PhysicsEntity.KINEMATIC; +// floor.resitution = 0; +floor.ay = 0.00000001; +floor.height = 10; +floor.width = 240*2; +floor.x = -(240/2); +floor.y = 160; +rm_game.entities.push(floor); diff --git a/src/js/rooms/mainMenu.js b/src/js/rooms/mainMenu.js index 1d55188..a76925b 100644 --- a/src/js/rooms/mainMenu.js +++ b/src/js/rooms/mainMenu.js @@ -13,7 +13,7 @@ rm_mainMenu.entities.push(logo); rm_mainMenu.drawGui = _ => { canvas.setFillColor('#0f0f0f'); - canvas.drawText("Press [ENTER] to start.", 30, canvas.height-55, {}); - canvas.drawText("(c) bye 2024", 30, canvas.height-35, {}); - canvas.drawText("Uses 3rd-party licenses. Press [L] to read.", 30, canvas.height-25, {}); + fR.draw("Press [ENTER] to start.", 30, canvas.height-35); + fR.draw("[c] bye 2024", 30, canvas.height-16); + // fR.draw("Uses 3rd-party licenses. Press [L] to read.", 30, canvas.height-16, {}); } \ No newline at end of file -- GitLab