One more time!
Blitz3D Forums/Blitz3D Beginners Area/One more time!
| ||
Sorry folks but I still have a problem with counter control everything works in the code below except instead of reading all 5 counters it reads only the first one. I shortened the code and added remarks to make it easy to look at and figure out the problem. I have been working every angle for the last few days and now I am stumped!!!!Also anywhere I can get a sample of "WW2 strategy" type gaming code (In blitz of course) for moving and controlling game counters on the board, that would be great. Graphics 1280,1024,16,2 SetBuffer BackBuffer() ;Load Image (5) counter 43x32 pixels each Global imgcounter = LoadAnimImage("AAshipcounter_all5.bmp",43,32,0,5) ;load background data into files backgroundimage = LoadImage("star1280.jpg") ECshipprofile = LoadImage ("ECShip_profile.bmp") Planets = LoadImage ("planets.bmp") GameLogo= LoadImage ("ShipGameLogo.bmp") ;Set up counter holder for placing existing counters Global CurrentCounter.FleetCounter = New FleetCounter CurrentCounter\X = -1 Type Fleetcounter Field X% Field Y% End Type ;Dimension board to place counters Dim Board(39,31) ;Starting placement for (5) Ship Counters using the "1" flag in the following functions Board (34, 4)=1 Board (34, 5)=1 Board (35, 5)=1 Board (35, 4)=1 Board (35, 6)=1 ;Start game loop While Not MouseHit(3) ;Draw background data to screen TileBlock backgroundimage MaskImage ECshipprofile,001,001,001 DrawImage ECshipprofile,300,-145 MaskImage Planets,001,001,001 DrawImage Planets,0,0 MaskImage Gamelogo,001,001,001 DrawImage Gamelogo,22,925 ;Start counter hold process but first it will draw the (5) counters in the first location discribed above in "board" array CheckInput1() DrawCounters1() Flip Cls Wend End ;;;;;;;;;;;;;;;;;;; Function CheckInput1() ;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 DrawCounters1() For x = 0 To 39 For y = 0 To 31 ;!!!!!The statement below is where I have the problem. I cannot control the "c" variable in this loop so it winds up creating 5 images of the first image from the .bmp file!!!!! If Board(x,y) = 1 Then DrawImage imgcounter, ((x*32)-6),(y*32),c MaskImage imgcounter,001,001,001 Next Next End Function |
| ||
Looking at your code, I can't tell what you are trying to do. Are you trying to draw the same image every time, or a different image based on the array data?. I can't tell because all of your array data seems to just equal 1, so how can your function tell the "ship counters" (whatever they are???) apart? You gripe about this 'c' variable. I don't know what you are trying to do with it for the reasons I mentioned above, but the c variable is local to the function, therefore it equals zero (since you didn't set it elsewhere in the function). If you want the c variable to contain a value that is used outside of the function then you either have to pass the value to the function Function DrawCounters1(c) or you have to make c a global variable Global c |
| ||
The problem is I can't find where to loop the "c" variable 5 times for each of the images in the .bmp file. Can you tell me where in the code to do this |
| ||
I really don't know what you want to achieve. What is this 'c' variable suppose to represent? Why do you want to loop it? You should try explaining what your program is about more... |
| ||
I'm trying to place 5 seperate counters on the board each from a different position in AAshipcounter_all5.bmp file. This file has five images in a row with different counter numbers from 1-5. Now to the program, The counter is first drawn 5 times for each place on the Board with the array Baord(x,y) Board (34, 4)=1 Board (34, 5)=1 Board (35, 5)=1 Board (35, 4)=1 Board (35, 6)=1 But this is only a flag to the Drawcounter1() function. So I thought if I control everytime it draws "Board (x,y)" with a c variable then it will draw the consecutive images from the AAshipcounter_all5.bmp file. What works is if I replace the variable c in: Then DrawImage imgcounter, ((x*32)-6),(y*32),c with any number, 1-5 I get its cooresponding image from AAshipcounter_all5.bmp but I cannot control it Here the Variable needs to change from 1 to 2 to 3 etc.. for each of the five draws from statements: Board (34, 4)=1 ; First image in AA*.bmp file Board (34, 5)=1 ; second Board (35, 5)=1 ; third Board (35, 4)=1 ; Forth Board (35, 6)=1 ; Fifth If "Then" in the DrawCounter() function calculates 5 times for each of the draws then c=C+1 would do the trick but it does not!(Of course first adding a Global c=0) So where can I change the c variable "x" number of times equal to the number of "Board(x,y)" iterations. This looks easier then it is due to the way the functions handle the counters. I adapted this from perputiato sample but its real limited in how it controls the counters. I may better off starting with a more robust counter countroller if someone has a sample to work with. If you ever played any WW2 Computer stategy games they are "counter" manipulation routines and I would like to see the code on one of these, |
| ||
I'm sorry but I still don't understand you. First of all, what is a 'counter' as you say it? Is this what you meant to do?: Board (34, 4)=1 ; First image in AA*.bmp file Board (34, 5)=2 ; second Board (35, 5)=3 ; third Board (35, 4)=4 ; Forth Board (35, 6)=5 ; Fifth ;later... Function DrawCounters1() For x = 0 To 39 For y = 0 To 31 If Board(x, y) > 0 DrawImage imgcounter, ((x*32)-6),(y*32), board(x, y) EndIf Next Next End Function |
| ||
Or did you mean to do this?: (which to be honest, I couldn't understand why, if it is...)Function DrawCounters1() For x = 0 To 39 For y = 0 To 31 If Board(x,y) = 1 DrawImage imgcounter, ((x*32)-6),(y*32),c c = c + 1 EndIf Next Next End Function |
| ||
My game board is a 40x32 square area (each square is a 32 pixels x 32 pixel for a 32 pixel square image) in space and the counters are simply individual fleets (32 pixel sqr. images) in space. I want to bring the counters (Images) on to the board and move them around much like the old game boards we use to use, before computers. Each fleet counter (Image)has data attached to it (Would be represented by "Fleet types")and that data changes as it moves to different sqaures (ie. planets) on the board. So I need to first: 1. place each of these counters (Images of a space fleet) 2. I need to move each of them around on the board. 3. I need them to interact with each square on the board where there is a Planet, enemy fleet etc ..... I created 5 races each with 5 fleets, the first is the AA race: Global imgcounter = LoadAnimImage("AAshipcounter_all5.bmp",43,32,0,5) This has five fleet counter images in it. Then I place them on specific areas of the board Board (34, 4)=1 Board (34, 5)=1 Board (35, 5)=1 Board (35, 4)=1 Board (35, 6)=1 The "=1" is a flag in the function Drawcounter1() and also used in the function "Checkinput()": Board(CurrentCounter\X,CurrentCounter\Y) = 0 Board(MouseX()/32,MouseY()/32) = 1 This allows you to pick up the counter (once its initially drawn)and move it to another location. Though there may be a better way to handle this, this is the sample I got and the only one I know. Back to the Drawcounter1()function This function needs to be smart enough to know how many fleets I am drawing onto the board and make sure it does not draw the same fleet over and over again. I am sure there is a better way to handle this but I am not sure where to start so I hoped to atleast make it work somewhat in the sample I am using now Your sample gives me a Memory violation I think due to the Checkinput() function I tryed your example by adding another array Dim Boardi(X,Y) and then more input Boardi (34, 4)=1 Boardi (34, 5)=2 Boardi (35, 5)=3 Boardi (35, 4)=4 Boardi (35, 6)=5 Then changed lines in Drawimage() function to If Board(x, y) > 0 DrawImage imgcounter, ((x*32)-6),(y*32), boardi(x, y) But no go! No images loaded If I use "Boardi" in If Boardi(x,y) > 1 I get a program violation |
| ||
OK, I think your problem resides in how you are storing your data. You don't have to try so hard to draw the correct images, if you would just assign your array elements with numbers that correspond to the image you want. You stated this: I created 5 races each with 5 fleets, the first is the AA race: and I assume you set all of those board positions with 1's because they are fleets from the FIRST race. I also assume that you would have used, say 2, for the second race, and so on. The problem, as you see, is that you don't know which fleet is which.Global imgcounter = LoadAnimImage("AAshipcounter_all5.bmp",43,32,0,5) This has five fleet counter images in it. Then I place them on specific areas of the board Board (34, 4)=1 Board (34, 5)=1 Board (35, 5)=1 Board (35, 4)=1 Board (35, 6)=1 You should try a method like this: 1-5 = fleets 1-5 of race 1 11-15 = fleets 1-5 of race 2 21-25 = fleets 1-5 of race 3 etc... Set up an array to store your animimages: Dim imgcounter(5)Load in your race images: Global imgcounter(1) = LoadAnimImage("AAshipcounter_all5.bmp",43,32,0,5) Global imgcounter(2) = LoadAnimImage("BBshipcounter_all5.bmp",43,32,0,5) Global imgcounter(3) = LoadAnimImage("CCshipcounter_all5.bmp",43,32,0,5) Global imgcounter(4) = LoadAnimImage("DDshipcounter_all5.bmp",43,32,0,5) Global imgcounter(5) = LoadAnimImage("EEshipcounter_all5.bmp",43,32,0,5) and mask them: (Note that it's not necessary to mask your images every time they are drawn like you were doing in the code above) For iter = 1 to 5 MaskImage imgcounter(iter),001,001,001 NextThen in your DrawCounter function, do something like I showed you above: Function DrawCounters() For x = 0 To 39 For y = 0 To 31 If Board(x, y) > 0 race = floor(board(x,y)/10.0) fleet = board(x,y) MOD 10 DrawImage imgcounter(race), ((x*32)-6),(y*32), fleet EndIf Next Next End Function That should do it for you. If not, then I am lost at what you are trying to achieve. |