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
Game/Game.cpp
- Committer:
- S_Tingle
- Date:
- 2019-05-08
- Revision:
- 19:1073cc64cb0b
- Parent:
- 18:ba4159ab4da7
- Child:
- 20:ad13b0fdd8ff
File content as of revision 19:1073cc64cb0b:
#include "Game.h"
Game::Game(){
}
Game::~Game(){
}
void Game::init(){
smiley.init(x,y);
_lives = 10;
coin1.init(41, 42);
coin2.init(41, 23);
coin3.init(78, 42);
coin4.init(31, 35);
}
void Game::dirmag(Gamepad &pad){
dir = pad.get_direction();
mag = pad.get_mag();
}
void Game::drawSprite(N5110 &lcd){
maze.drawSprite(lcd);
enemy1.drawSprite(lcd);
enemy2.drawSprite(lcd);
coin1.drawSprite(lcd);
coin2.drawSprite(lcd);
coin3.drawSprite(lcd);
coin4.drawSprite(lcd);
smiley.drawSprite(lcd);
}
void Game::movement(Gamepad &pad, N5110 &lcd){
smiley.movement(dir,lcd);
enemy1.movement(lcd);
enemy2.movement(lcd);
}
void Game::collect(N5110 &lcd, Gamepad &pad){
int x = smiley.get_x_char();
int y = smiley.get_y_char();
coin1.spawn(x, y, lcd, pad);
coin2.spawn(x, y, lcd, pad);
coin3.spawn(x, y, lcd, pad);
coin4.spawn(x, y, lcd, pad);
}
void Game::damage(N5110 &lcd, Gamepad &pad){
int x = smiley.get_x_char();
int y = smiley.get_y_char();
if (enemy1.collidePlayer(x, y, pad) == true || enemy2.collidePlayer(x, y, pad) == true ){
_lives--;
wait(0.1);
}
}
void Game::death(N5110 &lcd, Gamepad &pad){
if (_lives == 0) {
lcd.clear();
lcd.printString("YOU",30,2);
lcd.printString("DIED",30,3);
lcd.refresh();
wait(1);
}
}
void Game::UI(Gamepad &pad, N5110 &lcd){
menu.main(lcd,pad);
}
int Game::get_lives() {
return _lives;
}
void Game::display_health(N5110 &lcd) {
char buffer[14];
sprintf(buffer,"%d",_lives);
lcd.printString(buffer,2,5);
}