I had a problem locating tiles im my array. I had the problem because I was using a 2D matrix to hold locations for HEXAGONAL tiles.
Yes, making a SQUARE tiled boardgame would have been far too easy.
But I hard coded this NEW example that does work.
I took out the logic, I don't wanna make it too easy for you. If you need it hit me a PM!
Code: Select all
; hex display
Enumeration
#Board
#Player
#CPU
#Cursor
#CursorPoint
EndEnumeration
#Wide = 800
#High = 600
Structure Tile
x.f
y.f
ax.f
ay.f
EndStructure
Global NewList Tile.Tile()
Global Dim BOARD(8,5) ; array to hold WHAT type of tile goes where (0 = BLANK, 1 = PLAYER, 2=CPU)
Global Dim BX(8,5) ; X locations for tiles
Global Dim BY(8,5) ; Y locations for tiles
Global N
Global NE
Global SE
Global S
Global SW
Global NW
Global LEGALFLAG
BX(0,0) = 134 ; + 64
BX(0,2) = 229
BX(0,4) = 324
BX(1,1) = 181
BX(1,3) = 276
BX(1,5) = 371
BX(2,0) = 134
BX(2,2) = 229
BX(2,4) = 324
BX(3,1) = 181
BX(3,3) = 276
BX(3,5) = 371
BX(4,0) = 134
BX(4,2) = 229
BX(4,4) = 324
BX(5,1) = 181
BX(5,3) = 276
BX(5,5) = 371
BX(6,0) = 134
BX(6,2) = 229
BX(6,4) = 324
BX(7,1) = 181
BX(7,3) = 276
BX(7,5) = 371
BX(8,0) = 134
BX(8,2) = 229
BX(8,4) = 324
BY(0,0) = 10
BY(0,2) = 10
BY(0,4) = 10
BY(1,1) = 41
BY(1,3) = 41
BY(1,5) = 41
BY(2,0) = 72
BY(2,2) = 72
BY(2,4) = 72
BY(3,1) = 104
BY(3,3) = 104
BY(3,5) = 104
BY(4,0) = 135
BY(4,2) = 135
BY(4,4) = 135
BY(5,1) = 166
BY(5,3) = 166
BY(5,5) = 166
BY(6,0) = 197
BY(6,2) = 197
BY(6,4) = 197
BY(7,1) = 228
BY(7,3) = 228
BY(7,5) = 228
BY(8,0) = 259
BY(8,2) = 259
BY(8,4) = 259
For x = 0 To 8
For y = 0 To 5
BOARD(x,y) = 0 ; fill board with "blank" tiles
Next
Next
;- PROCEDURES
Procedure CheckforLegal(AX,AY, Color)
; This is where we check using the modified array
; note that even though every cell in the Board() array has a 0 in it
; we are reading offset rows
EndProcedure
;- EOP
If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
MessageRequester("Error", "DirectX 7+ Fail!", 0)
End
EndIf
If OpenScreen ( #Wide, #High,32,"Standard") = 0
MessageRequester("Error", "No screen could be Initialized...", 0)
End
EndIf
If InitSprite3D() = 0
MessageRequester("DirectX fail !", "Cannot open DirectX..."+Chr(10)+Chr(10)+"You must have DirectX 7+"+Chr(10)+"To play this game!", #PB_MessageRequester_Ok)
End
EndIf
LoadSprite(#Cursor, "cursor0.bmp",#PB_Sprite_Memory)
LoadSprite(#Player, "blue.bmp",#PB_Sprite_Memory)
LoadSprite(#CPU, "red.bmp",#PB_Sprite_Memory)
LoadSprite(#Board, "green.bmp",#PB_Sprite_Memory)
LoadSprite(#CursorPoint, "point0.bmp",#PB_Sprite_Memory)
Maus.Point
For y = 0 To 5
For x = 0 To 8
AddElement(Tile())
Tile()\x = BX(x,y)
Tile()\y = BY(x,y)
Tile()\ax = xray
Tile()\ay = yray
xray = xray + 1
If xray > 8
xray = 0
EndIf
Next
yray = yray + 1
Next
playercount = 2
cpucount = 2
Repeat
playercount = 0
cpucount = 0
ClearScreen(RGB(0,0,0))
ExamineMouse()
ExamineKeyboard()
Maus\x = MouseX()
Maus\y = MouseY()
Start3D()
; just a simple read the array and throw down the right tile
For y = 0 To 5
For x = 0 To 8
CHOWDERMONKEY = Board(X,Y)
Select CHOWDERMONKEY
Case 0
DisplayTransparentSprite(#Board, BX(X,y) ,BY(x,Y))
Case 1
DisplayTransparentSprite(#Player, BX(X,y) ,BY(x,Y))
cpucount = cpucount + 1
Case 2
DisplayTransparentSprite(#CPU, BX(X,y) ,BY(x,Y))
playercount = playercount + 1
EndSelect
Next
Next
; just to test the sprites
If MouseButton(1)
ForEach(Tile())
If SpritePixelCollision(#CursorPoint, Maus\x,Maus\y, #Board, Tile()\x, Tile()\y) ; 1011
ax = Tile()\ax
ay = Tile()\ay
color = Board(ax,ay)
If color = 0
;CheckforLegal(AX,AY,2)
;If LEGALFLAG = 1
colr = 1
board(ax,ay) = colr
;EndIf
EndIf
Break
EndIf
Next
EndIf
If MouseButton(2)
ForEach(Tile())
If SpritePixelCollision(#CursorPoint, Maus\x,Maus\y, #Board, Tile()\x, Tile()\y) ; 1011
ax = Tile()\ax
ay = Tile()\ay
color = Board(ax,ay)
If color = 0
;CheckforLegal(AX,AY,1)
colr = 2
; If LEGALFLAG = 1
board(ax,ay) = colr
; EndIf
EndIf
Break
EndIf
Next
EndIf
A = board(0,0)
B = board(0,1)
C = board(0,2)
D = board(0,3)
E = board(0,4)
F = board(0,5)
StartDrawing( ScreenOutput())
FrontColor(RGB(255,255,255))
BackColor(RGB(0,0,0))
DrawText(10, 65, "AX: "+ Str(ax)) ;+Str(playercount))
DrawText(10, 85, "AY: "+ Str(ay)) ;+Str(cpucount))
DrawText(10, 183, "TILE: "+Str(Tile()\x)+"/"+Str(Tile()\y))
DrawText(10,220,"ROW0: "+Str(Board(0,0))+Str(board(0,1))+Str(board(0,2))+Str(board(0,3))+Str(board(0,4))+Str(board(0,5)))
DrawText(10,235,"ROW1: "+Str(Board(1,0))+Str(board(1,1))+Str(board(1,2))+Str(board(1,3))+Str(board(1,4))+Str(board(1,5)))
DrawText(10,250,"ROW2: "+Str(Board(2,0))+Str(board(2,1))+Str(board(2,2))+Str(board(2,3))+Str(board(2,4))+Str(board(2,5)))
DrawText(10,265,"ROW3: "+Str(Board(3,0))+Str(board(3,1))+Str(board(3,2))+Str(board(3,3))+Str(board(3,4))+Str(board(3,5)))
DrawText(10,280,"ROW4: "+Str(Board(4,0))+Str(board(4,1))+Str(board(4,2))+Str(board(4,3))+Str(board(4,4))+Str(board(4,5)))
DrawText(10,295,"ROW5: "+Str(Board(5,0))+Str(board(5,1))+Str(board(5,2))+Str(board(5,3))+Str(board(5,4))+Str(board(5,5)))
DrawText(10,310,"ROW6: "+Str(Board(6,0))+Str(board(6,1))+Str(board(6,2))+Str(board(6,3))+Str(board(6,4))+Str(board(6,5)))
DrawText(10,325,"ROW7: "+Str(Board(7,0))+Str(board(7,1))+Str(board(7,2))+Str(board(7,3))+Str(board(7,4))+Str(board(7,5)))
DrawText(10,340,"ROW8: "+Str(Board(8,0))+Str(board(8,1))+Str(board(8,2))+Str(board(8,3))+Str(board(8,4))+Str(board(8,5)))
DrawText(10,390,"Mouse: "+Str(Maus\x)+"::"+Str(Maus\y))
StopDrawing()
DisplayTransparentSprite(#Cursor, Maus\x , Maus\y )
DisplayTransparentSprite(#CursorPoint, Maus\x , Maus\y )
Stop3D()
FlipBuffers()
If KeyboardPushed(#PB_Key_Escape)
Quit = 1
EndIf
Delay(3)
Until Quit
End
{{{ POSTED IN NEXT POST BY ME!}}






