Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions public/usage-examples/timers/timer_started-1-example-oop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using SplashKitSDK;

namespace TimerStarted
{
public class Program
{
public static void Main()
{
SplashKit.OpenWindow("Start-Stop Stopwatch", 600, 300);

// SplashKitSDK.Timer needed to distinguish from System.Threading.Timer
// Create a named timer - it is not started until StartTimer is called
SplashKitSDK.Timer gameTimer = new SplashKitSDK.Timer("game_timer");

while (!SplashKit.QuitRequested())
{
SplashKit.ProcessEvents();

// Start the timer when SPACE is pressed
if (SplashKit.KeyTyped(KeyCode.SpaceKey))
SplashKit.StartTimer(gameTimer);

// Stop the timer when S is pressed
if (SplashKit.KeyTyped(KeyCode.SKey))
SplashKit.StopTimer(gameTimer);

SplashKit.ClearScreen(Color.White);

// Use TimerStarted to check whether the timer is currently running
bool isRunning = SplashKit.TimerStarted(gameTimer);

// Display the timer status
if (isRunning)
{
SplashKit.DrawText("Status: Running", Color.Green, "Arial", 28, 170, 80);
}
else
{
SplashKit.DrawText("Status: Stopped", Color.Red, "Arial", 28, 170, 80);
}

// Display elapsed milliseconds
SplashKit.DrawText("Elapsed: " + SplashKit.TimerTicks(gameTimer) + " ms",
Color.Black, "Arial", 20, 185, 140);

SplashKit.DrawText("[SPACE] Start [S] Stop", Color.Gray, "Arial", 16, 165, 220);

SplashKit.RefreshScreen(60);
}

SplashKit.CloseAllWindows();
}
}
}
48 changes: 48 additions & 0 deletions public/usage-examples/timers/timer_started-1-example-top-level.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// using static allows calling SplashKit methods directly (e.g. TimerStarted, StartTimer)
// using SplashKitSDK is required for Timer and KeyCode types
using static SplashKitSDK.SplashKit;
using SplashKitSDK;

OpenWindow("Start-Stop Stopwatch", 600, 300);

// SplashKitSDK.Timer needed to distinguish from System.Threading.Timer
// Create a named timer - it is not started until StartTimer is called
SplashKitSDK.Timer gameTimer = new SplashKitSDK.Timer("game_timer");

while (!QuitRequested())
{
ProcessEvents();

// Start the timer when SPACE is pressed
if (KeyTyped(KeyCode.SpaceKey))
StartTimer(gameTimer);

// Stop the timer when S is pressed
if (KeyTyped(KeyCode.SKey))
StopTimer(gameTimer);

ClearScreen(ColorWhite());

// Use TimerStarted to check whether the timer is currently running
bool isRunning = TimerStarted(gameTimer);

// Display the timer status
if (isRunning)
{
DrawText("Status: Running", ColorGreen(), "Arial", 28, 170, 80);
}
else
{
DrawText("Status: Stopped", ColorRed(), "Arial", 28, 170, 80);
}

// Display elapsed milliseconds
DrawText("Elapsed: " + TimerTicks(gameTimer) + " ms",
ColorBlack(), "Arial", 20, 185, 140);

DrawText("[SPACE] Start [S] Stop", ColorGray(), "Arial", 16, 165, 220);

RefreshScreen(60);
}

CloseAllWindows();
49 changes: 49 additions & 0 deletions public/usage-examples/timers/timer_started-1-example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "splashkit.h"
#include <string>

int main()
{
open_window("Start-Stop Stopwatch", 600, 300);

// Create a named timer - it is not started until start_timer is called
timer game_timer = create_timer("game_timer");

while (!quit_requested())
{
process_events();

// Start the timer when SPACE is pressed
if (key_typed(SPACE_KEY))
start_timer(game_timer);

// Stop the timer when S is pressed
if (key_typed(S_KEY))
stop_timer(game_timer);

clear_screen(COLOR_WHITE);

// Use timer_started to check whether the timer is currently running
bool is_running = timer_started(game_timer);

// Display the timer status
if (is_running)
{
draw_text("Status: Running", COLOR_GREEN, "Arial", 28, 170, 80);
}
else
{
draw_text("Status: Stopped", COLOR_RED, "Arial", 28, 170, 80);
}

// Display elapsed milliseconds - std::to_string converts a number to a string
draw_text("Elapsed: " + std::to_string(timer_ticks(game_timer)) + " ms",
COLOR_BLACK, "Arial", 20, 185, 140);

draw_text("[SPACE] Start [S] Stop", COLOR_GRAY, "Arial", 16, 165, 220);

refresh_screen(60);
}

close_all_windows();
return 0;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions public/usage-examples/timers/timer_started-1-example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from splashkit import *

open_window("Start-Stop Stopwatch", 600, 300)

# Create a named timer - it is not started until start_timer is called
game_timer = create_timer("game_timer")

while not quit_requested():
process_events()

# Start the timer when SPACE is pressed
if key_typed(KeyCode.space_key):
start_timer(game_timer)

# Stop the timer when S is pressed
if key_typed(KeyCode.s_key):
stop_timer(game_timer)

clear_screen(color_white())

# Use timer_started to check whether the timer is currently running
is_running = timer_started(game_timer)

# Display the timer status
if is_running:
draw_text_font_as_string("Status: Running", color_green(), "Arial", 28, 170, 80)
else:
draw_text_font_as_string("Status: Stopped", color_red(), "Arial", 28, 170, 80)

# Display elapsed milliseconds
draw_text_font_as_string("Elapsed: " + str(timer_ticks(game_timer)) + " ms",
color_black(), "Arial", 20, 185, 140)

draw_text_font_as_string("[SPACE] Start [S] Stop", color_gray(), "Arial", 16, 165, 220)

refresh_screen_with_target_fps(60)

close_all_windows()
1 change: 1 addition & 0 deletions public/usage-examples/timers/timer_started-1-example.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Start-Stop Stopwatch