move ASSET_MOB to survival game

master
Dominik Madarász 2024-05-29 11:18:48 +02:00
parent 29d9b9306d
commit 23645ed32a
10 changed files with 285 additions and 305 deletions

View File

@ -20,7 +20,6 @@
X(ASSET_BLUEPRINT)\
X(ASSET_BLUEPRINT_DEMO_HOUSE)\
X(ASSET_BLUEPRINT_END)\
X(ASSET_MOB)\
X(ASSET_FENCE)\
X(ASSET_DEV)\
X(ASSET_GROUND)\

View File

@ -163,7 +163,6 @@ static debug_item items[] = {
.is_collapsed = false
}
},
{ .kind = DITEM_BUTTON, .name = "spawn mobs", .on_click = ActSpawnMobs },
{ .kind = DITEM_BUTTON, .name = "spawn car", .on_click = ActSpawnCar },
{ .kind = DITEM_BUTTON, .name = "place ice rink", .on_click = ActPlaceIceRink },
{ .kind = DITEM_BUTTON, .name = "erase world changes", .on_click = ActEraseWorldChanges },

View File

@ -54,32 +54,6 @@ ActSpawnSelItem(void) {
entity_set_position(e, origin->x, origin->y);
}
void
ActSpawnMobs(void) {
ecs_entity_t plr = camera_get().ent_id;
Position const* origin = ecs_get(world_ecs(), plr, Position);
const uint32_t w = 12*WORLD_BLOCK_SIZE;
const uint32_t h = 12*WORLD_BLOCK_SIZE;
uint32_t x = (uint32_t)origin->x - w/2;
uint32_t y = (uint32_t)origin->y - h/2;
for (uint32_t cy=y; cy<y+h; cy+=WORLD_BLOCK_SIZE) {
for (uint32_t cx=x; cx<x+w; cx+=WORLD_BLOCK_SIZE) {
if (cx >= world_dim()) continue;
if (cy >= world_dim()) continue;
if ((cy == y || cy == (y + h-WORLD_BLOCK_SIZE)) ||
(cx == x || cx == (x + w-WORLD_BLOCK_SIZE))) {
ecs_entity_t e = entity_spawn_id(ASSET_MOB);
entity_set_position(e, (float)cx, (float)cy);
ecs_add(world_ecs(), e, MobMelee);
}
}
}
}
void
ActSpawnCirclingDriver(void) {
ecs_entity_t plr = camera_get().ent_id;

View File

@ -57,9 +57,6 @@ Texture2D texgen_build_sprite_fallback(asset_id id) {
case ASSET_SPLITTER: return LoadTexEco("item_splitter");
case ASSET_ASSEMBLER: return LoadTexEco("assembler");
// Mobs
case ASSET_MOB: return LoadTexEco("enemy1");
default: break;
}

View File

@ -60,7 +60,6 @@ void tooltip_register_defaults(void) {
tooltip_register( (tooltip) { .name = "ASSET_IRON_ORE", .content = "Natural resource that can be smelted in ASSET_FURNACE." } );
tooltip_register( (tooltip) { .name = "ASSET_IRON_INGOT", .content = "Used as a building material. It is smelted from ASSET_IRON_ORE." } );
tooltip_register( (tooltip) { .name = "ASSET_SCREWS", .content = "Used as a building material. It is crafted from ASSET_IRON_PLATES." } );
tooltip_register( (tooltip) { .name = "ASSET_MOB", .content = "Enemy hunting player down." } );
tooltip_register( (tooltip) { .name = "craft", .content = "Crafting is the process of constructing tools, items, and blocks." } );
tooltip_register( (tooltip) { .name = "smelt", .content = "Smelting is a process of applying heat to ore, to extract a base metal. It is a form of extractive metallurgy. It is used to extract many metals from their ores, including silver, iron, copper, and other base metals." } );
}

View File

@ -44,7 +44,6 @@ void entity_default_spawnlist(void) {
entity_add_spawndef(ASSET_SPLITTER, splitter_spawn);
entity_add_spawndef(ASSET_ASSEMBLER, assembler_spawn);
entity_add_spawndef(ASSET_CREATURE, creature_spawn);
entity_add_spawndef(ASSET_MOB, mob_spawn);
entity_add_spawndef_data(ASSET_BLUEPRINT, blueprint_spawn_udata);
}

View File

@ -118,13 +118,3 @@ uint64_t storage_spawn(void) {
//------------------------------------------------------------------------
uint64_t mob_spawn(void) {
ecs_entity_t e = entity_spawn(EKIND_MONSTER);
ecs_add(world_ecs(), e, Mob);
ecs_set(world_ecs(), e, Health, { 60, 60, 0 });
ecs_set(world_ecs(), e, PhysicsBody, { .kind = PHYS_AABB, .mass = 1.0f });
ecs_set(world_ecs(), e, Sprite, { .frame = 101 + (rand()%3) });
return (uint64_t)e;
}

View File

@ -83,8 +83,23 @@ void mob_systems(ecs_world_t *ecs) {
ECS_OBSERVER(ecs, MobOnDead, EcsOnAdd, components.Mob, components.Sprite, components.Velocity, components.Dead);
}
void game_init(bool new_db) {
uint64_t mob_spawn(void) {
ecs_entity_t e = entity_spawn(EKIND_MONSTER);
ecs_add(world_ecs(), e, Mob);
ecs_set(world_ecs(), e, Health, { 60, 60, 0 });
ecs_set(world_ecs(), e, PhysicsBody, { .kind = PHYS_AABB, .mass = 1.0f });
ecs_set(world_ecs(), e, Sprite, { .frame = 101 + (rand()%3) });
return (uint64_t)e;
}
void game_init(bool new_db) {
if (new_db) {
assets_new("MOB");
}
entity_add_spawndef(ASSET_MOB, mob_spawn);
}
void game_input() {

View File

@ -4,4 +4,8 @@ enum {
SURV_CODE_SHOW_NOTIF,
};
enum {
ASSET_MOB = NEXT_FREE_ASSET,
};
void game_setup_ecs();

View File

@ -2,10 +2,14 @@
#include "world/world.h"
#include "zpl.h"
#include "utils/raylib_helpers.h"
#include "game.h"
Texture2D texgen_build_anim(asset_id id, int64_t counter) {
(void)counter;
switch (id) {
// Mobs
case ASSET_MOB: return LoadTexEco("enemy1");
default: return texgen_build_anim_fallback(id, counter); break;
}
}