87 lines
2.5 KiB
C
87 lines
2.5 KiB
C
/**** player.c - player creation, movement, etc. functions
|
|
This file contains the functions for initializing and commanding the player->
|
|
|
|
****/
|
|
#include <string.h> // for strcat
|
|
#include "player.h"
|
|
#include "game.h"
|
|
#include "stubs.h"
|
|
|
|
void playerSetCommand(int command_id, void(*function)) {
|
|
player_commands[command_id] = function;
|
|
}
|
|
|
|
/* in-game movement stuff */
|
|
void playerMove(int direction, int distance) {
|
|
switch(direction) {
|
|
case NORTH:
|
|
if (!gameCollision(player->x, (player->y-distance))) {
|
|
gameMoveTile(player, player->x, player->y-distance);
|
|
}
|
|
break;
|
|
case NORTHWEST:
|
|
if (!gameCollision(player->x-distance, (player->y-distance))) {
|
|
gameMoveTile(player, player->x-distance, player->y-distance);
|
|
}
|
|
break;
|
|
case NORTHEAST:
|
|
if (!gameCollision(player->x+distance, (player->y-distance))) {
|
|
gameMoveTile(player, player->x+distance, player->y-distance);
|
|
}
|
|
break;
|
|
case SOUTH:
|
|
if (!gameCollision(player->x, player->y+distance)) {
|
|
gameMoveTile(player, player->x, player->y+distance);
|
|
}
|
|
break;
|
|
case SOUTHWEST:
|
|
if (!gameCollision(player->x-distance, player->y+distance)) {
|
|
gameMoveTile(player, player->x-distance, player->y+distance);
|
|
}
|
|
break;
|
|
case SOUTHEAST:
|
|
if (!gameCollision(player->x+distance, player->y+distance)) {
|
|
gameMoveTile(player, player->x+distance, player->y+distance);
|
|
}
|
|
break;
|
|
case EAST:
|
|
if (!gameCollision(player->x+distance, player->y)) {
|
|
gameMoveTile(player, player->x+distance, player->y);
|
|
}
|
|
break;
|
|
case WEST:
|
|
if (!gameCollision(player->x-distance, player->y)) {
|
|
gameMoveTile(player, player->x-distance, player->y);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
void playerLook(int x, int y) {
|
|
char string[64];
|
|
string[0] = '\0';
|
|
struct Tile* debug_tile;
|
|
if ((x < current_map->width && x >= 0) && (y < current_map->height && y >= 0)) {
|
|
if (current_map->matrix[x][y].tid) {
|
|
strcat(string, "You see: ");
|
|
int chain_count = 0;
|
|
debug_tile = ¤t_map->matrix[x][y];
|
|
while(debug_tile != NULL) {
|
|
strcat(string, ((struct BasicTile*)debug_tile->data)->name);
|
|
if (debug_tile->next) {
|
|
strcat(string, ", ");
|
|
}
|
|
debug_tile = debug_tile->next;
|
|
chain_count++;
|
|
}
|
|
interfacePrint(string);
|
|
}
|
|
} else {
|
|
interfacePrint("You gaze into the void...");
|
|
}
|
|
}
|
|
|
|
void playerActivate(int x, int y) {
|
|
activateTile(getTopTile(current_map, x, y), player);
|
|
}
|