#include "../game/game.h"
#include "../score/score.h"
-static struct entity apple;
-
static void apple_step(struct entity *self, struct entity_step_data stepdata)
{
if (stepdata.dx == 0 && stepdata.dy == 0) {
}
}
+static struct entity apple_entity = {
+ .name = "apple",
+ .x = 0,
+ .y = 0,
+ .color = {0},
+ .use_color = false,
+ .texture = "🍎",
+ .remove = false,
+ .meta = NULL,
+ .health = 1,
+ .max_health = 1,
+ .collide_with_entities = false,
+
+ .on_step = &apple_step,
+ .on_collide = NULL,
+ .on_collide_with_entity = NULL,
+ .on_spawn = NULL,
+ .on_remove = NULL,
+ .on_death = NULL,
+ .on_damage = NULL,
+};
+
static void spawn_apple(int x, int y)
{
- spawn(apple, x, y, NULL);
+ spawn(apple_entity, x, y, NULL);
}
__attribute__((constructor)) static void init()
{
- apple = (struct entity) {
- .name = "apple",
- .x = 0,
- .y = 0,
- .color = get_color("#FF2A53"),
- .texture = "🍎",
- .remove = false,
- .meta = NULL,
- .health = 1,
- .max_health = 1,
- .collide_with_entities = false,
-
- .on_step = &apple_step,
- .on_collide = NULL,
- .on_collide_with_entity = NULL,
- .on_spawn = NULL,
- .on_remove = NULL,
- .on_death = NULL,
- .on_damage = NULL,
- };
-
register_air_function((struct generator_function) {
.chance = 25,
.callback = &spawn_apple,
#include "../score/score.h"
#include "../inventory/inventory.h"
-static struct entity cherry_entity;
-
static bool use_cherry(struct itemstack *stack)
{
(void) stack;
}
}
+static struct entity cherry_entity = {
+ .name = "cherry",
+ .x = 0,
+ .y = 0,
+ .color = {0},
+ .use_color = false,
+ .texture = "🍒",
+ .remove = false,
+ .meta = NULL,
+ .health = 1,
+ .max_health = 1,
+ .collide_with_entities = false,
+
+ .on_step = &cherry_step,
+ .on_collide = NULL,
+ .on_collide_with_entity = NULL,
+ .on_spawn = NULL,
+ .on_remove = NULL,
+ .on_death = NULL,
+ .on_damage = NULL,
+};
+
static void spawn_cherry(int x, int y)
{
spawn(cherry_entity, x, y, NULL);
__attribute__((constructor)) static void init()
{
- cherry_entity = (struct entity) {
- .name = "cherry",
- .x = 0,
- .y = 0,
- .color = get_color("#FF2A53"),
- .texture = "🍒",
- .remove = false,
- .meta = NULL,
- .health = 1,
- .max_health = 1,
- .collide_with_entities = false,
-
- .on_step = &cherry_step,
- .on_collide = NULL,
- .on_collide_with_entity = NULL,
- .on_spawn = NULL,
- .on_remove = NULL,
- .on_death = NULL,
- .on_damage = NULL,
- };
-
register_air_function((struct generator_function) {
.chance = 100,
.callback = &spawn_cherry,
#include "../game/game.h"
#include "../movement/movement.h"
-static struct entity fireball;
-
struct fireball_data
{
double timer;
self->remove = true;
}
+static struct entity fireball_entity = {
+ .name = "fireball",
+ .x = 0,
+ .y = 0,
+ .color = {0},
+ .use_color = true,
+ .texture = "⬤ ",
+ .remove = false,
+ .meta = NULL,
+ .health = 1,
+ .max_health = 1,
+ .collide_with_entities = true,
+
+ .on_step = &fireball_step,
+ .on_collide = &fireball_collide,
+ .on_collide_with_entity = &fireball_collide_with_entity,
+ .on_spawn = &fireball_spawn,
+ .on_remove = NULL,
+ .on_death = NULL,
+ .on_damage = NULL,
+};
+
static void shoot_fireball()
{
int vx, vy;
dir_to_xy(last_player_move, &vx, &vy);
- spawn(fireball, player.x + vx, player.y + vy, & (struct fireball_data) {
+ spawn(fireball_entity, player.x + vx, player.y + vy, & (struct fireball_data) {
.timer = 0.1,
.vx = vx,
.vy = vy,
__attribute__((constructor)) static void init()
{
- fireball = (struct entity) {
- .name = "fireball",
- .x = 0,
- .y = 0,
- .color = get_color("#FF6611"),
- .texture = "⬤ ",
- .remove = false,
- .meta = NULL,
- .health = 1,
- .max_health = 1,
- .collide_with_entities = true,
-
- .on_step = &fireball_step,
- .on_collide = &fireball_collide,
- .on_collide_with_entity = &fireball_collide_with_entity,
- .on_spawn = &fireball_spawn,
- .on_remove = NULL,
- .on_death = NULL,
- .on_damage = NULL,
- };
+ fireball_entity.color = get_color("#FF6611");
register_input_handler(' ', (struct input_handler) {
.run_if_dead = false,
/* Shared variables */
-struct color black = {0, 0, 0};
+struct color black = {0};
struct material wall;
struct material air;
struct node map[MAP_WIDTH][MAP_HEIGHT];
-struct entity player;
struct list *entities = & (struct list) {
.element = &player,
.next = NULL,
damage_overlay += (double) damage * 0.5;
}
+struct entity player = {
+ .name = "player",
+ .x = MAP_WIDTH / 2,
+ .y = MAP_HEIGHT / 2,
+ .color = {0},
+ .use_color = false,
+ .texture = "🙂",
+ .remove = false,
+ .meta = NULL,
+ .health = 10,
+ .max_health = 10,
+ .collide_with_entities = true,
+
+ .on_step = NULL,
+ .on_collide = NULL,
+ .on_collide_with_entity = NULL,
+ .on_spawn = NULL,
+ .on_remove = NULL,
+ .on_death = &player_death,
+ .on_damage = &player_damage,
+};
+
/* Mapgen */
static void mapgen_set_air(int x, int y)
/* Rendering */
-static bool render_color(struct color color, double light, bool bg)
+static bool render_color(struct color color, double light, bool bg, bool use_color)
{
if (light <= 0.0) {
set_color(black, bg);
return false;
- } else {
+ } else if (use_color) {
if (damage_overlay > 0.0)
mix_color(&color, damage_overlay_color, damage_overlay * 2.0);
set_color(color, bg);
return true;
+ } else {
+ return true;
}
}
double dist = sqrt(x * x + y * y);
double light = 1.0 - (double) dist / (double) LIGHT;
- render_color(node.material->color, light, true);
+ render_color(node.material->color, light, true, true);
struct entity *entity = render_entities[x + LIGHT][y + LIGHT];
render_entities[x + LIGHT][y + LIGHT] = NULL;
- if (entity && render_color(entity->color, light, false))
+ if (entity && render_color(entity->color, light, false, entity->use_color))
printf("%s", entity->texture);
else
printf(" ");
.color = black,
};
- player = (struct entity) {
- .name = "player",
- .x = MAP_WIDTH / 2,
- .y = MAP_HEIGHT / 2,
- .color = get_color("#00FFFF"),
- .texture = "🙂",
- .remove = false,
- .meta = NULL,
- .health = 10,
- .max_health = 10,
- .collide_with_entities = true,
-
- .on_step = NULL,
- .on_collide = NULL,
- .on_collide_with_entity = NULL,
- .on_spawn = NULL,
- .on_remove = NULL,
- .on_death = &player_death,
- .on_damage = &player_damage,
- };
-
entity_collision_map[player.x][player.y] = &player;
for (int x = 0; x < MAP_WIDTH; x++)
struct entity
{
- const char *name;
+ char *name;
int x, y;
struct color color;
- const char *texture;
+ bool use_color;
+ char *texture;
bool remove;
void *meta;
int health;
#include "../game/game.h"
#include "../score/score.h"
-static struct entity monster;
-
struct monster_data
{
double timer;
self->remove = true;
}
+static struct entity monster_entity = {
+ .name = "monster",
+ .x = 0,
+ .y = 0,
+ .color = {0},
+ .use_color = false,
+ .texture = "👾",
+ .remove = false,
+ .meta = NULL,
+ .health = 5,
+ .max_health = 5,
+ .collide_with_entities = true,
+
+ .on_step = &monster_step,
+ .on_collide = NULL,
+ .on_collide_with_entity = &monster_collide_with_entity,
+ .on_spawn = &monster_spawn,
+ .on_remove = NULL,
+ .on_death = &monster_death,
+ .on_damage = NULL,
+};
+
+
static void spawn_monster(int x, int y)
{
- spawn(monster, x, y, NULL);
+ spawn(monster_entity, x, y, NULL);
}
__attribute__((constructor)) static void init()
{
- monster = (struct entity) {
- .name = "monster",
- .x = 0,
- .y = 0,
- .color = get_color("#FF00F6"),
- .texture = "👾",
- .remove = false,
- .meta = NULL,
- .health = 5,
- .max_health = 5,
- .collide_with_entities = true,
-
- .on_step = &monster_step,
- .on_collide = NULL,
- .on_collide_with_entity = &monster_collide_with_entity,
- .on_spawn = &monster_spawn,
- .on_remove = NULL,
- .on_death = &monster_death,
- .on_damage = NULL,
- };
-
register_air_function((struct generator_function) {
.chance = 50,
.callback = &spawn_monster,