Perturbatio or anyone

Blitz3D Forums/Blitz3D Beginners Area/Perturbatio or anyone

PCBGuy(Posted 2004) [#1]
Perturbatio or anyone less, (about "the damn mouse" question)
Your code (supplied in previous message)was very helpful and I adapted to my code just fine but I am still stumped with an issue. I am using different graphic bitmaps as counters (ie KCFleet1.bmp) for the game so the Global "imgcounter" in your sample even adjusting it for using .bmp images won't work in its present form. It grabs the same image each time no mater how I set it up. Each of the counters I use in the game are different and actually a placement for a whole other level of the game. So they are more like "data head counters" (ie. So when I place and then move these (.bmp images) counters I am actually moving a header "variable" for each fleet of a varied number of ships. How can I use your imgcounter in a more robust form with the code you supplied?

Also a small issue: the curser grabs the counter at the corner when it would be kool to grab it in the center, No mater where I place AutoMidhande it doesn't do anything for the mouse curser. (I got it to center my .bmp images nicely on the board grid though) also this is all within the code you supplied. Anyone to help would be GREAT!


BlackD(Posted 2004) [#2]
1. In Pertubatio's example, add another field to the TYPE, or in fact as many as you want, to determine what counter is there.
eg.
     Type Counter
     Field X
     Field Y
     Field Image
     Field TypeOfCounter
     End Type
     
     for n = 1 to 10      ;10 different types of counters with 10 different images
     game.counter = new counter
     game\x = rand(7)
     game\y = rand(7)
     game\image = LoadImage("counter"+n+:.bmp")
     game\typeofcounter = n
     next
Then in your code, rather than just drawing imgcounter at the location, draw game\image for each counter.
     for game.counter = each game
     DrawImage game\image,game\x,game\y
     Next
And likewise, when you move a counter, keep track of which one has been moved where. I'm guessing you can figure out that for yourself. :)

2. If you want the mouse at the center of the counter, then use the MoveMouse command, to move it to the center. I assume you know where the center of the button is? Just use MoveMouse X,Y to move the cursor to that location before starting the dragging.

+BlackD

Then have,


PCBGuy(Posted 2004) [#3]
Thanks +BlackD,
I'll take it from there and see what I can do. I solved the second problem simply by adding a shift to the x,y in the Drawcounter function, Thanks again


PCBGuy(Posted 2004) [#4]
OK here is the problem once more. It all works except I still have no control on the number of counters. All I get is the first counter ("ECShipcounter1.bmp")printing over again for as many times as the loop goes which in this case is 5 times. They are printed where I want them its just they are all the same one not #2,#3 etc... Please anyone?????


Graphics 1280,1024,16,2 ; Create size of map

SetBuffer BackBuffer()

backgroundimage = LoadImage("star1280.jpg")
ECshipprofile = LoadImage ("ECShip_profile.bmp")
Planets = LoadImage ("planets.bmp")




;***************************************************************************************

Type Fleetcounter
Field X%
Field Y%
Field Image
Field TypeofCounter
End Type


Dim ECFleet(5)
ECFleet(0) = LoadImage ("ECShipcounter1.bmp")
ECFleet(1) = LoadImage ("ECShipcounter2.bmp")
ECFleet(2) = LoadImage ("ECShipcounter3.bmp")
ECFleet(3) = LoadImage ("ECShipcounter4.bmp")
ECFleet(4) = LoadImage ("ECShipcounter5.bmp")

For i = 0 To 4

NextCounter.Fleetcounter = New Fleetcounter
NextCounter\X = x
NextCounter\Y = y
NextCounter\image = LoadImage (ECFleet(i))
NextCounter\TypeofCounter = i
Next


Dim Board(39,31)


;***** Sets up a loop to place 5 counters when variablearray "Board" = 1 *************
For i = 0 To 4
AutoMidHandle True
x=x+1
Board (x, y)=1
Next



Global CurrentCounter.FleetCounter = New FleetCounter
CurrentCounter\X = -1

While Not MouseHit(3)

TileBlock backgroundimage
MaskImage ECshipprofile,001,001,001
DrawImage ECshipprofile,300,-145
MaskImage Planets,001,001,001
DrawImage Planets,0,0



CheckInput()
DrawGrid()
DrawCounters()


Flip
Cls
Wend

End


;;;;;;;;;;;;;;;;;;;
Function CheckInput()
;if left mouse button is pressed
If MouseHit(1) Then
;if there is no current counter
If CurrentCounter\X < 0 Then
;if a tile is under the mouse
If Board(MouseX()/32,MouseY()/32) = 1 Then


CurrentCounter\X = MouseX()/32
Currentcounter\Y = MouseY()/32
EndIf
Else ;there is already a current counter
If Board(MouseX()/32,MouseY()/32) = 0 Then

;move it to the new location
Board(CurrentCounter\X,CurrentCounter\Y) = 0
Board(MouseX()/32,MouseY()/32) = 1
CurrentCounter\X = -1
Currentcounter\Y = -1
EndIf
EndIf
EndIf

If MouseHit(2) Then
CurrentCounter\X = -1
EndIf

End Function


;;;;;;;;;;;;;;;;;;;
Function DrawGrid()
Color 45,45,45
For x = 0 To 39
For y = 0 To 31
Rect x*32,y*32,32,32,False
Next
Next
End Function


;;;;;;;;;;;;;;;;;;;
Function DrawCounters()
For x = 0 To 39
For y = 0 To 31
If Board(x,y) = 1 Then DrawImage (ECFleet(i)), (x*32)+16,(y*32)+16
MaskImage (ECFleet(i)),001,001,001
Next

Next
If CurrentCounter\X >-1 Then
If MouseX() = -1 Then
DrawImage (ECFleet(i)), (MouseX()+16), (MouseY()+16)
MaskImage (ECFleet(i)),001,001,001
Else
EndIf

EndIf
End Function


_PJ_(Posted 2004) [#5]
Why do you need to LoadImage twice?




and...

Im not 100% on this, but maybe you need some

For i=0 to 4
...
Next

lines in your functions???


_PJ_(Posted 2004) [#6]
Ahh...

You dont need to use DrawImage (ECFleet(i)) etc.

When you have CurrentCounter\image

also dont forget to For/Next your CurrentCounter types.

i.e. For f=CurrentCounter.Counters Each Counters
or whatever.

Sorry, Im at work and havent got b3d so cannot test this.


PCBGuy(Posted 2004) [#7]
I dont know what the line from previous message:

game\image = LoadImage("counter"+n+:.bmp")

does. As it is it doesnt work, can someone show how to use the +n+:. stuff


Perturbatio(Posted 2004) [#8]
there's a typo in that line, it should be:
game\image = LoadImage("counter"+n+".bmp") 


as a quick example of what it does, run this:


*EDIT*
However, you may be better off using LoadAnimImage and having one image with all your counters in it (assuming they are all the same size).
Then used DrawImage x,x,n where n is the number of the counter you want to use.

*EDIT*
to draw the counter with the mouse at the centre, simply offset the x and y coordinates by one half the image width and height respectively.

i.e.
DrawImage imgCounter, MouseX()-(ImageWidth(imgCounter)/2), MouseY()-(ImageHeight(imgCounter)/2)