Initial publish

Dependencies:   mbed

Fork of el17dg by Dmitrijs Griskovs

Committer:
Noximilien
Date:
Tue May 07 15:22:35 2019 +0000
Revision:
40:e3bbda7444fa
Parent:
32:5403bb974294
The Final, Submission Version. I have read and agreed to the academic integrity. SID:201160286

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Noximilien 4:02c63aaa2df9 1 #include "main.h"
Noximilien 4:02c63aaa2df9 2 #include "menu.h"
Noximilien 24:0570cb4b92d7 3 #include "constants.h"
Noximilien 26:676874c42883 4 #include "game.h"
Noximilien 28:35af3843de8f 5 #include "hud.h"
Noximilien 30:d454d0cb72bc 6 #include "models.h"
Noximilien 30:d454d0cb72bc 7 #include "gameobject.h"
Noximilien 32:5403bb974294 8 #include "stars.h"
Noximilien 4:02c63aaa2df9 9
Noximilien 28:35af3843de8f 10 Hud highScore;
Noximilien 30:d454d0cb72bc 11 GameObject cursor;
Noximilien 32:5403bb974294 12 GameObject pressASprite;
Noximilien 32:5403bb974294 13 Stars menuStars;
Noximilien 4:02c63aaa2df9 14
Noximilien 4:02c63aaa2df9 15 Menu::Menu() { // NOTE to self: The constructor for declerering intial states of variables.
Noximilien 32:5403bb974294 16 // As soon as Menu menu; happens in main, the zero is addressed to the variable.
Noximilien 32:5403bb974294 17 current_option = 0; // Another form of declering intial values.
Noximilien 32:5403bb974294 18 // cheking whether the joystick was moved to point at other options in the menu.
Noximilien 32:5403bb974294 19 }
Noximilien 4:02c63aaa2df9 20
Noximilien 32:5403bb974294 21 bool Menu::updateAndDraw() {
Noximilien 32:5403bb974294 22 checkJoystick();
Noximilien 4:02c63aaa2df9 23 drawPointer(); // Drawing pointer only ones.
Noximilien 28:35af3843de8f 24 highScore.drawHighScore();
Noximilien 32:5403bb974294 25 menuStars.starsSpawnDelay();
Noximilien 32:5403bb974294 26 menuStars.updateAndDrawSmallStars();
Noximilien 32:5403bb974294 27 menuStars.updateAndDrawMediumStars();
Noximilien 4:02c63aaa2df9 28
Noximilien 24:0570cb4b92d7 29 lcd.printString("Start Game",1,2);
Noximilien 24:0570cb4b92d7 30 lcd.printString("Tutorial",1,3);
Noximilien 24:0570cb4b92d7 31 lcd.printString("Settings",1,4);
Noximilien 32:5403bb974294 32 DrawPressAIcon();
Noximilien 4:02c63aaa2df9 33
Noximilien 4:02c63aaa2df9 34 bool option_picked = false; // Checking for the selecting button to be pressed and returning the boolean statement.
Noximilien 19:b78fa41d04a9 35 if (gamepad.check_event(gamepad.A_PRESSED)){
Noximilien 28:35af3843de8f 36 gamepad.check_event(gamepad.A_PRESSED);
Noximilien 4:02c63aaa2df9 37 option_picked = true;
Noximilien 4:02c63aaa2df9 38 }
Noximilien 28:35af3843de8f 39
Noximilien 4:02c63aaa2df9 40 return option_picked;
Noximilien 4:02c63aaa2df9 41 }
Noximilien 4:02c63aaa2df9 42
Noximilien 4:02c63aaa2df9 43 ScreenOption Menu::getCurrentScreenSelection() { // checking the current position of the pointer and main
Noximilien 4:02c63aaa2df9 44 if (current_option == 0) { // if the "Game" was selected and button be pressed, intilise game.
Noximilien 4:02c63aaa2df9 45 return ScreenOption_Game; // TASK for future: creat file with settings and tutorial.
Noximilien 4:02c63aaa2df9 46 }
Noximilien 4:02c63aaa2df9 47 if (current_option == 1) {
Noximilien 4:02c63aaa2df9 48 return ScreenOption_Tutorial;
Noximilien 4:02c63aaa2df9 49 }
Noximilien 4:02c63aaa2df9 50 if (current_option == 2) {
Noximilien 4:02c63aaa2df9 51 return ScreenOption_Settings;
Noximilien 4:02c63aaa2df9 52 }
Noximilien 4:02c63aaa2df9 53 return ScreenOption_Menu;
Noximilien 4:02c63aaa2df9 54 }
Noximilien 4:02c63aaa2df9 55
Noximilien 32:5403bb974294 56 void Menu::drawPointer(){ // Checking what option was selected and drawing the pointer
Noximilien 32:5403bb974294 57 // to indicate that postion.
Noximilien 32:5403bb974294 58 cursor.pos.x = 70;
Noximilien 32:5403bb974294 59 cursor.pos.y = 17;
Noximilien 4:02c63aaa2df9 60 if (current_option == 0){
Noximilien 30:d454d0cb72bc 61 cursor.pos.y = 17;
Noximilien 4:02c63aaa2df9 62 }
Noximilien 4:02c63aaa2df9 63 else if (current_option == 1){
Noximilien 30:d454d0cb72bc 64 cursor.pos.y = 25;
Noximilien 4:02c63aaa2df9 65 }
Noximilien 4:02c63aaa2df9 66 else if (current_option == 2){
Noximilien 30:d454d0cb72bc 67 cursor.pos.y = 32;
Noximilien 4:02c63aaa2df9 68 }
Noximilien 30:d454d0cb72bc 69 drawSprite(cursor.pos, menu_cursor_sprite);
Noximilien 32:5403bb974294 70 }
Noximilien 32:5403bb974294 71
Noximilien 32:5403bb974294 72 void Menu::DrawPressAIcon(){
Noximilien 32:5403bb974294 73 pressASprite.pos.x = screen_width - PressAWidth - 10;
Noximilien 32:5403bb974294 74 pressASprite.pos.y = screen_height - PressAHeight;
Noximilien 32:5403bb974294 75 drawSpriteOnTop(pressASprite.pos, Press_A_Icon_Sprite);
Noximilien 32:5403bb974294 76 }
Noximilien 32:5403bb974294 77
Noximilien 32:5403bb974294 78 void Menu::checkJoystick(){
Noximilien 32:5403bb974294 79 if(y_dir.read() > joy_threshold_max_y){
Noximilien 32:5403bb974294 80 current_option -= 1;
Noximilien 32:5403bb974294 81 wait_ms(time_delay);
Noximilien 32:5403bb974294 82 }
Noximilien 32:5403bb974294 83 else if (y_dir.read() < joy_threshold_min_y){
Noximilien 32:5403bb974294 84 current_option += 1;
Noximilien 32:5403bb974294 85 wait_ms(time_delay);
Noximilien 32:5403bb974294 86 }
Noximilien 32:5403bb974294 87 if (current_option < 0) {
Noximilien 32:5403bb974294 88 current_option += total_options;
Noximilien 32:5403bb974294 89 }
Noximilien 32:5403bb974294 90 if (current_option >= total_options) {
Noximilien 32:5403bb974294 91 current_option -= total_options;
Noximilien 32:5403bb974294 92 }
Noximilien 32:5403bb974294 93 }