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-23
- Revision:
- 10:9f54a6366e94
- Parent:
- 9:bc34f2243e43
- Child:
- 11:6d2027253aa9
File content as of revision 10:9f54a6366e94:
#include "GolfEngine.h" //Levels struct array containing all data for each level Levels levels[3] = { {{15,31}, {68,31}, //level one {{LEFT,{9,24},{9,39}}, {BOTTOM,{9,39},{74,39}}, {RIGHT,{74,24},{74,39}}, {TOP,{9,24},{74,24}}},4}, {{18,34}, {64,17}, //level two {{LEFT,{9,27},{9,41}}, {BOTTOM,{9,41},{61,41}}, {RIGHT,{73,11},{73,29}}, {BOTTOMRIGHT,{61,41},{73,29}}, {TOP,{56,11},{73,11}}, {LEFT,{56,11},{56,27}}, {TOP,{9,27},{56,27}}}, 7}, {{18,17}, {64,17}, {{TOP,{9,10},{27,10}}, {LEFT,{9,10},{9,35}}, {BOTTOMLEFT,{9,35},{19,45}}, {BOTTOM,{19,45},{63,45}}, {BOTTOMRIGHT,{63,45},{73,35}}, {RIGHT,{73,10},{73,35}}, {TOP,{56,10},{73,10}}, {LEFT,{56,10},{56,32}}, {TOP,{27,32},{56,32}}, {RIGHT,{27,10},{27,32}}}, 10} }; // constructor GolfEngine::GolfEngine() { } //deconstructor GolfEngine::~GolfEngine() { } void GolfEngine::init(int frame_rate) { _level = 0; //is level 1 _ball.set_total_shot_count(0); _ball.init(levels[_level].ball); _hole_flag = false; _ball.set_frame_rate(frame_rate); } 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) { _ball.shoot_ball(pad, _joy_coord); _ball.check_wall_bounce(levels[_level].walls, levels[_level].wall_count); _ball.move_ball(); _ball.check_wall_bounce(levels[_level].walls, levels[_level].wall_count); _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; }