diff options
-rw-r--r-- | game.c | 91 | ||||
-rw-r--r-- | game_config.h | 3 | ||||
-rw-r--r-- | intermediate/map.bmp | bin | 8330 -> 8330 bytes | |||
-rw-r--r-- | map.c | 12 | ||||
-rw-r--r-- | player.c | 1 | ||||
-rw-r--r-- | sprite.c | 17 | ||||
-rw-r--r-- | sprite.h | 5 | ||||
-rw-r--r-- | world.c | 3 | ||||
-rw-r--r-- | world.h | 1 |
9 files changed, 104 insertions, 29 deletions
@@ -96,47 +96,76 @@ static void menu_deinit(Game* game) { } static void gameplay_init(Game* game) { + World* world; + + world = &game->world; + 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); + init_map(&world->map, world); + init_player(&world->player, world); + new_skull(world, 0, 0); + + world->gmemory = gmemory_max; } static void render_hud(Game* game) { - int i; - const Sprite* heart_sprite; - const Bitmap* heart_bitmap; + int i, g; + const Sprite* sprite; + const Bitmap* 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); + sprite = get_sprite(sprite_heart_full); + bitmap = get_bitmap(sprite->bitmap); for (i = 0; i < player->hp; i++) { render_bitmap( - heart_bitmap, - 1 + i * (heart_sprite->rect.w + 1), + bitmap, + 1 + i * (sprite->rect.w + 1), 1, - &heart_sprite->rect + &sprite->rect ); } - heart_sprite = get_sprite(sprite_heart_empty); - heart_bitmap = get_bitmap(heart_sprite->bitmap); + sprite = get_sprite(sprite_heart_empty); + bitmap = get_bitmap(sprite->bitmap); for (; i < player_max_hp; i++) { render_bitmap( - heart_bitmap, - 1 + i * (heart_sprite->rect.w + 1), + bitmap, + 1 + i * (sprite->rect.w + 1), 1, - &heart_sprite->rect + &sprite->rect + ); + } + + sprite = get_sprite(sprite_ram_full); + bitmap = get_bitmap(sprite->bitmap); + g = world->gmemory / gmemory_units; + for (i = 0; i < g; i++) { + render_bitmap( + bitmap, + 1 + i * (sprite->rect.w + 1), + 8, + &sprite->rect + ); + } + sprite = get_sprite(sprite_ram_empty); + bitmap = get_bitmap(sprite->bitmap); + g = gmemory_max / gmemory_units; + for (; i < g; i++) { + render_bitmap( + bitmap, + 1 + i * (sprite->rect.w + 1), + 8, + &sprite->rect ); } } static void gameplay_update(Game* game) { - int cx, cy, i; + int cx, cy; World* world; Player* player; cx = game->world.cam_x; @@ -155,6 +184,11 @@ static void gameplay_update(Game* game) { sprite_system(world); render_hud(game); + + if (world->gmemory <= 0) { + world->oom = 1; + game_change_state(game, game_state_dead); + } } static void gameplay_deinit(Game* game) { @@ -183,8 +217,10 @@ static void dead_init(Game* game) { static void dead_update(Game* game) { const BM_Font* font; int cx, cy; + World* world; font = get_default_font(); + world = &game->world; update_menu(&game->menu); @@ -193,12 +229,21 @@ static void dead_update(Game* game) { render_map(&game->world.map, cx, cy); sprite_system(&game->world); - rfont_text( - font, - renderer_w / 2 - 40, - game->menu.y - 15, - "You died" - ); + if (world->oom) { + rfont_text( + font, + renderer_w / 2 - 65, + game->menu.y - 15, + "Out of Memory" + ); + } else { + rfont_text( + font, + renderer_w / 2 - 40, + game->menu.y - 15, + "You died" + ); + } render_menu(&game->menu, get_default_font()); } diff --git a/game_config.h b/game_config.h index 8609814..5094cf8 100644 --- a/game_config.h +++ b/game_config.h @@ -17,4 +17,7 @@ #define mbmp_w (map_width * map_tile_size) #define mbmp_h (map_height * map_tile_size) +#define gmemory_max 100 +#define gmemory_units 10 + #endif diff --git a/intermediate/map.bmp b/intermediate/map.bmp Binary files differindex e6a66ee..112f29b 100644 --- a/intermediate/map.bmp +++ b/intermediate/map.bmp @@ -7,13 +7,13 @@ void init_map(Map* map, World* world) { const Sprite* floor, * bricks; const Bitmap* fbmp, * bbmp; Bitmap bitmap; - int i, x, y; + int i, x, y, r; bitmap.pixels = map->pixels; bitmap.w = mbmp_w; bitmap.h = mbmp_h; - floor = get_sprite(sprite_floor_tile); + floor = get_sprite(sprite_floor_tile_1); bricks = get_sprite(sprite_bricks); fbmp = get_bitmap(floor->bitmap); bbmp = get_bitmap(bricks->bitmap); @@ -22,8 +22,12 @@ void init_map(Map* map, World* world) { bitmap.pixels[i] = make_black(); } - for (x = 1; x < map_width - 1; x++) { - for (y = 1; y < map_height - 1; y++) { + for (y = 1; y < map_height - 1; y++) { + for (x = 1; x < map_width - 1; x++) { + r = rng() % 60; + if (r > 50) { + floor = get_sprite((r % 4) + sprite_floor_tile_1); + } blit( &bitmap, fbmp, @@ -130,6 +130,7 @@ void update_player(Player* player, World* world) { } if (player->hp <= 0) { + world->oom = 0; game_change_state(&game, game_state_dead); } @@ -71,11 +71,26 @@ static const Sprite sprites[] = { asset_id_usr, { 0, 80, 171, 10 } }, - /* sprite_floor_tile */ + /* sprite_floor_tile_1 */ { asset_id_map, { 0, 0, 16, 16 } }, + /* sprite_floor_tile_2 */ + { + asset_id_map, + { 0, 16, 16, 16 } + }, + /* sprite_floor_tile_3 */ + { + asset_id_map, + { 16, 16, 16, 16 } + }, + /* sprite_floor_tile_4 */ + { + asset_id_map, + { 16, 16, 16, 16 } + }, /* sprite_bricks */ { asset_id_map, @@ -20,7 +20,10 @@ typedef enum { sprite_enemy_bullet, sprite_author, sprite_free, - sprite_floor_tile, + sprite_floor_tile_1, + sprite_floor_tile_2, + sprite_floor_tile_3, + sprite_floor_tile_4, sprite_bricks, sprite_heart_empty, sprite_heart_full, @@ -29,12 +29,15 @@ Entity new_entity(World* world) { world->bitmask[e] = 0; + world->gmemory--; + return e; } void destroy_entity(World* world, Entity e) { world->recycle_bin[world->recycle_bin_count++] = e; world->bitmask[e] = 0; + world->gmemory++; } void add_components(World* world, Entity e, CType bits) { @@ -28,6 +28,7 @@ struct World { Map map; int cam_x, cam_y; + int gmemory, oom; }; void init_world(World* world); |