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

View File

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

View File

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

View File

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

View File

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

View File

@ -282,5 +282,13 @@ roommatrix_reset(RoomMatrix *m)
void roommatrix_destroy(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); free(m);
} }