Public paste
gridnode klasse
By: GridNode.cpp | Date: Feb 5 2010 15:31 | Format: None | Expires: never | Size: 2.15 KB | Hits: 853

  1. //---------------------------
  2. // Includes
  3. //---------------------------
  4. #include "GridNode.h"
  5. #include "resource.h"
  6.  
  7. //---------------------------
  8. // Defines
  9. //---------------------------
  10. #define GAME_ENGINE (GameEngine::GetSingleton())
  11.  
  12. //---------------------------
  13. // Constructor & Destructor
  14. //---------------------------
  15. GridNode::GridNode(int x, int y, int type, bool walkable): m_xPos(x),
  16.                                                                                                                    m_yPos(y),
  17.                                                                                                                    m_Type(type),
  18.                                                                                                                    m_bWalkable(walkable),
  19.                                                                                                                    m_bmpDirtPtr(0),
  20.                                                                                                                    m_bmpGrassPtr(0),
  21.                                                                                                                    m_bmpWallPtr(0),
  22.                                                                                                                    m_bmpWaterPtr(0)
  23. {
  24.         // nothing to create
  25. }
  26.  
  27. GridNode::~GridNode()
  28. {
  29.         // nothing to destroy
  30. }
  31.  
  32. void GridNode::Create()
  33. {
  34.         m_bmpWaterPtr = new Bitmap(IDB_WATER, "BITMAP");
  35.         m_bmpWallPtr = new Bitmap(IDB_WALL, "BITMAP");
  36.         m_bmpGrassPtr = new Bitmap(IDB_GRASS, "BITMAP");
  37.         m_bmpDirtPtr = new Bitmap(IDB_DIRT, "BITMAP");
  38.  
  39.         if(!m_bmpWaterPtr->Exists() || !m_bmpWallPtr->Exists() || !m_bmpGrassPtr->Exists() || !m_bmpDirtPtr->Exists())
  40.         {
  41.                 GAME_ENGINE->MessageBox(String("Can't load images!"));
  42.         }
  43. }
  44.  
  45. void GridNode::Delete()
  46. {
  47.         delete m_bmpDirtPtr;
  48.         delete m_bmpGrassPtr;
  49.         delete m_bmpWallPtr;
  50.         delete m_bmpWaterPtr;
  51. }
  52.  
  53. void GridNode::Render()
  54. {
  55.         switch (m_Type)
  56.         {
  57.         case 1:
  58.                 GAME_ENGINE->DrawBitmap(m_bmpGrassPtr, m_xPos, m_yPos);
  59.                 break;
  60.         case 2:
  61.                 GAME_ENGINE->DrawBitmap(m_bmpDirtPtr, m_xPos, m_yPos);
  62.                 break;
  63.         case 3:
  64.                 GAME_ENGINE->DrawBitmap(m_bmpWaterPtr, m_xPos, m_yPos);
  65.                 break;
  66.         case 4:
  67.                 GAME_ENGINE->DrawBitmap(m_bmpWallPtr, m_xPos, m_yPos);
  68.                 break;
  69.         case 0:
  70.                 GAME_ENGINE->FillRect(-30,-30,25,25);
  71.                 break;
  72.         }
  73. }
  74.  
  75. void GridNode::SetWalkable(bool walkable)
  76. {
  77.         m_bWalkable = walkable;
  78. }
  79.  
  80. void GridNode::SetPosition( int x, int y )
  81. {
  82.         m_xPos = x;
  83.         m_yPos = y;
  84. }
  85. void GridNode::SetType(int type)
  86. {
  87.         m_Type = type;
  88. }
  89.  
  90. int GridNode::GetType()
  91. {
  92.         return m_Type;
  93. }
  94.  
  95. POSITIE GridNode::GetPosition()
  96. {
  97.         POSITIE temp;
  98.         temp.x = m_xPos;
  99.         temp.y = m_yPos;
  100.  
  101.         return temp;
  102. }
  103. //---------------------------
  104. // Eigen methoden
  105. //---------------------------
  106.  
  107. // vul aan met je eigen methoden.