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.
Dependencies: mbed N5110 ShiftReg PinDetect
Entity.h@15:d5eb13c4c1c6, 2015-05-10 (annotated)
- Committer:
- Siriagus
- Date:
- Sun May 10 09:37:51 2015 +0000
- Revision:
- 15:d5eb13c4c1c6
- Parent:
- 13:7ab71c7c311b
- Child:
- 16:caf613d5b85e
Enemy - bullet collison + entities can walk upwards slopes or climb walls with a height smaller than themselves.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Siriagus | 9:da608ae65df9 | 1 | #ifndef ENTITY_H |
Siriagus | 9:da608ae65df9 | 2 | #define ENTITY_H |
Siriagus | 9:da608ae65df9 | 3 | |
Siriagus | 12:8178fad5e660 | 4 | /** An entity represents a movable character, such as the player, enemies etc. |
Siriagus | 12:8178fad5e660 | 5 | * Note that the entity class does not contain the sprite (image) of the entity. |
Siriagus | 12:8178fad5e660 | 6 | * Different sprites are given as 2D const int arrays in |
Siriagus | 12:8178fad5e660 | 7 | * OBS! The entity's dimensions should be the same as the width and height or else this will lead to undefined behaviour! |
Siriagus | 12:8178fad5e660 | 8 | */ |
Siriagus | 9:da608ae65df9 | 9 | class Entity |
Siriagus | 9:da608ae65df9 | 10 | { |
Siriagus | 9:da608ae65df9 | 11 | public: |
Siriagus | 11:adb68da98262 | 12 | Entity() {x = y = width = height = vx = vy = 0; facingLeft = true; onGround = false;} |
Siriagus | 11:adb68da98262 | 13 | Entity(int x, int y, int w, int h) : x(x), y(y), width(w), height(h) {vx = vy = 0; facingLeft = true; onGround = false;} |
Siriagus | 9:da608ae65df9 | 14 | |
Siriagus | 13:7ab71c7c311b | 15 | int x, y; /// Position of entity (origin: left upper corner) |
Siriagus | 12:8178fad5e660 | 16 | int vx, vy; /// Velocity of entity |
Siriagus | 12:8178fad5e660 | 17 | int width; /// Width of entity |
Siriagus | 12:8178fad5e660 | 18 | int height; /// Height of entity |
Siriagus | 9:da608ae65df9 | 19 | |
Siriagus | 11:adb68da98262 | 20 | bool facingLeft; /// True if the entity is facing left |
Siriagus | 12:8178fad5e660 | 21 | bool onGround; /// True if entity is standing on the ground. |
Siriagus | 13:7ab71c7c311b | 22 | |
Siriagus | 13:7ab71c7c311b | 23 | int getRight() {return x + width - 1;} /// Returns x-position of the right edge |
Siriagus | 13:7ab71c7c311b | 24 | int getBottom() {return y + height - 1;} /// Returns y-position of the bottom edge |
Siriagus | 13:7ab71c7c311b | 25 | |
Siriagus | 9:da608ae65df9 | 26 | }; |
Siriagus | 9:da608ae65df9 | 27 | |
Siriagus | 15:d5eb13c4c1c6 | 28 | class Enemy : public Entity |
Siriagus | 15:d5eb13c4c1c6 | 29 | { |
Siriagus | 15:d5eb13c4c1c6 | 30 | public: |
Siriagus | 15:d5eb13c4c1c6 | 31 | Enemy(int x, int y, int w, int h) : Entity(x,y,w,h) {dead = false;} |
Siriagus | 15:d5eb13c4c1c6 | 32 | bool dead; |
Siriagus | 15:d5eb13c4c1c6 | 33 | }; |
Siriagus | 15:d5eb13c4c1c6 | 34 | |
Siriagus | 9:da608ae65df9 | 35 | #endif |