@@ -3,35 +3,40 @@ export default () =>
33// Learn more tapping on the question mark (?) above.
44// Join our discord: https://discord.com/invite/r2c3rGsvH3
55
6- let x, y, size, speed, color
6+ // Start the engine
7+ litecanvas({
8+ loop: { init, update, draw, tapped },
9+ })
710
8- litecanvas()
11+ let bg, color, radius, posx, posy
912
10- // run once before the game starts
13+ // this function runs once at the beginning
1114function init() {
12- x = CX
13- y = CY
14- size = 32
15- speed = 250
16- color = 4
15+ bg = 0 // the color #0 (black)
16+ color = 3 // the color #3 (white)
17+ radius = W / 10 // the canvas width/10
18+ posx = CX // center X (or canvas width/2)
19+ posy = CY // center Y (or canvas width/2)
1720}
1821
19- // called when touches/clicks happens
20- function tapped(tapx, tapy) {
21- x = tapx
22- y = tapy
22+ // this function detect clicks/touches
23+ function tapped(x, y) {
24+ // changes the circle position
25+ // based on the position of the tap
26+ posx = x
27+ posy = y
2328}
2429
25- // this function controls the game logic
30+ // put the game logic in this function
2631function update(dt) {
27- x += speed * dt * (iskeydown('D') - iskeydown('A'))
28- y += speed * dt * (iskeydown('S') - iskeydown('W'))
32+ // make the circle falls 100 pixels per second
33+ posy += 200 * dt
2934}
3035
31- // this function render the game scene
36+ // put the game rendering in this function
3237function draw() {
33- cls(0)
34- rectfill(x, y, size, size, color)
35- text(0, 0 , 'use WASD keys or taps/clicks')
38+ cls(bg) // clear the screen
39+ circfill(posx, posy, radius, color) // draw a circle
40+ text(10, 10 , 'Tap anywhere') // draw a text
3641}
3742` ;
0 commit comments