Implemented stupid agressive and coward pathing.
This commit is contained in:
parent
3a464d8ea6
commit
c88c64f4b8
|
@ -47,7 +47,6 @@ add_executable(breakhack
|
|||
src/stats
|
||||
src/actiontext
|
||||
src/random
|
||||
src/pathfind
|
||||
)
|
||||
|
||||
target_link_libraries(breakhack
|
||||
|
|
7
TODO.txt
7
TODO.txt
|
@ -10,10 +10,13 @@ x Nicer enemy hits (Text textures, healthbars?)
|
|||
- This could need some love later on. (Misses seem to be broken) (Add hits to stats)
|
||||
x Moving enemies
|
||||
x Stupid roaming enemies
|
||||
- Smart agressive enemies
|
||||
- Fleeing enemies
|
||||
x Smart agressive enemies
|
||||
x Fleeing enemies
|
||||
- Add hooks to lua
|
||||
- Lower levels
|
||||
o XP
|
||||
- Some xp amount logic
|
||||
- Level threshholds
|
||||
- gui
|
||||
- Items
|
||||
- More gui
|
||||
|
|
|
@ -158,6 +158,7 @@ void run()
|
|||
position_to_matrix_coords(&gPlayer->sprite->pos);
|
||||
gRoomMatrix->spaces[rp.x][rp.y].occupied = true;
|
||||
gRoomMatrix->spaces[rp.x][rp.y].player = gPlayer;
|
||||
gRoomMatrix->playerRoomPos = rp;
|
||||
map_move_monsters(gMap, gRoomMatrix);
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ monster_create(SDL_Renderer *renderer)
|
|||
m->sprite = sprite_create();
|
||||
m->sprite->clip = (SDL_Rect) { 0, 0, 16, 16 };
|
||||
m->stats = (Stats) { 11, 1, 0, 0, 1, 1 };
|
||||
m->state = AGRESSIVE;
|
||||
|
||||
monster_load_texts(m, renderer);
|
||||
|
||||
|
@ -55,6 +56,11 @@ has_collided(Monster *monster, RoomMatrix *matrix)
|
|||
|
||||
Position roomPos = position_to_matrix_coords(&monster->sprite->pos);
|
||||
RoomSpace *space = &matrix->spaces[roomPos.x][roomPos.y];
|
||||
|
||||
if (space->player) {
|
||||
stats_fight(&monster->stats, &space->player->stats);
|
||||
}
|
||||
|
||||
return space->occupied;
|
||||
}
|
||||
|
||||
|
@ -102,19 +108,14 @@ move_down(Monster *m, RoomMatrix *rm)
|
|||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
monster_move(Monster *m, RoomMatrix *rm)
|
||||
static void
|
||||
monster_drunk_walk(Monster *m, RoomMatrix *rm)
|
||||
{
|
||||
unsigned int i, maxMoveAttempts = 6;
|
||||
Position monsterRoomPos;
|
||||
|
||||
if (get_random(2) == 0)
|
||||
return;
|
||||
|
||||
monsterRoomPos = position_to_matrix_coords(&m->sprite->pos);
|
||||
rm->spaces[monsterRoomPos.x][monsterRoomPos.y].occupied = false;
|
||||
rm->spaces[monsterRoomPos.x][monsterRoomPos.y].monster = NULL;
|
||||
|
||||
for (i = 0; i < maxMoveAttempts; ++i) {
|
||||
int move = get_random(3);
|
||||
if (move == 0 && move_left(m, rm))
|
||||
|
@ -126,6 +127,78 @@ monster_move(Monster *m, RoomMatrix *rm)
|
|||
else if (move == 3 && move_down(m, rm))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
monster_agressive_walk(Monster *m, RoomMatrix *rm)
|
||||
{
|
||||
int x_dist, y_dist;
|
||||
Position mPos;
|
||||
|
||||
mPos = position_to_matrix_coords(&m->sprite->pos);
|
||||
|
||||
x_dist = mPos.x - rm->playerRoomPos.x;
|
||||
y_dist = mPos.y - rm->playerRoomPos.y;
|
||||
|
||||
|
||||
if (abs(x_dist) > abs(y_dist)) {
|
||||
if (x_dist > 0)
|
||||
move_left(m, rm);
|
||||
else
|
||||
move_right(m, rm);
|
||||
} else {
|
||||
if (y_dist > 0)
|
||||
move_up(m, rm);
|
||||
else
|
||||
move_down(m, rm);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
monster_coward_walk(Monster *m, RoomMatrix *rm)
|
||||
{
|
||||
int x_dist, y_dist;
|
||||
Position mPos;
|
||||
|
||||
mPos = position_to_matrix_coords(&m->sprite->pos);
|
||||
|
||||
x_dist = mPos.x - rm->playerRoomPos.x;
|
||||
y_dist = mPos.y - rm->playerRoomPos.y;
|
||||
|
||||
|
||||
if (abs(x_dist) > abs(y_dist)) {
|
||||
if (x_dist > 0)
|
||||
move_right(m, rm);
|
||||
else
|
||||
move_left(m, rm);
|
||||
} else {
|
||||
if (y_dist > 0)
|
||||
move_down(m, rm);
|
||||
else
|
||||
move_up(m, rm);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
monster_move(Monster *m, RoomMatrix *rm)
|
||||
{
|
||||
Position monsterRoomPos;
|
||||
|
||||
monsterRoomPos = position_to_matrix_coords(&m->sprite->pos);
|
||||
rm->spaces[monsterRoomPos.x][monsterRoomPos.y].occupied = false;
|
||||
rm->spaces[monsterRoomPos.x][monsterRoomPos.y].monster = NULL;
|
||||
|
||||
switch (m->state) {
|
||||
case PASSIVE:
|
||||
monster_drunk_walk(m, rm);
|
||||
break;
|
||||
case AGRESSIVE:
|
||||
monster_agressive_walk(m, rm);
|
||||
break;
|
||||
case COWARD:
|
||||
monster_coward_walk(m, rm);
|
||||
break;
|
||||
};
|
||||
|
||||
monster_update_pos(m, m->sprite->pos);
|
||||
|
||||
|
|
|
@ -6,11 +6,14 @@
|
|||
#include "stats.h"
|
||||
#include "actiontext.h"
|
||||
|
||||
typedef enum { PASSIVE, AGRESSIVE, COWARD } State;
|
||||
|
||||
typedef struct Monster_t {
|
||||
Sprite *sprite;
|
||||
ActionText *hitText;
|
||||
ActionText *missText;
|
||||
Stats stats;
|
||||
State state;
|
||||
} Monster;
|
||||
|
||||
Monster* monster_create(SDL_Renderer*);
|
||||
|
|
|
@ -31,7 +31,6 @@ has_collided(Player *player, RoomMatrix *matrix)
|
|||
space->monster->hitText->active = true;
|
||||
space->monster->missText->active = false;
|
||||
} else {
|
||||
// TODO(Linus): The misses seem to be missing
|
||||
space->monster->missText->active = true;
|
||||
space->monster->hitText->active = false;
|
||||
}
|
||||
|
@ -48,8 +47,6 @@ has_collided(Player *player, RoomMatrix *matrix)
|
|||
static void
|
||||
player_step(Player *p, RoomMatrix* m)
|
||||
{
|
||||
Position pos = position_to_matrix_coords(&p->sprite->pos);
|
||||
m->spaces[pos.x][pos.y].occupied = true;
|
||||
p->total_steps++;
|
||||
p->steps++;
|
||||
}
|
||||
|
@ -181,10 +178,10 @@ player_print(Player *p)
|
|||
|
||||
printf("\n");
|
||||
printf("--------=== <[ Player Stats ]> ===--------\n");
|
||||
printf("HP: %u\n", p->stats.hp);
|
||||
printf("Level: %u XP: %u\n", p->stats.lvl, p->xp);
|
||||
printf("HP: %d\n", p->stats.hp);
|
||||
printf("Level: %d XP: %d\n", p->stats.lvl, p->xp);
|
||||
printf("Pos: %dx%d RoomPos: %dx%d\n", pos.x, pos.y, roomPos.x, roomPos.y);
|
||||
printf("Steps: %u\n", p->total_steps);
|
||||
printf("Steps: %d\n", p->total_steps);
|
||||
printf("------------------------------------------\n");
|
||||
}
|
||||
|
||||
|
|
|
@ -157,6 +157,7 @@ void roommatrix_reset(RoomMatrix *m)
|
|||
}
|
||||
}
|
||||
m->roomPos = (Position) { 0, 0 };
|
||||
m->playerRoomPos = (Position) { 1, 1 };
|
||||
}
|
||||
|
||||
void roommatrix_destroy(RoomMatrix *m)
|
||||
|
|
|
@ -22,6 +22,7 @@ typedef struct {
|
|||
typedef struct {
|
||||
RoomSpace spaces[MAP_ROOM_WIDTH][MAP_ROOM_HEIGHT];
|
||||
Position roomPos;
|
||||
Position playerRoomPos;
|
||||
} RoomMatrix;
|
||||
|
||||
RoomMatrix* roommatrix_create();
|
||||
|
|
13
src/stats.c
13
src/stats.c
|
@ -8,7 +8,7 @@
|
|||
unsigned int
|
||||
stats_fight(Stats *attacker, Stats *defender)
|
||||
{
|
||||
unsigned int atkRoll, defRoll, dmgRoll;
|
||||
int atkRoll, defRoll, dmgRoll;
|
||||
bool critical = false;
|
||||
|
||||
atkRoll = get_random(19) + 1;
|
||||
|
@ -18,14 +18,19 @@ stats_fight(Stats *attacker, Stats *defender)
|
|||
defRoll = (get_random(19) + 1) + defender->def;
|
||||
dmgRoll = 0;
|
||||
|
||||
//printf("Attacking: %u, Defending: %u\n", atkRoll, defRoll);
|
||||
printf("\n");
|
||||
printf("-----------[ FIGHT ]---------\n");
|
||||
printf("Attacking: %d Defending: %d\n", atkRoll, defRoll);
|
||||
|
||||
if (atkRoll > defRoll) {
|
||||
dmgRoll = (rand() % 8) + attacker->dmg;
|
||||
dmgRoll = (rand() % attacker->dmg) + 1;
|
||||
defender->hp -= dmgRoll;
|
||||
if (critical)
|
||||
defender->hp -= dmgRoll;
|
||||
}
|
||||
//printf("Attacker hp: %u, Defender hp: %u\n", attacker->hp, defender->hp);
|
||||
|
||||
printf("Attacker hp: %d Defender hp: %d\n", attacker->hp, defender->hp);
|
||||
printf("-----------------------------\n");
|
||||
|
||||
return dmgRoll;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue