From 051ab9c5d5b6bca88b4d25e3996f04e17bb96c5f Mon Sep 17 00:00:00 2001 From: Juan Manuel Tomas Date: Wed, 26 Jan 2022 03:36:35 -0300 Subject: Fix map editor --- main.c | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index b79850a..1f1b9c0 100644 --- a/main.c +++ b/main.c @@ -16,6 +16,8 @@ typedef struct { float vy; float angle; float power; + int dead; + int stable; } Cannon; typedef struct { @@ -130,25 +132,27 @@ void GameMain(SDL_Renderer *context) { double dt = (new_t - old_t); old_t = new_t; + int mouse_x, mouse_y; + Uint32 mouse_state = SDL_GetMouseState(&mouse_x, &mouse_y); + float size = 20; + if (mouse_state & SDL_BUTTON_LMASK) { + PaintTerrain(&terrain, mouse_x, WINDOW_H - mouse_y, 1.0, size); + } else if (mouse_state & SDL_BUTTON_RMASK) { + PaintTerrain(&terrain, mouse_x, WINDOW_H - mouse_y, 0.0, size); + } + int times_to_simulate = 10; while (times_to_simulate > 0) { times_to_simulate--; - int mouse_x, mouse_y; - Uint32 mouse_state = SDL_GetMouseState(&mouse_x, &mouse_y); - float size = 20; - if (mouse_state & SDL_BUTTON_LMASK) { - PaintTerrain(&terrain, mouse_x, WINDOW_H - mouse_y, 1.0, size); - } else if (mouse_state & SDL_BUTTON_RMASK) { - PaintTerrain(&terrain, mouse_x, WINDOW_H - mouse_y, 0.0, size); - } - const Uint8 *keys = SDL_GetKeyboardState(0); if (keys[SDL_SCANCODE_D] && player.x < WINDOW_W) { player.x += WALK_VEL * dt; + player.stable = 0; } if (keys[SDL_SCANCODE_A] && player.x >= 0) { player.x -= WALK_VEL * dt; + player.stable = 0; } if (keys[SDL_SCANCODE_W] && player.angle < PI / 2) { player.angle += PI / 180 * dt; @@ -158,18 +162,21 @@ void GameMain(SDL_Renderer *context) { player.angle -= PI / 180 * dt; } - if (player.y >= WINDOW_H) { - player.y = WINDOW_H - 1; - player.vy = 0; - } - if (terrain.mask[(int)player.x + (int)player.y * WINDOW_W] == 0.0 && - player.y >= 0) { - player.y += player.vy * dt; - player.vy += GRAVITY * dt; - while (terrain.mask[(int)player.x + (int)player.y * WINDOW_W] != 0.0) { - player.y += 1; + if (!player.stable) { + if (player.y >= WINDOW_H) { + player.y = WINDOW_H - 1; player.vy = 0; } + if (terrain.mask[(int)player.x + (int)player.y * WINDOW_W] == 0.0 && + player.y >= 0) { + player.y += player.vy * dt; + player.vy += GRAVITY * dt; + while (terrain.mask[(int)player.x + (int)player.y * WINDOW_W] != 0.0) { + player.y += 1; + player.vy = 0; + player.stable = 1; + } + } } if (projectile.alive) { -- cgit v1.2.3