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.
main.cpp@19:08c582bcdc98, 2020-05-13 (annotated)
- Committer:
- ZhongYufan
- Date:
- Wed May 13 14:07:20 2020 +0000
- Revision:
- 19:08c582bcdc98
- Parent:
- 14:3731b0791970
The final version
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ZhongYufan | 0:edf120185e12 | 1 | /* |
| ZhongYufan | 1:9c7bb3db32bc | 2 | ELEC2645 Embedded Systems Project |
| ZhongYufan | 0:edf120185e12 | 3 | School of Electronic & Electrical Engineering |
| ZhongYufan | 0:edf120185e12 | 4 | University of Leeds |
| ZhongYufan | 0:edf120185e12 | 5 | |
| ZhongYufan | 0:edf120185e12 | 6 | Name: Yufan Zhong |
| ZhongYufan | 0:edf120185e12 | 7 | Username: el17yz |
| ZhongYufan | 0:edf120185e12 | 8 | Student ID Number: 201199708 |
| ZhongYufan | 1:9c7bb3db32bc | 9 | Date: May,2020 |
| ZhongYufan | 1:9c7bb3db32bc | 10 | |
| ZhongYufan | 1:9c7bb3db32bc | 11 | */ |
| ZhongYufan | 1:9c7bb3db32bc | 12 | |
| ZhongYufan | 1:9c7bb3db32bc | 13 | |
| ZhongYufan | 1:9c7bb3db32bc | 14 | ///////// pre-processor directives //////// |
| ZhongYufan | 1:9c7bb3db32bc | 15 | #include "mbed.h" |
| ZhongYufan | 1:9c7bb3db32bc | 16 | #include "Gamepad.h" |
| ZhongYufan | 1:9c7bb3db32bc | 17 | #include "N5110.h" |
| ZhongYufan | 1:9c7bb3db32bc | 18 | #include "MinerEngine.h" |
| ZhongYufan | 1:9c7bb3db32bc | 19 | |
| ZhongYufan | 19:08c582bcdc98 | 20 | #ifdef DEBUG |
| ZhongYufan | 1:9c7bb3db32bc | 21 | # include "tests.h" |
| ZhongYufan | 1:9c7bb3db32bc | 22 | #endif |
| ZhongYufan | 1:9c7bb3db32bc | 23 | |
| ZhongYufan | 1:9c7bb3db32bc | 24 | #define WINCH_WIDTH 12 |
| ZhongYufan | 1:9c7bb3db32bc | 25 | #define WINCH_HEIGHT 6 |
| ZhongYufan | 1:9c7bb3db32bc | 26 | #define CLAW_SPEED 3 |
| ZhongYufan | 1:9c7bb3db32bc | 27 | #define MONSTER_SIZE 3 |
| ZhongYufan | 11:9da147cd7c18 | 28 | #define MONSTER_SPEED 1 |
| ZhongYufan | 7:5bb5cde8951a | 29 | #define GOLD_NUM 9 |
| ZhongYufan | 1:9c7bb3db32bc | 30 | /////////////// structs ///////////////// |
| ZhongYufan | 1:9c7bb3db32bc | 31 | struct UserInput { |
| ZhongYufan | 1:9c7bb3db32bc | 32 | Direction d; |
| ZhongYufan | 1:9c7bb3db32bc | 33 | float mag; |
| ZhongYufan | 1:9c7bb3db32bc | 34 | }; |
| ZhongYufan | 1:9c7bb3db32bc | 35 | /////////////// objects /////////////// |
| ZhongYufan | 1:9c7bb3db32bc | 36 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); |
| ZhongYufan | 1:9c7bb3db32bc | 37 | Gamepad pad; |
| ZhongYufan | 7:5bb5cde8951a | 38 | MinerEngine miner; |
| ZhongYufan | 1:9c7bb3db32bc | 39 | |
| ZhongYufan | 1:9c7bb3db32bc | 40 | ///////////// prototypes /////////////// |
| ZhongYufan | 1:9c7bb3db32bc | 41 | void init(); |
| ZhongYufan | 0:edf120185e12 | 42 | |
| ZhongYufan | 1:9c7bb3db32bc | 43 | ///////////// functions //////////////// |
| ZhongYufan | 1:9c7bb3db32bc | 44 | int main() |
| ZhongYufan | 1:9c7bb3db32bc | 45 | { |
| ZhongYufan | 1:9c7bb3db32bc | 46 | |
| ZhongYufan | 19:08c582bcdc98 | 47 | #ifdef DEBUG |
| ZhongYufan | 1:9c7bb3db32bc | 48 | int number_of_failures = run_all_tests(); |
| ZhongYufan | 1:9c7bb3db32bc | 49 | |
| ZhongYufan | 1:9c7bb3db32bc | 50 | if(number_of_failures > 0) return number_of_failures; |
| ZhongYufan | 1:9c7bb3db32bc | 51 | #endif |
| ZhongYufan | 1:9c7bb3db32bc | 52 | |
| ZhongYufan | 1:9c7bb3db32bc | 53 | init(); // initialise and then display welcome screen... |
| ZhongYufan | 19:08c582bcdc98 | 54 | miner.welcome(pad,lcd); // waiting for the user to start |
| ZhongYufan | 19:08c582bcdc98 | 55 | |
| ZhongYufan | 19:08c582bcdc98 | 56 | // game loop - switch the state - read input, update the game state and render the display |
| ZhongYufan | 1:9c7bb3db32bc | 57 | while (1) { |
| ZhongYufan | 7:5bb5cde8951a | 58 | miner.state_switch(pad,lcd); |
| ZhongYufan | 1:9c7bb3db32bc | 59 | } |
| ZhongYufan | 1:9c7bb3db32bc | 60 | } |
| ZhongYufan | 0:edf120185e12 | 61 | |
| ZhongYufan | 1:9c7bb3db32bc | 62 | // initialies all classes and libraries |
| ZhongYufan | 1:9c7bb3db32bc | 63 | void init() |
| ZhongYufan | 0:edf120185e12 | 64 | { |
| ZhongYufan | 1:9c7bb3db32bc | 65 | // need to initialise LCD and Gamepad |
| ZhongYufan | 1:9c7bb3db32bc | 66 | lcd.init(); |
| ZhongYufan | 1:9c7bb3db32bc | 67 | pad.init(); |
| ZhongYufan | 19:08c582bcdc98 | 68 | // initialise the game with correct winch sizes, gold number and monster speed |
| ZhongYufan | 7:5bb5cde8951a | 69 | miner.init(WINCH_WIDTH,WINCH_HEIGHT,GOLD_NUM,MONSTER_SPEED); |
| ZhongYufan | 19:08c582bcdc98 | 70 | miner.init_unchanged_parameter(); //initialise the highest score |
| ZhongYufan | 1:9c7bb3db32bc | 71 | } |