'// Ludo v.01 By John Onyon a.k.a Unseen Machine \\
CONST White
= 1, Green
= 2, Yellow
= 3, Red
= 4, Blue
= 5, Home
= 6, Human
= 1, CPU
= 2, MainMenu
= 1, InGame
= 2 CONST Attack
= 1, Move
= 2, GetOut
= 3
DIM Mouse
(1) AS MouseState
, Kb
(1) AS KeyBoardState
, VQB_Mouse
(1) AS MouseInfo
GDK_Screen_SetRes MainScreen&, 800, 600
VQB_Button_New Btn
(0), 300, 160, 200, 35, _RGB32(155, 155, 255), "One Player Game"VQB_Button_New Btn
(1), 300, 210, 200, 35, _RGB32(155, 155, 255), "Two Player Game"VQB_Button_New Btn
(2), 300, 260, 200, 35, _RGB32(155, 155, 255), "Three Player Game"VQB_Button_New Btn
(3), 300, 310, 200, 35, _RGB32(155, 155, 255), "Four Player Game"
GDK_Sprite_New Piece
, "Ludo\Tiles.png", 6, 3, 18, _RGB32(255, 0, 255)Piece.Scale = .8
GDK_Sprite_New D_Sprite
, "Ludo\Dice.png", 6, 1, 6, _RGB32(255, 0, 255)GDK_Sprite_SetRotationAsCenter D_Sprite
GameState = MainMenu
Debug% = TRUE
'////////// Main Screen Setup \\\\\\\
IF k%
= 0 THEN Board
(i%
, j%
) = Piece%
ELSE Board2
(i%
, j%
) = Piece%
VQB_Frame
5, 5, 790, 590, _RGB32(20, 70, 155)VQB_Frame
155, 55, 490, 490, _RGB32(50, 40, 85)VQB_Frame
300, 15, 200, 30, _RGB32(0, 0, 0)y% = 60
x% = 160
GDK_Sprite_DrawXY Piece, x%, y%, 0, Board(i%, j%)
x% = x% + 32
y% = y% + 32
BckGrnd& = VQB_StoreScreen&
'///////////// Load Path Data \\\\\\\\\\\
READ PlyrMove
(Plyr%
, Bit%
)
'//////////////// Main Loop \\\\\\\\\\\\\
VQB_RestoreScreen BckGrnd&
GDK_Mouse_GetState Mouse(0)
GDK_Keyboard_GetState Kb(0)
Col% = (Mouse(0).X - 160) \ 32
Row% = (Mouse(0).Y - 60) \ 32
'// Ensure we cant get an out off bounds error by capping the array refs
Row% = 0
Col% = 0
VQB_Mouse_GetInfo VQB_Mouse(0)
VQB_Frame
255, 135, 290, 240, _RGB32(150, 40, 5)
IF VQB_Button_Click
(Btn
(i%
), VQB_Mouse
(0)) THEN Num_Players% = i% + 1
GameState = InGame
Player(j%).Control = Human
Player(j%).Control = CPU
Player
(j%
).Persona
= INT(RND * 3) + 1 '// randomize priority (a.i mode) Current_Plyr = 1
Rolling = TRUE
VQB_Button_Draw Btn(i%)
NumRolls% = NumRolls% + 1
'// Check to see if player has only one piece out and the distance fits up to home, if not then skip to next player
IF Player
(Current_Plyr
- 1).Num_Out
= 1 THEN IF BoardBits
(i%
, j%
) = Current_Plyr
THEN ActualBlock% = (j% * 15) + i% + 1
Ref1% = -1
IF PlyrMove
(Current_Plyr
- 1, i%
) = ActualBlock%
THEN Ref1%
= i%
Rolling = FALSE
SelectPiece = TRUE
IF Current_Plyr
< 4 THEN Current_Plyr
= Current_Plyr
+ 1 ELSE Current_Plyr
= 1 NumRolls% = 0
Rolling = FALSE
SelectPiece = TRUE
Rolling = FALSE
SelectPiece = TRUE
NumRolls% = 0
BBHlp(0) = 2
BBHlp(1) = 6
BBHlp(2) = 1
BBHlp(0) = 8
BBHlp(1) = 2
BBHlp(2) = 2
BBHlp(0) = 12
BBHlp(1) = 8
BBHlp(2) = 3
BBHlp(0) = 6
BBHlp(1) = 12
BBHlp(2) = 4
IF Player
(Current_Plyr
- 1).Num_Home
< 4 THEN '// Player still has availble bits to use (still in the game) IF Player
(Current_Plyr
- 1).Num_Out
= 0 OR NewBit%
= TRUE
THEN '// If the player has no bits out automatically place one if a six is rolled
IF Dice
= 6 THEN '// roll a six to start moving a bit IF Player
(Current_Plyr
- 1).Num_Out
+ Player
(Current_Plyr
- 1).Num_Home
< 4 THEN IF BoardBits
(BBHlp
(0), BBHlp
(1)) <> Current_Plyr
THEN IF BoardBits
(BBHlp
(0), BBHlp
(1)) > 0 THEN '// Kick who ever is there back home
Player(BoardBits(BBHlp(0), BBHlp(1)) - 1).Num_Out = Player(BoardBits(BBHlp(0), BBHlp(1)) - 1).Num_Out - 1
'// Allocate the square
BoardBits(BBHlp(0), BBHlp(1)) = BBHlp(2)
Player(Current_Plyr - 1).Num_Out = Player(Current_Plyr - 1).Num_Out + 1
IF Current_Plyr
< 4 THEN Current_Plyr
= Current_Plyr
+ 1 ELSE Current_Plyr
= 1 Rolling = TRUE
IF Current_Plyr
< 4 THEN Current_Plyr
= Current_Plyr
+ 1 ELSE Current_Plyr
= 1 Rolling = TRUE
ELSE '// Have pieces out on the board
IF Player
(Current_Plyr
- 1).Control
= Human
THEN '// Human Player
IF Player
(Current_Plyr
- 1).Num_Out
+ Player
(Current_Plyr
- 1).Num_Home
< 4 THEN
Xpos% = 176 + (BBHlp(0) * 32)
Ypos% = 76 + (BBHlp(1) * 32)
CIRCLE (Xpos%
, Ypos%
), 6 + CSize%
, clr&
IF CSize%
< 6 THEN CSize%
= CSize%
+ 1 ELSE CSize%
= 1
IF BoardBits
(Col%
, Row%
) <> Current_Plyr
THEN IF BoardBits
(Col%
, Row%
) > 0 THEN Player(BoardBits(Col%, Row%) - 1).Num_Out = Player(BoardBits(Col%, Row%) - 1).Num_Out - 1
Player(Current_Plyr - 1).Num_Out = Player(Current_Plyr - 1).Num_Out + 1
BoardBits(Col%, Row%) = Current_Plyr
IF Current_Plyr
< 4 THEN Current_Plyr
= Current_Plyr
+ 1 ELSE Current_Plyr
= 1 Rolling = TRUE
IF Board2
(Col%
, Row%
) AND BoardBits
(Col%
, Row%
) = Current_Plyr
THEN '// Players bit Selected(0) = Col%
Selected(1) = Row%
SelectPiece = FALSE
IF Player
(Current_Plyr
- 1).Num_Out
> 0 THEN '// Player has active pieces FOR Bit%
= 0 TO Player
(Current_Plyr
- 1).Num_Out
'// Cycle through all bits the player has out Lp_Start% = 0
Lp_End% = 14
StepVal% = 1
Lp_Start% = 14
Lp_End% = 0
StepVal% = -1
FOR j%
= Lp_Start%
TO Lp_End%
STEP StepVal%
'// Rows FOR i%
= Lp_Start%
TO Lp_End%
STEP StepVal%
'// Columns
IF Player
(Current_Plyr
- 1).Num_Out
+ Player
(Current_Plyr
- 1).Num_Home
< 4 THEN '// Have pieces left to put out IF BoardBits
(BBHlp
(0), BBHlp
(1)) <> Current_Plyr
THEN '// Can place a new piece NewPiece% = TRUE
IF BoardBits
(BBHlp
(0), BBHlp
(1)) > 0 THEN '// Kick who ever is there back home Player(BoardBits(BBHlp(0), BBHlp(1)) - 1).Num_Out = Player(BoardBits(BBHlp(0), BBHlp(1)) - 1).Num_Out - 1
END IF '// Allocate the square BoardBits(BBHlp(0), BBHlp(1)) = BBHlp(2)
Player(Current_Plyr - 1).Num_Out = Player(Current_Plyr - 1).Num_Out + 1
IF Current_Plyr
< 4 THEN Current_Plyr
= Current_Plyr
+ 1 ELSE Current_Plyr
= 1 Rolling = TRUE
NewPiece% = FALSE
IF BoardBits
(i%
, j%
) = Current_Plyr
THEN '// Current players piece '// Get Array ref's
ActualBlock% = (j% * 15) + i% + 1
IF PlyrMove
(Current_Plyr
- 1, a%
) = ActualBlock%
THEN Ref1%
= a%
IF Ref1%
+ Dice
< 57 THEN '// Move is within range NewActual% = PlyrMove(Current_Plyr - 1, Ref1% + Dice)
NewRow% = (NewActual% - 1) \ 15
NewCol%
= (NewActual%
- 1) MOD 15 IF BoardBits
(NewCol%
, NewRow%
) <> Current_Plyr
THEN IF BoardBits
(NewCol%
, NewRow%
) > 0 THEN Player(BoardBits(NewCol%, NewRow%) - 1).Num_Out = Player(BoardBits(NewCol%, NewRow%) - 1).Num_Out - 1
BoardBits(NewCol%, NewRow%) = Current_Plyr
BoardBits(i%, j%) = 0
IF Current_Plyr
< 4 THEN Current_Plyr
= Current_Plyr
+ 1 ELSE Current_Plyr
= 1 Rolling = TRUE
IF Bit%
= Player
(Current_Plyr
- 1).Num_Out
THEN '// Last piece we could check so no valid moves at all - skip to next player IF Current_Plyr
< 4 THEN Current_Plyr
= Current_Plyr
+ 1 ELSE Current_Plyr
= 1 '// Skip players who've won Rolling = TRUE
GOTO NextBit
'// Skip to next player piece BoardBits(i%, j%) = 0
Rolling = TRUE
Player(Current_Plyr - 1).Num_Out = Player(Current_Plyr - 1).Num_Out - 1
Player(Current_Plyr - 1).Num_Home = Player(Current_Plyr - 1).Num_Home + 1
IF Player
(crrent_plyr
).Num_Home
= 4 THEN '// Win event
'// Ask if new game
IF Current_Plyr
< 4 THEN Current_Plyr
= Current_Plyr
+ 1 ELSE Current_Plyr
= 1 ELSE '// No valid move for this piece IF Bit%
= Player
(Current_Plyr
- 1).Num_Out
THEN '// Last piece we could check so no valid moves at all - skip to next player IF Current_Plyr
< 4 THEN Current_Plyr
= Current_Plyr
+ 1 ELSE Current_Plyr
= 1 '// Skip players who've won Rolling = TRUE
NextBit:
IF Current_Plyr
< 4 THEN Current_Plyr
= Current_Plyr
+ 1 ELSE Current_Plyr
= 1 '// Skip players who've won
Skip_Loops:
IF Player
(Current_Plyr
- 1).Control
= Human
THEN '// Calculate how many squares the move is (must be same as dice roll value)
ActualBlock% = (Selected(1) * 15) + Selected(0) + 1
NewActual% = (Row% * 15) + Col% + 1
Ref1% = -1: Ref2% = -1
'// Find origin and new point in array and get differance in position
IF PlyrMove
(Current_Plyr
- 1, i%
) = ActualBlock%
THEN Ref1%
= i%
IF PlyrMove
(Current_Plyr
- 1, i%
) = NewActual%
THEN Ref2%
= i%
Distance% = Ref2% - Ref1%
IF Board2
(Col%
, Row%
) THEN '// Selected destination is allowed to be moved to IF BoardBits
(Col%
, Row%
) = Current_Plyr
THEN '// Own piece, dependant on rule settings what happens here SelectPiece = TRUE
ELSE '// Occupied by someone else, kick them home! IF BoardBits
(Col%
, Row%
) <> Current_Plyr
AND BoardBits
(Col%
, Row%
) > 0 THEN Player(BoardBits(Col%, Row%) - 1).Num_Out = Player(BoardBits(Col%, Row%) - 1).Num_Out - 1
'// If dest was ok then move bit and change player
BoardBits(Selected(0), Selected(1)) = 0
BoardBits(Col%, Row%) = Current_Plyr
IF Current_Plyr
< 4 THEN Current_Plyr
= Current_Plyr
+ 1 ELSE Current_Plyr
= 1 Rolling = TRUE
ELSEIF NewActual%
= PlyrMove
(Current_Plyr
- 1, 57) THEN '// Home Square BoardBits(Selected(0), Selected(1)) = 0
Player(Current_Plyr - 1).Num_Home = Player(Current_Plyr - 1).Num_Home + 1
Player(Current_Plyr - 1).Num_Out = Player(Current_Plyr - 1).Num_Out - 1
IF Current_Plyr
< 4 THEN Current_Plyr
= Current_Plyr
+ 1 ELSE Current_Plyr
= 1 Rolling = TRUE
IF Col%
= Selected
(0) AND Row%
= Selected
(1) THEN SelectPiece = TRUE
Selected(0) = 0
Selected(1) = 0
'/////////////////// Draw Bits \\\\\\\\\\\\\\\\\\\\\\\\\\
y% = 76
x% = 176
IF i%
= Selected
(0) AND j%
= Selected
(1) THEN x% = x% + 32
y% = y% + 32
GDK_Sprite_DrawXY D_Sprite, 720, 300, Rot!, Dice
GDK_Sprite_DrawXY Piece, 440, 550, 0, 10 + Current_Plyr
GDK_Sprite_DrawXY Piece, 340, 550, 0, 15
GDK_Sprite_DrawXY Piece, 372, 550, 0, 16
GDK_Sprite_DrawXY Piece, 404, 550, 0, 17
'///////////////////
Kb(1) = Kb(0)
Mouse(1) = Mouse(0)
VQB_Mouse(1) = VQB_Mouse(0)
'///////////////////
NewActual% = (Row% * 15) + Col% + 1
PRINT "Last Dice Roll : "; Dice
PRINT "Distance calc : "; Distance%
PRINT "Select piece mode : "; SelectPiece
PRINT "Current Player : "; Current_Plyr
PRINT "Actual Block # : "; ActualBlock%
PRINT "New Block # : "; NewActual%
PRINT "Player Num Out : "; Player
(Current_Plyr
- 1).Num_Out
PRINT "Player Num Home : "; Player
(Current_Plyr
- 1).Num_Home
'///////////////////
Blank_Board:
DATA 2,2,2,2,2,2,1,1,1,3,3,3,3,3,3 DATA 2,1,2,2,1,2,1,3,3,3,1,3,3,1,3 DATA 2,2,2,2,2,2,1,3,1,3,3,3,3,3,3 DATA 2,2,2,2,2,2,1,3,1,3,3,3,3,3,3 DATA 2,1,2,2,1,2,1,3,1,3,1,3,3,1,3 DATA 2,2,2,2,2,2,1,3,1,3,3,3,3,3,3 DATA 1,2,1,1,1,1,7,3,8,1,1,1,1,1,1 DATA 1,2,2,2,2,2,2,6,5,5,5,5,5,5,1 DATA 1,1,1,1,1,1,10,4,9,1,1,1,1,5,1 DATA 4,4,4,4,4,4,1,4,1,5,5,5,5,5,5 DATA 4,1,4,4,1,4,1,4,1,5,1,5,5,1,5 DATA 4,4,4,4,4,4,1,4,1,5,5,5,5,5,5 DATA 4,4,4,4,4,4,1,4,1,5,5,5,5,5,5 DATA 4,1,4,4,1,4,4,4,1,5,1,5,5,1,5 DATA 4,4,4,4,4,4,1,1,1,5,5,5,5,5,5
DATA 0,0,0,0,0,0,1,1,1,0,0,0,0,0,0 DATA 0,0,0,0,0,0,1,1,1,0,0,0,0,0,0 DATA 0,0,0,0,0,0,1,1,1,0,0,0,0,0,0 DATA 0,0,0,0,0,0,1,1,1,0,0,0,0,0,0 DATA 0,0,0,0,0,0,1,1,1,0,0,0,0,0,0 DATA 0,0,0,0,0,0,1,1,1,0,0,0,0,0,0 DATA 1,1,1,1,1,1,0,0,0,1,1,1,1,1,1 DATA 1,1,1,1,1,1,0,0,0,1,1,1,1,1,1 DATA 1,1,1,1,1,1,0,0,0,1,1,1,1,1,1 DATA 0,0,0,0,0,0,1,1,1,0,0,0,0,0,0 DATA 0,0,0,0,0,0,1,1,1,0,0,0,0,0,0 DATA 0,0,0,0,0,0,1,1,1,0,0,0,0,0,0 DATA 0,0,0,0,0,0,1,1,1,0,0,0,0,0,0 DATA 0,0,0,0,0,0,1,1,1,0,0,0,0,0,0 DATA 0,0,0,0,0,0,1,1,1,0,0,0,0,0,0
'// Player movement data, actual square numbers. I had to make another program just to make this!
DATA 93,94,95,96,82,67,52,37,22,7,8,9,24,39,54,69,84,100,101,102,103,104,105,120,135,134,133,132,131,130,144,159,174,189,204,219,218,217,202,187,172,157,142,126,125,124,123,122,121,106,91,92,107,108,109,110,111,112 DATA 39,54,69,84,100,101,102,103,104,105,120,135,134,133,132,131,130,144,159,174,189,204,219,218,217,202,187,172,157,142,126,125,124,123,122,121,106,91,92,93,94,95,96,82,67,52,37,22,7,8,9,24,23,38,53,68,83,98 DATA 133,132,131,130,144,159,174,189,204,219,218,217,202,187,172,157,142,126,125,124,123,122,121,106,91,92,93,94,95,96,82,67,52,37,22,7,8,9,24,39,54,69,84,100,101,102,103,104,105,120,135,134,119,118,117,116,115,114 DATA 187,172,157,142,126,125,124,123,122,121,106,91,92,93,94,95,96,82,67,52,37,22,7,8,9,24,39,54,69,84,100,101,102,103,104,105,120,135,134,133,132,131,130,144,159,174,189,204,219,218,217,202,203,188,173,158,143,128
REM $include:'Vqb\Vqb_lite.bm'