home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 June / PCFJune.iso / Xenon / XenonSource.exe / demo2 / playgamestate.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-13  |  2.7 KB  |  136 lines

  1. //-------------------------------------------------------------
  2. //
  3. // Class:    CPlayGameState
  4. //
  5. // Author:    John M Phillips
  6. //
  7. // Started:    06/05/00
  8. //
  9. // Base:    CGameState
  10. //
  11. // Derived:    None
  12. //
  13. //-------------------------------------------------------------
  14.  
  15. #include "demo2.h"
  16.  
  17. //-------------------------------------------------------------
  18.  
  19. CPlayGameState *CPlayGameState::m_instance = 0;
  20.  
  21. int CPlayGameState::m_yscroll = 1;
  22.  
  23. //-------------------------------------------------------------
  24.  
  25. CPlayGameState::CPlayGameState()
  26. {
  27.     m_ship = 0;
  28. }
  29.  
  30. //-------------------------------------------------------------
  31.  
  32. CPlayGameState::~CPlayGameState()
  33. {
  34. }
  35.  
  36. //-------------------------------------------------------------
  37.  
  38. CGameState *CPlayGameState::instance()
  39. {
  40.     if (!m_instance)
  41.         m_instance = new CPlayGameState;
  42.  
  43.     return m_instance;
  44. }
  45.  
  46. //-------------------------------------------------------------
  47.  
  48. bool CPlayGameState::create()
  49. {
  50.     m_ship = 0;
  51.     m_mode = CREATEPLAYER;
  52.  
  53.     return true;
  54. }
  55.  
  56. //-------------------------------------------------------------
  57.  
  58. void CPlayGameState::createPlayer()
  59. {
  60.     m_scene.killAllActors();
  61.  
  62.     m_ship = new CShip;
  63.     m_scene.addActor(m_ship);
  64.  
  65.     m_ship->activate();
  66.  
  67.     gsCVector start_position((float) m_screen.getSize().getX() / 2,
  68.                              (float) m_screen.getSize().getY() - PLAYER_START_OFFSET);
  69.  
  70.     m_ship->setPosition(start_position);
  71.  
  72.     m_ship->setWeapon(MISSILE_WEAPON);
  73. }
  74.  
  75. //-------------------------------------------------------------
  76.  
  77. bool CPlayGameState::update()
  78. {
  79.     if (!CGameState::update())
  80.         return false;
  81.  
  82.     gsKeyCode key = m_keyboard.getKey();
  83.  
  84.     if (key == gsKEY_ESCAPE)
  85.         return false;
  86.  
  87.     if (m_mode == CREATEPLAYER) {
  88.         createPlayer();
  89.         m_mode = PLAYERACTIVE;
  90.         }
  91.  
  92.     Controls controls;
  93.  
  94.     getControl(controls,0);
  95.  
  96.     m_screen.clear(gsCColour(gsBLACK));
  97.  
  98.     m_starfield.move(4);
  99.     m_starfield.draw();
  100.  
  101.     m_scene.updateAllActors(&controls);
  102.     m_scene.drawAllActors();
  103.     m_scene.checkActorCollisions();
  104.     m_scene.removeDeadActors();
  105.  
  106.     m_small_font.setTextCursor(gsCPoint(2,2));
  107.     m_small_font.printString("Cursor Keys  - move");
  108.     m_small_font.setTextCursor(gsCPoint(2,12));
  109.     m_small_font.printString("Left Control - fire");
  110.     m_small_font.setTextCursor(gsCPoint(2,24));
  111.     m_small_font.printString("Escape       - exit");
  112.     
  113.     m_screen.flip();
  114.  
  115.     return true;
  116. }
  117.  
  118. //-------------------------------------------------------------
  119.  
  120. bool CPlayGameState::destroy()
  121. {
  122.     m_scene.killAllActors();
  123.     m_ship = 0;
  124.  
  125.     return true;
  126. }
  127.  
  128. //-------------------------------------------------------------
  129.  
  130. int CPlayGameState::getYScroll()
  131. {
  132.     return m_yscroll;
  133. }
  134.  
  135. //-------------------------------------------------------------
  136.