@@ -24,7 +24,7 @@ I quickly decided it was going to (a) be a platformer game and (b) be playable i
2424Digging through old git commit history, here's the very first test I ever made using KAPLAY. It is date-stamped July 19.
2525
2626%%% figure
27- <iframe src = " kdemo.html " height =" 125 " width =" 450 " style =" margin-left :auto ;margin-right :auto " ></iframe >
27+ <canvas id = " a " height =" 125 " width =" 450 " style =" margin-left :auto ;margin-right :auto " ></canvas >
2828
2929 %: You can click on the canvas and use the <kbd>←</kbd> and <kbd>→</kbd> arrow keys to move the red rectangle (the player) and the <kbd>↑</kbd> key to jump. There's not much to do, but hey... it works!
3030
@@ -63,3 +63,78 @@ I turned him down, mostly because I knew that I should be prioritizing my studie
6363I'd say it's been a productive 3 months.
6464
6565<!-- cSpell: ignore kaplay -->
66+ <!-- markdownlint-disable no-reversed-links -->
67+
68+ <script async type =" module " >
69+ import kaboom from " https://unpkg.com/kaplay@3001.0.0-alpha.18/dist/kaboom.mjs" ;
70+ const canvas = document .getElementById (" a" );
71+ // Hack to make focus() not get called, since the focus
72+ // option doesn't seem to work.
73+ Object .defineProperty (canvas, " focus" , {
74+ value () {
75+ console .log (" skipping focusing canvas:" , this );
76+ }
77+ });
78+ const k = kaboom ({
79+ crisp: true ,
80+ background: " #000000" ,
81+ focus: false ,
82+ canvas,
83+ global: false
84+ });
85+ k .setGravity (300 );
86+ const level = k .addLevel ([
87+ " ==========================" ,
88+ " = =" ,
89+ " = =" ,
90+ " = ===== =" ,
91+ " = @ =" ,
92+ " = ^^ ============" ,
93+ " =============== "
94+ ], {
95+ tileWidth: 16 ,
96+ tileHeight: 16 ,
97+ pos: k .vec2 (20 , 20 ),
98+ tiles: {
99+ " @ " : () => [
100+ k .rect (15 , 31 ),
101+ k .area (),
102+ k .body ({ jumpForce: 150 , maxVelocity: 400 }),
103+ k .anchor (" bot" ),
104+ k .color (" #ff0000" ),
105+ k .z (Infinity ),
106+ " player"
107+ ],
108+ " ^ " : () => [
109+ k .rect (16 , 16 ),
110+ k .area (),
111+ k .anchor (" bot" ),
112+ k .color (" #ffff00" ),
113+ " coin"
114+ ],
115+ " = " : () => [
116+ k .rect (16 , 16 ),
117+ k .area (),
118+ k .body ({ isStatic: true }),
119+ k .anchor (" bot" ),
120+ k .color (" #0000ff" ),
121+ " ground"
122+ ],
123+ }
124+ });
125+ const player = level .get (" player" )[0 ];
126+ // ?!? hacky ?!?
127+ player .vel = k .vec2 (0 , - 100 );
128+ k .onKeyDown (" up" , () => {
129+ if (player .isGrounded ()) {
130+ player .jump ();
131+ }
132+ });
133+ const SPEED = 64 ;
134+ k .onKeyDown (" left" , () => {
135+ player .move (- SPEED , 0 );
136+ });
137+ k .onKeyDown (" right" , () => {
138+ player .move (SPEED , 0 );
139+ });
140+ </script >
0 commit comments