-
Notifications
You must be signed in to change notification settings - Fork 1
Timer
DuncanSzabaga edited this page Nov 23, 2025
·
1 revision
This document explains the current timer implementation and provides a guide for implementing a full turn-based chess system in the future.
The timer is a simple countdown mechanism managed by the Timer object.
-
Initialization (
CreateEvent):- Reads
global.turnTime(e.g., "5 mins"). - Parses the string to calculate total seconds.
- Converts seconds to game frames:
timer_total_frames = total_seconds * room_speed. - Sets
timer_frames_leftto this total.
- Reads
-
Countdown (
StepEvent):- Checks if
global.timer_enabledistrue. - Decrements
timer_frames_leftby 1 every frame. - Stops at 0.
- Checks if
-
Display (
DrawEvent):- Calculates minutes (
div 60) and seconds (mod 60) from the remaining frames. - Formats them as
MM:SSstring. - Draws the text on screen.
- Calculates minutes (
-
global.turnTime: String setting the duration (e.g., "5 mins"). -
global.timer_enabled: Boolean to pause/resume the timer. -
global.turnOrder: String tracking whose turn it is (e.g., "player", "cpu").
To implement a proper turn-based system where the timer resets each turn, follow these steps:
Create a TurnManager script or object to handle state changes. Do not scatter this logic across buttons or pieces.
// Script: TurnManager.gml
function end_turn() {
// 1. Switch Sides
if (global.turnOrder == "player") {
global.turnOrder = "cpu";
} else {
global.turnOrder = "player";
}
// 2. Reset Timer
with (Timer) {
timer_frames_left = timer_total_frames;
}
// 3. Trigger AI (if CPU turn)
if (global.turnOrder == "cpu") {
// alarm[0] = 60; // Wait 1 second then move
}
}Call end_turn() only after a valid move is completed.
-
In
BoardPiece(Mouse Left Pressed):- Currently, the code moves the piece and updates
global.boardLineUp. -
Add: Check if the move is valid, execute it, and then call
end_turn().
- Currently, the code moves the piece and updates
Update the Timer object to trigger a game-over or forced turn switch when time runs out.
In Timer (Step Event):
if (timer_frames_left <= 0) {
timer_frames_left = 0;
// Option A: Lose the game
// show_message(global.turnOrder + " ran out of time!");
// Option B: Force end turn
// end_turn();
}- Use
TurnIndicatorto show not just text, but maybe a color change (Green for Player, Red for CPU). - Flash the timer red when it drops below 10 seconds.
Wiki
User Stories
Design
Requirements
Architecture
Considerations & Issues
Documentation
- How to Add a Card to the Game
- How the Music Controller & Script work
- Card Paging & Search System (CardManager)
- How to Spawn Cards in a Room
- How the Chessboard works
- How to Add a New Board Color
- How to use Alert System
- Chess Logic
- Cheat Mode
- Timer
- How the new card system works
- How the NEW Chessboard works