// ============================================================================
// Map.h
// Contains the map base class
// ============================================================================
#ifndef MAP_H
#define MAP_H
#include "Array2D.h"
#include "Array3D.h"
#include "Item.h"
#include "Person.h"
#include
float Distance( int x1, int y1, int x2, int y2 )
{
int dx = x1 - x2;
int dy = y1 - y2;
dx = dx * dx;
dy = dy * dy;
return (float)sqrt( (double)dx + (double)dy );
}
// ============================================================================
// Map Class
// ============================================================================
class Map
{
protected:
// =======================================================
// Data
// =======================================================
// -------------------------------------------------------
// Name: m_viewer
// Description: The person that the map is currently
// being viewed by.
// -------------------------------------------------------
Person* m_viewer;
// -------------------------------------------------------
// Name: m_exits
// Description: array of strings containing information
// about the exits in the level.
// -------------------------------------------------------
char m_exits[3][64];
public:
// =======================================================
// Functions
// =======================================================
// -------------------------------------------------------
// Name: Map
// Description: Constructs the map
// -------------------------------------------------------
Map()
{
m_viewer = 0;
// clear the exit strings
strcpy( m_exits[0], "" );
strcpy( m_exits[1], "" );
strcpy( m_exits[2], "" );
}
// -------------------------------------------------------
// Name: GetViewer
// Description: returns a pointer to the viewer
// -------------------------------------------------------
Person* GetViewer()
{
return m_viewer;
}
// -------------------------------------------------------
// Name: SetViewer
// Description: Sets the viewer of the map
// -------------------------------------------------------
void SetViewer( Person* p_viewer )
{
m_viewer = p_viewer;
}
// -------------------------------------------------------
// Name: GetExitName
// Description: Gets the name of the given exit
// -------------------------------------------------------
char* GetExitName( int p_exit )
{
return m_exits[p_exit];
}
// =======================================================
// Virtual Functions
// =======================================================
// -------------------------------------------------------
// Name: Draw
// Description: Draws the map onto the given surface,
// using the viewers coordinates as the
// midpoint of the screen.
// -------------------------------------------------------
virtual void Draw( SDL_Surface* p_surface,
int p_midx, int p_midy ) = 0;
// -------------------------------------------------------
// Name: CanMove
// Description: Determines if the given person can move
// in the given direction
// -------------------------------------------------------
virtual bool CanMove( Person* p_person, int p_direction ) = 0;
// -------------------------------------------------------
// Name: Move
// Description: Moves the given person in the given
// direction
// -------------------------------------------------------
virtual void Move( Person* p_object, int p_direction ) = 0;
// -------------------------------------------------------
// Name: GetItem
// Description: Gets a pointer to the item in the given
// cell
// -------------------------------------------------------
virtual Item* GetItem( int p_cell ) = 0;
// -------------------------------------------------------
// Name: SetItem
// Description: Sets the item in the given cell.
// -------------------------------------------------------
virtual void SetItem( int p_cell, Item* p_item ) = 0;
// -------------------------------------------------------
// Name: GetPerson
// Description: Gets a pointer to the person in the given
// cell
// -------------------------------------------------------
virtual Person* GetPerson( int p_cell ) = 0;
// -------------------------------------------------------
// Name: SetPerson
// Description: sets the person in the given cell.
// -------------------------------------------------------
virtual void SetPerson( int p_cell, Person* p_person ) = 0;
// -------------------------------------------------------
// Name: GetCellNumber
// Description: Gets the number of the cell in the
// given direction
// -------------------------------------------------------
virtual int GetCellNumber( int p_cell, int p_direction ) = 0;
// -------------------------------------------------------
// Name: GetNumberOfCells
// Description: Gets the number of cells in the map
// -------------------------------------------------------
virtual int GetNumberOfCells() = 0;
// -------------------------------------------------------
// Name: GetClosestDirection
// Description: Gets the direction that will move the
// first person closer to the second person.
// -------------------------------------------------------
virtual int GetClosestDirection( Person* p_one, Person* p_two ) = 0;
};
#endif