Monsters now indicate their state with speech bubbles
This commit is contained in:
parent
f049d66219
commit
c4dc8382a9
|
@ -521,6 +521,8 @@ run_game(void)
|
|||
if (!is_player_dead())
|
||||
player_render(gPlayer, gCamera);
|
||||
|
||||
map_render_top_layer(gMap, gCamera);
|
||||
|
||||
if (gPlayer->class == MAGE || gPlayer->class == PALADIN)
|
||||
roommatrix_render_mouse_square(gRoomMatrix, gCamera);
|
||||
|
||||
|
|
11
src/map.c
11
src/map.c
|
@ -246,8 +246,6 @@ map_update(UpdateData *data)
|
|||
void map_render(Map *map, Camera *cam)
|
||||
{
|
||||
unsigned int i, j;
|
||||
LinkedList *monsterItem;
|
||||
LinkedList *items;
|
||||
Room *room;
|
||||
|
||||
if (!timer_started(map->renderTimer)) {
|
||||
|
@ -278,14 +276,19 @@ void map_render(Map *map, Camera *cam)
|
|||
particle_engine_wind(room->modifier.data.wind.direction);
|
||||
}
|
||||
|
||||
monsterItem = map->monsters;
|
||||
}
|
||||
|
||||
void
|
||||
map_render_top_layer(Map *map, Camera *cam)
|
||||
{
|
||||
LinkedList *monsterItem = map->monsters;
|
||||
while (monsterItem != NULL) {
|
||||
Monster *monster = monsterItem->data;
|
||||
monsterItem = monsterItem->next;
|
||||
monster_render(monster, cam);
|
||||
}
|
||||
|
||||
items = map->items;
|
||||
LinkedList *items = map->items;
|
||||
while (items != NULL) {
|
||||
Item *item = items->data;
|
||||
items = items->next;
|
||||
|
|
|
@ -94,6 +94,9 @@ map_update(struct UpdateData_t*);
|
|||
void
|
||||
map_render(Map*, Camera*);
|
||||
|
||||
void
|
||||
map_render_top_layer(Map*, Camera*);
|
||||
|
||||
void
|
||||
map_set_current_room(Map*, Position*);
|
||||
|
||||
|
|
|
@ -328,9 +328,7 @@ l_add_monster(lua_State *L)
|
|||
monster_update_pos(monster, (Position) { x, y });
|
||||
sprite_set_texture(monster->sprite, texture1, 0);
|
||||
sprite_set_texture(monster->sprite, texture2, 1);
|
||||
monster->state.normal = nstate;
|
||||
monster->state.challenge = cstate;
|
||||
monster->state.current = nstate;
|
||||
monster_set_states(monster, nstate, cstate);
|
||||
if (strlen(label)) {
|
||||
monster->label = label;
|
||||
monster->lclabel = to_lower(label);
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include "defines.h"
|
||||
#include "update_data.h"
|
||||
#include "actiontextbuilder.h"
|
||||
#include "texturecache.h"
|
||||
|
||||
Monster*
|
||||
monster_create(void)
|
||||
|
@ -51,12 +52,16 @@ monster_create(void)
|
|||
1 // lvl
|
||||
};
|
||||
|
||||
m->state.normal = PASSIVE;
|
||||
m->state.challenge = AGRESSIVE;
|
||||
m->state.current = m->state.normal;
|
||||
m->label = NULL;
|
||||
m->lclabel = NULL;
|
||||
m->steps = 0;
|
||||
m->stateIndicator.sprite = sprite_create();
|
||||
sprite_set_texture(m->stateIndicator.sprite, texturecache_add("GUI/GUI0.png"), 0);
|
||||
sprite_set_texture(m->stateIndicator.sprite, texturecache_add("GUI/GUI1.png"), 1);
|
||||
m->stateIndicator.sprite->dim = GAME_DIMENSION;
|
||||
m->stateIndicator.displayCount = 0;
|
||||
m->stateIndicator.shownOnPlayerRoomEnter = false;
|
||||
monster_set_states(m, PASSIVE, AGRESSIVE);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
@ -66,8 +71,9 @@ monster_update_pos(Monster *m, Position pos)
|
|||
{
|
||||
m->sprite->pos = pos;
|
||||
|
||||
Position textPos = pos;
|
||||
textPos.y += 10;
|
||||
Position indicatorPos = pos;
|
||||
indicatorPos.y -= 32;
|
||||
m->stateIndicator.sprite->pos = indicatorPos;
|
||||
}
|
||||
|
||||
static bool
|
||||
|
@ -253,6 +259,8 @@ monster_move(Monster *m, RoomMatrix *rm)
|
|||
|
||||
m->steps++;
|
||||
if (m->steps >= m->stats.speed) {
|
||||
if (m->stateIndicator.displayCount > 0)
|
||||
m->stateIndicator.displayCount -= 1;
|
||||
m->steps = 0;
|
||||
return true;
|
||||
}
|
||||
|
@ -263,8 +271,47 @@ monster_move(Monster *m, RoomMatrix *rm)
|
|||
void
|
||||
monster_update(Monster *m, UpdateData *data)
|
||||
{
|
||||
UNUSED(m);
|
||||
UNUSED(data);
|
||||
Position monsterRoomPos = position_to_room_coords(&m->sprite->pos);
|
||||
if (position_equals(&data->matrix->roomPos, &monsterRoomPos)) {
|
||||
if (m->stateIndicator.shownOnPlayerRoomEnter)
|
||||
return;
|
||||
|
||||
m->stateIndicator.shownOnPlayerRoomEnter = true;
|
||||
if (m->state.current != PASSIVE)
|
||||
m->stateIndicator.displayCount = 5;
|
||||
} else {
|
||||
m->stateIndicator.shownOnPlayerRoomEnter = false;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
monster_set_sprite_clip_for_current_state(Monster *m)
|
||||
{
|
||||
switch (m->state.current) {
|
||||
case AGRESSIVE:
|
||||
m->stateIndicator.sprite->clip = CLIP16(16 * 11, 16 * 3);
|
||||
break;
|
||||
case PASSIVE:
|
||||
m->stateIndicator.sprite->clip = CLIP16(16 * 10, 16);
|
||||
break;
|
||||
case SCARED:
|
||||
m->stateIndicator.sprite->clip = CLIP16(16 * 12, 16 * 3);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
monster_state_change(Monster *m)
|
||||
{
|
||||
if (m->state.current == m->state.challenge)
|
||||
return;
|
||||
|
||||
m->state.current = m->state.challenge;
|
||||
m->stateIndicator.displayCount = 5;
|
||||
|
||||
monster_set_sprite_clip_for_current_state(m);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -287,7 +334,7 @@ monster_hit(Monster *monster, unsigned int dmg)
|
|||
&monster->sprite->pos);
|
||||
}
|
||||
|
||||
monster->state.current = monster->state.challenge;
|
||||
monster_state_change(monster);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -355,6 +402,17 @@ void
|
|||
monster_render(Monster *m, Camera *cam)
|
||||
{
|
||||
sprite_render(m->sprite, cam);
|
||||
if (m->stateIndicator.displayCount > 0)
|
||||
sprite_render(m->stateIndicator.sprite, cam);
|
||||
}
|
||||
|
||||
void
|
||||
monster_set_states(Monster *m, StateType normal, StateType challenge)
|
||||
{
|
||||
m->state.normal = normal;
|
||||
m->state.current = normal;
|
||||
m->state.challenge = challenge;
|
||||
monster_set_sprite_clip_for_current_state(m);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -365,5 +423,6 @@ monster_destroy(Monster *m)
|
|||
free(m->label);
|
||||
if (m->lclabel)
|
||||
free(m->lclabel);
|
||||
sprite_destroy(m->stateIndicator.sprite);
|
||||
free(m);
|
||||
}
|
||||
|
|
|
@ -36,12 +36,19 @@ typedef struct {
|
|||
StateType challenge;
|
||||
} State;
|
||||
|
||||
typedef struct MonsterStateIndicator {
|
||||
Sprite *sprite;
|
||||
bool shownOnPlayerRoomEnter;
|
||||
int displayCount;
|
||||
} MonsterStateIndicator;
|
||||
|
||||
typedef struct Monster_t {
|
||||
char *label;
|
||||
char *lclabel;
|
||||
Sprite *sprite;
|
||||
Stats stats;
|
||||
State state;
|
||||
MonsterStateIndicator stateIndicator;
|
||||
unsigned int steps;
|
||||
} Monster;
|
||||
|
||||
|
@ -68,6 +75,9 @@ monster_update(Monster*, struct UpdateData_t*);
|
|||
void
|
||||
monster_drop_loot(Monster*, Map*, Player*);
|
||||
|
||||
void
|
||||
monster_set_states(Monster *, StateType normal, StateType challenge);
|
||||
|
||||
void
|
||||
monster_destroy(Monster*);
|
||||
|
||||
|
|
Loading…
Reference in New Issue