Import mojo2
Import os
Function Main()
New MyApp
End
Class MyApp Extends App
Field canvas:Canvas
Field readonlyimage:Image
Field paint2:Canvas
Field paint3:Canvas
Field image2:Image
Field image3:Image
Field size:Int=32
Field wx:Int, wy:Int
Field tilemap:Int[512*512]
Field path:String
Field path2:String
Method OnCreate()
For Local y :=0 To 511
For Local x := 0 To 511
tilemap[x + y * 512] = Int(Rnd(127))
Next
Next
' -------------------------------------------------------------------------------------------------
path = AppPath()
path2 = RealPath("")
' Print path
' Print path2
' Example of path
' . . .. /Desktop/gamefix/test.buildv2020-11-15/glfw3/xcode/build/Release/CerberusGame.app/Contents/MacOS/CerberusGame
path=path+"/"+"betatestsprites.png" ' Get path where application is
readonlyimage = Image.Load(path,0,0,0) ' Try load beta-sprites placed inside the application at correct spot inside the app.
' -------------------------------------------------------------------------------------------------
' readonlyimage = Image.Load("512x512sprites2.png",0,0,0)
image3 = New Image(readonlyimage.Width,readonlyimage.Height,,,0)
image2 = New Image(256,256,0,0,0)
paint2 = New Canvas(image2)
paint3 = New Canvas(image3)
canvas = New Canvas
SetSwapInterval 1
SetUpdateRate 0
End
Method OnRender()
Local w=DeviceWidth, h=DeviceHeight
canvas.SetViewport 0,0,w,h ; canvas.SetScissor 0,0,w,h ; canvas.SetProjection2d 0,w,0,h ; canvas.Clear 0,0,0
paint3.SetViewport 0,0,w,h ; paint3.SetScissor 0,0,w,h ; paint3.SetProjection2d 0,w,0,h
paint3.Clear ; paint3.DrawImage readonlyimage,0,0 ; paint3.Flush
paint2.SetViewport 0,0,w,h ; paint2.SetScissor 0,0,w,h ; paint2.SetProjection2d 0,w,0,h ; paint2.Clear 0,0,0
paint2.DrawImage readonlyimage,0,0
paint2.DrawImage image3,256,256
paint2.Flush
Local scrx := wx Mod size, scry:=wy Mod size
Local mapx := wx / size, mapy:=wy / size
Local cnty := -scry
For Local y := mapy To mapy+((h/size)+1)
Local cntx := -scrx
For Local x:=mapx To mapx+((w/size)+1)
Local char:= tilemap[x + y * 512] ; Local tilex := char & 15 ; Local tiley := char Shr 4
canvas.DrawRect cntx,cnty,size,size,image2,tilex Shl 5,tiley Shl 5,32,32
cntx=cntx+size
Next
cnty = cnty + size
Next
canvas.DrawText path,-450,100
wx = wx + 1
canvas.Flush
End
End