int main() { LoadAssets(); ClearObjects(); InitialiseStage(); uint16_t oldKeys = REG_P1; Cursor cursor = Cursor(0); bool pieceSelected = false; int currentPiece = 0; int* moves = new int[28]; int* takingMoves = new int[16]; int currentTurnColor = WHITE; for(int i = 0; i < 2; i++) for(int j = 0; j < 16; j++) _lostPieces[i][j] = -1; while (true) { if(!(REG_P1 & KEY_RIGHT) && (oldKeys & KEY_RIGHT)) cursor.Move(1, 0); if(!(REG_P1 & KEY_LEFT) && (oldKeys & KEY_LEFT)) cursor.Move(-1, 0); if(!(REG_P1 & KEY_DOWN) && (oldKeys & KEY_DOWN)) cursor.Move(0, 1); if(!(REG_P1 & KEY_UP) && (oldKeys & KEY_UP)) cursor.Move(0, -1); if(!(REG_P1 & KEY_A) && (oldKeys & KEY_A)) { if(PieceAt(cursor.X(), cursor.Y())) { pieceSelected = true; for(int i = 0; i < 16 && takingMoves[i] >= 0; i++) if(takingMoves[i] % 8 == cursor.X() && takingMoves[i] / 8 == cursor.Y()) { TakePiece(currentPiece % 8, currentPiece / 8, cursor.X(), cursor.Y()); currentTurnColor = (currentTurnColor == WHITE ? BLACK : WHITE); pieceSelected = false; ClearHighlights(); takingMoves[0] = -1; break; } if(pieceSelected && PieceColor(cursor.X(), cursor.Y()) == currentTurnColor) { ClearHighlights(); AvailableMoves(cursor.X(), cursor.Y(), moves, takingMoves); currentPiece = cursor.Y() * 8 + cursor.X(); for(int i = 0; i < 28 && moves[i] >= 0; i++) Highlight(moves[i] % 8, moves[i] / 8, GREEN); for(int i = 0; i < 16 && takingMoves[i] >= 0; i++) Highlight(takingMoves[i] % 8, takingMoves[i] / 8, RED); } } else if(pieceSelected) { ClearHighlights(); if(!PieceAt(cursor.X(), cursor.Y())) { for(int i = 0; i < 28 && moves[i] >= 0; i++) if(moves[i] % 8 == cursor.X() && moves[i] / 8 == cursor.Y()) { MovePiece(currentPiece % 8, currentPiece / 8, cursor.X(), cursor.Y()); currentTurnColor = (currentTurnColor == WHITE ? BLACK : WHITE); pieceSelected = false; break; } } } } oldKeys = REG_P1; if(currentTurnColor == WHITE) DrawString(20, 1, "WHITE", 5); else DrawString(20, 1, "BLACK", 5); WaitVSync(); UpdateObjects(); } return 0; }