Unit.cpp 570 B

123456789101112131415161718192021222324252627282930313233
  1. #include "Unit.h"
  2. #include "Game.h"
  3. Unit::Unit(): _game(0), _dead(false)
  4. {
  5. }
  6. void Unit::init(const Vector2& pos, Game* game)
  7. {
  8. //initialize base
  9. _game = game;
  10. _view = new Actor;
  11. _view->attachTo(game);
  12. _view->setPosition(pos);
  13. //adds to global units list
  14. _game->_units.push_back(this);
  15. //should be overloaded in inherited classes
  16. _init();
  17. }
  18. const Vector2& Unit::getPosition() const
  19. {
  20. return _view->getPosition();
  21. }
  22. void Unit::update(const UpdateState& us)
  23. {
  24. //should be overloaded in inherited classes
  25. _update(us);
  26. }