aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--game.c72
-rw-r--r--intermediate/usr.bmpbin68178 -> 75378 bytes
-rw-r--r--main.c2
-rw-r--r--sprite.c25
-rw-r--r--sprite.h7
-rw-r--r--world.h4
6 files changed, 94 insertions, 16 deletions
diff --git a/game.c b/game.c
index b3d40fb..2cba35c 100644
--- a/game.c
+++ b/game.c
@@ -3,6 +3,7 @@
#include "game.h"
#include "platform.h"
#include "sprite.h"
+#include "standard.h"
#include "systems.h"
static void menu_new(Menu* menu) {
@@ -53,11 +54,10 @@ static void menu_init(Game* game) {
static void menu_update(Game* game) {
const Sprite* msg;
const Bitmap* bmp;
- int h, y;
+ int y;
update_menu(&game->menu);
- h = game->menu.h;
y = game->menu.y;
msg = get_sprite(sprite_author);
@@ -78,6 +78,16 @@ static void menu_update(Game* game) {
&msg->rect
);
+ /* Logo. */
+ msg = get_sprite(sprite_logo);
+ bmp = get_bitmap(msg->bitmap);
+ render_bitmap(
+ bmp,
+ renderer_w / 2 - msg->rect.w / 2,
+ y - msg->rect.h - 8,
+ &msg->rect
+ );
+
render_menu(&game->menu, get_default_font());
}
@@ -86,25 +96,65 @@ static void menu_deinit(Game* game) {
}
static void gameplay_init(Game* game) {
+ seed_rng(500);
init_world(&game->world);
init_map(&game->world.map, &game->world);
init_player(&game->world.player, &game->world);
new_skull(&game->world, 0, 0);
}
+static void render_hud(Game* game) {
+ int i;
+ const Sprite* heart_sprite;
+ const Bitmap* heart_bitmap;
+ World* world;
+ Player* player;
+
+ world = &game->world;
+ player = &world->player;
+
+ heart_sprite = get_sprite(sprite_heart_full);
+ heart_bitmap = get_bitmap(heart_sprite->bitmap);
+ for (i = 0; i < player->hp; i++) {
+ render_bitmap(
+ heart_bitmap,
+ 1 + i * (heart_sprite->rect.w + 1),
+ 1,
+ &heart_sprite->rect
+ );
+ }
+ heart_sprite = get_sprite(sprite_heart_empty);
+ heart_bitmap = get_bitmap(heart_sprite->bitmap);
+ for (; i < player_max_hp; i++) {
+ render_bitmap(
+ heart_bitmap,
+ 1 + i * (heart_sprite->rect.w + 1),
+ 1,
+ &heart_sprite->rect
+ );
+ }
+}
+
static void gameplay_update(Game* game) {
- int cx, cy;
+ int cx, cy, i;
+ World* world;
+ Player* player;
cx = game->world.cam_x;
cy = game->world.cam_y;
- update_player(&game->world.player, &game->world);
- enemy_system(&game->world);
- bullet_system(&game->world);
- collision_system(&game->world);
- animation_system(&game->world);
- render_map(&game->world.map, cx, cy);
- update_camera(&game->world.player, &game->world);
- sprite_system(&game->world);
+ world = &game->world;
+ player = &world->player;
+
+ update_player(player, world);
+ enemy_system(world);
+ bullet_system(world);
+ collision_system(world);
+ animation_system(world);
+ render_map(&world->map, cx, cy);
+ update_camera(player, world);
+ sprite_system(world);
+
+ render_hud(game);
}
static void gameplay_deinit(Game* game) {
diff --git a/intermediate/usr.bmp b/intermediate/usr.bmp
index 7735e60..b8bcd09 100644
--- a/intermediate/usr.bmp
+++ b/intermediate/usr.bmp
Binary files differ
diff --git a/main.c b/main.c
index 0e26dd3..4f1c979 100644
--- a/main.c
+++ b/main.c
@@ -4,8 +4,6 @@
Game game;
void on_init(int argc, char** argv) {
- seed_rng(500);
-
init_renderer();
load_assets();
diff --git a/sprite.c b/sprite.c
index 708c5e9..9663cbd 100644
--- a/sprite.c
+++ b/sprite.c
@@ -80,6 +80,31 @@ static const Sprite sprites[] = {
{
asset_id_map,
{ 16, 0, 16, 16 }
+ },
+ /* sprite_heart_empty */
+ {
+ asset_id_usr,
+ { 90, 60, 7, 6 }
+ },
+ /* sprite_heart_full */
+ {
+ asset_id_usr,
+ { 98, 60, 7, 6 }
+ },
+ /* sprite_ram_empty */
+ {
+ asset_id_usr,
+ { 105, 60, 14, 14 }
+ },
+ /* sprite_ram_full */
+ {
+ asset_id_usr,
+ { 119, 60, 14, 14 }
+ },
+ /* sprite_logo */
+ {
+ asset_id_usr,
+ { 1, 94, 153, 16 }
}
};
diff --git a/sprite.h b/sprite.h
index 9f09747..852fa4c 100644
--- a/sprite.h
+++ b/sprite.h
@@ -21,7 +21,12 @@ typedef enum {
sprite_author,
sprite_free,
sprite_floor_tile,
- sprite_bricks
+ sprite_bricks,
+ sprite_heart_empty,
+ sprite_heart_full,
+ sprite_ram_empty,
+ sprite_ram_full,
+ sprite_logo
} Sprite_ID;
typedef struct {
diff --git a/world.h b/world.h
index ee2dc1a..fdc19c9 100644
--- a/world.h
+++ b/world.h
@@ -24,10 +24,10 @@ struct World {
CEnemy enemies [max_entities];
CCollider colliders [max_entities];
- int cam_x, cam_y;
-
Player player;
Map map;
+
+ int cam_x, cam_y;
};
void init_world(World* world);