aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-06-27 23:18:22 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-06-27 23:18:22 +0100
commit399e039d799186aeacebee60e1c2009a46677c0d (patch)
tree6b0d2dc98f86e7aecea073e40c35cd21ee6314f3
parentcb51a0b3973399c4adfb1406b93cd8a25e2f726c (diff)
downloadgold-mine-run-399e039d799186aeacebee60e1c2009a46677c0d.tar.gz
gold-mine-run-399e039d799186aeacebee60e1c2009a46677c0d.zip
Add pikcups
WIP: only time and bonuses for now.
-rw-r--r--data/sprites.pngbin21055 -> 21201 bytes
-rw-r--r--data/stage.json41
-rw-r--r--src/effect.c41
-rw-r--r--src/effect.h7
-rw-r--r--src/entities.h1
-rw-r--r--src/game.c7
-rw-r--r--src/game.h1
-rw-r--r--src/map.c3
-rw-r--r--src/pickup.c195
-rw-r--r--src/pickup.h11
-rwxr-xr-xtools/map.py2
11 files changed, 304 insertions, 5 deletions
diff --git a/data/sprites.png b/data/sprites.png
index 69116e6..57f5fb5 100644
--- a/data/sprites.png
+++ b/data/sprites.png
Binary files differ
diff --git a/data/stage.json b/data/stage.json
index f118222..bb04ee9 100644
--- a/data/stage.json
+++ b/data/stage.json
@@ -84,13 +84,46 @@
{
"height":16,
"id":5,
- "name":"Snake",
+ "name":"Time",
"rotation":0,
"type":"",
"visible":true,
"width":16,
- "x":32,
- "y":152
+ "x":80,
+ "y":128
+ },
+ {
+ "height":16,
+ "id":10,
+ "name":"Bonus",
+ "rotation":0,
+ "type":"",
+ "visible":true,
+ "width":16,
+ "x":56,
+ "y":104
+ },
+ {
+ "height":16,
+ "id":11,
+ "name":"Bonus",
+ "rotation":0,
+ "type":"",
+ "visible":true,
+ "width":16,
+ "x":80,
+ "y":104
+ },
+ {
+ "height":16,
+ "id":12,
+ "name":"Bonus",
+ "rotation":0,
+ "type":"",
+ "visible":true,
+ "width":16,
+ "x":80,
+ "y":80
},
{
"height":16,
@@ -161,7 +194,7 @@
"y":0
}],
"nextlayerid":4,
- "nextobjectid":10,
+ "nextobjectid":13,
"orientation":"orthogonal",
"renderorder":"right-down",
"tiledversion":"1.7.2",
diff --git a/src/effect.c b/src/effect.c
new file mode 100644
index 0000000..030f223
--- /dev/null
+++ b/src/effect.c
@@ -0,0 +1,41 @@
+#include <stdint.h>
+
+#include "vga.h"
+#include "entities.h"
+
+#include "effect.h"
+
+#define MAX_FRAME 3
+
+static const Rect frames[2 * 4] =
+{
+ { 96, 16, 144, 144 },
+ { 112, 16, 144, 144 },
+ { 128, 16, 144, 144 },
+
+ /* not used */
+ { 0, 0, 144, 144 },
+ { 0, 0, 144, 144 },
+ { 0, 0, 144, 144 },
+ { 0, 0, 144, 144 },
+ { 0, 0, 144, 144 }
+};
+
+void effect_out_init(Entity *e)
+{
+ e->frames = (const Rect *)frames;
+ e->frame = 1;
+ e->delay = 0;
+ e->update = effect_out_update;
+}
+
+void effect_out_update(Entity *e)
+{
+ if (e->delay++ == WALK_DELAY - 2)
+ {
+ e->delay = 0;
+ e->frame++;
+ if (e->frame == MAX_FRAME)
+ e->used = 0;
+ }
+}
diff --git a/src/effect.h b/src/effect.h
new file mode 100644
index 0000000..9c9d654
--- /dev/null
+++ b/src/effect.h
@@ -0,0 +1,7 @@
+#ifndef _EFFECT_H
+#define _EFFECT_H
+
+void effect_out_init(Entity *e);
+void effect_out_update(Entity *e);
+
+#endif /* _EFFECT_H */
diff --git a/src/entities.h b/src/entities.h
index 016dcd2..d7a6a83 100644
--- a/src/entities.h
+++ b/src/entities.h
@@ -16,6 +16,7 @@ typedef struct entity_s
uint8_t delay;
uint8_t gravity;
uint8_t flags;
+ uint16_t counter;
uint8_t bg[16 * 16];
/* expected to be 2 directions per 4 frames max; 8 Rect */
const Rect *frames;
diff --git a/src/game.c b/src/game.c
index 001ce21..70b1e74 100644
--- a/src/game.c
+++ b/src/game.c
@@ -184,3 +184,10 @@ uint8_t dec_lives()
hud |= HUD_LIVES;
return lives;
}
+
+void reset_time()
+{
+ time = GAME_TIME_MAX;
+ hud |= HUD_TIME;
+ timer_start(GAME_TIME_MAX, &clock_updated);
+}
diff --git a/src/game.h b/src/game.h
index 3058018..5a13927 100644
--- a/src/game.h
+++ b/src/game.h
@@ -6,5 +6,6 @@ void add_score(uint8_t v);
uint32_t get_hiscore();
uint8_t dec_lives();
+void reset_time();
#endif /* _GAME_H */
diff --git a/src/map.c b/src/map.c
index f7c271b..cf25426 100644
--- a/src/map.c
+++ b/src/map.c
@@ -10,6 +10,7 @@
#include "player.h"
#include "snake.h"
#include "bat.h"
+#include "pickup.h"
#include "map.h"
@@ -28,6 +29,8 @@ static void (* const init[])(Entity *) =
{
snake_init,
bat_init,
+ pickup_time_init,
+ pickup_bonus_init,
};
void map_init(const uint8_t map[])
diff --git a/src/pickup.c b/src/pickup.c
new file mode 100644
index 0000000..6b53cda
--- /dev/null
+++ b/src/pickup.c
@@ -0,0 +1,195 @@
+#include <stdint.h>
+#include <stdlib.h>
+
+#include "vga.h"
+#include "entities.h"
+#include "game.h"
+
+#include "player.h"
+#include "effect.h"
+
+#include "pickup.h"
+
+#define MAX_FRAME 3
+#define MAX_BONUS_FRAME 4
+
+#define MAX_TTL ((uint16_t)800)
+
+typedef enum
+{
+ PICKUP_TIME = 0,
+ PICKUP_BONUS,
+ PICKUP_PICKAXE,
+ PICKUP_GOLD_KEY,
+ PICKUP_SILVER_KEY,
+} PickupType;
+
+static const Rect frames_in[2 * 4] =
+{
+ { 96, 16, 144, 144 },
+ { 128, 16, 144, 144 },
+ { 112, 16, 144, 144 },
+
+ /* not used */
+ { 0, 0, 144, 144 },
+ { 0, 0, 144, 144 },
+ { 0, 0, 144, 144 },
+ { 0, 0, 144, 144 },
+ { 0, 0, 144, 144 }
+};
+
+static const Rect frames[2 * 4] =
+{
+ /* time */
+ { 80, 16, 144, 144 },
+
+ /* pickaxe */
+ { 16, 32, 144, 144 },
+
+ /* gold key */
+ { 0, 0, 144, 144 },
+
+ /* siver key */
+ { 0, 0, 144, 144 },
+
+ /* not used */
+ { 0, 0, 144, 144 },
+ { 0, 0, 144, 144 },
+ { 0, 0, 144, 144 },
+ { 0, 0, 144, 144 }
+};
+
+static const Rect frames_bonus0[2 * 4] =
+{
+ { 0, 48, 144, 144 },
+ { 16, 48, 144, 144 },
+ { 32, 48, 144, 144 },
+ { 48, 48, 144, 144 },
+
+ /* not used */
+ { 0, 0, 144, 144 },
+ { 0, 0, 144, 144 },
+ { 0, 0, 144, 144 },
+ { 0, 0, 144, 144 }
+};
+
+static const Rect frames_bonus1[2 * 4] =
+{
+ { 0, 64, 144, 144 },
+ { 16, 64, 144, 144 },
+ { 32, 64, 144, 144 },
+ { 48, 64, 144, 144 },
+
+ /* not used */
+ { 0, 0, 144, 144 },
+ { 0, 0, 144, 144 },
+ { 0, 0, 144, 144 },
+ { 0, 0, 144, 144 }
+};
+
+static const Rect frames_bonus2[2 * 4] =
+{
+ { 64, 64, 144, 144 },
+ { 80, 64, 144, 144 },
+ { 96, 64, 144, 144 },
+ { 112, 64, 144, 144 },
+
+ /* not used */
+ { 0, 0, 144, 144 },
+ { 0, 0, 144, 144 },
+ { 0, 0, 144, 144 },
+ { 0, 0, 144, 144 }
+};
+
+static const Rect *frames_bonuses[] =
+{
+ frames_bonus0, frames_bonus1, frames_bonus2
+};
+
+void pickup_time_init(Entity *e)
+{
+ e->frames = (const Rect *)frames_in;
+ e->flags = PICKUP_TIME;
+ e->counter = MAX_TTL * 2 + (rand() % MAX_TTL);
+ e->update = pickup_wait_update;
+}
+
+void pickup_bonus_init(Entity *e)
+{
+ e->frames = (const Rect *)frames_in;
+ e->flags = PICKUP_BONUS;
+ e->counter = MAX_TTL + (rand() % MAX_TTL);
+ e->update = pickup_wait_update;
+}
+
+void pickup_wait_update(Entity *e)
+{
+ if (e->counter-- == 0)
+ e->update = pickup_in_update;
+}
+
+void pickup_in_update(Entity *e)
+{
+ if (e->delay++ == WALK_DELAY - 2)
+ {
+ e->delay = 0;
+ e->frame++;
+ if (e->frame == MAX_FRAME)
+ {
+ switch (e->flags)
+ {
+ 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;
+ }
+
+ }
+ }
+}
+
+void pickup_update(Entity *e)
+{
+ if (e->counter++ == MAX_TTL)
+ {
+ effect_out_init(e);
+ return;
+ }
+
+ /* the bonuses have an animation */
+ if (e->flags == PICKUP_BONUS)
+ {
+ e->delay++;
+ /* first frame lasts longer */
+ if ((e->frame == 0 && e->delay == WALK_DELAY * 4)
+ || (e->frame != 0 && e->delay == WALK_DELAY - 2))
+ {
+ e->delay = 0;
+ e->frame++;
+ if (e->frame == MAX_BONUS_FRAME)
+ e->frame = 0;
+ }
+ }
+
+ if (player_collision(e))
+ {
+ switch (e->flags)
+ {
+ case PICKUP_TIME:
+ reset_time();
+ break;
+ case PICKUP_BONUS:
+ add_score(250);
+ break;
+ }
+ e->used = 0;
+ }
+}
diff --git a/src/pickup.h b/src/pickup.h
new file mode 100644
index 0000000..97777c2
--- /dev/null
+++ b/src/pickup.h
@@ -0,0 +1,11 @@
+#ifndef _PIKCUP_H
+#define _PIKCUP_H
+
+void pickup_time_init(Entity *e);
+void pickup_bonus_init(Entity *e);
+
+void pickup_wait_update(Entity *e);
+void pickup_in_update(Entity *e);
+void pickup_update(Entity *e);
+
+#endif /* _PIKCUP_H */
diff --git a/tools/map.py b/tools/map.py
index c2f05f4..1b134bb 100755
--- a/tools/map.py
+++ b/tools/map.py
@@ -10,7 +10,7 @@ __version__ = "1.0"
ld = os.environ.get("LD", "i586-pc-msdosdjgpp-ld")
strip = os.environ.get("STRIP", "i586-pc-msdosdjgpp-strip")
-entity_types = ("Player", "Snake", "Bat")
+entity_types = ("Player", "Snake", "Bat", "Time", "Bonus")
def get_layer(data, name):