#include "ai_player.h" #include AI_Player::AI_Player(int id, int x, int y, QCanvasSprite* sprite) : Player(id, x, y, sprite) { m_direction = Down; m_counter = 0; xwaypoints = NULL; ywaypoints = NULL; m_waypoints = 0; m_firstwaypoint = 0; } void AI_Player::direction(Direction direction) { m_direction = direction; } AI_Player::Direction AI_Player::direction(void) { return m_direction; } void AI_Player::clearWaypoints() { if(m_waypoints) { free(xwaypoints); free(ywaypoints); xwaypoints = NULL; ywaypoints = NULL; m_waypoints = 0; m_firstwaypoint = 0; } } void AI_Player::pushWaypoint(int x, int y) { xwaypoints = (int*)realloc(xwaypoints, sizeof(int) * (m_waypoints + 1)); ywaypoints = (int*)realloc(ywaypoints, sizeof(int) * (m_waypoints + 1)); xwaypoints[m_waypoints] = x; ywaypoints[m_waypoints] = y; m_waypoints++; } int AI_Player::nextX() { if(m_firstwaypoint < m_waypoints) return xwaypoints[m_firstwaypoint]; return -1; } int AI_Player::nextY() { if(m_firstwaypoint < m_waypoints) return ywaypoints[m_firstwaypoint]; return -1; } void AI_Player::popWaypoint() { if(m_firstwaypoint <= m_waypoints) m_firstwaypoint++; } int AI_Player::numWaypoints() { return m_waypoints - m_firstwaypoint; }