Skip to content

Instantly share code, notes, and snippets.


exelotl/test.nim Secret

Created Feb 14, 2020
What would you like to do?
verao test
import verao/entity
import verao/events
import verao/engine
import verao/input
import sdl2/sdl
import sdl2/sdl_gpu as gpu
import sugar
# create a new event type
# this one will... uh, teleport gold horizontally for some reason
event TeleportGold:
distance: float32
# this one teleports every entity left
event TeleportLeft
entity Gold:
x; y: float32
proc init(x, y:float32) =
self.x = x
self.y = y
proc draw() =
screen.rectangleFilled2((x, y, 10f, 10f), (255,255,0))
# every Gold entity will listen for the event
# 'data' is an object of type TeleportGold which is passed implicitly
on TeleportGold:
x += data.distance
on TeleportLeft:
x -= 5
entity Player:
x; y: float32
proc init(x, y:float32) =
self.x = x
self.y = y
proc update() =
if held "left": x -= 100*dt
if held "right": x += 100*dt
if held "up": y -= 100*dt
if held "down": y += 100*dt
# when the player presses X, we can broadcast the event to all listening entities
if pressed "x":
emit TeleportGold(distance:20f)
if pressed "z":
emit TeleportLeft
on TeleportLeft:
x -= 8
proc draw() =
screen.rectangleFilled2((x, y, 30f, 30f), (255,255,255)) do:
engine.add(newPlayer(100, 30))
engine.add(newGold(120, 50))
engine.add(newGold(90, 70))
engine.add(newGold(100, 90))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.