```
Strict
'#TILEMAP_EDITOR=True
Import mojo2
Import tilemap
Class player
Field x:Float,y:Float
Field dx:Float,dy:Float
Field img:Image
Method Draw:Void(cnvs:TileLayer)
cnvs.DrawImage img,x,y
End
Method Update:Void()
End
End
Class myClass Extends App
Field cnvs:Canvas
Field tiles:Tilemap
Field p:player
Method OnCreate:Int()
' level data
tiles = LoadTilemap("ab1.gtm")
' red ambient light
tiles.SetBackgroundAmbientLight(.8,0,0)
tiles.SetForegroundAmbientLight(.2,0,0)
' set up player
p=New player()
p.x=300
p.y=300
p.img = Image.Load("smiley.png",0.5,0.5)
tiles.SetNormalMap(p.img)
SetUpdateRate(60)
cnvs = New Canvas
Return 0
End
Method OnUpdate:Int()
p.dx = 0
p.dy = 0
If KeyDown(KEY_UP) Then p.dy=-3
If KeyDown(KEY_DOWN) Then p.dy=3
If KeyDown(KEY_RIGHT) Then p.dx=3
If KeyDown(KEY_LEFT) Then p.dx=-3
If KeyHit(KEY_E) Then tiles.EnableEditor()
If Not tiles.CollideRect(p.x-16+p.dx,p.y-16,32,32,p.dx,p.dy) Then p.x+=p.dx
If Not tiles.CollideRect(p.x-16,p.y-16+p.dy,32,32,p.dx,p.dy) Then p.y+=p.dy
tiles.Update()
p.Update()
Return 0
End
Method OnRender:Int()
' Clear the canvas with a green color.
cnvs.SetScissor(0,0,DeviceWidth(),DeviceHeight())
cnvs.Clear (0,0.5,0)
' set tiles posiiton
tiles.SetPosition(p.x-300,p.y-200)
' draw floor (layer 2)
tiles.Draw(cnvs,[2])
' player light
Local light:TileLight = tiles.AddLight(1,1,1,p.x,p.y,-100,800)
' green light
light = tiles.AddLight(0.2,1,0.2,1200,900,-100,800)
' flashing light
If (Millisecs()/250) Mod 4 < 3 Then light = tiles.AddLight(1,0,1,800,900,-100,800)
' draw player
Local draw:TileLayer = tiles.DrawLayer()
draw.PushMatrix()
tiles.Translate(draw,2)
draw.DrawImage p.img,p.x,p.y
draw.DrawImage p.img,800,800
draw.PopMatrix()
' draw walls (top layer unaffected by light)
tiles.Draw(cnvs,[0])
' Flush the canvas so it becomes visible.
cnvs.Flush
Return 0
End
End
Function Main:Int()
New myClass
Return 0
End
```