Add mapgen contexts
parent
90114b876b
commit
0f4153099c
|
@ -34,7 +34,7 @@ static struct entity apple_entity = {
|
|||
.on_damage = NULL,
|
||||
};
|
||||
|
||||
static void spawn_apple(int x, int y)
|
||||
static void spawn_apple(int x, int y, enum mg_context ctx)
|
||||
{
|
||||
spawn(apple_entity, x, y, NULL);
|
||||
}
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
|
||||
static bool use_cherry(struct itemstack *stack)
|
||||
{
|
||||
(void) stack;
|
||||
|
||||
add_health(&player, 2);
|
||||
return true;
|
||||
}
|
||||
|
@ -56,7 +54,7 @@ static struct entity cherry_entity = {
|
|||
.on_damage = NULL,
|
||||
};
|
||||
|
||||
static void spawn_cherry(int x, int y)
|
||||
static void spawn_cherry(int x, int y, enum mg_context ctx)
|
||||
{
|
||||
spawn(cherry_entity, x, y, NULL);
|
||||
}
|
||||
|
|
|
@ -33,8 +33,6 @@ static void fireball_step(struct entity *self, struct entity_step_data stepdata)
|
|||
|
||||
static void fireball_collide(struct entity *self, int x, int y)
|
||||
{
|
||||
(void) x, y;
|
||||
|
||||
self->remove = true;
|
||||
}
|
||||
|
||||
|
@ -82,8 +80,6 @@ static void shoot_fireball()
|
|||
|
||||
static bool shoot_fireball_item(struct itemstack *stack)
|
||||
{
|
||||
(void) stack;
|
||||
|
||||
shoot_fireball();
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -129,12 +129,6 @@ double calculate_dtime(struct timespec from, struct timespec to)
|
|||
return (double) (to.tv_sec - from.tv_sec) + (double) (to.tv_nsec - from.tv_nsec) / 1000000000.0;
|
||||
}
|
||||
|
||||
/*struct roman_conversion_rule
|
||||
{
|
||||
int number;
|
||||
const char *symbol;
|
||||
};*/
|
||||
|
||||
static struct
|
||||
{
|
||||
int number;
|
||||
|
@ -327,7 +321,7 @@ struct entity player = {
|
|||
|
||||
/* Mapgen */
|
||||
|
||||
static void mapgen_set_air(int x, int y)
|
||||
static void mapgen_set_air(int x, int y, enum mg_context ctx)
|
||||
{
|
||||
if (is_outside(x, y))
|
||||
return;
|
||||
|
@ -341,7 +335,7 @@ static void mapgen_set_air(int x, int y)
|
|||
struct generator_function *func = ptr->element;
|
||||
|
||||
if (rand() % func->chance == 0)
|
||||
func->callback(x, y);
|
||||
func->callback(x, y, ctx);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -363,7 +357,7 @@ static void generate_room(int origin_x, int origin_y)
|
|||
}
|
||||
|
||||
for (int y = -up; y <= down; y++)
|
||||
mapgen_set_air(origin_x + x, origin_y + y);
|
||||
mapgen_set_air(origin_x + x, origin_y + y, MG_CTX_ROOM);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -385,7 +379,7 @@ static void generate_corridor(int lx, int ly, enum direction ldir)
|
|||
return;
|
||||
}
|
||||
|
||||
mapgen_set_air(lx, ly);
|
||||
mapgen_set_air(lx, ly, MG_CTX_CORRIDOR);
|
||||
|
||||
int x, y;
|
||||
|
||||
|
@ -511,8 +505,6 @@ static void render()
|
|||
|
||||
static void handle_interrupt(int signal)
|
||||
{
|
||||
(void) signal;
|
||||
|
||||
quit();
|
||||
}
|
||||
|
||||
|
@ -526,8 +518,6 @@ static void handle_input(unsigned char c)
|
|||
|
||||
static void *input_thread(void *unused)
|
||||
{
|
||||
(void) unused;
|
||||
|
||||
while (running)
|
||||
handle_input(tolower(fgetc(stdin)));
|
||||
|
||||
|
|
|
@ -63,10 +63,16 @@ struct list
|
|||
struct list *next;
|
||||
};
|
||||
|
||||
enum mg_context
|
||||
{
|
||||
MG_CTX_CORRIDOR,
|
||||
MG_CTX_ROOM,
|
||||
};
|
||||
|
||||
struct generator_function
|
||||
{
|
||||
int chance;
|
||||
void (*callback)(int x, int y);
|
||||
void (*callback)(int x, int y, enum mg_context ctx);
|
||||
};
|
||||
|
||||
struct input_handler
|
||||
|
|
|
@ -7,7 +7,6 @@ static struct color darkgray;
|
|||
|
||||
static bool use_item(struct itemstack *stack)
|
||||
{
|
||||
(void) stack;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,8 +10,6 @@ struct monster_data
|
|||
|
||||
static void monster_spawn(struct entity *self, void *data)
|
||||
{
|
||||
(void) data;
|
||||
|
||||
self->meta = malloc(sizeof(struct monster_data));
|
||||
((struct monster_data *) self->meta)->timer = 0.5;
|
||||
}
|
||||
|
@ -62,7 +60,7 @@ static struct entity monster_entity = {
|
|||
};
|
||||
|
||||
|
||||
static void spawn_monster(int x, int y)
|
||||
static void spawn_monster(int x, int y, enum mg_context ctx)
|
||||
{
|
||||
spawn(monster_entity, x, y, NULL);
|
||||
}
|
||||
|
|
|
@ -7,8 +7,6 @@
|
|||
|
||||
static bool use_broken_sword(struct itemstack *stack)
|
||||
{
|
||||
(void) stack;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue