Explorar el Código

Merged Adbook's menu

Eiyeron Fulmincendii hace 11 años
padre
commit
bf5510b321
Se han modificado 4 ficheros con 31 adiciones y 7 borrados
  1. 2 3
      draw_states.c
  2. 2 0
      init_states.c
  3. 1 0
      struct.h
  4. 26 4
      update_states.c

+ 2 - 3
draw_states.c

@@ -61,8 +61,7 @@ void draw_menu(Game_Data *data)
 	fillBackground(data);
 	drawPolygon(data, data->nb_lines, data->line_transition);
 	drawDiagonals(data, data->nb_lines, data->line_transition);
-	drawTopRightCornerText("WIP Menu. Forget that.", data->are_colors_reversed);
-
+	drawTopRightCornerText(data->entry_difficulties[data->current_entry - 1], data->are_colors_reversed);
 }
 void draw_game_over(Game_Data *data)
 {
@@ -151,7 +150,7 @@ static void drawHud(Game_Data *data) {
 
 static void drawPolygon(Game_Data *data, int nb_lines, Line_Transition line_transition) {
 	int x[32];
-	int y[32];
+ 	int y[32];
 	int i = 0;
 	int angle = 0;
 

+ 2 - 0
init_states.c

@@ -127,6 +127,7 @@ const unsigned char patternTest7[] = {
 
 void init_game(Game_Data *data)
 {
+//TODO: init the level depending on the value of data->current_entry
 	data->level = NULL;
 	data->level = malloc(sizeof(Level));
 	if(data->level == NULL)
@@ -240,6 +241,7 @@ void init_menu(Game_Data *data)
 	data->line_transition.counter_start = 0;
 	data->line_transition.delta_nb_lines = 0;
 
+	data->keypress_delay = 50;
 	data->nb_entries = 6;
 	data->current_entry = 1;
 data->current_entry_high_score = 0; //to load from a save file

+ 1 - 0
struct.h

@@ -112,6 +112,7 @@ struct Game_Data{
 	unsigned int current_entry; //from 1 to 6
 	unsigned int current_entry_high_score;
 	char **entry_difficulties; //a table of null-terminated strings
+	unsigned int keypress_delay;
 };
 
 struct Pattern{

+ 26 - 4
update_states.c

@@ -94,8 +94,7 @@ void update_game(Game_Data *data)
 	updateCamera(&(data->cam), data->current_time - data->last_time);
 
 }
-
-void update_menu(Game_Data *data)
+void update_game_over(Game_Data *data)
 {
 	data->last_time = data->current_time;
 	data->current_time = RTC_GetTicks();
@@ -111,9 +110,32 @@ void update_menu(Game_Data *data)
 
 	updateCamera(&(data->cam), data->current_time - data->last_time);
 }
-void update_game_over(Game_Data *data)
+void update_menu(Game_Data *data)
 {
-// TODO
+//WARNING: THIS IS JUST PLACEHOLDER TO TEST THE GRAPHICS (too lazy to do some real level handling right now...)
+        data->last_time = data->current_time;//updating the time variables
+        data->current_time = RTC_GetTicks();
+
+	if(data->keypress_delay == 0) //to make sure that the user isn't scrolling too fast
+	{
+		if(KeyDown(K_EXE)) //load the selected level
+			switch_to_state(GAME, data);//TODO: change some values in data first
+		else if(KeyDown(K_LEFT))
+		{
+			data->current_entry --;//change the selected id
+			if(data->current_entry == 0)//check for overflows
+				data->current_entry = 6;
+			data->keypress_delay = 15;//init the delay
+			//TODO: load high score data and stuff, probably not at run time, but in init_states
+		}else if(KeyDown(K_RIGHT))
+		{
+			data->current_entry ++;
+			if(data->current_entry == 7)
+				data->current_entry = 1;
+			data->keypress_delay = 15;
+		}
+	}else data->keypress_delay --;
+	updateCamera(&(data->cam), data->current_time - data->last_time);//update the camera for the background
 }
 
 void updateCamera(Camera *cam, unsigned int delta_time){