summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcitrons <citrons@mondecitronne.com>2023-10-17 18:44:33 -0500
committercitrons <citrons@mondecitronne.com>2023-10-17 18:44:33 -0500
commit31530c9b9da7a579406633792507177c9435c5eb (patch)
tree41e346b32292482ff127ab0da2534a7f65fbff60
parent7c5f7142f76ca1be5eaf3f7795f18f8451aa30d5 (diff)
stamina based on # of movements rather than time
-rw-r--r--world.c7
-rw-r--r--world.h4
2 files changed, 6 insertions, 5 deletions
diff --git a/world.c b/world.c
index 228823e..33ce1ab 100644
--- a/world.c
+++ b/world.c
@@ -128,8 +128,7 @@ SDL_bool is_solid(tile t) {
}
SDL_bool player_grounded(world *w) {
- if (SDL_TICKS_PASSED(SDL_GetTicks(), w->player.stamina_time))
- return SDL_FALSE;
+ if (w->player.stamina <= 0) return SDL_FALSE;
SDL_bool grounded = SDL_FALSE;
for (int y = w->player.pos.y; y < w->player.pos.y + 2; y++) {
for (int x = w->player.pos.x - 1; x < w->player.pos.x + 2; x++)
@@ -142,6 +141,8 @@ void player_walk(world *w, int x, int y) {
if (!SDL_TICKS_PASSED(SDL_GetTicks(), w->player.walk_wait))
return;
+ if (w->player.stamina > 0) w->player.stamina--;
+
if (x != 0 || y != 0) {
SDL_Point new_pos = w->player.pos;
new_pos.x += x;
@@ -315,7 +316,7 @@ void tick_world(world *w) {
tile below = get_tile(w,
(SDL_Point) {w->player.pos.x, w->player.pos.y + 1});
if (is_solid(below))
- w->player.stamina_time = SDL_GetTicks() + PLAYER_STAMINA;
+ w->player.stamina = PLAYER_STAMINA;
if (!player_grounded(w)) {
if (SDL_TICKS_PASSED(SDL_GetTicks(), w->player.gravity_time)) {
diff --git a/world.h b/world.h
index 33d5984..afa8829 100644
--- a/world.h
+++ b/world.h
@@ -19,14 +19,14 @@ typedef enum tile {
extern SDL_Color tile_colors[];
-#define PLAYER_STAMINA 1250
+#define PLAYER_STAMINA 10
#define PLAYER_WALK_DELAY 100
#define PLAYER_PLACE_DELAY 175
#define PLAYER_GRAVITY 30
typedef struct player {
SDL_Point pos;
int scores[MAX_COLLECTIBLE];
- int stamina_time;
+ int stamina;
int walk_wait;
int place_wait;
int gravity_time;