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.
Diff: main.cpp
- Revision:
- 1:9c7bb3db32bc
- Parent:
- 0:edf120185e12
- Child:
- 7:5bb5cde8951a
--- a/main.cpp Mon Mar 09 08:27:42 2020 +0000
+++ b/main.cpp Wed Apr 22 15:52:04 2020 +0000
@@ -1,21 +1,100 @@
/*
-ELEC2645 Embedded Systems Project
+ELEC2645 Embedded Systems Project
School of Electronic & Electrical Engineering
University of Leeds
Name: Yufan Zhong
Username: el17yz
Student ID Number: 201199708
-Date:
+Date: May,2020
+
+*/
+
+
+///////// pre-processor directives ////////
+#include "mbed.h"
+#include "Gamepad.h"
+#include "N5110.h"
+#include "MinerEngine.h"
+
+#ifdef WITH_TESTING
+# include "tests.h"
+#endif
+
+#define WINCH_WIDTH 12
+#define WINCH_HEIGHT 6
+#define CLAW_SPEED 3
+#define MONSTER_SIZE 3
-*/
+/////////////// structs /////////////////
+struct UserInput {
+ Direction d;
+ float mag;
+};
+/////////////// objects ///////////////
+N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
+Gamepad pad;
+MinerEngine Miner;
+
+///////////// prototypes ///////////////
+void init();
+void update_game(UserInput input);
+void render();
+void welcome();
-#include "mbed.h"
-#include "FXOS8700Q.h"
+///////////// functions ////////////////
+int main()
+{
+
+#ifdef WITH_TESTING
+ int number_of_failures = run_all_tests();
+
+ if(number_of_failures > 0) return number_of_failures;
+#endif
+
+ int fps = 8; // frames per second
+
+ init(); // initialise and then display welcome screen...
+ welcome(); // waiting for the user to start
+
+ render(); // first draw the initial frame
+ wait(1.0f/fps); // and wait for one frame period
+ // game loop - read input, update the game state and render the display
+ while (1) {
+ miner.read_input(pad);
+ miner.update(pad);
+ render();
+ wait(1.0f/fps);
+ }
+}
-int main(void)
+// initialies all classes and libraries
+void init()
{
-
+ // need to initialise LCD and Gamepad
+ lcd.init();
+ pad.init();
+
+ // initialise the game with correct claw and winch sizes
+ miner.init(WINCH_WIDTH,WINCH_HEIGHT,MONSTER_SIZE,CLAW_SPEED);
+
+}
+
+// this function draws each frame on the LCD
+void render()
+{
+ // clear screen, re-draw and refresh
+ lcd.clear();
+ miner.draw(lcd);
+ lcd.refresh();
+}
+
+// simple splash screen displayed on start-up
+void welcome() {
+
+ miner.welcome(pad,lcd);
+ miner.menu(pad,lcd);
+
}
\ No newline at end of file