przemek
New member
- Joined
- Sep 18, 2017
- Messages
- 62
Hi
In my code I have put a movable character and I want to input another entity. However when i put code to draw it, it says memory access violation. Can someone help me a bit with that? (sorry for being a bit bothersome)
In my code I have put a movable character and I want to input another entity. However when i put code to draw it, it says memory access violation. Can someone help me a bit with that? (sorry for being a bit bothersome)
Code:
Strict
Import mojo
Class Game Extends App
'timer
Field lastTick:Int
Field secs:Int
Field mins:Int
Field hrs:Int
Field dys:Int
'resources
Field wood:Float
Field loopedtimeforwood:Int
Field x2:Float = 500
Field y2:Float = 400
'character
Field x:Float = 575
Field y:Float = 420
Field size:Float = 10
Field BorderXMin:Float = 1
Field BorderXMax:Float = 1270
Field BorderYMin:Float = 25
Field BorderYMax:Float = 870
Field character:Image
Field Farm:Image
Field p1:Game
Method OnCreate:Int()
SetUpdateRate(0)
lastTick = Millisecs()
loopedtimeforwood = 0
wood = 0
SetDeviceWindow(1280,960,0)
'character
character = LoadImage("character.png")
Farm = LoadImage("farm.png")
SetUpdateRate 60
Return 0
End Method
Method OnUpdate:Int()
Local tick:Int = Millisecs()
If tick>=(lastTick+1000)
lastTick = tick
secs += 1
loopedtimeforwood+=1
Endif
If secs > 59 Then
secs = 0
mins +=1
If mins > 59 Then
mins = 0
hrs +=1
If hrs > 23 Then
hrs = 0
dys += 1
Endif
Endif
Endif
If loopedtimeforwood >= 20
wood+=1
If KeyDown (KEY_A) Then wood+=1
loopedtimeforwood =0
End
x = Clamp(x, BorderXMin, BorderXMax - size)
y = Clamp(y, BorderYMin, BorderYMax - size)
If KeyDown (KEY_LEFT) Then x = x - 4
If KeyDown (KEY_RIGHT) Then x = x + 4
If KeyDown (KEY_UP) Then y = y-4
If KeyDown (KEY_DOWN) Then y = y +4
'keydown means keep moving until key is down where keyhit is do a thing until
Return 0
End Method
Method OnRender:Int()
Cls 124, 256, 0
DrawText("Mins: "+secs, 10, 12)
DrawText("Min: "+mins, 80, 12)
DrawText("Hour: "+hrs, 140, 12)
DrawText("Day: "+dys, 200, 12)''''''''''''''''
DrawText("Wood: "+wood, 400, 80)
DrawImage character, x, y
DrawImage Farm, x2, y2
Return 0
End Method
End Class
Function Main:Int()
New Game()
Return 0
End Function