Skip to content

Multimedia Functions to Use

The following function and procedure declarations provide you with access to the functionality in SplashKit to open windows, draw things, and interact with the user. The main difference is the style of identifier used - for example OpenWindow is now open_window.

// These needs...
// #include "splashkit.h";
window open_window(string caption, int width, int height);
void clear_screen();
void refresh_screen();
// Event loop
void process_events();
bool quit_requested();
// Colors
color color_white();
color color_blue();
// and many others...
// Drawing
void fill_rectangle(Color clr, double x, double y, double width, double height);
void draw_rectangle(Color clr, double x, double y, double width, double height);
void fill_ellipse(Color clr, double x, double y, double width, double height);
void draw_ellipse(Color clr, double x, double y, double width, double height);
void fill_triangle(Color clr, double x1, double y1, double x2, double y2, double x3, double y3);
void draw_triangle(Color clr, double x1, double y1, double x2, double y2, double x3, double y3);
void draw_line(Color clr, double x1, double y1, double x2, double y2);
// Key input
// This also requiers... to get access to the KeyCode details.
// using SplashKitSDK;
bool key_down(KeyCode key);
// Random numbers
float rnd(); // 0 to 1
int rnd(int ubound); // 0 to ubound - 1
int rnd(int min, int max); // min to max
// Time tracking
timer create_timer(string name);
void start_timer(string name);
uint timer_ticks(string name);
// Collision detection
bool circles_intersect(double c1_x_, double c1_y_, double c1_radius, double c2_x, double c2_y, double c2_radius);

Key Codes

The key_code values in C/C++ act like constants, so are all uppercase:

BACKSPACE_KEY_TAB_KEYRETURN_KEYESCAPE_KEYSPACE_KEY
NUM0_KEYNUM1_KEYNUM2_KEYNUM3_KEYNUM4_KEY
NUM5_KEYNUM6_KEYNUM7_KEYNUM8_KEYNUM9_KEY
COLON_KEYSEMICOLON_KEYA_KEYB_KEYC_KEY
D_KEYE_KEYF_KEYG_KEYH_KEY
I_KEYJ_KEYK_KEYL_KEYM_KEY
N_KEYO_KEYP_KEYQ_KEYR_KEY
S_KEYT_KEYU_KEYV_KEYW_KEY
X_KEYY_KEYZ_KEYDELETE_KEYKEYPAD_0
KEYPAD_1KEYPAD_2KEYPAD_3KEYPAD_4KEYPAD_5
KEYPAD_6KEYPAD_7KEYPAD_8KEYPAD_9KEYPAD_PERIOD
KEYPAD_DIVIDEKEYPAD_MULTIPLYKEYPAD_MINUSKEYPAD_PLUSKEYPAD_ENTER
KEYPAD_EQUALSUP_KEYDOWN_KEYRIGHT_KEYLEFT_KEY
INSERT_KEYHOME_KEYEND_KEYPAGE_UP_KEYPAGE_DOWN_KEY
F1_KEYF2_KEYF3_KEYF4_KEYF5_KEY
F6_KEYF7_KEYF8_KEYF9_KEYF10_KEY
F11_KEYF12_KEYF13_KEYF14_KEYF15_KEY
RIGHT_SHIFT_KEYLEFT_SHIFT_KEYRIGHT_CTRL_KEYLEFT_CTRL_KEYRIGHT_ALT_KEY
LEFT_ALT_KEYLEFT_SUPER_KEYRIGHT_SUPER_KEY

:::

Example Multimedia Code

The following code demonstrates how to use these functions and procedures to create an interactive program.

#include "splashkit.h"
const int MOVE_SPEED = 3;
int main()
{
open_window("Movement", 800, 600);
// Event loop
double x = 400;
color clr = color_black();
while( !quit_requested() )
{
process_events();
if (key_down(RIGHT_KEY))
{
x += MOVE_SPEED;
}
if (key_down(LEFT_KEY))
{
x -= MOVE_SPEED;
}
if (key_typed(SPACE_KEY))
{
clr = random_color();
}
clear_screen(color_white());
fill_circle(clr, x, 300, 50);
refresh_screen(60);
}
}