Skip to content

Instantly share code, notes, and snippets.

@darkf
Created January 15, 2012 01:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darkf/1613682 to your computer and use it in GitHub Desktop.
Save darkf/1613682 to your computer and use it in GitHub Desktop.
mockup program 2
# mockup of a game-oriented behavior modeling language, v1 (1/14/2012)
# copyright (c) 2012 darkf
playership <- Sprite(Vec2(64, 64)) # 64x64 sprite
enemyship <- Sprite(Vec2(64, 64))
projectiles <- List() # dynamic list
on playership:collide b do
if b is? enemyship do
# collided with enemy ship
end
end
on sys:load do
playership.loadImageFrom("player.png")
enemyship.loadImageFrom("enemy.png")
end
on screen:tick dt do
playership.pos += playership.vel * dt
enemyship.pos += enemyship.vel * dt
for p in projectiles do
p.pos += p.vel * dt
end
end
on input:keydown key do
if key is? KeySpace do
# shoot
p <- Projectile(mouse.getpos())
projectiles.add(p)
end
if key is? KeyLeft do
playership.rotation -= 1
end
if key is? KeyRight do
playership.rotation += 1
end
if key is? KeyUp do
# too lazy to think about the math, but this is about right ;)
playership.vel.x += math.cos(playership.rotation)
playership.vel.y += math.sin(playership.rotation)
end
end
on screen:draw do
emit playership:draw
emit enemyship:draw
for p in projectiles do
emit p:draw
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment