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: main/main.cpp
- Revision:
- 4:02c63aaa2df9
- Parent:
- 3:10918b0f7a7d
- Child:
- 5:2b9181bc5c89
--- a/main/main.cpp Thu Feb 28 16:13:06 2019 +0000
+++ b/main/main.cpp Sun Mar 03 23:36:34 2019 +0000
@@ -9,21 +9,24 @@
*/
-#include "mbed.h"
-#include "N5110.h"
-#include "Gamepad.h"
+#include "main.h"
#include "game.h"
+#include "menu.h"
N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
+
Gamepad gamepad;
+
AnalogIn pot(PTB2);
-
AnalogIn x_dir(PTB11);
AnalogIn y_dir(PTB10);
-static const unsigned int MAX_LINE_LENGTH = 14;
+Menu menu;
+Game game;
+
+//static const unsigned int MAX_LINE_LENGTH = 14;
void intro();
@@ -31,118 +34,52 @@
void pointer_position(int menu_number);
void ship_movement();
-char line_buffer[MAX_LINE_LENGTH];
+//char line_buffer[MAX_LINE_LENGTH];
-int menu_number = 0;
-int total_menu_number = 3;
-float time_delay = 100;
+
int x_movement = 20;
int y_movement = 30;
+ScreenOption current_screen = ScreenOption_Menu;
+
+void intro();
+
int main(){
lcd.init();
+ gamepad.init();
intro();
-
- while(1){
-
+ while(1){ //Waiting for the option "start game" to be selected and for the button B to be pressed
lcd.clear();
- pointer_position(menu_number);
-
- if(y_dir.read() > 0.6){
- menu_number -= 1;
- wait_ms(time_delay);
- }
- if (y_dir.read() < 0.4){
- menu_number += 1;
- wait_ms(time_delay);
- }
- if (menu_number < 0) {
- menu_number += total_menu_number;
- }
- if (menu_number >= total_menu_number) {
- menu_number -= total_menu_number;
+ if (current_screen == ScreenOption_Game) {
+ bool gameIsPaused = game.updateAndDraw();
+ if (gameIsPaused) {
+ current_screen = ScreenOption_Menu;
+ }
+ }
+ else if (current_screen == ScreenOption_Menu) {
+ bool wantsToChangeScreen = menu.updateAndDraw();
+ if (wantsToChangeScreen) {
+ current_screen = menu.getCurrentScreenSelection();
+ }
}
- lcd.printString(" Start ",1,2);
- lcd.printString(" Tutorial",1,3);
- lcd.printString(" Settings",1,4);
- sprintf(line_buffer, "%i", gamepad.L_PRESSED);
- lcd.printString(line_buffer,0,0);
-
- if (menu_number == 1 && gamepad.A_PRESSED == 1){
- ship_movement();
- game_start(lcd, x_movement, y_movement);
- }
lcd.refresh();
wait_ms(1000/10);
-
-
}
-
-
-
}
-void intro(){
+void intro(){ // This just will be an intro for the game.
lcd.clear();
lcd.printString(" StarBarians",1,1);
lcd.refresh();
wait(0.5);
lcd.printString(" And the quest ",1,2);
- lcd.printString(" of the Princess Boobeta",1,3);
- lcd.printString(" Boobeta",1,4);
+ lcd.printString(" of the Princess Spacecate",1,3);
+ lcd.printString(" Spacecate",1,4);
lcd.refresh();
wait(0.5);
-}
-
-void pointer(int x, int y){
-
- 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};
-
-
- lcd.drawSprite(x,y,7,12,cursor);
-}
-
-void pointer_position(int menu_number){ //32 for 5th row- 25 for 4th row
- if (menu_number == 0){
- pointer(70, 17);
- }
- if (menu_number == 1){
- pointer(70, 25);
- }
- if (menu_number == 2){
- pointer(70, 32);
- }
-}
-
-void ship_movement(){
- if(y_dir.read() > 0.6){
- y_movement += 1;
- //wait_ms(time_delay);
- }
- if (y_dir.read() < 0.4){
- y_movement -= 1;
- //wait_ms(time_delay);
- }
-
- if(x_dir.read() > 0.6){
- x_movement += 1;
- //wait_ms(time_delay);
- }
- if (x_dir.read() < 0.4){
- x_movement -= 1;
- //wait_ms(time_delay);
- }
-
-}
-
+}
\ No newline at end of file
