Platform game written for the GHI/OutrageousCircuits RETRO game device. Navigate the caves collecting all the pickups and avoiding the creatures and haunted mine carts that patrol the caves. Oh and remember to watch out for the poisonous plants... This game demonstrates the ability to have multiple animated sprites where the sprites can overlap the background environment. See how the player moves past the fence and climbs the wall in the 3rd screen.
Diff: Player.h
- Revision:
- 0:2ee0812e2615
- Child:
- 1:ecf7bbccddc1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Player.h Sat Nov 29 06:40:50 2014 +0000 @@ -0,0 +1,80 @@ +class Player : public GameObject +{ +public: + enum State { Stopped, Walking, Jumping, Falling }; + + Player(Game &game) : + GameObject(game), + _state(Stopped), + _jumpY(0), + _jumpX(0) + { + } + + virtual void update() + { + char buffer[20]; + sprintf(buffer, "%d ", _state); + Game::Screen.drawString(font_ibm, 0, 0, buffer); + + if (_state == Stopped) _jumpX = 0; + + if (_state != Jumping && _state != Falling) + { + if (GameInput::isLeftPressed()) + { + _state = moveLeft() ? Walking : Stopped; + _jumpX = -1; + animate(); + } + else if (GameInput::isRightPressed()) + { + _state = moveRight() ? Walking : Stopped; + _jumpX = 1; + animate(); + } + } + + if (GameInput::isCirclePressed() && _state != Jumping && _state != Falling) + { + _state = Jumping; + _jumpY = 0; + } + else if (_state != Jumping) + { + if (moveDown()) + { + _state = Falling; + if (_jumpY > 0) + { + if (_jumpX < 0) { moveLeft(); animate(); } + else if (_jumpX > 0) { moveRight(); animate(); } + } + } + else + { + _state = Stopped; + _jumpY = 0; + } + } + + if (_state == Jumping) + { + if (_jumpY < 10 && moveUp()) + { + if (_jumpX < 0) { moveLeft(); animate(); } + else if (_jumpX > 0) { moveRight(); animate(); } + ++_jumpY; + } + else + { + _state = Falling; + } + } + } + +private: + State _state; + uint8_t _jumpY; + int8_t _jumpX; +}; \ No newline at end of file