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:
- 32:5403bb974294
- Parent:
- 31:becb8f6bf7b7
--- a/menu/menu.cpp Tue Apr 23 18:18:57 2019 +0000
+++ b/menu/menu.cpp Fri Apr 26 13:09:03 2019 +0000
@@ -5,44 +5,31 @@
#include "hud.h"
#include "models.h"
#include "gameobject.h"
-
-
-const int total_options = 3;
-const float time_delay = 100;
+#include "stars.h"
Hud highScore;
GameObject cursor;
-//Stars menuStars;
+GameObject pressASprite;
+Stars menuStars;
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.
+ // As soon as Menu menu; happens in main, the zero is addressed to the variable.
+ current_option = 0; // Another form of declering intial values.
+ // cheking whether the joystick was moved to point at other options in the menu.
+}
-bool Menu::updateAndDraw() { // cheking whether the joystick was moved to point at other options in the menu.
- if(y_dir.read() > joy_threshold_max_y){
- current_option -= 1;
- wait_ms(time_delay);
- }
- else if (y_dir.read() < joy_threshold_min_y){
- current_option += 1;
- wait_ms(time_delay);
- }
- if (current_option < 0) {
- current_option += total_options;
- }
- if (current_option >= total_options) {
- current_option -= total_options;
- }
-
+bool Menu::updateAndDraw() {
+ checkJoystick();
drawPointer(); // Drawing pointer only ones.
highScore.drawHighScore();
- //stars.starsSpawnDelay();
- //stars.updateAndDrawSmallStars();
- //stars.updateAndDrawMediumStars();
+ menuStars.starsSpawnDelay();
+ menuStars.updateAndDrawSmallStars();
+ menuStars.updateAndDrawMediumStars();
lcd.printString("Start Game",1,2);
lcd.printString("Tutorial",1,3);
lcd.printString("Settings",1,4);
+ DrawPressAIcon();
bool option_picked = false; // Checking for the selecting button to be pressed and returning the boolean statement.
if (gamepad.check_event(gamepad.A_PRESSED)){
@@ -66,9 +53,10 @@
return ScreenOption_Menu;
}
-void Menu::drawPointer(){ // Checking what option was selected and drawing the pointer
- cursor.pos.x = 70; // to indicate that postion.
- cursor.pos.y = 17;
+void Menu::drawPointer(){ // Checking what option was selected and drawing the pointer
+ // to indicate that postion.
+ cursor.pos.x = 70;
+ cursor.pos.y = 17;
if (current_option == 0){
cursor.pos.y = 17;
}
@@ -79,4 +67,27 @@
cursor.pos.y = 32;
}
drawSprite(cursor.pos, menu_cursor_sprite);
-}
\ No newline at end of file
+}
+
+void Menu::DrawPressAIcon(){
+ pressASprite.pos.x = screen_width - PressAWidth - 10;
+ pressASprite.pos.y = screen_height - PressAHeight;
+ drawSpriteOnTop(pressASprite.pos, Press_A_Icon_Sprite);
+}
+
+void Menu::checkJoystick(){
+ if(y_dir.read() > joy_threshold_max_y){
+ current_option -= 1;
+ wait_ms(time_delay);
+ }
+ else if (y_dir.read() < joy_threshold_min_y){
+ current_option += 1;
+ wait_ms(time_delay);
+ }
+ if (current_option < 0) {
+ current_option += total_options;
+ }
+ if (current_option >= total_options) {
+ current_option -= total_options;
+ }
+}
