OK heres the code of this simple 2D game. Please read the comments carefully. This code works but only draws the first image of the file. The two functions in this code are nessesary to control the image and cannot be overstepped or ignored.
The purpose: Once each images is drawn they can be picked up and placed in another location over and over again just like a counter on a game board. Also each image has data attached to them for the next step of the game.
The problem: Only one of the images is drawn over and over again. Global arrays don't work. The DrawCounter function will not take a variable. So I only get the first image of the file each time it draws an image. Also the functions make it difficult to add data to these images. Can someone solve this problem. I would gladly email them the image. the image is (5) 32 pixel pictures in a row, thats it. I would like to add more images in the future. So far all attempts failed miserably, so please try this code before sending suggestions.
Graphics 1280,1024,16,2 ; Create size of map
SetBuffer BackBuffer()
Global imgcounter = LoadAnimImage("AAshipcounter_all5.bmp",43,32,0,5) ;Loads the image with 5 seperate images attached in a row
Global imgcounter2 = LoadAnimImage("KEshipcounter_all5.bmp",43,32,0,5) ;Currently not used I Would like to eventually add this one and 3 more
Global CurrentCounter.FleetCounter = New FleetCounter ;Creates counter to be used as place holder for image
CurrentCounter\X = -1
Type Fleetcounter
Field X%
Field Y%
Field Image
End Type
Dim Board(39,31) ; Dimensions the game board
For n = 1 To 5 ;Makes 5 places on the game board that "=1" or True
x=x+1 ;Initial x location on gameboard, I can put anything here but its not important for now
y=y+1 ;Initial Y location on gameboard
Board (x, y)=1 ;Counter 1 ="true" 0 = "False" for use in Function
Next
While Not MouseHit(3) ;Start of main loop
CheckInput() ;Checks for control of moving image
DrawCounters1() ;Initially draws image then continues to draw as image is selected to a new location
Flip
Cls ;Removes last placement of current image
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
Currentcounter\image = imgcounter
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 DrawCounters1() ; Problem:This loop will not allow me to change the image not mater how many times it loops
For x = 0 To 39
For y = 0 To 31
If Board(x,y) = 1 Then DrawImage imgcounter, ((x*32)-6),(y*32),2 ;last number determines which counter in image file is drawn
MaskImage imgcounter,001,001,001
Next
Next
End Function
The purpose: Once each images is drawn they can be picked up and placed in another location over and over again just like a counter on a game board. Also each image has data attached to them for the next step of the game.
The problem: Only one of the images is drawn over and over again. Global arrays don't work. The DrawCounter function will not take a variable. So I only get the first image of the file each time it draws an image. Also the functions make it difficult to add data to these images. Can someone solve this problem. I would gladly email them the image. the image is (5) 32 pixel pictures in a row, thats it. I would like to add more images in the future. So far all attempts failed miserably, so please try this code before sending suggestions.
Graphics 1280,1024,16,2 ; Create size of map
SetBuffer BackBuffer()
Global imgcounter = LoadAnimImage("AAshipcounter_all5.bmp",43,32,0,5) ;Loads the image with 5 seperate images attached in a row
Global imgcounter2 = LoadAnimImage("KEshipcounter_all5.bmp",43,32,0,5) ;Currently not used I Would like to eventually add this one and 3 more
Global CurrentCounter.FleetCounter = New FleetCounter ;Creates counter to be used as place holder for image
CurrentCounter\X = -1
Type Fleetcounter
Field X%
Field Y%
Field Image
End Type
Dim Board(39,31) ; Dimensions the game board
For n = 1 To 5 ;Makes 5 places on the game board that "=1" or True
x=x+1 ;Initial x location on gameboard, I can put anything here but its not important for now
y=y+1 ;Initial Y location on gameboard
Board (x, y)=1 ;Counter 1 ="true" 0 = "False" for use in Function
Next
While Not MouseHit(3) ;Start of main loop
CheckInput() ;Checks for control of moving image
DrawCounters1() ;Initially draws image then continues to draw as image is selected to a new location
Flip
Cls ;Removes last placement of current image
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
Currentcounter\image = imgcounter
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 DrawCounters1() ; Problem:This loop will not allow me to change the image not mater how many times it loops
For x = 0 To 39
For y = 0 To 31
If Board(x,y) = 1 Then DrawImage imgcounter, ((x*32)-6),(y*32),2 ;last number determines which counter in image file is drawn
MaskImage imgcounter,001,001,001
Next
Next
End Function