Adds sentinel monster behaviour.

This commit is contained in:
Linus Probert 2018-05-21 21:03:59 +02:00
parent a66f16de79
commit 2462e4cf33
6 changed files with 80 additions and 18 deletions

View File

@ -42,7 +42,8 @@ local behaviour = {
normal = 1,
hostile = 2,
guerilla = 3,
coward = 4
coward = 4,
sentinel = 5
}
local stats = {
@ -60,6 +61,13 @@ local stats = {
def = 0,
speed = 1
},
misc = {
hp = 18,
dmg = 2,
atk = 0,
def = 0,
speed = 1
},
dog = {
hp = 12,
dmg = 2,
@ -134,6 +142,12 @@ local pests = {
--{ texturePaths.pest0, texturePaths.pest1, 48, 112 },
}
local misc = {
{ texturePaths.misc0, texturePaths.misc1, stats.misc, 0, 0, "A Giant Black Rat", behaviour.sentinel },
{ texturePaths.misc0, texturePaths.misc1, stats.misc, 16, 0, "A Giant White Rat", behaviour.sentinel },
{ texturePaths.misc0, texturePaths.misc1, stats.misc, 64, 0, "An Owl Bear", behaviour.sentinel },
}
local undead = {
-- UNDEAD
--{ texturePaths.undead0, texturePaths.undead1, 0, 0, "", behaviour.normal };
@ -179,7 +193,7 @@ local reptile = {
}
local platino = {
{ texturePaths.reptile0, texturePaths.reptile1, stats.platino, 48, 12*16, "Platino", behaviour.hostile };
{ texturePaths.reptile0, texturePaths.reptile1, stats.platino, 48, 12*16, "Platino", behaviour.sentinel };
}
local demon = {
@ -217,26 +231,31 @@ local enemies = {}
if(CURRENT_LEVEL > 0 and CURRENT_LEVEL < 10) then
if (CURRENT_LEVEL == 1) then
enemies = concat(enemies, pests)
enemies = concat(enemies, misc)
enemies = concat(enemies, dogs)
elseif (CURRENT_LEVEL > 5) then
enemies = {}
enemies = concat(enemies, demon)
enemies = concat(enemies, undead)
enemies = concat(enemies, reptile)
enemies = concat(enemies, misc)
elseif (CURRENT_LEVEL > 3) then
enemies = {}
enemies = concat(enemies, undead)
enemies = concat(enemies, reptile)
enemies = concat(enemies, misc)
enemies = concat(enemies, dogs)
elseif (CURRENT_LEVEL > 2) then
enemies = {}
enemies = concat(enemies, undead)
enemies = concat(enemies, reptile)
enemies = concat(enemies, misc)
enemies = concat(enemies, dogs)
elseif (CURRENT_LEVEL > 1) then
enemies = {}
enemies = concat(enemies, undead)
enemies = concat(enemies, reptile)
enemies = concat(enemies, misc)
enemies = concat(enemies, dogs)
end
end
@ -247,6 +266,9 @@ end
function module.add_monster_to_room(map, roomx, roomy)
local count = random(3)
if (CURRENT_LEVEL > 3) then
count = random(4)
end
for i=0,count do
local x = (roomx * 512) + (random(13) + 1) * 32
local y = (roomy * 384) + (random(9) + 1) * 32

View File

@ -468,8 +468,6 @@ run_game(void)
if (gGameState == IN_GAME_MENU)
menu_update(inGameMenu, &input);
if (gGameState != PLAYING && gGameState != IN_GAME_MENU)
return;
map_clear_dead_monsters(gMap, gPlayer);
map_clear_collected_items(gMap);
@ -556,10 +554,10 @@ run_game(void)
gui_event_message("You died!");
mixer_play_effect(SPLAT);
gGameState = GAME_OVER;
}
} else {
check_next_level();
}
}
static void
run_menu(void)

View File

@ -48,6 +48,11 @@ monster_set_sprite_clip_for_current_state(Monster *m)
case SCARED:
m->stateIndicator.sprite->clip = CLIP16(16 * 12, 16 * 3);
break;
case SLEEPING:
m->stateIndicator.sprite->clip = CLIP16(16 * 10, 16 * 4);
break;
case SCANNING:
m->stateIndicator.sprite->clip = CLIP16(16 * 13, 16 * 4);
default:
break;
}
@ -70,14 +75,12 @@ static void
monster_behaviour_check_post_hit(Monster *m)
{
switch (m->behaviour) {
case NORMAL:
monster_state_change(m, AGRESSIVE);
break;
case PACIFIST:
case COWARD:
monster_state_change(m, SCARED);
break;
default:
monster_state_change(m, AGRESSIVE);
break;
}
}
@ -94,10 +97,31 @@ monster_behaviour_check_post_attack(Monster *m)
}
}
static void
handle_sentinel_behaviour(Monster *m, RoomMatrix *rm)
{
if (m->state.current == AGRESSIVE)
return;
Position monsterPos = m->sprite->pos;
if (!position_in_room(&monsterPos, &rm->roomPos))
return;
monsterPos = position_to_matrix_coords(&monsterPos);
Position playerPos = rm->playerRoomPos;
unsigned int dx = abs(playerPos.x - monsterPos.x);
unsigned int dy = abs(playerPos.y - monsterPos.y);
if (dx < 3 && dy < 3)
monster_state_change(m, AGRESSIVE);
else if (dx <= 3 && dy <= 3)
monster_state_change(m, SCANNING);
else
monster_state_change(m, SLEEPING);
}
static void
monster_behaviour_check(Monster *m, RoomMatrix *rm)
{
UNUSED(rm);
switch (m->behaviour) {
case GUERILLA:
if (m->state.stepsSinceChange > 8
@ -105,6 +129,9 @@ monster_behaviour_check(Monster *m, RoomMatrix *rm)
monster_state_change(m, AGRESSIVE);
}
break;
case SENTINEL:
handle_sentinel_behaviour(m, rm);
break;
default:
break;
}
@ -312,12 +339,12 @@ monster_move(Monster *m, RoomMatrix *rm)
{
Position monsterRoomPos;
monster_behaviour_check(m, rm);
monsterRoomPos = position_to_matrix_coords(&m->sprite->pos);
rm->spaces[monsterRoomPos.x][monsterRoomPos.y].occupied = false;
rm->spaces[monsterRoomPos.x][monsterRoomPos.y].monster = NULL;
monster_behaviour_check(m, rm);
switch (m->state.current) {
case PASSIVE:
monster_drunk_walk(m, rm);
@ -329,6 +356,8 @@ monster_move(Monster *m, RoomMatrix *rm)
monster_coward_walk(m, rm);
break;
case STATIONARY:
case SLEEPING:
case SCANNING:
default:
break;
};
@ -360,7 +389,7 @@ monster_update(Monster *m, UpdateData *data)
return;
m->stateIndicator.shownOnPlayerRoomEnter = true;
if (m->state.current != PASSIVE)
if (m->state.current != PASSIVE && m->state.current != STATIONARY)
m->stateIndicator.displayCount = 5;
} else {
m->stateIndicator.shownOnPlayerRoomEnter = false;
@ -471,6 +500,9 @@ monster_set_behaviour(Monster *m, MonsterBehaviour behaviour)
case COWARD:
m->state.current = AGRESSIVE;
break;
case SENTINEL:
m->state.current = SLEEPING;
break;
case PACIFIST:
case NORMAL:
default:

View File

@ -33,14 +33,17 @@ typedef enum {
NORMAL,
HOSTILE,
GUERILLA,
COWARD
COWARD,
SENTINEL
} MonsterBehaviour;
typedef enum {
PASSIVE,
AGRESSIVE,
SCARED,
STATIONARY
STATIONARY,
SLEEPING,
SCANNING
} StateType;
typedef struct {

View File

@ -411,9 +411,6 @@ player_monster_kill_check(Player *player, Monster *monster)
void
player_hit(Player *p, unsigned int dmg)
{
if (p->stats.hp <= 0) {
dmg = 200;
}
if (dmg > 0) {
Position pos = p->sprite->pos;
pos.x += 8;
@ -455,6 +452,8 @@ player_reset_steps(Player *p)
void player_update(UpdateData *data)
{
Player *player = data->player;
if (player->stats.hp <= 0)
return;
check_skill_activation(data);
if (!check_skill_trigger(data))

View File

@ -282,5 +282,13 @@ roommatrix_reset(RoomMatrix *m)
void roommatrix_destroy(RoomMatrix *m)
{
for (int i = 0; i < MAP_ROOM_WIDTH; ++i) {
for (int j = 0; j < MAP_ROOM_HEIGHT; ++j) {
RoomSpace *space = &m->spaces[i][j];
while (space->items)
item_destroy(linkedlist_pop(&space->items));
}
}
free(m);
}