Created
February 11, 2026 14:48
-
-
Save luizbills/114d061c4a6e079d558510b419d4b9d2 to your computer and use it in GitHub Desktop.
Top-down movement like old pokemons games #litecanvas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| litecanvas({ | |
| width: 8*8, | |
| autoscale: 3 | |
| }) | |
| const p = { | |
| x: 0, | |
| y: 0, | |
| dx: 0, | |
| dy: 0, | |
| dist: 0, | |
| state: 'idle', | |
| spd: 0.5 | |
| } | |
| function init() { | |
| } | |
| function update(dt) { | |
| if ('idle'===p.state) { | |
| if (iskeydown('d')) { | |
| p.dx+=p.spd | |
| } else if (iskeydown('a')) { | |
| p.dx-=p.spd | |
| } else if (iskeydown('s')) { | |
| p.dy+=p.spd | |
| } else if (iskeydown('w')) { | |
| p.dy-=p.spd | |
| } | |
| if (p.dx || p.dy) { | |
| p.dist=8 | |
| p.state='moving' | |
| } | |
| } else if ('moving'===p.state) { | |
| move() | |
| } | |
| } | |
| function draw() { | |
| cls() | |
| for (let y = 0; y < 8; y++) { | |
| for (let x = 0; x < 8; x++) { | |
| rectfill(x*8,y*8,8,8,(x+y)%2?0:1) | |
| } | |
| } | |
| rectfill(p.x,p.y,8,8,3) | |
| } | |
| function move() { | |
| p.x+=p.dx | |
| p.y+=p.dy | |
| p.dist-=p.spd | |
| if (p.dist<=0){ | |
| p.state='idle' | |
| p.dx=p.dy=0 | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Live Demo