Compare commits

..

3 Commits

Author SHA1 Message Date
b842bd0095 Move global variables to main().
Should not make variables global unnecessarily.
2026-03-03 09:20:50 +01:00
bb28285794 Fix possible precision loss by converting to float. 2026-03-03 09:20:00 +01:00
6621decc09 Add fullscreen mode support. 2026-03-03 09:19:16 +01:00
2 changed files with 48 additions and 27 deletions

View File

@@ -113,29 +113,32 @@ void handle_event() {
ALLEGRO_EVENT evnt;
al_wait_for_event(event_queue, &evnt);
switch(evnt.type)
do
{
case ALLEGRO_EVENT_TIMER:
redraw = 1;
break;
case ALLEGRO_EVENT_DISPLAY_CLOSE:
run = 0;
break;
case ALLEGRO_EVENT_KEY_DOWN:
if(evnt.keyboard.keycode == ALLEGRO_KEY_H)
show_help = !show_help;
else if(evnt.keyboard.keycode == ALLEGRO_KEY_I)
show_info = !show_info;
else if(evnt.keyboard.keycode == ALLEGRO_KEY_Q ||
evnt.keyboard.keycode == ALLEGRO_KEY_ESCAPE)
switch(evnt.type)
{
case ALLEGRO_EVENT_TIMER:
redraw = 1;
break;
case ALLEGRO_EVENT_DISPLAY_CLOSE:
run = 0;
else
set_key(evnt.keyboard.keycode, 1);
break;
case ALLEGRO_EVENT_KEY_UP:
set_key(evnt.keyboard.keycode, 0);
break;
}
break;
case ALLEGRO_EVENT_KEY_DOWN:
if(evnt.keyboard.keycode == ALLEGRO_KEY_H)
show_help = !show_help;
else if(evnt.keyboard.keycode == ALLEGRO_KEY_I)
show_info = !show_info;
else if(evnt.keyboard.keycode == ALLEGRO_KEY_Q ||
evnt.keyboard.keycode == ALLEGRO_KEY_ESCAPE)
run = 0;
else
set_key(evnt.keyboard.keycode, 1);
break;
case ALLEGRO_EVENT_KEY_UP:
set_key(evnt.keyboard.keycode, 0);
break;
}
} while(al_get_next_event(event_queue, &evnt));
}
int key_is_down(int code) {

View File

@@ -20,11 +20,6 @@
#include "event_manager.h"
#include "ship.h"
int run;
int redraw;
int show_help;
int show_info;
#include <stdio.h>
#include <allegro5/allegro.h>
#include <allegro5/allegro_primitives.h>
@@ -38,6 +33,7 @@ const char *help =
"P - pause/unpause the simulation\n"
"I - show/hide simulation information\n"
"H - show/hide this help information\n"
"F - toggle fullscreen\n"
"Q/ESC - quit";
const char *info_format =
@@ -49,6 +45,10 @@ const char *info_format =
"velY: %f px/sec";
int main() {
int run;
int redraw;
int show_help;
int show_info;
char title[32];
sprintf(title, "SpaceShipSim v%s", VERSION);
puts(title);
@@ -107,6 +107,7 @@ int main() {
show_info = 1;
int paused = 0;
int old_paused = 0;
int just_toggled_fullscreen = 0;
while(run)
{
handle_event();
@@ -127,6 +128,23 @@ int main() {
ship_update(&ship);
}
if (key_is_down(KEY_FULLSCREEN) && !just_toggled_fullscreen)
{
if(al_get_display_flags(display) & ALLEGRO_FULLSCREEN_WINDOW)
{
al_set_display_flag(display, ALLEGRO_FULLSCREEN_WINDOW, 0);
}
else
{
al_set_display_flag(display, ALLEGRO_FULLSCREEN_WINDOW, 1);
}
just_toggled_fullscreen = 1;
}
else if (!key_is_down(KEY_FULLSCREEN) && just_toggled_fullscreen)
{
just_toggled_fullscreen = 0;
}
al_clear_to_color(al_map_rgb(0, 0, 0));
ship_draw(&ship);
if(show_info)
@@ -148,7 +166,7 @@ int main() {
{
al_draw_multiline_text(font,
al_map_rgb(0xFF, 0xFF, 0xFF),
WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2 - 50,
(float)WINDOW_WIDTH / 2, (float)WINDOW_HEIGHT / 2 - 50,
WINDOW_WIDTH, 10.0f,
ALLEGRO_ALIGN_CENTRE,
help);