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
Fork of el17dg by
Diff: menu/menu.cpp
- Revision:
- 4:02c63aaa2df9
- Child:
- 19:b78fa41d04a9
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/menu/menu.cpp Sun Mar 03 23:36:34 2019 +0000
@@ -0,0 +1,78 @@
+#include "main.h"
+#include "menu.h"
+
+const int total_options = 3;
+const float time_delay = 100;
+
+int cursor[84] = {
+ 0,0,0,0,1,0,0,0,0,0,1,1,
+ 0,0,1,1,1,1,0,0,0,1,0,0,
+ 0,1,0,0,1,1,1,0,1,0,0,0,
+ 1,1,1,1,1,0,1,1,1,0,1,1,
+ 0,1,0,0,1,1,1,0,1,0,0,0,
+ 0,0,1,1,1,1,0,0,0,1,0,0,
+ 0,0,0,0,1,0,0,0,0,0,1,1
+};
+
+
+Menu::Menu() { // NOTE to self: The constructor for declerering intial states of variables.
+ current_option = 0; // As soon as Menu menu; happens in main, the zero is addressed to the variable.
+} // Another form of declering intial values.
+
+
+bool Menu::updateAndDraw() { // cheking whether the joystick was moved to point at other options in the menu.
+ if(y_dir.read() > 0.6f){
+ current_option -= 1;
+ wait_ms(time_delay);
+ }
+ else if (y_dir.read() < 0.4f){
+ current_option += 1;
+ wait_ms(time_delay);
+ }
+ if (current_option < 0) {
+ current_option += total_options;
+ }
+ if (current_option >= total_options) {
+ current_option -= total_options;
+ }
+
+ drawPointer(); // Drawing pointer only ones.
+
+ lcd.printString(" Start Game",1,2);
+ lcd.printString(" Tutorial",1,3);
+ lcd.printString(" Settings",1,4);
+
+ bool option_picked = false; // Checking for the selecting button to be pressed and returning the boolean statement.
+ if (gamepad.check_event(gamepad.B_PRESSED)){
+ option_picked = true;
+ }
+ return option_picked;
+}
+
+ScreenOption Menu::getCurrentScreenSelection() { // checking the current position of the pointer and main
+ if (current_option == 0) { // if the "Game" was selected and button be pressed, intilise game.
+ return ScreenOption_Game; // TASK for future: creat file with settings and tutorial.
+ }
+ if (current_option == 1) {
+ return ScreenOption_Tutorial;
+ }
+ if (current_option == 2) {
+ return ScreenOption_Settings;
+ }
+ return ScreenOption_Menu;
+}
+
+void Menu::drawPointer(){ // Checking what option was selected and drawing the pointer
+ int x = 70; // to indicate that postion.
+ int y = 17;
+ if (current_option == 0){
+ y = 17;
+ }
+ else if (current_option == 1){
+ y = 25;
+ }
+ else if (current_option == 2){
+ y = 32;
+ }
+ lcd.drawSprite(x, y, 7, 12, cursor);
+}
\ No newline at end of file
