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@13:12276eed13ac, 2020-04-26 (annotated)
- Committer:
- evanso
- Date:
- Sun Apr 26 17:08:10 2020 +0000
- Revision:
- 13:12276eed13ac
- Parent:
- 12:1c0b6796aaca
- Child:
- 14:7419c680656f
Changed spaceship unit test code so it now done properly and doesn't require my input. Changed where objects are defined to reduce the number of arguments that need passing when a function is called. Edited gamepad code to properly add ADC pin.
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 | 13:12276eed13ac | 13 | // pre-processor directives ---------------------------------------------------- |
eencae | 0:b7f1f47bb26a | 14 | #include "mbed.h" |
eencae | 0:b7f1f47bb26a | 15 | #include "Gamepad.h" |
eencae | 0:b7f1f47bb26a | 16 | #include "N5110.h" |
evanso | 11:ab578a151f67 | 17 | #include "GameEngine.h" |
evanso | 3:dee187b8b30c | 18 | #include "Spaceship.h" |
evanso | 6:12e8433382b3 | 19 | #include "Map.h" |
evanso | 11:ab578a151f67 | 20 | |
evanso | 12:1c0b6796aaca | 21 | #ifdef GAME_TEST |
evanso | 11:ab578a151f67 | 22 | # include "test.h" |
evanso | 11:ab578a151f67 | 23 | #endif |
evanso | 11:ab578a151f67 | 24 | |
eencae | 0:b7f1f47bb26a | 25 | |
evanso | 9:1ddb8dc93e48 | 26 | // to do |
evanso | 11:ab578a151f67 | 27 | // sort of objects out |
evanso | 9:1ddb8dc93e48 | 28 | // add debug functions for variables |
evanso | 10:aca793aa7abc | 29 | // add test files |
evanso | 13:12276eed13ac | 30 | // move object into correct class rrpivates. |
evanso | 13:12276eed13ac | 31 | // change spcacehip test |
evanso | 13:12276eed13ac | 32 | // fix direction thing |
evanso | 13:12276eed13ac | 33 | // @details Radius of the circle in metres to all doxygen comments |
eencae | 0:b7f1f47bb26a | 34 | |
evanso | 13:12276eed13ac | 35 | // Objects --------------------------------------------------------------------- |
evanso | 13:12276eed13ac | 36 | |
evanso | 13:12276eed13ac | 37 | // Ticker object for ISR |
evanso | 13:12276eed13ac | 38 | Ticker ticker; |
evanso | 13:12276eed13ac | 39 | |
evanso | 13:12276eed13ac | 40 | //Game Engine object |
evanso | 8:dd1037c5435b | 41 | GameEngine engine; |
evanso | 11:ab578a151f67 | 42 | |
evanso | 13:12276eed13ac | 43 | // Global variables ------------------------------------------------------------ |
evanso | 3:dee187b8b30c | 44 | |
evanso | 13:12276eed13ac | 45 | // Volatile flag for ISR |
evanso | 7:0af4ced868f5 | 46 | volatile int g_lcd_frame_time_flag = 0; |
evanso | 3:dee187b8b30c | 47 | |
evanso | 13:12276eed13ac | 48 | // Function prototypes --------------------------------------------------------- |
evanso | 4:0df2b85e47f1 | 49 | void lcd_frame_time_isr(); |
eencae | 0:b7f1f47bb26a | 50 | |
evanso | 13:12276eed13ac | 51 | // functions ------------------------------------------------------------------- |
eencae | 0:b7f1f47bb26a | 52 | int main() |
evanso | 3:dee187b8b30c | 53 | { |
evanso | 3:dee187b8b30c | 54 | // Sets fram rate of lcd by using time-triggered tasks |
evanso | 7:0af4ced868f5 | 55 | ticker.attach(&lcd_frame_time_isr,0.03); |
evanso | 13:12276eed13ac | 56 | engine.init(); |
eencae | 0:b7f1f47bb26a | 57 | |
evanso | 11:ab578a151f67 | 58 | // Compile with tests |
evanso | 12:1c0b6796aaca | 59 | #ifdef GAME_TEST |
evanso | 13:12276eed13ac | 60 | run_spaceship_movement_tests(); |
evanso | 13:12276eed13ac | 61 | run_spaceship_draw_tests(); |
evanso | 13:12276eed13ac | 62 | //run_map_tests(); |
evanso | 11:ab578a151f67 | 63 | #endif |
evanso | 11:ab578a151f67 | 64 | |
evanso | 3:dee187b8b30c | 65 | while (1) { |
evanso | 8:dd1037c5435b | 66 | |
evanso | 3:dee187b8b30c | 67 | // Checks flag and prints spaceship on lcd then resets flag |
evanso | 3:dee187b8b30c | 68 | if (g_lcd_frame_time_flag) { |
evanso | 8:dd1037c5435b | 69 | g_lcd_frame_time_flag = 0; // resets flag |
evanso | 7:0af4ced868f5 | 70 | |
evanso | 13:12276eed13ac | 71 | engine.gameplay_loop(); |
evanso | 3:dee187b8b30c | 72 | } |
evanso | 8:dd1037c5435b | 73 | |
evanso | 3:dee187b8b30c | 74 | // MCU put to sleep between each frame to save power |
evanso | 3:dee187b8b30c | 75 | sleep(); |
evanso | 3:dee187b8b30c | 76 | } |
eencae | 0:b7f1f47bb26a | 77 | } |
eencae | 0:b7f1f47bb26a | 78 | |
evanso | 3:dee187b8b30c | 79 | // Time-triggered interrupt to wake MCU from sleep |
evanso | 4:0df2b85e47f1 | 80 | void lcd_frame_time_isr() |
evanso | 3:dee187b8b30c | 81 | { |
evanso | 3:dee187b8b30c | 82 | g_lcd_frame_time_flag = 1; // set flag in ISR |
evanso | 3:dee187b8b30c | 83 | } |