Added labels to monsters

This commit is contained in:
Linus Probert 2018-01-17 09:32:49 +01:00
parent 22139f37bd
commit 38a584f418
5 changed files with 82 additions and 68 deletions

3
.vimrc
View File

@ -1,7 +1,6 @@
nnoremap <F1> :Make<cr>
nnoremap <F2> :Make clean<cr>
au FileType c setl makeprg=ninja\ -C\ build
au FileType h setl makeprg=ninja\ -C\ build
au FileType c,h setl makeprg=ninja\ -C\ build
let g:syntastic_c_include_dirs = [ 'build' ]

View File

@ -46,81 +46,81 @@ local state = {
local enemies = {
-- PESTS
{ texturePaths.pest0, texturePaths.pest1, 0, 0 },
{ texturePaths.pest0, texturePaths.pest1, 16, 0 },
{ texturePaths.pest0, texturePaths.pest1, 32, 0 },
{ texturePaths.pest0, texturePaths.pest1, 48, 0 },
{ texturePaths.pest0, texturePaths.pest1, 64, 0 },
{ texturePaths.pest0, texturePaths.pest1, 96, 0 },
{ texturePaths.pest0, texturePaths.pest1, 112, 0 },
{ texturePaths.pest0, texturePaths.pest1, 0, 0, "Beetle" },
{ texturePaths.pest0, texturePaths.pest1, 16, 0, "Beetle" },
{ texturePaths.pest0, texturePaths.pest1, 32, 0, "Beetle" },
{ texturePaths.pest0, texturePaths.pest1, 48, 0, "Beetle" },
{ texturePaths.pest0, texturePaths.pest1, 64, 0, "Large Grub" },
{ texturePaths.pest0, texturePaths.pest1, 80, 0, "Small Grub" },
{ texturePaths.pest0, texturePaths.pest1, 96, 0, "Slim Worm" },
{ texturePaths.pest0, texturePaths.pest1, 112, 0, "Fat Worm" },
{ texturePaths.pest0, texturePaths.pest1, 0, 16 },
{ texturePaths.pest0, texturePaths.pest1, 16, 16 },
{ texturePaths.pest0, texturePaths.pest1, 32, 16 },
{ texturePaths.pest0, texturePaths.pest1, 48, 16 },
{ texturePaths.pest0, texturePaths.pest1, 64, 16 },
{ texturePaths.pest0, texturePaths.pest1, 80, 16 },
--{ texturePaths.pest0, texturePaths.pest1, 0, 16, "Female Dragonfly" },
{ texturePaths.pest0, texturePaths.pest1, 16, 16, "Fly" },
{ texturePaths.pest0, texturePaths.pest1, 32, 16, "Larva" },
{ texturePaths.pest0, texturePaths.pest1, 48, 16, "Moth" },
--{ texturePaths.pest0, texturePaths.pest1, 64, 16 },
{ texturePaths.pest0, texturePaths.pest1, 80, 16, "Gnat" },
{ texturePaths.pest0, texturePaths.pest1, 0, 32 },
{ texturePaths.pest0, texturePaths.pest1, 16, 32 },
{ texturePaths.pest0, texturePaths.pest1, 32, 32 },
{ texturePaths.pest0, texturePaths.pest1, 48, 32 },
{ texturePaths.pest0, texturePaths.pest1, 64, 32 },
{ texturePaths.pest0, texturePaths.pest1, 80, 32 },
{ texturePaths.pest0, texturePaths.pest1, 0, 32, "Small Spider" },
{ texturePaths.pest0, texturePaths.pest1, 16, 32, "Medium Spider" },
{ texturePaths.pest0, texturePaths.pest1, 32, 32, "Large Spider" },
{ texturePaths.pest0, texturePaths.pest1, 48, 32, "Small Scorpion" },
{ texturePaths.pest0, texturePaths.pest1, 64, 32, "Medium Scorpion" },
{ texturePaths.pest0, texturePaths.pest1, 80, 32, "Large Scorpion" },
{ texturePaths.pest0, texturePaths.pest1, 0, 48 },
{ texturePaths.pest0, texturePaths.pest1, 16, 48 },
{ texturePaths.pest0, texturePaths.pest1, 0, 48, "Slug" },
{ texturePaths.pest0, texturePaths.pest1, 16, 48, "Large Slug" },
--{ texturePaths.pest0, texturePaths.pest1, 32, 48 },
{ texturePaths.pest0, texturePaths.pest1, 48, 48 },
{ texturePaths.pest0, texturePaths.pest1, 64, 48 },
{ texturePaths.pest0, texturePaths.pest1, 48, 48, "Red Slug" },
{ texturePaths.pest0, texturePaths.pest1, 64, 48, "Large Red Slug" },
{ texturePaths.pest0, texturePaths.pest1, 0, 64 },
{ texturePaths.pest0, texturePaths.pest1, 16, 64 },
{ texturePaths.pest0, texturePaths.pest1, 32, 64 },
{ texturePaths.pest0, texturePaths.pest1, 48, 64 },
{ texturePaths.pest0, texturePaths.pest1, 0, 64, "Giant Brown Ant" },
{ texturePaths.pest0, texturePaths.pest1, 16, 64, "Giant Black Ant" },
{ texturePaths.pest0, texturePaths.pest1, 32, 64, "Giant Gold Ant" },
{ texturePaths.pest0, texturePaths.pest1, 48, 64, "Giant Silver Ant" },
{ texturePaths.pest0, texturePaths.pest1, 0, 80 },
{ texturePaths.pest0, texturePaths.pest1, 16, 80 },
{ texturePaths.pest0, texturePaths.pest1, 32, 80 },
{ texturePaths.pest0, texturePaths.pest1, 48, 80 },
--{ texturePaths.pest0, texturePaths.pest1, 0, 80 },
--{ texturePaths.pest0, texturePaths.pest1, 16, 80 },
--{ texturePaths.pest0, texturePaths.pest1, 32, 80 },
--{ texturePaths.pest0, texturePaths.pest1, 48, 80 },
{ texturePaths.pest0, texturePaths.pest1, 0, 96 },
{ texturePaths.pest0, texturePaths.pest1, 16, 96 },
{ texturePaths.pest0, texturePaths.pest1, 32, 96 },
--{ texturePaths.pest0, texturePaths.pest1, 0, 96 },
--{ texturePaths.pest0, texturePaths.pest1, 16, 96 },
--{ texturePaths.pest0, texturePaths.pest1, 32, 96 },
{ texturePaths.pest0, texturePaths.pest1, 0, 112 },
{ texturePaths.pest0, texturePaths.pest1, 16, 112 },
{ texturePaths.pest0, texturePaths.pest1, 32, 112 },
{ texturePaths.pest0, texturePaths.pest1, 48, 112 },
--{ texturePaths.pest0, texturePaths.pest1, 0, 112 },
--{ texturePaths.pest0, texturePaths.pest1, 16, 112 },
--{ texturePaths.pest0, texturePaths.pest1, 32, 112 },
--{ texturePaths.pest0, texturePaths.pest1, 48, 112 },
-- UNDEAD
{ texturePaths.undead0, texturePaths.undead1, 0, 0, state.passive, state.agressive };
{ texturePaths.undead0, texturePaths.undead1, 16, 0, state.passive, state.agressive };
{ texturePaths.undead0, texturePaths.undead1, 32, 0, state.passive, state.agressive };
{ texturePaths.undead0, texturePaths.undead1, 48, 0, state.passive, state.agressive };
{ texturePaths.undead0, texturePaths.undead1, 64, 0, state.passive, state.agressive };
{ texturePaths.undead0, texturePaths.undead1, 80, 0, state.passive, state.agressive };
{ texturePaths.undead0, texturePaths.undead1, 96, 0, state.passive, state.agressive };
{ texturePaths.undead0, texturePaths.undead1, 112, 0, state.passive, state.agressive };
--{ texturePaths.undead0, texturePaths.undead1, 0, 0, "", state.passive, state.agressive };
--{ texturePaths.undead0, texturePaths.undead1, 16, 0, "", state.passive, state.agressive };
--{ texturePaths.undead0, texturePaths.undead1, 32, 0, "", state.passive, state.agressive };
--{ texturePaths.undead0, texturePaths.undead1, 48, 0, "", state.passive, state.agressive };
--{ texturePaths.undead0, texturePaths.undead1, 64, 0, "", state.passive, state.agressive };
--{ texturePaths.undead0, texturePaths.undead1, 80, 0, "", state.passive, state.agressive };
--{ texturePaths.undead0, texturePaths.undead1, 96, 0, "", state.passive, state.agressive };
--{ texturePaths.undead0, texturePaths.undead1, 112, 0, "", state.passive, state.agressive };
{ texturePaths.undead0, texturePaths.undead1, 0, 16, state.passive, state.agressive };
{ texturePaths.undead0, texturePaths.undead1, 16, 16, state.passive, state.agressive };
{ texturePaths.undead0, texturePaths.undead1, 32, 16, state.passive, state.agressive };
{ texturePaths.undead0, texturePaths.undead1, 48, 16, state.passive, state.agressive };
{ texturePaths.undead0, texturePaths.undead1, 64, 16, state.passive, state.agressive };
{ texturePaths.undead0, texturePaths.undead1, 80, 16, state.passive, state.agressive };
{ texturePaths.undead0, texturePaths.undead1, 96, 16, state.passive, state.agressive };
{ texturePaths.undead0, texturePaths.undead1, 112, 16, state.passive, state.agressive };
--{ texturePaths.undead0, texturePaths.undead1, 0, 16, "", state.passive, state.agressive };
--{ texturePaths.undead0, texturePaths.undead1, 16, 16, "", state.passive, state.agressive };
--{ texturePaths.undead0, texturePaths.undead1, 32, 16, "", state.passive, state.agressive };
--{ texturePaths.undead0, texturePaths.undead1, 48, 16, "", state.passive, state.agressive };
--{ texturePaths.undead0, texturePaths.undead1, 64, 16, "", state.passive, state.agressive };
--{ texturePaths.undead0, texturePaths.undead1, 80, 16, "", state.passive, state.agressive };
--{ texturePaths.undead0, texturePaths.undead1, 96, 16, "", state.passive, state.agressive };
--{ texturePaths.undead0, texturePaths.undead1, 112, 16, "", state.passive, state.agressive };
{ texturePaths.undead0, texturePaths.undead1, 0, 32, state.passive, state.agressive };
{ texturePaths.undead0, texturePaths.undead1, 16, 32, state.passive, state.agressive };
{ texturePaths.undead0, texturePaths.undead1, 32, 32, state.passive, state.agressive };
{ texturePaths.undead0, texturePaths.undead1, 48, 32, state.passive, state.agressive };
{ texturePaths.undead0, texturePaths.undead1, 64, 32, state.passive, state.agressive };
{ texturePaths.undead0, texturePaths.undead1, 80, 32, state.passive, state.agressive };
{ texturePaths.undead0, texturePaths.undead1, 96, 32, state.passive, state.agressive };
{ texturePaths.undead0, texturePaths.undead1, 112, 32,
state.passive, state.scared };
{ texturePaths.undead0, texturePaths.undead1, 0, 32, "Skeleton", state.passive, state.agressive };
{ texturePaths.undead0, texturePaths.undead1, 16, 32, "Umber Skeleton", state.passive, state.agressive };
{ texturePaths.undead0, texturePaths.undead1, 32, 32, "Caustic Skeleton", state.passive, state.agressive };
{ texturePaths.undead0, texturePaths.undead1, 48, 32, "Black Skeleton", state.passive, state.agressive };
--{ texturePaths.undead0, texturePaths.undead1, 64, 32, "", state.passive, state.agressive };
--{ texturePaths.undead0, texturePaths.undead1, 80, 32, "", state.passive, state.agressive };
--{ texturePaths.undead0, texturePaths.undead1, 96, 32, "", state.passive, state.agressive };
--{ texturePaths.undead0, texturePaths.undead1, 112, 32, "", state.passive, state.scared };
}
local function repack(data)
@ -129,8 +129,9 @@ local function repack(data)
texturePath2 = data[2],
clipX = data[3],
clipY = data[4],
nstate = data[5] or state.passive,
cstate = data[6] or state.scared
label = data[5] or "",
nstate = data[6] or state.passive,
cstate = data[7] or state.scared,
}
end

View File

@ -158,7 +158,8 @@ l_add_monster(lua_State *L)
Monster *monster;
Map *map;
int x, y, clip_x, clip_y, nstate, cstate;
const char *texture_path_1, *texture_path_2;
const char *texture_path_1, *texture_path_2, *tmp_label;
char *label;
Texture *texture1, *texture2;
SDL_Renderer *renderer;
@ -171,6 +172,7 @@ l_add_monster(lua_State *L)
lua_settop(L, 4);
luaL_checktype(L, 4, LUA_TTABLE);
lua_getfield(L, 4, "label");
lua_getfield(L, 4, "texturePath1");
lua_getfield(L, 4, "texturePath2");
lua_getfield(L, 4, "clipX");
@ -178,6 +180,7 @@ l_add_monster(lua_State *L)
lua_getfield(L, 4, "nstate");
lua_getfield(L, 4, "cstate");
tmp_label = luaL_checkstring(L, -7);
texture_path_1 = luaL_checkstring(L, -6);
texture_path_2 = luaL_checkstring(L, -5);
clip_x = (int) luaL_checkinteger(L, -4);
@ -188,6 +191,8 @@ l_add_monster(lua_State *L)
texture1 = map_add_monster_texture(map, texture_path_1, renderer);
texture2 = map_add_monster_texture(map, texture_path_2, renderer);
label = strdup(tmp_label);
texture1->dim = (Dimension) { TILE_DIMENSION, TILE_DIMENSION };
texture2->dim = (Dimension) { TILE_DIMENSION, TILE_DIMENSION };
@ -201,6 +206,8 @@ l_add_monster(lua_State *L)
monster->state.normal = nstate;
monster->state.challenge = cstate;
monster->state.current = nstate;
if (strlen(label))
monster->label = label;
map_add_monster(map, monster);

View File

@ -34,6 +34,7 @@ monster_create(SDL_Renderer *renderer)
m->state.normal = PASSIVE;
m->state.challenge = AGRESSIVE;
m->state.current = m->state.normal;
m->label = NULL;
monster_load_texts(m, renderer);
@ -210,6 +211,9 @@ monster_move(Monster *m, RoomMatrix *rm)
monsterRoomPos = position_to_matrix_coords(&m->sprite->pos);
rm->spaces[monsterRoomPos.x][monsterRoomPos.y].occupied = true;
rm->spaces[monsterRoomPos.x][monsterRoomPos.y].monster = m;
if (m->label)
printf("Monster '%s' moved.\n", m->label);
}
void
@ -240,6 +244,8 @@ void
monster_destroy(Monster *m)
{
sprite_destroy(m->sprite);
if (m->label)
free(m->label);
if (m->hitText)
actiontext_destroy(m->hitText);
if (m->missText)

View File

@ -15,6 +15,7 @@ typedef struct {
} State;
typedef struct Monster_t {
char *label;
Sprite *sprite;
ActionText *hitText;
ActionText *missText;