Fix display transformation and star generation for fullscreen mode.
This commit is contained in:
21
src/main.c
21
src/main.c
@@ -55,6 +55,9 @@ const char *info_format =
|
|||||||
int main() {
|
int main() {
|
||||||
char title[32];
|
char title[32];
|
||||||
float zoom = 1.0f;
|
float zoom = 1.0f;
|
||||||
|
float display_width = WINDOW_WIDTH;
|
||||||
|
float display_height = WINDOW_HEIGHT;
|
||||||
|
|
||||||
sprintf(title, "SpaceShipSim v%s", VERSION);
|
sprintf(title, "SpaceShipSim v%s", VERSION);
|
||||||
puts(title);
|
puts(title);
|
||||||
|
|
||||||
@@ -121,6 +124,12 @@ int main() {
|
|||||||
// only redraw or run simulation if the timer event has occurred
|
// only redraw or run simulation if the timer event has occurred
|
||||||
if(redraw)
|
if(redraw)
|
||||||
{
|
{
|
||||||
|
if(just_toggled_fullscreen)
|
||||||
|
{
|
||||||
|
display_width = al_get_display_width(display);
|
||||||
|
display_height = al_get_display_height(display);
|
||||||
|
}
|
||||||
|
|
||||||
if(paused == old_paused && key_is_down(KEY_PAUSE))
|
if(paused == old_paused && key_is_down(KEY_PAUSE))
|
||||||
paused = !paused;
|
paused = !paused;
|
||||||
else if(paused != old_paused && !key_is_down(KEY_PAUSE))
|
else if(paused != old_paused && !key_is_down(KEY_PAUSE))
|
||||||
@@ -176,11 +185,11 @@ int main() {
|
|||||||
al_identity_transform(&transform);
|
al_identity_transform(&transform);
|
||||||
al_scale_transform(&transform, zoom, zoom);
|
al_scale_transform(&transform, zoom, zoom);
|
||||||
al_translate_transform(&transform,
|
al_translate_transform(&transform,
|
||||||
WINDOW_WIDTH / 2.0f - ship.x * zoom,
|
display_width / 2.0f - ship.x * zoom,
|
||||||
WINDOW_HEIGHT / 2.0f - ship.y * zoom);
|
display_height / 2.0f - ship.y * zoom);
|
||||||
al_use_transform(&transform);
|
al_use_transform(&transform);
|
||||||
|
|
||||||
starfield_draw(ship.x, ship.y, zoom);
|
starfield_draw(ship.x, ship.y, zoom, display_width, display_height);
|
||||||
ship_draw(&ship);
|
ship_draw(&ship);
|
||||||
|
|
||||||
al_identity_transform(&transform);
|
al_identity_transform(&transform);
|
||||||
@@ -196,7 +205,7 @@ int main() {
|
|||||||
ship.velX * FPS, ship.velY * FPS);
|
ship.velX * FPS, ship.velY * FPS);
|
||||||
al_draw_multiline_text(font,
|
al_draw_multiline_text(font,
|
||||||
al_map_rgb(0xFF, 0xFF, 0xFF),
|
al_map_rgb(0xFF, 0xFF, 0xFF),
|
||||||
5, 5, WINDOW_WIDTH, 10.0f,
|
5, 5, (int)display_width, 10.0f,
|
||||||
ALLEGRO_ALIGN_LEFT,
|
ALLEGRO_ALIGN_LEFT,
|
||||||
info);
|
info);
|
||||||
}
|
}
|
||||||
@@ -205,8 +214,8 @@ int main() {
|
|||||||
{
|
{
|
||||||
al_draw_multiline_text(font,
|
al_draw_multiline_text(font,
|
||||||
al_map_rgb(0xFF, 0xFF, 0xFF),
|
al_map_rgb(0xFF, 0xFF, 0xFF),
|
||||||
(float)WINDOW_WIDTH / 2, (float)WINDOW_HEIGHT / 2 - 50,
|
display_width / 2, display_height / 2 - 50,
|
||||||
WINDOW_WIDTH, 10.0f,
|
(int)display_width, 10.0f,
|
||||||
ALLEGRO_ALIGN_CENTRE,
|
ALLEGRO_ALIGN_CENTRE,
|
||||||
help);
|
help);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,9 +51,9 @@ static void generate_chunk_stars(int chunk_x, int chunk_y) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void starfield_draw(float camera_x, float camera_y, float zoom) {
|
void starfield_draw(float camera_x, float camera_y, float zoom, float width, float height) {
|
||||||
float view_width = WINDOW_WIDTH / zoom;
|
float view_width = width / zoom;
|
||||||
float view_height = WINDOW_HEIGHT / zoom;
|
float view_height = height / zoom;
|
||||||
|
|
||||||
float left = camera_x - view_width / 2.0f;
|
float left = camera_x - view_width / 2.0f;
|
||||||
float right = camera_x + view_width / 2.0f;
|
float right = camera_x + view_width / 2.0f;
|
||||||
|
|||||||
@@ -24,5 +24,7 @@
|
|||||||
* @param camera_x The x position of the camera center.
|
* @param camera_x The x position of the camera center.
|
||||||
* @param camera_y The y position of the camera center.
|
* @param camera_y The y position of the camera center.
|
||||||
* @param zoom The zoom level (scale factor).
|
* @param zoom The zoom level (scale factor).
|
||||||
|
* @param width The display width in pixels.
|
||||||
|
* @param height The display height in pixels.
|
||||||
*/
|
*/
|
||||||
void starfield_draw(float camera_x, float camera_y, float zoom);
|
void starfield_draw(float camera_x, float camera_y, float zoom, float width, float height);
|
||||||
|
|||||||
Reference in New Issue
Block a user