przemek
New member
- Joined
- Sep 18, 2017
- Messages
- 62
Hi, I would like to ask you how do i get co-ordinates from my game. What I want to do is have a menu with buildings and place them where my mouse is. So what I planned to do is move the cursor, press right mouse button, gets co-ords from the mouse cursor and say DrawImage farm cursor co-ords. How should i do that?
Also, i tried to draw a character in a specific pixel (lets say 300 by 300), however when I launched it, I couldnt move the character because on what i suspect is, I took out x, y. So I got another DrawImage character with x and y and what I ended up with is 2 same sprites, one in 300,300 and other at the top right corner which I can move. How do i make a sprite appear on special pixel and being able to move it?
Tried to use example from this: https://www.cerberus-x.com/community/cxDocs/Modules_mojo.graphics.html#DrawImage
Also, i tried to draw a character in a specific pixel (lets say 300 by 300), however when I launched it, I couldnt move the character because on what i suspect is, I took out x, y. So I got another DrawImage character with x and y and what I ended up with is 2 same sprites, one in 300,300 and other at the top right corner which I can move. How do i make a sprite appear on special pixel and being able to move it?
Tried to use example from this: https://www.cerberus-x.com/community/cxDocs/Modules_mojo.graphics.html#DrawImage
Code:
Strict
Import mojo
Class CGame 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
'character
Field x:Float
Field y:Float
Field character:Image
Field p1:CGame
Method OnCreate:Int()
SetUpdateRate(0)
lastTick = Millisecs()
loopedtimeforwood = 0
wood = 0
SetDeviceWindow(1280,960,0)
'character
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
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, 200, 200)
DrawText("Min: "+mins, 570, 10)
DrawText("Hour: "+hrs, 510, 10)
DrawText("Day: "+dys, 460, 10)''''''''''''''''
DrawText("Wood: "+wood, 400, 80)
DrawImage character, 300, 300
DrawImage character, x, y
Return 0
End Method
End Class
Function Main:Int()
New CGame()
Return 0
End Function