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
Game.h
- Committer:
- Siriagus
- Date:
- 2015-05-10
- Revision:
- 15:d5eb13c4c1c6
- Parent:
- 14:b4fed570abaf
- Child:
- 16:caf613d5b85e
File content as of revision 15:d5eb13c4c1c6:
#ifndef GAME_H
#define GAME_H
/** @file Game.h
* @author Andreas Garmannslund
*/
#include "State.h"
#include "Resources.h" // TODO: Move to State.h ?
#include "Entity.h"
#include "map.h"
#include <vector>
#define TERMINAL_VELOCITY 3
/// Simple objects with a position (x,y) and velocity (vx, vy)
struct Point
{
int x;
int y;
int vx, vy;
};
struct Rectangle
{
Rectangle(int x, int y, int w, int h) : x(x), y(y), width(w), height(h) {}
int x;
int y;
int width;
int height;
};
/// State: Game
class Game : public State
{
public:
/// Creates the Game state
Game(StateManager* fsm, N5110 *lcd, InputManager* input)
: State(fsm, lcd, input) {init();}
/// Handle input and update logic
virtual void update(float dt);
/// Draw state to lcd
virtual void render();
private:
/// Moves entity in map. If collision occurs, entity can not move further
void moveWithCollisionTest(Entity* entity, const int map[HEIGHT][WIDTH]);
bool hitTestRect(Rectangle r1, Rectangle r2); /// Returns true if two rectangles overlap
bool bulletHitMap(Rectangle &bulletColRect, const int map[HEIGHT][WIDTH]); /// Help function for detecting collision between moving bullet and map.
void init(); /// Sets some initial values
Entity player; /// Player object
Enemy *enemy; /// Enemy object
bool releasedBtnB; /// True if button B has been released after being pressed down
bool releasedBtnC;
bool paused; // True if the game is paused
std::vector<Point*> bullets; /// Container for bullets
};
#endif