Ben Evans University Second Year Project. Game Called Defender.
Hello, soldier, you have been specially selected as the defender of planet earth.
Your mission, if you choose to accept it. Fly around the planet and pulverise invading alien ships for as long as you can. Stop the aliens abducting the innocent people on the ground. Be warned if an alien ship manages to abduct a person and take them to top of the screen, they will no longer move randomly and will begin to hunt you down. This sounds like a challenge you were trained for.
But don’t worry soldier you’re not going into battle empty-handed. Your ship is equipped with a state of the art laser beam that has unlimited ammo and four smart bombs that will destroy anything on the screen. The ship also has three lives so use them wisely.
As time goes on more alien ships will arrive on planet earth increasing the difficulty of your mission. And remember the landscape bellow loops around so if you continually fly in the same direction you go to your original position. Good luck soldier.
GameEngine/GameEngine.cpp@11:ab578a151f67, 2020-04-23 (annotated)
- Committer:
- evanso
- Date:
- Thu Apr 23 18:17:28 2020 +0000
- Revision:
- 11:ab578a151f67
- Parent:
- 8:dd1037c5435b
- Child:
- 13:12276eed13ac
Added test files and ran a spaceship unit test, which it passed! Also cleaned up code and comments.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
evanso | 8:dd1037c5435b | 1 | #include "GameEngine.h" |
evanso | 8:dd1037c5435b | 2 | |
evanso | 8:dd1037c5435b | 3 | GameEngine::GameEngine() { |
evanso | 8:dd1037c5435b | 4 | |
evanso | 8:dd1037c5435b | 5 | } |
evanso | 8:dd1037c5435b | 6 | |
evanso | 8:dd1037c5435b | 7 | GameEngine::~GameEngine() { |
evanso | 8:dd1037c5435b | 8 | |
evanso | 8:dd1037c5435b | 9 | } |
evanso | 8:dd1037c5435b | 10 | |
evanso | 8:dd1037c5435b | 11 | void GameEngine::init(N5110 &lcd, Spaceship &spaceship, Map &map, Gamepad &pad, AnalogIn &adc) { |
evanso | 8:dd1037c5435b | 12 | pad.init(); |
evanso | 8:dd1037c5435b | 13 | lcd.init(); |
evanso | 8:dd1037c5435b | 14 | spaceship.init(); |
evanso | 8:dd1037c5435b | 15 | map.init(adc); |
evanso | 8:dd1037c5435b | 16 | move_map_= 0; |
evanso | 11:ab578a151f67 | 17 | |
evanso | 8:dd1037c5435b | 18 | } |
evanso | 8:dd1037c5435b | 19 | |
evanso | 8:dd1037c5435b | 20 | void GameEngine::gameplay_loop(N5110 &lcd, Spaceship &spaceship, Map &map, Gamepad &pad, AnalogIn &pot_1) { |
evanso | 11:ab578a151f67 | 21 | // clear screen |
evanso | 8:dd1037c5435b | 22 | lcd.setContrast(pot_1.read()); |
evanso | 8:dd1037c5435b | 23 | lcd.clear(); |
evanso | 11:ab578a151f67 | 24 | |
evanso | 11:ab578a151f67 | 25 | // re-draws |
evanso | 8:dd1037c5435b | 26 | spaceship.movement(pad); |
evanso | 8:dd1037c5435b | 27 | spaceship.draw(lcd); |
evanso | 8:dd1037c5435b | 28 | map_movement(spaceship, pad); |
evanso | 8:dd1037c5435b | 29 | map.draw_map(lcd, move_map_); |
evanso | 11:ab578a151f67 | 30 | |
evanso | 11:ab578a151f67 | 31 | //refresh's screen |
evanso | 8:dd1037c5435b | 32 | lcd.refresh(); |
evanso | 8:dd1037c5435b | 33 | } |
evanso | 8:dd1037c5435b | 34 | |
evanso | 8:dd1037c5435b | 35 | |
evanso | 11:ab578a151f67 | 36 | void GameEngine::map_movement(Spaceship &spaceship, Gamepad &pad){ |
evanso | 11:ab578a151f67 | 37 | // Gets postition of spaceship and joystick input |
evanso | 11:ab578a151f67 | 38 | int position_x_spaceship_= spaceship.get_position_x_spaceship(); |
evanso | 8:dd1037c5435b | 39 | Direction joystick_direction = pad.get_direction(); |
evanso | 8:dd1037c5435b | 40 | //usb.printf("joystick_direction = %d\n", joystick_direction); |
evanso | 11:ab578a151f67 | 41 | //usb.printf("position_x_spaceship_ = %d\n", position_x_spaceship_); |
evanso | 8:dd1037c5435b | 42 | |
evanso | 11:ab578a151f67 | 43 | // moves the map in oposite direction to spaceship when it's position is at min and max x positions and joystick has direction |
evanso | 8:dd1037c5435b | 44 | if (position_x_spaceship_ == 22 && joystick_direction != CENTRE){ |
evanso | 8:dd1037c5435b | 45 | move_map_ = 1; |
evanso | 8:dd1037c5435b | 46 | }else if (position_x_spaceship_ == 52 && joystick_direction != CENTRE){ |
evanso | 8:dd1037c5435b | 47 | move_map_ = -1; |
evanso | 8:dd1037c5435b | 48 | }else { |
evanso | 8:dd1037c5435b | 49 | move_map_ = 0; |
evanso | 8:dd1037c5435b | 50 | } |
evanso | 8:dd1037c5435b | 51 | } |