'// Quake Chess V.01
'// By John Onyon a.k.a Unseen Machine
'// Created 01/04/2020
'// Last Update 07/04/2020
CONST FP
= 1, Fixed
= 2, Action
= 3, Battle
= 4 CONST Standing
= 1, Walking
= 2, Attack
= 3, BeingHit
= 4, Falling
= 5 '// Animation ref constants CONST North
= 270, NE
= 315, East
= 360, SE
= 45, South
= 90, SW
= 135, West
= 180, NW
= 225 '// Rotation Direction Constants
DIM SHARED Board
(1 TO 8, 1 TO 8) AS Square
'// T1: Pawn = 1, Rook = 2, knight = 3, Bishop = 4, King = 5, Queen = 6 / Team 2 = same + 6 DIM SHARED Anim
(5, 1 TO 5) AS ANIMATION
'// Standing, Walking, Running, Attacking, Falling DIM Mouse
(1) AS MouseState
, KB
(1) AS KeyBoardState
DIM SHARED Blank_Square
AS Square
'// Used for easily resetting squares
RadHelp#
= (4 * ATN(1)) / 180
_FPS 30
CamMode = Fixed
CamVec.Rot.X
= 270: CamVec.Rot.Y
= 180: CamVec.
Pos.Y
= 400Debug% = True
Select_Piece% = True
Plyr% = 1
'// Limit (x,xx,y,yy) 134, 664, 34, 564 '// step 66.25
Limit(0) = 134: Limit(1) = 664: Limit(2) = 34: Limit(3) = 564
Allow_GL = True
GDK_Keyboard_GetState KB(0)
GDK_Mouse_GetState Mouse(0) '// Get the mouse state
CamVec.Rot.X = CamVec.Rot.X + (Mouse(0).Y - Mouse(1).Y)
CamVec.Rot.Y = CamVec.Rot.Y + (Mouse(0).X - Mouse(1).X)
IF CamVec.Rot.Y
> 360 THEN CamVec.Rot.Y
= CamVec.Rot.Y
- 360 StrafeY# = (CamVec.Rot.Y + 90) * RadHelp#
StrafeX# = (CamVec.Rot.X + 90) * RadHelp#
YSin#
= SIN(CamVec.Rot.Y
* RadHelp#
) * 5 YCos#
= COS(CamVec.Rot.Y
* RadHelp#
) * 5 XSin#
= SIN(CamVec.Rot.X
* RadHelp#
) * 5 CamVec.
Pos.X
= CamVec.
Pos.X
- YSin#
CamVec.
Pos.Y
= CamVec.
Pos.Y
- XSin#
CamVec.
Pos.Z
= CamVec.
Pos.Z
+ YCos#
CamVec.
Pos.X
= CamVec.
Pos.X
+ YSin#
CamVec.
Pos.Y
= CamVec.
Pos.Y
+ XSin#
CamVec.
Pos.Z
= CamVec.
Pos.Z
- YCos#
CamVec.Rot.X = 270
IF Mouse
(0).X
>= Limit
(0) AND Mouse
(0).X
<= Limit
(1) THEN IF Mouse
(0).Y
>= Limit
(2) AND Mouse
(0).Y
<= Limit
(3) THEN MX% = Mouse(0).X - Limit(0)
MY% = Mouse(0).Y - Limit(2)
MouseCol% = 1 + (MX% \ 66.25)
MouseRow% = 1 + (MY% \ 66.25)
IF Mouse
(0).LB
AND NOT Mouse
(1).LB
THEN '// Selecting a piece to move IF Board
(MouseCol%
, MouseRow%
).PieceID
< 7 AND Board
(MouseCol%
, MouseRow%
).PieceID
> 0 THEN Selected(0) = MouseCol%
Selected(1) = MouseRow%
Select_Piece% = False
IF Board
(MouseCol%
, MouseRow%
).PieceID
>= 7 THEN Selected(0) = MouseCol%
Selected(1) = MouseRow%
Select_Piece% = False
ELSE '// Setting destination
SELECT CASE Board
(Selected
(0), Selected
(1)).PieceID
IF MouseCol%
<> Selected
(0) THEN '// Diagonal attack IF MouseRow%
= Selected
(1) + 1 THEN IF MouseCol%
= Selected
(0) - 1 OR MouseCol%
= Selected
(0) + 1 THEN IF Board
(MouseCol%
, MouseRow%
).PieceID
>= 7 THEN Moving
= True
IF MouseRow%
= Selected
(1) - 1 THEN IF MouseCol%
= Selected
(0) - 1 OR MouseCol%
= Selected
(0) + 1 THEN IF Board
(MouseCol%
, MouseRow%
).PieceID
<= 6 AND Board
(MouseCol%
, MouseRow%
).PieceID
> 0 THEN Moving
= True
IF Board
(MouseCol%
, MouseRow%
).PieceID
= 0 THEN IF Board
(Selected
(0), Selected
(1)).First_Move
= False
THEN IF MouseRow%
= 3 OR MouseRow%
= 4 THEN Moving
= True
IF MouseRow%
= Selected
(1) + 1 THEN Moving
= True
IF Board
(Selected
(0), Selected
(1)).First_Move
= False
THEN IF MouseRow%
= 5 OR MouseRow%
= 6 THEN Moving
= True
IF MouseRow%
= Selected
(1) - 1 THEN Moving
= True
IF MouseCol%
= Selected
(0) THEN '// Vertical move
FOR Row%
= Selected
(1) + StepVal%
TO MouseRow%
STEP StepVal%
IF Board
(Selected
(0), Row%
).PieceID
> 0 THEN IF Row%
= MouseRow%
THEN '// Attacking move IF Board
(Selected
(0), Row%
).PieceID
<= 6 THEN GOTO Skip_Case
IF Board
(Selected
(0), Row%
).PieceID
>= 7 THEN GOTO Skip_Case
Moving = True
IF Row%
= MouseRow%
THEN Moving
= True
ELSEIF MouseRow%
= Selected
(1) THEN '// Horizontal move
FOR Col%
= Selected
(0) + StepVal%
TO MouseCol%
STEP StepVal%
IF Board
(Col%
, Selected
(1)).PieceID
> 0 THEN IF Row%
= MouseRow%
THEN '// Attacking move IF Board
(Col%
, Selected
(1)).PieceID
<= 6 THEN GOTO Skip_Case
IF Board
(Col%
, Selected
(1)).PieceID
>= 7 THEN GOTO Skip_Case
Moving = True
IF Col%
= MouseCol%
THEN Moving
= True
IF MouseRow%
> Selected
(1) THEN RowDif% = MouseRow% - Selected(1)
Y_Inc% = 1
RowDif% = Selected(1) - MouseRow%
Y_Inc% = -1
IF MouseCol%
> Selected
(0) THEN ColDif% = MouseCol% - Selected(0)
X_Inc% = 1
ColDif% = Selected(0) - MouseCol%
X_Inc% = -1
IF RowDif%
= ColDif%
THEN '// Might be a valid move, check for stuff in the way
Row% = Selected(1) + Y_Inc%
FOR Col%
= Selected
(0) + X_Inc%
TO MouseCol%
STEP X_Inc%
IF Board
(Col%
, Row%
).PieceID
> 0 THEN '// Something on the square IF Board
(Col%
, Row%
).PieceID
> 6 THEN Moving
= True
ELSE GOTO Skip_Case
IF Board
(Col%
, Row%
).PieceID
<= 6 THEN Moving
= True
ELSE GOTO Skip_Case
GOTO Skip_Case
'// illegal move IF Col%
= MouseCol%
THEN Moving
= True
Row% = Row% + Y_Inc%
IF MouseRow%
> Selected
(1) THEN RowDif% = MouseRow% - Selected(1)
RowDif% = Selected(1) - MouseRow%
GOTO Skip_Case
'// Invalid move
IF MouseCol%
> Selected
(0) THEN ColDif% = MouseCol% - Selected(0)
ColDif% = Selected(0) - MouseCol%
GOTO Skip_Case
'// Invalid move
IF (RowDif%
= 2 AND ColDif%
= 1) OR (RowDif%
= 1 AND ColDif%
= 2) THEN IF Board
(MouseCol%
, MouseRow%
).PieceID
= 0 OR Board
(MouseCol%
, MouseRow%
).PieceID
> 6 THEN Moving
= True
ELSE GOTO Skip_Case
IF Board
(MouseCol%
, MouseRow%
).PieceID
= 0 OR Board
(MouseCol%
, MouseRow%
).PieceID
< 7 THEN Moving
= True
ELSE GOTO Skip_Case
GOTO Skip_Case
'// Invalid move
IF MouseRow%
> Selected
(1) THEN RowDif% = MouseRow% - Selected(1)
RowDif% = Selected(1) - MouseRow%
RowDif% = 0
IF MouseCol%
> Selected
(0) THEN ColDif% = MouseCol% - Selected(0)
ColDif% = Selected(0) - MouseCol%
ColDif% = 0
IF Board
(MouseCol%
, MouseRow%
).PieceID
= 0 OR Board
(MouseCol%
, MouseRow%
).PieceID
> 6 THEN Moving
= True
ELSE GOTO Skip_Case
IF Board
(MouseCol%
, MouseRow%
).PieceID
= 0 OR Board
(MouseCol%
, MouseRow%
).PieceID
< 7 THEN Moving
= True
ELSE GOTO Skip_Case
CASE 6, 12 '// queen '// Mixture of rook and bishop movement
IF MouseCol%
= Selected
(0) THEN '// Vertical move
FOR Row%
= Selected
(1) + StepVal%
TO MouseRow%
STEP StepVal%
IF Board
(Selected
(0), Row%
).PieceID
> 0 THEN IF Row%
= MouseRow%
THEN '// Attacking move IF Board
(Selected
(0), Row%
).PieceID
<= 6 THEN GOTO Skip_Case
IF Board
(Selected
(0), Row%
).PieceID
>= 7 THEN GOTO Skip_Case
Moving = True
IF Row%
= MouseRow%
THEN Moving
= True
ELSEIF MouseRow%
= Selected
(1) THEN '// Horizontal move
FOR Col%
= Selected
(0) + StepVal%
TO MouseCol%
STEP StepVal%
IF Board
(Col%
, Selected
(1)).PieceID
> 0 THEN IF Row%
= MouseRow%
THEN '// Attacking move IF Board
(Col%
, Selected
(1)).PieceID
<= 6 THEN GOTO Skip_Case
IF Board
(Col%
, Selected
(1)).PieceID
>= 7 THEN GOTO Skip_Case
Moving = True
IF Col%
= MouseCol%
THEN Moving
= True
IF MouseRow%
> Selected
(1) THEN RowDif% = MouseRow% - Selected(1)
Y_Inc% = 1
RowDif% = Selected(1) - MouseRow%
Y_Inc% = -1
IF MouseCol%
> Selected
(0) THEN ColDif% = MouseCol% - Selected(0)
X_Inc% = 1
ColDif% = Selected(0) - MouseCol%
X_Inc% = -1
IF RowDif%
= ColDif%
THEN '// Might be a valid move, check for stuff in the way Row% = Selected(1) + Y_Inc%
FOR Col%
= Selected
(0) + X_Inc%
TO MouseCol%
STEP X_Inc%
IF Board
(Col%
, Row%
).PieceID
> 0 THEN '// Something on the square IF Board
(Col%
, Row%
).PieceID
> 6 THEN Moving
= True
ELSE GOTO Skip_Case
IF Board
(Col%
, Row%
).PieceID
<= 6 THEN Moving
= True
ELSE GOTO Skip_Case
GOTO Skip_Case
'// illegal move IF Col%
= MouseCol%
THEN Moving
= True
Row% = Row% + Y_Inc%
Select_Piece% = True
'/////////////////////////////////////////
IF Moving
= True
THEN '// If any pieces have been set to move then do stuff here
IF NOT Board
(Selected
(0), Selected
(1)).PieceID
= 4 AND NOT Board
(Selected
(0), Selected
(1)).PieceID
= 10 THEN '// Calculate rotation
IF Selected
(0) <> MouseCol%
THEN IF Selected
(1) <> MouseRow%
THEN '// Diagonal movement IF MouseCol%
> Selected
(0) THEN IF MouseRow%
< Selected
(1) THEN Board(Selected(0), Selected(1)).Rotation = SE
Board(Selected(0), Selected(1)).Rotation = NE
IF MouseRow%
< Selected
(1) THEN Board(Selected(0), Selected(1)).Rotation = SW
Board(Selected(0), Selected(1)).Rotation = NW
ELSE '// Horizontal movement only IF MouseCol%
> Selected
(0) THEN Board(Selected(0), Selected(1)).Rotation = East
Board(Selected(0), Selected(1)).Rotation = West
ELSE '// Vertical movement only IF MouseRow%
< Selected
(1) THEN Board(Selected(0), Selected(1)).Rotation = South
Board(Selected(0), Selected(1)).Rotation = North
ELSE '// a knight - rotation calculated on the fly IF MouseCol%
> Selected
(0) THEN XVal% = MouseCol% - Selected(0)
XVal% = Selected(0) - MouseCol%
IF MouseRow%
> Selected
(1) THEN YVal% = MouseRow% - Selected(1)
YVal% = Selected(1) - MouseRow%
Board(Selected(0), Selected(1)).Rotation = atan2(XVal%, YVal%) + 315
'// calculate relative x/y offset per animation frame for moving
IF Board
(Selected
(0), Selected
(1)).PieceID
>= 7 THEN PieceId% = Board(Selected(0), Selected(1)).PieceID - 6
PieceId% = Board(Selected(0), Selected(1)).PieceID
Frames% = Anim(PieceId% - 1, Walking).ResetFrame - Anim(PieceId% - 1, Walking).StartFrame
IF MouseCol%
< Selected
(0) THEN Board(Selected(0), Selected(1)).X_Inc = 3
Board(Selected(0), Selected(1)).X_Inc = -3
Board(Selected(0), Selected(1)).X_Inc = 0
IF MouseRow%
< Selected
(1) THEN Board(Selected(0), Selected(1)).Z_Inc = -3
Board(Selected(0), Selected(1)).Z_Inc = 3
Board(Selected(0), Selected(1)).Z_Inc = 0
Board(Selected(0), Selected(1)).Anim = Anim(PieceId% - 1, Walking)
'// Switch cam mode to action view
CamMode = Action
CASE Action
'// Action camera used for movement animations /////////////////////////////////////////
IF Board
(Selected
(0), Selected
(1)).X_Offset
< 0 THEN Rel_Col% = Selected(0) - (Board(Selected(0), Selected(1)).X_Offset / 66.25)
Rel_Col% = Selected(0) + (Board(Selected(0), Selected(1)).X_Offset / -66.25)
IF Board
(Selected
(0), Selected
(1)).Z_Offset
< 0 THEN Rel_Row% = Selected(1) - (Board(Selected(0), Selected(1)).Z_Offset / -66.25)
Rel_Row% = Selected(1) + (Board(Selected(0), Selected(1)).Z_Offset / 66.25)
IF Rel_Col%
= MouseCol%
AND Rel_Row%
= MouseRow%
THEN '// At the end of movement - trigger battle if needed then swap/clear sqaures
Board(MouseCol%, MouseRow%) = Blank_Square
IF Board
(Selected
(0), Selected
(1)).First_Move
= False
THEN Board
(Selected
(0), Selected
(1)).First_Move
= True
SWAP Board
(MouseCol%
, MouseRow%
), Board
(Selected
(0), Selected
(1)) Board(MouseCol%, MouseRow%).X_Offset = 0
Board(MouseCol%, MouseRow%).Z_Offset = 0
IF Board
(MouseCol%
, MouseRow%
).PieceID
>= 7 THEN PieceId% = Board(MouseCol%, MouseRow%).PieceID - 6
PieceId% = Board(MouseCol%, MouseRow%).PieceID
Board(MouseCol%, MouseRow%).Anim = Anim(PieceId% - 1, Standing)
Moving = False
CamMode = Fixed
Board(Selected(0), Selected(1)).X_Offset = Board(Selected(0), Selected(1)).X_Offset + Board(Selected(0), Selected(1)).X_Inc
Board(Selected(0), Selected(1)).Z_Offset = Board(Selected(0), Selected(1)).Z_Offset + Board(Selected(0), Selected(1)).Z_Inc
CASE Battle
'// Fighting animations /////////////////////////////////////////
Skip_Case: '// get sent here by doing an invalid move
'////////////// DEBUG ////////////////////
PRINT "MOUSE (X,Y) : "; Mouse
(0).X; Mouse
(0).Y
PRINT "Col/Row : "; MouseCol%; MouseRow%
PRINT "Selected Col/Row : "; Selected
(0); Selected
(1) PRINT "Rel_Col/Rel_Row : "; Rel_Col%; Rel_Row%
'/////////////////////////////////////////
KB(1) = KB(0)
Mouse(1) = Mouse(0)
Default_Board:
'//////////////////////////////////
'//////////////////////////////////
Anim
AS ANIMATION
'// Current animation First_Move
AS _BYTE '// If the piece has moved before or not X_Offset
AS INTEGER '// Position offsets for movement animations X_Inc
AS _BYTE '// Position offset increments (per animation frame)
'//////////////////////////////////
IF NOT GDK_GL_MODEL_LOAD
(Model
(0), "GDK_Gl\QuakeChess\zombie.mdl") THEN PRINT "Failed to load model." '// Pawn IF NOT GDK_GL_MODEL_LOAD
(Model
(1), "GDK_Gl\QuakeChess\ogre.mdl") THEN PRINT "Failed to load model." '// Rook IF NOT GDK_GL_MODEL_LOAD
(Model
(2), "GDK_Gl\QuakeChess\wizard.mdl") THEN PRINT "Failed to load model." '// Bishop IF NOT GDK_GL_MODEL_LOAD
(Model
(3), "GDK_Gl\QuakeChess\knight.mdl") THEN PRINT "Failed to load model." '// Knight IF NOT GDK_GL_MODEL_LOAD
(Model
(4), "GDK_Gl\QuakeChess\soldier.mdl") THEN PRINT "Failed to load model." '// King IF NOT GDK_GL_MODEL_LOAD
(Model
(5), "GDK_Gl\QuakeChess\demon.mdl") THEN PRINT "Failed to load model." '// Queen
'// Zombie animations - Pawns
GDK_ANIMATION_NEW Anim
(0, Standing
), 1, 1, 14, .1, TIMER(.001) GDK_ANIMATION_NEW Anim
(0, Walking
), 34, 34, 51, .05, TIMER(.001) GDK_ANIMATION_NEW Anim
(0, Attack
), 52, 52, 90, .1, TIMER(.001) GDK_ANIMATION_NEW Anim
(0, BeingHit
), 131, 131, 149, .1, TIMER(.001) GDK_ANIMATION_NEW Anim
(0, Falling
), 163, 163, 173, .1, TIMER(.001)
'// Ogre animations - Rooks
GDK_ANIMATION_NEW Anim
(1, Standing
), 1, 1, 8, .1, TIMER(.001) GDK_ANIMATION_NEW Anim
(1, Walking
), 9, 9, 24, .05, TIMER(.001) GDK_ANIMATION_NEW Anim
(1, Attack
), 33, 33, 60, .1, TIMER(.001) GDK_ANIMATION_NEW Anim
(1, BeingHit
), 131, 131, 149, .1, TIMER(.001) '// Not set yet GDK_ANIMATION_NEW Anim
(1, Falling
), 112, 112, 125, .1, TIMER(.001)
'// Wizard animation - Bishops
GDK_ANIMATION_NEW Anim
(2, Standing
), 1, 1, 14, .1, TIMER(.001) GDK_ANIMATION_NEW Anim
(2, Walking
), 15, 15, 28, .05, TIMER(.001) GDK_ANIMATION_NEW Anim
(2, Attack
), 29, 29, 41, .1, TIMER(.001) GDK_ANIMATION_NEW Anim
(2, BeingHit
), 131, 131, 149, .1, TIMER(.001) '// Not set yet GDK_ANIMATION_NEW Anim
(2, Falling
), 42, 42, 53, .1, TIMER(.001)
'// Knight animations - Knight
GDK_ANIMATION_NEW Anim
(3, Standing
), 1, 1, 8, .1, TIMER(.001) GDK_ANIMATION_NEW Anim
(3, Walking
), 53, 53, 66, .05, TIMER(.001) GDK_ANIMATION_NEW Anim
(3, Attack
), 42, 42, 52, .1, TIMER(.001) GDK_ANIMATION_NEW Anim
(3, BeingHit
), 28, 28, 41, .1, TIMER(.001) GDK_ANIMATION_NEW Anim
(3, Falling
), 86, 86, 97, .1, TIMER(.001)
'// Demon animations - King
GDK_ANIMATION_NEW Anim
(4, Standing
), 1, 1, 7, .1, TIMER(.001) GDK_ANIMATION_NEW Anim
(4, Walking
), 90, 90, 114, .05, TIMER(.001) GDK_ANIMATION_NEW Anim
(4, Attack
), 81, 81, 89, .1, TIMER(.001) GDK_ANIMATION_NEW Anim
(4, BeingHit
), 46, 46, 60, .1, TIMER(.001) GDK_ANIMATION_NEW Anim
(5, Falling
), 9, 9, 17, .1, TIMER(.001)
'// Soldier animations - Queen
GDK_ANIMATION_NEW Anim
(5, Standing
), 1, 1, 12, .1, TIMER(.001) GDK_ANIMATION_NEW Anim
(5, Walking
), 13, 13, 20, .05, TIMER(.001) GDK_ANIMATION_NEW Anim
(5, Attack
), 54, 54, 69, .1, TIMER(.001) GDK_ANIMATION_NEW Anim
(5, BeingHit
), 131, 131, 149, .1, TIMER(.001) '// Not set yet GDK_ANIMATION_NEW Anim
(5, Falling
), 44, 44, 53, .1, TIMER(.001)
IF Piece%
>= 7 THEN AnimRef%
= Piece%
- 7 ELSE AnimRef%
= Piece%
- 1
Board(i%, 2).PieceID = Piece%
Board(i%, 2).Anim = Anim(AnimRef%, Standing)
Board(i%, 1).PieceID = Piece%
Board(i%, 1).Anim = Anim(AnimRef%, Standing)
Board(i%, 7).PieceID = Piece%
Board(i%, 7).Anim = Anim(AnimRef%, Standing)
Board(i%, 8).PieceID = Piece%
Board(i%, 8).Anim = Anim(AnimRef%, Standing)
Floor(0) = GDK_GL_LOAD_TEXTURE("GDK_GL\QuakeChess\FloorRed.png")
Floor(1) = GDK_GL_LOAD_TEXTURE("GDK_GL\QuakeChess\FloorWhite.png")
FloorZ% = -200
FloorY% = 20
FloorX% = -200
GDK_GL_SET_TEXTURE Floor(1)
White% = False
GDK_GL_SET_TEXTURE Floor(0)
White% = True
FloorX% = FloorX% + 50
FloorZ% = FloorZ% + 50
Init = True
GDK_GL_CLS
'// Set the view to the cameras position
GDK_GL_VECTOR_APPLY_RT CamVec
CASE Fixed
, Action
'// Very similar so easier to adda fe IF's over a whole case block
FloorZ% = -175
FloorY% = -55
FloorX% = 175
_glTranslatef FloorX%
+ Board
(i%
, j%
).X_Offset
, FloorY%
, FloorZ%
+ Board
(i%
, j%
).Z_Offset
IF Moving
= False
THEN '// Normal view IF i%
= Selected
(0) AND j%
= Selected
(1) THEN
GDK_ANIMATION_UPDATE Board(i%, j%).Anim
GDK_GL_MODEL_DRAW Model(0), Board(i%, j%).Anim.Frame
GDK_GL_MODEL_DRAW Model(1), Board(i%, j%).Anim.Frame
GDK_GL_MODEL_DRAW Model(2), Board(i%, j%).Anim.Frame
GDK_GL_MODEL_DRAW Model(3), Board(i%, j%).Anim.Frame
GDK_GL_MODEL_DRAW Model(4), Board(i%, j%).Anim.Frame
GDK_GL_MODEL_DRAW Model(5), Board(i%, j%).Anim.Frame
FloorX% = FloorX% - 50
FloorZ% = FloorZ% + 50