Kaynağa Gözat

Started support for the start screen (initialisation and main loop modifications).

Adrien Boucaud 12 yıl önce
ebeveyn
işleme
678aec5d9b
2 değiştirilmiş dosya ile 41 ekleme ve 0 silme
  1. 34 0
      init_states.c
  2. 7 0
      struct.h

+ 34 - 0
init_states.c

@@ -44,9 +44,43 @@ void init_title(Game_Data *data)
 
 
 }
+
+
+void load_difficulty_names(char **str_list)
+{
+	char c_1[] = "Hard";
+	char c_2[] = "Harder";
+	char c_3[] = "Hardest";
+	char c_4[] = "Hardester";
+	char c_5[] = "Hardestest";
+	char c_6[] = "Hardestestest";
+
+	for(int i = 0; i < 6; i++)
+	{
+		str_list[i] = NULL;
+		str_list[i] = malloc(sizeof(char) * 24);
+		if(str_list[i] == NULL)
+			return;
+		for(int j = 0; j < 24; str_list[i][j] = 0, j++);
+	}
+	memcpy(str_list[0], c_1, sizeof(char) * strlen(c_1));
+	memcpy(str_list[1], c_2, sizeof(char) * strlen(c_2));
+	memcpy(str_list[2], c_3, sizeof(char) * strlen(c_3));
+	memcpy(str_list[3], c_4, sizeof(char) * strlen(c_4));
+	memcpy(str_list[4], c_5, sizeof(char) * strlen(c_5));
+	memcpy(str_list[5], c_6, sizeof(char) * strlen(c_6));
+}
 void init_menu(Game_Data *data)
 {
+	data->nb_entries = 6;
+	data->current_entry = 1;
+	data->current_entry_high_score = 0; //to load from a save file
 
+	data->entry_difficulties = NULL;
+	data->entry_difficulties = malloc(sizeof(char*) * 6);
+	if(data->entry_difficulties == NULL)
+		return;
+	load_difficulty_names(data->entry_difficulties);
 }
 void init_game_over(Game_Data *data)
 {

+ 7 - 0
struct.h

@@ -84,6 +84,7 @@ struct Line_Transition{
 };
 
 struct Game_Data{
+//Main game data
 	unsigned int start_time;
 	unsigned int last_time;
 	unsigned int current_time;
@@ -97,6 +98,12 @@ struct Game_Data{
 	Level *level;
 
 	Camera cam;
+
+//Start menu data
+	unsigned int nb_entries;
+	unsigned int current_entry; //from 1 to 6
+	unsigned int current_entry_high_score;
+	char **entry_difficulties; //a table of null-terminated strings
 };
 
 #endif