ELEC2645 (2018/19) / Mbed 2 deprecated el17ebs

Dependencies:   mbed FATFileSystem

Committer:
ellisbhastroud
Date:
Thu Apr 18 10:42:42 2019 +0000
Revision:
8:d410856c6d04
Parent:
7:5a19dd9fe8a4
Child:
9:bc34f2243e43
Course map draw and bounce algorithms complete

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ellisbhastroud 5:0b31909caf7f 1 #include "GolfEngine.h"
ellisbhastroud 5:0b31909caf7f 2
ellisbhastroud 7:5a19dd9fe8a4 3 // constructor
ellisbhastroud 7:5a19dd9fe8a4 4
ellisbhastroud 7:5a19dd9fe8a4 5 GolfEngine::GolfEngine()
ellisbhastroud 7:5a19dd9fe8a4 6 {
ellisbhastroud 7:5a19dd9fe8a4 7
ellisbhastroud 7:5a19dd9fe8a4 8 }
ellisbhastroud 7:5a19dd9fe8a4 9
ellisbhastroud 7:5a19dd9fe8a4 10 //deconstructor
ellisbhastroud 7:5a19dd9fe8a4 11
ellisbhastroud 7:5a19dd9fe8a4 12 GolfEngine::~GolfEngine()
ellisbhastroud 7:5a19dd9fe8a4 13 {
ellisbhastroud 7:5a19dd9fe8a4 14
ellisbhastroud 7:5a19dd9fe8a4 15 }
ellisbhastroud 7:5a19dd9fe8a4 16
ellisbhastroud 8:d410856c6d04 17 Course map_1[6] = {{LEFT,{9,26},{9,40}},
ellisbhastroud 8:d410856c6d04 18 {BOTTOM,{9,40},{74,40}},
ellisbhastroud 8:d410856c6d04 19 {RIGHT,{74,9},{74,40}},
ellisbhastroud 8:d410856c6d04 20 {TOP,{56,9},{74,9}},
ellisbhastroud 8:d410856c6d04 21 {LEFT,{56,9},{56,26}},
ellisbhastroud 8:d410856c6d04 22 {TOP,{9,26},{56,26}}};
ellisbhastroud 8:d410856c6d04 23
ellisbhastroud 5:0b31909caf7f 24 void GolfEngine::init()
ellisbhastroud 5:0b31909caf7f 25 {
ellisbhastroud 8:d410856c6d04 26
ellisbhastroud 8:d410856c6d04 27 _x_pos = 30;
ellisbhastroud 8:d410856c6d04 28 _y_pos = 30;
ellisbhastroud 8:d410856c6d04 29 _ball.init(_x_pos,_y_pos);
ellisbhastroud 5:0b31909caf7f 30 }
ellisbhastroud 5:0b31909caf7f 31
ellisbhastroud 8:d410856c6d04 32 void GolfEngine::drawGame(N5110 &lcd, Gamepad &pad)
ellisbhastroud 5:0b31909caf7f 33 {
ellisbhastroud 5:0b31909caf7f 34 _ball.drawBall(lcd);
ellisbhastroud 8:d410856c6d04 35 _ball.drawPower(lcd, _mag);
ellisbhastroud 8:d410856c6d04 36 _ball.drawAim(lcd, _joy_coord, _angle);
ellisbhastroud 5:0b31909caf7f 37 _ball.printShotCount(lcd);
ellisbhastroud 8:d410856c6d04 38 drawCourseWalls(lcd,map_1,6);
ellisbhastroud 8:d410856c6d04 39 }
ellisbhastroud 8:d410856c6d04 40
ellisbhastroud 8:d410856c6d04 41 void GolfEngine::read_input(Gamepad &pad)
ellisbhastroud 8:d410856c6d04 42 {
ellisbhastroud 8:d410856c6d04 43 _joy_coord = pad.get_mapped_coord();
ellisbhastroud 8:d410856c6d04 44 _mag = pad.get_mag();
ellisbhastroud 8:d410856c6d04 45 _angle = pad.get_angle();
ellisbhastroud 5:0b31909caf7f 46 }
ellisbhastroud 5:0b31909caf7f 47
ellisbhastroud 5:0b31909caf7f 48 void GolfEngine::update_ball(Gamepad &pad, int frame_rate)
ellisbhastroud 5:0b31909caf7f 49 {
ellisbhastroud 5:0b31909caf7f 50
ellisbhastroud 8:d410856c6d04 51 _ball.shoot_ball(pad, _joy_coord);
ellisbhastroud 8:d410856c6d04 52 _ball.check_wall_bounce(map_1, 6);
ellisbhastroud 5:0b31909caf7f 53 _ball.move_ball(frame_rate);
ellisbhastroud 8:d410856c6d04 54 _ball.check_wall_bounce(map_1, 6);
ellisbhastroud 8:d410856c6d04 55
ellisbhastroud 8:d410856c6d04 56 }
ellisbhastroud 8:d410856c6d04 57 void GolfEngine::drawCourseWalls(N5110 &lcd, Course map[], int size)
ellisbhastroud 8:d410856c6d04 58 {
ellisbhastroud 8:d410856c6d04 59 for(int i = 0; i < size; i++){
ellisbhastroud 8:d410856c6d04 60 lcd.drawLine(map[i].start.x,map[i].start.y,map[i].end.x,map[i].end.y,1);
ellisbhastroud 8:d410856c6d04 61 }
ellisbhastroud 8:d410856c6d04 62
ellisbhastroud 8:d410856c6d04 63 }
ellisbhastroud 8:d410856c6d04 64
ellisbhastroud 8:d410856c6d04 65 void GolfEngine::set_level(int level)
ellisbhastroud 8:d410856c6d04 66 {
ellisbhastroud 8:d410856c6d04 67 _level = level;
ellisbhastroud 5:0b31909caf7f 68 }
ellisbhastroud 5:0b31909caf7f 69
ellisbhastroud 8:d410856c6d04 70 int GolfEngine::get_level()
ellisbhastroud 5:0b31909caf7f 71 {
ellisbhastroud 8:d410856c6d04 72 return _level;
ellisbhastroud 8:d410856c6d04 73 }