Last active
February 18, 2025 13:11
-
-
Save luizbills/b702a5dc82f505987f75e3dcd0432028 to your computer and use it in GitHub Desktop.
Simple shmup demo in 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
let scale = 2 | |
litecanvas({ | |
width: 640, | |
height: 480, | |
autoscale: false, | |
}) | |
// Art Code: 8x8/# # 6 6 6 6 # # # # 6 6 6 6 # # # # 6 6 6 6 # # 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 # # 6 6 6 6 6 6 # # 6 6 6 | |
const ship = paint(8, 8, [ | |
'..6666..', | |
'..6666..', | |
'..6666..', | |
'66666666', | |
'66666666', | |
'66666666', | |
'666..666', | |
'666..666', | |
], { | |
scale, | |
}) | |
// Art Code: 11x8/# # 9 # # # # # 9 # # # # # 9 # # # 9 # # # # # 9 9 9 9 9 9 9 # # # 9 9 # 9 9 9 # 9 9 # 9 9 9 9 9 9 9 9 9 9 9 9 # 9 9 9 9 9 9 9 # 9 9 # 9 # # # # # 9 # 9 # # # 9 9 # 9 9 # # # | |
const alien = paint(11, 8, [ | |
'..9.....9..', | |
'...9...9...', | |
'..9999999..', | |
'.99.999.99.', | |
'99999999999', | |
'9.9999999.9', | |
'9.9.....9.9', | |
'...99.99...', | |
], { | |
scale, | |
}) | |
function init() { | |
CANVAS.style.cursor='none' | |
bullets = new Set() | |
bulletSize = 2 * scale | |
bulletSpeed = 64 * scale | |
aliens = new Set() | |
alienSpeed = 48 * scale | |
shipY = HEIGHT*0.9 | |
aliensTimer = { value: 1, cooldown: 0 } | |
} | |
function tapped() { | |
bullets.add(utils.vec(MOUSEX+randi(3,4),shipY)) | |
} | |
function update(dt) { | |
for (let b of bullets) { | |
b.y -= bulletSpeed * dt | |
if (b.y < 0) { | |
bullets.delete(b) | |
} | |
} | |
aliensTimer.cooldown -= dt | |
if (aliensTimer.cooldown <= 0) { | |
aliensTimer.cooldown += aliensTimer.value | |
aliens.add( | |
utils.vec( | |
randi(0,WIDTH-alien.width), | |
-alien.height | |
) | |
) | |
} | |
for (let a of aliens) { | |
a.y += alienSpeed * dt | |
} | |
for (let b of bullets) { | |
for (let a of aliens) { | |
if (colrect( | |
b.x,b.y,bulletSize,bulletSize, | |
a.x,a.y,alien.width,alien.height | |
)) { | |
bullets.delete(b) | |
aliens.delete(a) | |
break | |
} | |
} | |
} | |
} | |
function draw() { | |
cls(0) | |
image(MOUSEX, shipY, ship) | |
for (let b of bullets) { | |
rectfill(b.x, b.y, bulletSize, bulletSize, 3) | |
} | |
for (let a of aliens) { | |
image(a.x, a.y, alien) | |
// rect(a.x, a.y, alien.width, alien.height, 4) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Demo