summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c45
1 files changed, 26 insertions, 19 deletions
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) {