RogueLife/src/level.h

90 lines
2.0 KiB
C
Raw Normal View History

//---
// level: Static level model
//
// This module provides representations for read-only data structures
// describing levels, from which dynamic maps can be built. The only role of
// models is that we can import them into the game and then load them into
// maps. This is a convenience to abstract away the storage format of levels.
//---
#pragma once
2021-07-16 15:51:32 +02:00
#include "fixed.h"
#include "map.h"
2022-03-10 19:34:32 +01:00
#include "item.h"
#include <stdint.h>
2021-07-16 15:51:32 +02:00
#include <stdbool.h>
2021-12-25 18:21:31 +01:00
#include <gint/display.h>
2021-07-16 15:51:32 +02:00
/* A level wave is a list of pairs (enemy identity, amount) pairs which
indicate how many enemies to spawn. The order might be random and another
dynamically-allocated structure is used in game_t to keep track of this
assignment. */
2021-07-16 15:51:32 +02:00
typedef struct {
int entry_count;
2021-07-16 15:51:32 +02:00
struct {
uint8_t identity;
uint8_t amount;
} *entries;
2021-07-16 15:51:32 +02:00
} level_wave_t;
2022-03-10 19:34:32 +01:00
enum {
/* Nothing happens for a short while */
LEVEL_EVENT_DELAY = 0,
/* A wave of monster spawns! */
LEVEL_EVENT_WAVE = 1,
/* An item is dropped at a random position */
LEVEL_EVENT_ITEM = 2,
};
/* Levels are made of a sequence of simple events. */
typedef struct {
int type;
2022-03-14 22:50:24 +01:00
fixed_t duration;
2022-03-10 19:34:32 +01:00
union {
2022-03-14 22:50:24 +01:00
/* LEVEL_EVENT_DELAY: Nothing */
2022-03-10 19:34:32 +01:00
/* LEVEL_EVENT_WAVE */
level_wave_t *wave;
/* LEVEL_EVENT_ITEM */
int item;
};
} level_event_t;
2021-06-02 09:38:59 +02:00
typedef struct {
2022-02-13 12:09:35 +01:00
char const *name;
map_t const *map;
2021-12-28 22:23:09 +01:00
/* Player spawn location */
uint8_t player_spawn_x;
uint8_t player_spawn_y;
2021-07-16 15:51:32 +02:00
/* Spawner positions */
int spawner_count;
2021-12-28 22:23:09 +01:00
uint8_t *spawner_x;
uint8_t *spawner_y;
2022-03-14 22:50:24 +01:00
/* List of events (the array is not terminated) */
int event_count;
level_event_t *events;
2021-07-16 15:51:32 +02:00
2021-06-02 09:38:59 +02:00
} level_t;
/* Get the number of waves in a level */
int level_wave_count(level_t const *lv);
/* List of levels */
extern level_t level_lv1;
extern level_t level_lv2;
2022-06-25 18:49:43 +02:00
extern level_t level_lv3;
2022-06-25 20:29:11 +02:00
extern level_t level_lv4;
extern level_t level_lv5;
extern level_t level_lvsandbox;
#define LEVEL_COUNT 6
extern level_t const *level_all[LEVEL_COUNT];