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
Diff: GolfEngine/GolfEngine.cpp
- Revision:
- 9:bc34f2243e43
- Parent:
- 8:d410856c6d04
- Child:
- 10:9f54a6366e94
--- a/GolfEngine/GolfEngine.cpp Thu Apr 18 10:42:42 2019 +0000 +++ b/GolfEngine/GolfEngine.cpp Sat Apr 20 10:42:17 2019 +0000 @@ -1,5 +1,21 @@ #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() @@ -14,28 +30,28 @@ } -Course map_1[6] = {{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}}}; - void GolfEngine::init() { - - _x_pos = 30; - _y_pos = 30; - _ball.init(_x_pos,_y_pos); + _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,map_1,6); + drawCourseWalls(lcd,levels[_level].walls,levels[_level].wall_count); } void GolfEngine::read_input(Gamepad &pad) @@ -47,21 +63,32 @@ void GolfEngine::update_ball(Gamepad &pad, int frame_rate) { - _ball.shoot_ball(pad, _joy_coord); - _ball.check_wall_bounce(map_1, 6); + _ball.check_wall_bounce(levels[_level].walls, 6); _ball.move_ball(frame_rate); - _ball.check_wall_bounce(map_1, 6); + _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, Course map[], int size) +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; @@ -71,3 +98,13 @@ { return _level; } + +bool GolfEngine::get_hole_flag() +{ + return _hole_flag; +} + +void GolfEngine::reset_hole_flag() +{ + _hole_flag = false; +} \ No newline at end of file