Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
GameObject.h
00001 #include "Point.h" 00002 #include "Rect.h" 00003 00004 #ifndef __GAMEOBJECT_H__ 00005 #define __GAMEOBJECT_H__ 00006 00007 class TileViewer; 00008 00009 class GameObject 00010 { 00011 public: 00012 GameObject(); 00013 00014 public: 00015 void setPosition(const Point &position); 00016 void setSpriteId(uint8_t spriteId); 00017 void setSpeed(uint8_t speed); 00018 void setCollisionRect(uint8_t x, uint8_t y, uint8_t w, uint8_t h); 00019 void animate(); 00020 virtual void update(); 00021 virtual void draw(); 00022 00023 //protected: 00024 public: 00025 bool moveLeft(); 00026 bool moveRight(); 00027 bool moveUp(); 00028 bool moveDown(); 00029 00030 inline bool canGoLeft() { return canGoLeft(_position.X, _position.Y); } 00031 inline bool canGoRight(){ return canGoRight(_position.X, _position.Y); }; 00032 inline bool canGoUp() { return canGoUp(_position.X, _position.Y); }; 00033 inline bool canGoDown() { return canGoDown(_position.X, _position.Y); }; 00034 00035 const GameObject* detectCollision(); 00036 bool detectCollision(GameObject* other); 00037 const Block* detectBlock(); 00038 Rect getCollisionRect(); 00039 00040 bool pickupObject(); 00041 00042 inline Point& getPosition() {return _position;} 00043 00044 void setParent(TileViewer *pParent) { _pParent = pParent; } 00045 TileViewer* getParent() { return _pParent; } 00046 00047 private: 00048 bool canGoLeft(uint16_t x, uint16_t y); 00049 bool canGoRight(uint16_t x, uint16_t y); 00050 bool canGoUp(uint16_t x, uint16_t y); 00051 bool canGoDown(uint16_t x, uint16_t y); 00052 00053 private: 00054 uint8_t _spriteId; 00055 Point _position; 00056 uint8_t _speed; 00057 uint8_t _animationCounter; 00058 Rect _collisionRect; 00059 00060 TileViewer *_pParent; 00061 00062 friend class TileViewer; 00063 }; 00064 00065 #endif //__GAMEOBJECT_H__
Generated on Tue Jul 12 2022 21:15:25 by
