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.
Dependencies: mbed FATFileSystem
Game_Manager/Game_Manager.cpp@15:3d29fb195958, 2019-05-07 (annotated)
- Committer:
- rottenegg
- Date:
- Tue May 07 03:20:24 2019 +0000
- Revision:
- 15:3d29fb195958
- Parent:
- 14:165fff6d1854
- Child:
- 17:7d4d8905b608
SceneFunctions: Added a new Scene; Game_Manager: set up the Main story flow; CaMove: fixed a error with chaser ( typo in code causes the chaser to be unable to move right)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rottenegg | 14:165fff6d1854 | 1 | #include "Game_Manager.h" |
rottenegg | 14:165fff6d1854 | 2 | #include "AllPaths.h" |
rottenegg | 14:165fff6d1854 | 3 | |
rottenegg | 14:165fff6d1854 | 4 | Timer Time; |
rottenegg | 14:165fff6d1854 | 5 | |
rottenegg | 14:165fff6d1854 | 6 | Game_Manager::Game_Manager(PinName sd0, |
rottenegg | 14:165fff6d1854 | 7 | PinName sd1, |
rottenegg | 14:165fff6d1854 | 8 | PinName sd2, |
rottenegg | 14:165fff6d1854 | 9 | PinName sd3, |
rottenegg | 14:165fff6d1854 | 10 | PinName lcd0, |
rottenegg | 14:165fff6d1854 | 11 | PinName lcd1, |
rottenegg | 14:165fff6d1854 | 12 | PinName lcd2, |
rottenegg | 14:165fff6d1854 | 13 | PinName lcd3, |
rottenegg | 14:165fff6d1854 | 14 | PinName lcd4, |
rottenegg | 14:165fff6d1854 | 15 | PinName lcd5, |
rottenegg | 14:165fff6d1854 | 16 | PinName cm0, |
rottenegg | 14:165fff6d1854 | 17 | PinName cm1, |
rottenegg | 14:165fff6d1854 | 18 | PinName cm2, |
rottenegg | 14:165fff6d1854 | 19 | PinName wd, |
rottenegg | 14:165fff6d1854 | 20 | PinName sc ) |
rottenegg | 14:165fff6d1854 | 21 | : |
rottenegg | 14:165fff6d1854 | 22 | sd(new SDFileSystem(sd0, sd1, sd2, sd3, "sd")), |
rottenegg | 14:165fff6d1854 | 23 | lcd(new N5110(lcd0,lcd1,lcd2,lcd3,lcd4,lcd5)), |
rottenegg | 14:165fff6d1854 | 24 | CM(new CaMove(cm0,cm1,cm2)), |
rottenegg | 14:165fff6d1854 | 25 | wav(new WDplayer(wd)), |
rottenegg | 14:165fff6d1854 | 26 | SNC(new SceneCreator(sc)) |
rottenegg | 14:165fff6d1854 | 27 | |
rottenegg | 14:165fff6d1854 | 28 | {}; |
rottenegg | 14:165fff6d1854 | 29 | |
rottenegg | 14:165fff6d1854 | 30 | |
rottenegg | 14:165fff6d1854 | 31 | bool Game_Manager::boot_error() { |
rottenegg | 14:165fff6d1854 | 32 | //Check SD card Status |
rottenegg | 14:165fff6d1854 | 33 | lcd->init(); |
rottenegg | 14:165fff6d1854 | 34 | lcd->clear(); |
rottenegg | 14:165fff6d1854 | 35 | lcd->printString("BOOTING...",0,0); |
rottenegg | 14:165fff6d1854 | 36 | lcd->refresh(); |
rottenegg | 14:165fff6d1854 | 37 | sd->disk_initialize(); |
rottenegg | 14:165fff6d1854 | 38 | int check = sd->disk_status(); |
rottenegg | 14:165fff6d1854 | 39 | if (check == 1) { |
rottenegg | 14:165fff6d1854 | 40 | lcd->printString("SD Card Error",0,0); |
rottenegg | 14:165fff6d1854 | 41 | lcd->printString("Details in ",0,1); |
rottenegg | 14:165fff6d1854 | 42 | lcd->printString("Terminal try",0,2); |
rottenegg | 14:165fff6d1854 | 43 | lcd->printString("Re-inserting",0,3); |
rottenegg | 14:165fff6d1854 | 44 | lcd->printString("SD Card",0,4); |
rottenegg | 14:165fff6d1854 | 45 | lcd->refresh(); |
rottenegg | 14:165fff6d1854 | 46 | return true; |
rottenegg | 14:165fff6d1854 | 47 | } else { |
rottenegg | 14:165fff6d1854 | 48 | std::cerr << "Error Report" << std::endl; |
rottenegg | 14:165fff6d1854 | 49 | if (this->check()) { |
rottenegg | 14:165fff6d1854 | 50 | lcd->clear(); |
rottenegg | 14:165fff6d1854 | 51 | lcd->printString("Game Files",0,0); |
rottenegg | 14:165fff6d1854 | 52 | lcd->printString("Missing",0,1); |
rottenegg | 14:165fff6d1854 | 53 | lcd->printString("Details in",0,2); |
rottenegg | 14:165fff6d1854 | 54 | lcd->printString("Terminal",0,3); |
rottenegg | 14:165fff6d1854 | 55 | lcd->refresh(); |
rottenegg | 14:165fff6d1854 | 56 | return true; |
rottenegg | 14:165fff6d1854 | 57 | } else { |
rottenegg | 14:165fff6d1854 | 58 | std::cerr << "Boot Successful No Errors" << std::endl; |
rottenegg | 14:165fff6d1854 | 59 | } |
rottenegg | 14:165fff6d1854 | 60 | } |
rottenegg | 14:165fff6d1854 | 61 | return false; |
rottenegg | 14:165fff6d1854 | 62 | } |
rottenegg | 14:165fff6d1854 | 63 | |
rottenegg | 14:165fff6d1854 | 64 | void Game_Manager::main() { |
rottenegg | 14:165fff6d1854 | 65 | const char *path; |
rottenegg | 14:165fff6d1854 | 66 | path = "/sd/Game-Files/AudBin/play1.wav"; |
rottenegg | 14:165fff6d1854 | 67 | wav->intWD(path, true); |
rottenegg | 14:165fff6d1854 | 68 | Time.start(); |
rottenegg | 14:165fff6d1854 | 69 | SNC->Scenesp(*lcd,*CM,0,40,20,Fd,0,*wav); |
rottenegg | 14:165fff6d1854 | 70 | |
rottenegg | 14:165fff6d1854 | 71 | Time.stop(); |
rottenegg | 14:165fff6d1854 | 72 | int Random = (int)Time.read(); |
rottenegg | 14:165fff6d1854 | 73 | Random = Random % 3; |
rottenegg | 14:165fff6d1854 | 74 | |
rottenegg | 14:165fff6d1854 | 75 | if (Random == 0 || Random == 1) { |
rottenegg | 14:165fff6d1854 | 76 | wav->intWD(path, true); |
rottenegg | 14:165fff6d1854 | 77 | SNC->Scenesp(*lcd,*CM,1,35,29,Fd,0,*wav); |
rottenegg | 14:165fff6d1854 | 78 | } else { |
rottenegg | 14:165fff6d1854 | 79 | wav->intWD(path, true); |
rottenegg | 14:165fff6d1854 | 80 | SNC->Scenesp(*lcd,*CM,3,58,26,Bd,0,*wav); |
rottenegg | 14:165fff6d1854 | 81 | } |
rottenegg | 15:3d29fb195958 | 82 | if (Random == 2 && SNC->get_dead()) { |
rottenegg | 15:3d29fb195958 | 83 | //go death |
rottenegg | 15:3d29fb195958 | 84 | } else if ((Random == 2 && !SNC->get_dead()) || (Random != 2 && SNC->get_dead())) { |
rottenegg | 15:3d29fb195958 | 85 | SNC->set_dead(false); |
rottenegg | 15:3d29fb195958 | 86 | wav->intWD(path, true); |
rottenegg | 15:3d29fb195958 | 87 | SNC->Scenesp(*lcd,*CM,4,69,19,Rt,0,*wav); |
rottenegg | 15:3d29fb195958 | 88 | } else { |
rottenegg | 15:3d29fb195958 | 89 | wav->intWD(path, true); |
rottenegg | 15:3d29fb195958 | 90 | SNC->Scenesp(*lcd,*CM,2,61,17,Lt,0,*wav); |
rottenegg | 15:3d29fb195958 | 91 | } |
rottenegg | 14:165fff6d1854 | 92 | } |
rottenegg | 14:165fff6d1854 | 93 | |
rottenegg | 14:165fff6d1854 | 94 | bool Game_Manager::check() { |
rottenegg | 14:165fff6d1854 | 95 | FILE *bmp; |
rottenegg | 14:165fff6d1854 | 96 | bool error = false; |
rottenegg | 14:165fff6d1854 | 97 | for (int i = 0; i <= 34; i++) { |
rottenegg | 14:165fff6d1854 | 98 | bmp = fopen(All[i],"r"); |
rottenegg | 14:165fff6d1854 | 99 | if (bmp == NULL) { |
rottenegg | 14:165fff6d1854 | 100 | std::cerr << All[i] << " is not present" << std::endl; |
rottenegg | 14:165fff6d1854 | 101 | error = true; |
rottenegg | 14:165fff6d1854 | 102 | } else { |
rottenegg | 14:165fff6d1854 | 103 | fclose(bmp); |
rottenegg | 14:165fff6d1854 | 104 | } |
rottenegg | 14:165fff6d1854 | 105 | } |
rottenegg | 14:165fff6d1854 | 106 | return error; |
rottenegg | 14:165fff6d1854 | 107 | } |