Skip to content

Instantly share code, notes, and snippets.

@luizbills
Last active February 18, 2025 13:11
Show Gist options
  • Save luizbills/b702a5dc82f505987f75e3dcd0432028 to your computer and use it in GitHub Desktop.
Save luizbills/b702a5dc82f505987f75e3dcd0432028 to your computer and use it in GitHub Desktop.
Simple shmup demo in Litecanvas
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)
}
}
@luizbills
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment