From 927b93f19d0fee4ec5cf47a973ad7df8672b2a2f Mon Sep 17 00:00:00 2001 From: Bye <bye@byecorps.com> Date: Tue, 20 Aug 2024 19:09:44 +0100 Subject: [PATCH] i forgor --- README.md | 4 +- assets/font.aseprite | Bin 0 -> 2788 bytes assets/fontSheet.aseprite | Bin 0 -> 813 bytes hampsterengine | 2 +- package.json | 4 +- src/img/font.json | 346 +++++++++++++++++++++++++++++++++ src/img/font.webp | Bin 0 -> 254 bytes src/js/main.js | 45 +++-- src/js/objects.js | 47 +++++ src/js/rooms/debug_mouse.js | 8 +- src/js/rooms/debug_text.js | 21 ++ src/js/rooms/mainMenu.js | 14 +- {configs => utils}/size.js | 0 utils/sprite_editor/index.html | 30 +++ 14 files changed, 487 insertions(+), 34 deletions(-) create mode 100644 assets/font.aseprite create mode 100644 assets/fontSheet.aseprite create mode 100644 src/img/font.json create mode 100644 src/img/font.webp create mode 100644 src/js/rooms/debug_text.js rename {configs => utils}/size.js (100%) create mode 100644 utils/sprite_editor/index.html diff --git a/README.md b/README.md index 7773cf3..5e68628 100644 --- a/README.md +++ b/README.md @@ -2,5 +2,7 @@ ## External code -This entry uses [player-small.js](https://sb.bitsnbites.eu/player-small.js) from SoundBox. `player-small.js` is licensed +- [player-small.js](https://sb.bitsnbites.eu/player-small.js) from SoundBox. `player-small.js` is licensed under [the zlib/libpng License](https://opensource.org/license/Zlib). + +- diff --git a/assets/font.aseprite b/assets/font.aseprite new file mode 100644 index 0000000000000000000000000000000000000000..cd7b4971ae6bd3bb043bb04813d1e54bf6af7dca GIT binary patch literal 2788 zcmaFD#lY}jsVV~-0|x^K10w?iLka^jP-I{P2{H&U2p|hnjUB<r!0_uM3)of`1_lN( z1_lOp1+bM!c06EUV31T$go-FYX=KXI)a^e5LzRK+e+GtZyVCy*4BT<4{}~uOyvqMG zFeHV7*e|TD|1&VmbG7`>!0<a;_CEu|*$mtN3=GXOvHuwu4y%OxXJD9?lk=Z};e&t0 ze+CA*J;nbS7*<cI0;%5#lAU-v^FITFZ|au+3=9+ER)TEl>i^HcVDNA!NPPCQ{|pS@ z8XNyJF#K6Q;Xebz;}g?BdjGfmXJA;-^7%gl!>hG#|1&W3U;Ymwe?0on!0`Y7|Nrs~ z3=Av^%t#*k4+;kcpTx@4A_YTZ1_lOJsIUJs!Bl~wtYS`bLPAPP0)t?Wf!LH5h7>^o zP6npw4AKq^pm1dbhbt&F4e%L}!otL+kd%<%qH1{5k%xg<f<fLEO}{Qa{Ru4$Yzhbb zjT){pGBCw4h})rQ*2AY6X1R(>lLQ0P8wOd@bc3vRP<3pQQ0ie|y38O$lEYJAx@SCM zU^>YlVUOl;eS8iF``ST$;iCYdL#zx;GZ>^ub9qWaLPE+BCntto77R?s8DvP)&BDmW zCUDHZNz{mmfvJW;k|d|6urRU-9Pn&<Dk*t@i;?jagRmQ#&&}}pJO%9ZmdQO1U5$c@ zEQ!uX8$}qHCNfA`qnV<O-xLNWw?!TT3=E8q7(_`+upkGpFljI@Qc$|#$-wlTLB<)) zYP@*{>;V=gl}U|)oh}no5?H`#o+KwEK=aHIf1`#_CI+T$Waqhuk2F*mn0_-zkr;)r zJiD=*nSoh=LDmH=1WfP+KFIlQYzhrQ4s1Pc&zMpjwHO&MG6<0tf#5W#*2coXl*b@S zTJi-&V2Vl;%f%iZ2Bt0sDMvKN8{%_3IQmkKcr#_PaZGPyWMFDykRZnZU!x`u4Mq`0 z2BwwdB%l-*B}a}U4T26GD%=cA+6<y3#Q@Y33XUc-ScMWBx(yf@n3@?RN%Kbw0~;Hg zfSZzlPlpZ*0|S!}gSZn~NE+b_NpR(nkdVSKk>`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 literal 0 HcmV?d00001 diff --git a/assets/fontSheet.aseprite b/assets/fontSheet.aseprite new file mode 100644 index 0000000000000000000000000000000000000000..cf6fbfad09826c5ed718aa5abfbd7341bea72d62 GIT binary patch literal 813 zcmdO8W?*=*l#xM;!GJ-5fsuiMA%y`MC^9gD1Q`Sv1dxTP#$L<B!0_uM3)of`1_lN( z1_lOp1+bM!c06EUV31T$go-FYX=KXI)a^e5LzRK+e+GtZyVCy*4BT<4{}~uOyvqMG zFeHV7*e|TD|1&VmbG7`>!0<a;_CEu|*$mtN3=GXOvHuwu4y%OxXJD9?lk=Z};e&t0 ze+CA*J;nbS7*<cI0;%5#lAU-v^FITFZ|au+3=9+ER)TEl>i^HcVDNA!NPPCQ{|pS@ z8XNyJF#K6Q;Xebz;}g?BdjGfmXJA;-^7%gl!>hG#|1&W3U;Ymwe?0on!0`Y7|Nrs~ z3=Av^%t#*k4+;kcpTx@4A_c<^Mg|5}sIUJs!BlB6=rdHzc{}AG-(dp|=g+~r-|hJS zf3fdnJyE9H0kf6`Ppr~VJ!h;a`&j(^@z;NA+bZwdy@(E3e{GZLw2P-JYYw}(*P6+{ zyg#SP&e}Ti+$o-_Qtj`b=UeQZb!v`*@0R_C=GXSUus@}2`^5hA$#+*T&UvvX$1cfs zR&eC{FYz-!YNc-}7hk@1ebK7dS1Z$OJH8nGGPbyAvtZ7u#YI)~1i4SAmuStI`!jJ- za^0@a(@rPHwHn{5XG>4BQ~oA7XN|tx<mvIPn_tV_%)ck~z9#gXhx^CnSL7|v&;4Wk zkN<FsZSZaL_4~TpH!6IyopZwaanCo`H`C5WPriBm*Xds&mKSZEW_6`M>HHbCb9MRU z%K@)K=bzDk)%@vw;=RScy7)ecey!E7Z&SC@KXQJb<}caGrRTYlr@CK#`RvZS!{_!I zg}+*3XkYz%+SL;;HvIQjPcL03uzA+$IpV9_txm|#KDgTL$!i}q{Y~GWui0T){n%^H N>U)d%{~j(f0RT#_D}ew2 literal 0 HcmV?d00001 diff --git a/hampsterengine b/hampsterengine index fbfeacd..87eea2e 160000 --- a/hampsterengine +++ b/hampsterengine @@ -1 +1 @@ -Subproject commit fbfeacd075bf597acf3de2b5f803cd46ca6583df +Subproject commit 87eea2e2f818e955307768a179031c2111e43061 diff --git a/package.json b/package.json index e1117a3..6b56efc 100644 --- a/package.json +++ b/package.json @@ -5,10 +5,10 @@ "dev:js": "esbuild src/js/main.js --bundle --watch --sourcemap --format=iife --loader:.webp=dataurl --outfile=build/main.js", "dev:html": "browser-sync build src --watch --https", "build": "run-s clear build:*", - "build:js": "esbuild src/js/main.js --bundle --minify --format=iife --loader:.webp=dataurl --outfile=build/main.js", + "build:js": "esbuild src/js/main.js --bundle --format=iife --loader:.webp=dataurl | terser -c -m --mangle-props keep_quoted -o build/main.js", "build:html": "html-inline src/index.html -b build | html-minifier -c configs/html-minifier.json -o build/index.html", "build:zip": "zip -FS -qjX9 build/game.zip build/index.html && advzip -z -4 build/game.zip", - "build:zipSize": "node configs/size.js" + "build:zipSize": "node utils/size.js" }, "devDependencies": { "advzip-bin": "^2.0.0", diff --git a/src/img/font.json b/src/img/font.json new file mode 100644 index 0000000..063b441 --- /dev/null +++ b/src/img/font.json @@ -0,0 +1,346 @@ +{ "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 new file mode 100644 index 0000000000000000000000000000000000000000..fad7b19026b5af571b749beb30d8c48767a8c388 GIT binary patch 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 literal 0 HcmV?d00001 diff --git a/src/js/main.js b/src/js/main.js index 585c46e..c97615e 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -6,7 +6,10 @@ import SoundBox from "./sb-player-small"; // import {mus_DEMOSONG} from "./songs/DEMOSONGDONOTCOMMIT"; // dependencies used for debugging. comment out code that uses this and they won't be included -import Stats from "stats.js"; +// import Stats from "stats.js"; + +// Images +import font from "../img/font.webp"; // Rooms import {rm_mainMenu} from "./rooms/mainMenu"; @@ -15,6 +18,9 @@ import {rm_DEBUG_button} from "./rooms/debug_button"; import {rm_DEBUG_mouse} from "./rooms/debug_mouse"; 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 @@ -23,34 +29,41 @@ import {rm_DEBUG_INCURSION} from "./rooms/debug_incursion"; const canvas = new Canvas('canvas'); const engine = new Engine(canvas); const assets = engine.assetStore; +assets.addImage('font', font); + +const fontRenderer = new FontRenderer(assets.get('font')); +window.fR = fontRenderer +// const mouse = new Mouse(engine); +// window.mouse = mouse; -canvas.width = 640; -canvas.height = 480; -canvas.pixelRatio = 2; +canvas.width = 256*4; +canvas.height = 240*4; +canvas.pixelRatio = 4; canvas.ctx.setTransform(canvas.pixelRatio, 0, 0, canvas.pixelRatio, 0, 0); canvas.ctx.imageSmoothingEnabled = false; engine.running = false; // Game uses this as a pause state actually // Parse query parameters -const query = new URLSearchParams(window.location.search) +const query = new URLSearchParams(window.location.search); engine.registerRoom(rm_mainMenu, 'mainMenu'); engine.registerRoom(rm_game, 'game'); -engine.registerRoom(rm_DEBUG_button, 'debug_button'); -engine.registerRoom(rm_DEBUG_mouse, 'debug_mouse'); +// engine.registerRoom(rm_DEBUG_button, 'debug_button'); +// engine.registerRoom(rm_DEBUG_mouse, 'debug_mouse'); // engine.registerRoom(rm_DEBUG_music, 'debug_music'); engine.registerRoom(rm_DEBUG_INCURSION, 'debug_incursion'); +engine.registerRoom(rm_DEBUG_text, 'debug_text'); // Init stats.js -const stats = new Stats(); -stats.showPanel(0); -document.body.appendChild( stats.dom ); +// const stats = new Stats(); +// stats.showPanel(0); +// document.body.appendChild( stats.dom ); function main() { try { - stats.begin(); + // stats.begin(); engine.frames++; canvas.fill(engine.room.bgColor ?? 'black'); @@ -60,7 +73,7 @@ function main() { // engine.drawCursor(); - stats.end(); + // stats.end(); // Ask to run at the next frame requestAnimationFrame(main); @@ -75,10 +88,12 @@ function main() { canvas.drawImage(logo, 10, 10, logo.width, logo.height) canvas.setFillColor('black'); - canvas.drawText(e, 10, canvas.height-10, { - maxWidth: canvas.width-20, + canvas.drawText(e, 5, canvas.height-5, { + maxWidth: canvas.width-10, textBaseline: 'bottom' }); + + throw e; } } @@ -102,7 +117,6 @@ if (query.get('room')) { // Ensure assets are loaded. function load() { - stats.begin(); if (engine.loading) { engine.loadLoop(); setTimeout(load, 1000/60); @@ -110,7 +124,6 @@ function load() { main(); setInterval(physicsTick, 1000/60); // Update physics 60 times a second } - stats.end(); } load(); diff --git a/src/js/objects.js b/src/js/objects.js index f9dbd59..ddaa16d 100644 --- a/src/js/objects.js +++ b/src/js/objects.js @@ -126,6 +126,53 @@ export class Logo extends Entity { } +export class FontRenderer { + constructor(font) { + this.font = font; + this.h = 8; + this.w = 6; + } + + draw(text, x, y) { + text = text.toUpperCase(); + let split + try{ + split = text.split(""); + } catch (TypeError) { + return; + } + for (let i = 0; i < split.length; i++) { + const char = split[i]; + 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; + + if (slice < 0) { + canvas.setFillColor('red'); + // debugger + } + else canvas.setFillColor('black'); + // canvas.drawText(`${Math.round(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); + } + } + + drawLines(text, x, y) { + const lines = text.split(/\n/); + for (let i = 0; i < lines.length; i++) { + this.draw(lines[i], x, y+(i*(this.h+1))); + } + } +} + // ENTITIES export class Player extends Entity { diff --git a/src/js/rooms/debug_mouse.js b/src/js/rooms/debug_mouse.js index 22389fc..866410c 100644 --- a/src/js/rooms/debug_mouse.js +++ b/src/js/rooms/debug_mouse.js @@ -6,18 +6,18 @@ export const rm_DEBUG_mouse = new Room(); rm_DEBUG_mouse.drawGui = _=> { // Draw the last click - const lastClick = engine.lastClickPos; + const lastClick = mouse.lastClickPos; canvas.setFillColor('red'); canvas.setStrokeColor('red'); canvas.drawLine(lastClick.x, 0, lastClick.x, canvas.height); canvas.drawLine(0, lastClick.y, canvas.width, lastClick.y); canvas.drawText(`LAST(${Math.round(lastClick.x)},${Math.round(lastClick.y)})`, lastClick.x+2, lastClick.y-2, {}) - const cur = engine.mouse; + const cur = mouse.mouse; - if (engine.mouseDown) { + if (mouse.mouseDown) { // Draw the mousedown position - const moused = engine.mouseDownPos; + const moused = mouse.mouseDownPos; canvas.setFillColor('green'); canvas.setStrokeColor('green'); canvas.drawLine(moused.x, 0, moused.x, canvas.height); diff --git a/src/js/rooms/debug_text.js b/src/js/rooms/debug_text.js new file mode 100644 index 0000000..2f0e3f6 --- /dev/null +++ b/src/js/rooms/debug_text.js @@ -0,0 +1,21 @@ + +import {Room} from "../../../hampsterengine/src/things"; + +export const rm_DEBUG_text = new Room(); + +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:` + +rm_DEBUG_text.drawGui = _=>{ + canvas.setFillColor('black'); + + canvas.drawText(sample_text, canvas.center.x, 10, { + textBaseline: 'top', textAlign: 'center', maxWidth: canvas.width-20, size: 16 + }) + + fR.drawLines(sample_text, 10, canvas.center.y); +} diff --git a/src/js/rooms/mainMenu.js b/src/js/rooms/mainMenu.js index 3b4782b..1d55188 100644 --- a/src/js/rooms/mainMenu.js +++ b/src/js/rooms/mainMenu.js @@ -10,16 +10,10 @@ logo.y = 45; logo.align = 2 rm_mainMenu.entities.push(logo); -const newGameButton = new MainMenuButton('New Game', _=>{ - engine.room = engine.getRoomIndex('game'); -}); -newGameButton.x = 30; -newGameButton.y = 70; -rm_mainMenu.entities.push(newGameButton); - rm_mainMenu.drawGui = _ => { canvas.setFillColor('#0f0f0f'); - canvas.drawText("(c) bye 2024", 30, canvas.height-25,{ - font: '8px serif' - }); + + 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, {}); } \ No newline at end of file diff --git a/configs/size.js b/utils/size.js similarity index 100% rename from configs/size.js rename to utils/size.js diff --git a/utils/sprite_editor/index.html b/utils/sprite_editor/index.html new file mode 100644 index 0000000..613f182 --- /dev/null +++ b/utils/sprite_editor/index.html @@ -0,0 +1,30 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="UTF-8"> + <title>Sprite editor</title> +</head> +<body> + <canvas id=a> + <script> + ctx=a.getContext`2d` // ctx + pallette="000f000f000fff00fff0f" // color palette (you can remove the colors you didn't use to save bytes) + pixels=[]; + "@@@@HHA@@A@@HIIAACCHQCSHARBHHIIA".replace(/./g, + character=>{ + characterCode=character.charCodeAt(), + pixels.push(characterCode&7), // Gets the last three bits + pixels.push((characterCode>>3)&7) // Gets the first three bits + }) // pixel decoding + size=8; + for (let y = 0; y < size; y++) { + for (let x = 0; x < size; x++) { + if (pixels[y * size + x]) { + ctx.fillStyle = "#" + pallette.substr(3 * (pixels[y * size + x] - 1), 3), + ctx.fillRect(x, y, 1, 1) + } + } + } // drawing + </script> +</body> +</html> \ No newline at end of file -- GitLab