/**** player.c - player creation, movement, etc. functions This file contains the functions for initializing and commanding the player. ****/ #include // 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[32]; struct Tile* debug_tile; if ((x < current_map->width && x >= 0) && (y < current_map->height && y >= 0)) { //if (current_map->matrix[x][y].tid != TILE_NULL) { if (current_map->matrix[x][y].tid) { int chain_count = 0; debug_tile = ¤t_map->matrix[x][y]; while(debug_tile != NULL) { //itoa(debug_tile->id, string, 10); //strcat(string, " "); strcat(string, "You see: "); strcat(string, ((struct BasicTile*)debug_tile->data)->name); interfacePrint(string); //interfacePrintf("You see: %s", *((struct BasicTile*)debug_tile->data)->name); //mvwaddstr(screen, 20+chain_count, 0, string); debug_tile = debug_tile->next; chain_count++; } } } else { interfacePrint("You gaze into the void..."); } }