aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-06-29 21:47:55 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-06-29 21:47:55 +0100
commit2d2379251e71b5f315235db7980d0cfe03132561 (patch)
tree346ddd8719753fa1470cb8dc7456328d033ebff1 /src
parent16fb9f0d5e5904cca7c256b63f20f1fc1466bd5e (diff)
downloadgold-mine-run-2d2379251e71b5f315235db7980d0cfe03132561.tar.gz
gold-mine-run-2d2379251e71b5f315235db7980d0cfe03132561.zip
Add pickaxe pickup
Diffstat (limited to 'src')
-rw-r--r--src/game.c37
-rw-r--r--src/game.h4
-rw-r--r--src/map.c11
-rw-r--r--src/pickup.c24
-rw-r--r--src/pickup.h1
-rw-r--r--src/player.c12
6 files changed, 68 insertions, 21 deletions
diff --git a/src/game.c b/src/game.c
index 70b1e74..64a7b23 100644
--- a/src/game.c
+++ b/src/game.c
@@ -16,12 +16,14 @@
#define GAME_LIVES_START 3
#define GAME_LIVES_MAX 9
#define GAME_TIME_MAX 60
+#define GAME_MAX_PICKAXE 3
#define HUD_CLEAN 0
#define HUD_LIVES 1
#define HUD_SCORE 2
#define HUD_STAGE 4
#define HUD_TIME 8
+#define HUD_PICKAXE 16
#define HUD_ALL 255
#define GAMEOVER_DELAY 96
@@ -35,8 +37,8 @@ static volatile uint8_t clock_updated;
static uint8_t lives;
static uint32_t score;
static uint8_t stage;
-static uint8_t gold;
static uint8_t time;
+static uint8_t pickaxe;
static uint8_t gameover;
static void hud_render()
@@ -51,6 +53,11 @@ static void hud_render()
/* lives */
blitrc(binary_sprites_start, &src, &dst);
+ /* pickaxe */
+ src.x = 112;
+ dst.x = 90;
+ blitrc(binary_sprites_start, &src, &dst);
+
put_text(132, 4, "TIME", 1);
put_text(249, 4, "STAGE", 1);
}
@@ -67,6 +74,12 @@ static void hud_render()
put_text(34, 4, b, 5);
}
+ if (hud & HUD_PICKAXE)
+ {
+ sprintf(b, "%d", pickaxe);
+ put_text(106, 4, b, 1);
+ }
+
if (hud & HUD_TIME)
{
sprintf(b, "%02d", time);
@@ -105,7 +118,7 @@ void run_game()
lives = GAME_LIVES_START;
score = 0;
stage = 0;
- gold = 30;
+ pickaxe = 0;
time = GAME_TIME_MAX;
hud = HUD_ALL;
@@ -191,3 +204,23 @@ void reset_time()
hud |= HUD_TIME;
timer_start(GAME_TIME_MAX, &clock_updated);
}
+
+void add_pickaxe()
+{
+ if (pickaxe < GAME_MAX_PICKAXE)
+ {
+ pickaxe++;
+ hud |= HUD_PICKAXE;
+ }
+}
+
+uint8_t use_pickaxe()
+{
+ if (pickaxe)
+ {
+ pickaxe--;
+ hud |= HUD_PICKAXE;
+ return 1;
+ }
+ return 0;
+}
diff --git a/src/game.h b/src/game.h
index 5a13927..ea01495 100644
--- a/src/game.h
+++ b/src/game.h
@@ -2,10 +2,12 @@
#define _GAME_H
void run_game();
+
void add_score(uint8_t v);
uint32_t get_hiscore();
-
uint8_t dec_lives();
void reset_time();
+void add_pickaxe();
+uint8_t use_pickaxe();
#endif /* _GAME_H */
diff --git a/src/map.c b/src/map.c
index cf25426..d34a5a9 100644
--- a/src/map.c
+++ b/src/map.c
@@ -14,12 +14,6 @@
#include "map.h"
-typedef enum
-{
- Player = 0,
- Snake,
-} EntityType;
-
/* current map; set via map_init */
static const uint8_t *cmap;
static uint8_t gold[MAP_W * MAP_H];
@@ -31,6 +25,7 @@ static void (* const init[])(Entity *) =
bat_init,
pickup_time_init,
pickup_bonus_init,
+ pickup_pickaxe_init,
};
void map_init(const uint8_t map[])
@@ -58,8 +53,8 @@ void map_init(const uint8_t map[])
ent += 4
)
{
- /* the player is not part of the entity system */
- if (*ent == Player)
+ /* the player (entity 0) is not part of the entity system */
+ if (*ent == 0)
{
player_init(ent[1] * MAP_TILE_W, ent[2] * MAP_TILE_H, ent[3] & 1);
continue;
diff --git a/src/pickup.c b/src/pickup.c
index 6b53cda..e1ad424 100644
--- a/src/pickup.c
+++ b/src/pickup.c
@@ -44,7 +44,7 @@ static const Rect frames[2 * 4] =
{ 80, 16, 144, 144 },
/* pickaxe */
- { 16, 32, 144, 144 },
+ { 64, 16, 144, 144 },
/* gold key */
{ 0, 0, 144, 144 },
@@ -122,6 +122,14 @@ void pickup_bonus_init(Entity *e)
e->update = pickup_wait_update;
}
+void pickup_pickaxe_init(Entity *e)
+{
+ e->frames = (const Rect *)frames_in;
+ e->flags = PICKUP_PICKAXE;
+ e->counter = MAX_TTL / 2 + (rand() % MAX_TTL);
+ e->update = pickup_wait_update;
+}
+
void pickup_wait_update(Entity *e)
{
if (e->counter-- == 0)
@@ -141,17 +149,18 @@ void pickup_in_update(Entity *e)
case PICKUP_TIME:
e->frames = (const Rect *)frames;
e->frame = 0;
- e->counter = 0;
- e->update = pickup_update;
break;
case PICKUP_BONUS:
e->frames = (const Rect *)frames_bonuses[rand() % 3];
e->frame = 0;
- e->counter = 0;
- e->update = pickup_update;
+ break;
+ case PICKUP_PICKAXE:
+ e->frames = (const Rect *)frames;
+ e->frame = 1;
break;
}
-
+ e->counter = 0;
+ e->update = pickup_update;
}
}
}
@@ -189,6 +198,9 @@ void pickup_update(Entity *e)
case PICKUP_BONUS:
add_score(250);
break;
+ case PICKUP_PICKAXE:
+ add_pickaxe();
+ break;
}
e->used = 0;
}
diff --git a/src/pickup.h b/src/pickup.h
index 97777c2..ecb5350 100644
--- a/src/pickup.h
+++ b/src/pickup.h
@@ -3,6 +3,7 @@
void pickup_time_init(Entity *e);
void pickup_bonus_init(Entity *e);
+void pickup_pickaxe_init(Entity *e);
void pickup_wait_update(Entity *e);
void pickup_in_update(Entity *e);
diff --git a/src/player.c b/src/player.c
index ae50348..71c951a 100644
--- a/src/player.c
+++ b/src/player.c
@@ -309,8 +309,12 @@ uint8_t player_collision(Entity *e)
void player_hit()
{
- /* TODO: pickaxe */
- dying = 1;
- frame = FRAME_DYING;
- gravity = GRAVITY_UP;
+ if (use_pickaxe())
+ invuln = INVULN_TIME;
+ else
+ {
+ dying = 1;
+ frame = FRAME_DYING;
+ gravity = GRAVITY_UP;
+ }
}