Hugo Hu / Mbed 2 deprecated BRAVEHEART

Dependencies:   mbed N5110 ShiftReg PinDetect

Committer:
Siriagus
Date:
Sun May 10 13:14:33 2015 +0000
Revision:
16:caf613d5b85e
Parent:
15:d5eb13c4c1c6
Child:
17:d6a3b29cab31
Added wrapping (when entity goes outside the map, it enters on the other side).

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Siriagus 9:da608ae65df9 1 #ifndef ENTITY_H
Siriagus 9:da608ae65df9 2 #define ENTITY_H
Siriagus 16:caf613d5b85e 3 /// @file Entity.h
Siriagus 9:da608ae65df9 4
Siriagus 12:8178fad5e660 5 /** An entity represents a movable character, such as the player, enemies etc.
Siriagus 12:8178fad5e660 6 * Note that the entity class does not contain the sprite (image) of the entity.
Siriagus 12:8178fad5e660 7 * Different sprites are given as 2D const int arrays in
Siriagus 12:8178fad5e660 8 * 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 9 */
Siriagus 9:da608ae65df9 10 class Entity
Siriagus 9:da608ae65df9 11 {
Siriagus 9:da608ae65df9 12 public:
Siriagus 11:adb68da98262 13 Entity() {x = y = width = height = vx = vy = 0; facingLeft = true; onGround = false;}
Siriagus 11:adb68da98262 14 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 15
Siriagus 13:7ab71c7c311b 16 int x, y; /// Position of entity (origin: left upper corner)
Siriagus 12:8178fad5e660 17 int vx, vy; /// Velocity of entity
Siriagus 12:8178fad5e660 18 int width; /// Width of entity
Siriagus 12:8178fad5e660 19 int height; /// Height of entity
Siriagus 9:da608ae65df9 20
Siriagus 11:adb68da98262 21 bool facingLeft; /// True if the entity is facing left
Siriagus 12:8178fad5e660 22 bool onGround; /// True if entity is standing on the ground.
Siriagus 13:7ab71c7c311b 23
Siriagus 13:7ab71c7c311b 24 int getRight() {return x + width - 1;} /// Returns x-position of the right edge
Siriagus 13:7ab71c7c311b 25 int getBottom() {return y + height - 1;} /// Returns y-position of the bottom edge
Siriagus 13:7ab71c7c311b 26
Siriagus 9:da608ae65df9 27 };
Siriagus 9:da608ae65df9 28
Siriagus 16:caf613d5b85e 29 /// Enemy class
Siriagus 15:d5eb13c4c1c6 30 class Enemy : public Entity
Siriagus 15:d5eb13c4c1c6 31 {
Siriagus 15:d5eb13c4c1c6 32 public:
Siriagus 16:caf613d5b85e 33 enum Type{SIMPLE, JUMPER, RUNNER};
Siriagus 16:caf613d5b85e 34
Siriagus 16:caf613d5b85e 35 public:
Siriagus 16:caf613d5b85e 36 Enemy(int x, int y, int w, int h, Type type = SIMPLE) : Entity(x,y,w,h), type(type) {dead = false;}
Siriagus 15:d5eb13c4c1c6 37 bool dead;
Siriagus 16:caf613d5b85e 38 Type type;
Siriagus 15:d5eb13c4c1c6 39 };
Siriagus 15:d5eb13c4c1c6 40
Siriagus 9:da608ae65df9 41 #endif