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.
main.cpp@6:12e8433382b3, 2020-04-16 (annotated)
- Committer:
- evanso
- Date:
- Thu Apr 16 16:25:53 2020 +0000
- Revision:
- 6:12e8433382b3
- Parent:
- 4:0df2b85e47f1
- Child:
- 7:0af4ced868f5
Restricted spaceship movement to middle third of the screen in the x-direction. Started adding drawing functions to map class.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
eencae | 0:b7f1f47bb26a | 1 | /* |
eencae | 0:b7f1f47bb26a | 2 | ELEC2645 Embedded Systems Project |
eencae | 0:b7f1f47bb26a | 3 | School of Electronic & Electrical Engineering |
eencae | 0:b7f1f47bb26a | 4 | University of Leeds |
eencae | 0:b7f1f47bb26a | 5 | 2019/20 |
eencae | 0:b7f1f47bb26a | 6 | |
evanso | 1:1f2ae263248e | 7 | Name:Benjamin Evans |
evanso | 1:1f2ae263248e | 8 | Username:el18bpe |
evanso | 1:1f2ae263248e | 9 | Student ID Number:201216635 |
evanso | 1:1f2ae263248e | 10 | Date:23/02/2020 |
eencae | 0:b7f1f47bb26a | 11 | */ |
eencae | 0:b7f1f47bb26a | 12 | |
evanso | 3:dee187b8b30c | 13 | // Includes libaries |
eencae | 0:b7f1f47bb26a | 14 | #include "mbed.h" |
eencae | 0:b7f1f47bb26a | 15 | #include "Gamepad.h" |
eencae | 0:b7f1f47bb26a | 16 | #include "N5110.h" |
evanso | 3:dee187b8b30c | 17 | #include "Spaceship.h" |
evanso | 6:12e8433382b3 | 18 | #include "Map.h" |
eencae | 0:b7f1f47bb26a | 19 | |
eencae | 0:b7f1f47bb26a | 20 | |
evanso | 3:dee187b8b30c | 21 | // Objects |
eencae | 0:b7f1f47bb26a | 22 | Gamepad pad; |
eencae | 0:b7f1f47bb26a | 23 | N5110 lcd; |
evanso | 3:dee187b8b30c | 24 | Ticker ticker; |
evanso | 3:dee187b8b30c | 25 | Spaceship spaceship; |
evanso | 4:0df2b85e47f1 | 26 | AnalogIn pot_1(PTB2); |
evanso | 6:12e8433382b3 | 27 | Map map; |
evanso | 3:dee187b8b30c | 28 | |
evanso | 3:dee187b8b30c | 29 | // Global varable definitions |
evanso | 3:dee187b8b30c | 30 | volatile int g_lcd_frame_time_flag = 0; |
evanso | 3:dee187b8b30c | 31 | |
evanso | 3:dee187b8b30c | 32 | // Function definitions |
evanso | 4:0df2b85e47f1 | 33 | void lcd_frame_time_isr(); |
eencae | 0:b7f1f47bb26a | 34 | |
eencae | 0:b7f1f47bb26a | 35 | int main() |
evanso | 3:dee187b8b30c | 36 | { |
evanso | 3:dee187b8b30c | 37 | // Sets fram rate of lcd by using time-triggered tasks |
evanso | 4:0df2b85e47f1 | 38 | ticker.attach(&lcd_frame_time_isr,0.04); |
evanso | 3:dee187b8b30c | 39 | |
evanso | 4:0df2b85e47f1 | 40 | pad.init(); |
evanso | 3:dee187b8b30c | 41 | lcd.init(); |
evanso | 3:dee187b8b30c | 42 | spaceship.init(); |
evanso | 6:12e8433382b3 | 43 | map.init(); |
evanso | 4:0df2b85e47f1 | 44 | lcd.setContrast(0.45); |
evanso | 3:dee187b8b30c | 45 | lcd.refresh(); |
evanso | 4:0df2b85e47f1 | 46 | spaceship.draw(lcd); |
eencae | 0:b7f1f47bb26a | 47 | |
evanso | 3:dee187b8b30c | 48 | while (1) { |
evanso | 3:dee187b8b30c | 49 | // Checks flag and prints spaceship on lcd then resets flag |
evanso | 3:dee187b8b30c | 50 | if (g_lcd_frame_time_flag) { |
evanso | 4:0df2b85e47f1 | 51 | g_lcd_frame_time_flag = 0; |
evanso | 3:dee187b8b30c | 52 | |
evanso | 4:0df2b85e47f1 | 53 | lcd.setContrast(pot_1.read()); |
evanso | 4:0df2b85e47f1 | 54 | spaceship.clear_spaceship(lcd); |
evanso | 4:0df2b85e47f1 | 55 | spaceship.movement(pad); |
evanso | 6:12e8433382b3 | 56 | spaceship.draw(lcd); |
evanso | 6:12e8433382b3 | 57 | map.draw_triangle(lcd); |
evanso | 3:dee187b8b30c | 58 | lcd.refresh(); |
evanso | 3:dee187b8b30c | 59 | } |
evanso | 3:dee187b8b30c | 60 | // MCU put to sleep between each frame to save power |
evanso | 3:dee187b8b30c | 61 | sleep(); |
evanso | 3:dee187b8b30c | 62 | } |
eencae | 0:b7f1f47bb26a | 63 | } |
eencae | 0:b7f1f47bb26a | 64 | |
evanso | 3:dee187b8b30c | 65 | // Time-triggered interrupt to wake MCU from sleep |
evanso | 4:0df2b85e47f1 | 66 | void lcd_frame_time_isr() |
evanso | 3:dee187b8b30c | 67 | { |
evanso | 3:dee187b8b30c | 68 | g_lcd_frame_time_flag = 1; // set flag in ISR |
evanso | 3:dee187b8b30c | 69 | } |