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 FATFileSystem
GolfEngine/GolfEngine.cpp
- Committer:
- ellisbhastroud
- Date:
- 2019-04-20
- Revision:
- 9:bc34f2243e43
- Parent:
- 8:d410856c6d04
- Child:
- 10:9f54a6366e94
File content as of revision 9:bc34f2243e43:
#include "GolfEngine.h" Levels levels[2] = {{{15,31}, {68,31}, {{LEFT,{9,24},{9,39}}, {BOTTOM,{9,39},{74,39}}, {RIGHT,{74,24},{74,39}}, {TOP,{9,24},{74,24}}},4}, {{15,33}, {64,17}, {{LEFT,{9,26},{9,40}}, {BOTTOM,{9,40},{74,40}}, {RIGHT,{74,9},{74,40}}, {TOP,{56,9},{74,9}}, {LEFT,{56,9},{56,26}}, {TOP,{9,26},{56,26}}}, 6}}; // constructor GolfEngine::GolfEngine() { } //deconstructor GolfEngine::~GolfEngine() { } void GolfEngine::init() { _level = 0; //is level 1 _ball.set_total_shot_count(0); _ball.init(levels[_level].ball); } void GolfEngine::new_level() { _level++; //increases level _ball.init(levels[_level].ball); //initialises ball in position for current level } void GolfEngine::drawGame(N5110 &lcd, Gamepad &pad) { drawHole(lcd, levels[_level].hole); _ball.drawBall(lcd); _ball.drawPower(lcd, _mag); _ball.drawAim(lcd, _joy_coord, _angle); _ball.printShotCount(lcd); drawCourseWalls(lcd,levels[_level].walls,levels[_level].wall_count); } void GolfEngine::read_input(Gamepad &pad) { _joy_coord = pad.get_mapped_coord(); _mag = pad.get_mag(); _angle = pad.get_angle(); } void GolfEngine::update_ball(Gamepad &pad, int frame_rate) { _ball.shoot_ball(pad, _joy_coord); _ball.check_wall_bounce(levels[_level].walls, 6); _ball.move_ball(frame_rate); _ball.check_wall_bounce(levels[_level].walls, 6); _hole_flag = _ball.check_hole(levels[_level].hole); //when ball is in hole this returns true and next level begins and flag reset for next level } void GolfEngine::drawCourseWalls(N5110 &lcd, WallMap map[], int size) { for(int i = 0; i < size; i++){ lcd.drawLine(map[i].start.x,map[i].start.y,map[i].end.x,map[i].end.y,1); } } void GolfEngine::drawHole(N5110 &lcd, Coord hole) { lcd.drawRect(hole.x,hole.y,3,3,FILL_TRANSPARENT); //draws ball } void GolfEngine::printLevel(N5110 &lcd) { char buffer[14]; sprintf(buffer,"Level %i",_level+1); lcd.printString(buffer,24,2); } void GolfEngine::set_level(int level) { _level = level; } int GolfEngine::get_level() { return _level; } bool GolfEngine::get_hole_flag() { return _hole_flag; } void GolfEngine::reset_hole_flag() { _hole_flag = false; }