przemek
New member
- Joined
- Sep 18, 2017
- Messages
- 62
Hi there,
So, in my previous threat I have asked about sprite following cursor and it works great but now I have another problem. I am planning to have several sprites following the mouse and i will just try and copy and paste the code for the first sprite with few changes (if it doesnt work ill do another threat). However I dont want all 3 or 4 sprites to follow my mouse at the same time so I've decided to try to bind each sprite to different keys and when I press, for example 1, it will make farm sprite appear and when I press B it will disappear.
So my question is how do I make sprites dissapear when the game starts, how do i make them appear and disappear again and where should I put the code for appear and disappear?
Also I nearly forgot how do I make them stay with ,for example left mouse botton, on the coordinates where i pressed it?
If you need the code here it is:
So, in my previous threat I have asked about sprite following cursor and it works great but now I have another problem. I am planning to have several sprites following the mouse and i will just try and copy and paste the code for the first sprite with few changes (if it doesnt work ill do another threat). However I dont want all 3 or 4 sprites to follow my mouse at the same time so I've decided to try to bind each sprite to different keys and when I press, for example 1, it will make farm sprite appear and when I press B it will disappear.
So my question is how do I make sprites dissapear when the game starts, how do i make them appear and disappear again and where should I put the code for appear and disappear?
Also I nearly forgot how do I make them stay with ,for example left mouse botton, on the coordinates where i pressed it?
If you need the code here it is:
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 y2:Float
Field x2:Float
'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(60)
lastTick = Millisecs()
loopedtimeforwood = 0
wood = 0
SetDeviceWindow(1280,960,0)
'character
farm = LoadImage("ground.png")
character = LoadImage("character.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 x2 < MouseX() Then x2+=40
If x2 > MouseX() Then x2-=40
If y2 < MouseY() Then y2+=40
If y2 > MouseY() Then y2-=40
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 farm, x2, y2
DrawImage character, x, y
Return 0
End Method
End Class
Function Main:Int()
New Game()
Return 0
End Function
Last edited: