@@ -3,35 +3,40 @@ export default () =>
3
3
// Learn more tapping on the question mark (?) above.
4
4
// Join our discord: https://discord.com/invite/r2c3rGsvH3
5
5
6
- let x, y, size, speed, color
6
+ // Start the engine
7
+ litecanvas({
8
+ loop: { init, update, draw, tapped },
9
+ })
7
10
8
- litecanvas()
11
+ let bg, color, radius, posx, posy
9
12
10
- // run once before the game starts
13
+ // this function runs once at the beginning
11
14
function 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)
17
20
}
18
21
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
23
28
}
24
29
25
- // this function controls the game logic
30
+ // put the game logic in this function
26
31
function 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
29
34
}
30
35
31
- // this function render the game scene
36
+ // put the game rendering in this function
32
37
function 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
36
41
}
37
42
` ;
0 commit comments