Ver código fonte

Started menu/title states

Eiyeron Fulmincendii 11 anos atrás
pai
commit
87729eeeef
7 arquivos alterados com 95 adições e 36 exclusões
  1. 20 11
      draw_states.c
  2. 1 1
      hexagon.c
  3. 29 0
      init_states.c
  4. BIN
      sprites/Title.bmp
  5. BIN
      sprites/Title.xcf
  6. 1 0
      states.c
  7. 44 24
      update_states.c

+ 20 - 11
draw_states.c

@@ -3,7 +3,8 @@
 #include "fixed.h"
 #include <stdio.h>
 // static functions
-static void drawPlayer(Camera *cam, int player_angle, int nb_lines, Line_Transition line_transition);
+static void drawPlayer(Camera *cam, int player_angle);
+static void drawPolygon(Camera *cam, int nb_lines, Line_Transition line_transition);
 static void drawDiagonals(Camera cam, int nb_lines, Line_Transition line_transition);
 static void drawHud(Game_Data *data);
 static void drawChrono(Game_Data *data);
@@ -12,7 +13,8 @@ static void drawStep(Game_Data *data);
 void draw_game(Game_Data *data)
 {
 	//draw the player and the lines
-	drawPlayer(&(data->cam), data->player_angle, data->nb_lines, data->line_transition);
+	drawPlayer(&(data->cam), data->player_angle);
+	drawPolygon(&(data->cam), data->nb_lines, data->line_transition);
 	drawDiagonals(data->cam, data->nb_lines, data->line_transition);
 	drawHud(data);
     	//showing the walls
@@ -21,10 +23,14 @@ void draw_game(Game_Data *data)
 }
 void draw_title(Game_Data *data)
 {
+	drawPolygon(&(data->cam), data->nb_lines, data->line_transition);
+	drawDiagonals(data->cam, data->nb_lines, data->line_transition);
 
 }
 void draw_menu(Game_Data *data)
 {
+	drawPolygon(&(data->cam), data->nb_lines, data->line_transition);
+	drawDiagonals(data->cam, data->nb_lines, data->line_transition);
 
 }
 void draw_game_over(Game_Data *data)
@@ -102,13 +108,8 @@ static void drawHud(Game_Data *data) {
 
 }
 
-//draws the player
-//at first, was supposed to draw an hexagon in the center, plus a triangle to show the player,
-//but the hexagon was not visible, and it was a pixel mess, so we're showing a circle instead.
-//there is still for code to calculate the vertices of the hexagon, in case we want to change that again
-static void drawPlayer(Camera *cam, int player_angle, int nb_lines, Line_Transition line_transition)
-{
-	int x[32];
+static void drawPolygon(Camera *cam, int nb_lines, Line_Transition line_transition) {
+		int x[32];
 	int y[32];
 	int i = 0;
 	int angle = 0;
@@ -156,6 +157,14 @@ static void drawPlayer(Camera *cam, int player_angle, int nb_lines, Line_Transit
 	ML_polygone(x, y, nb_lines, BLACK);
 	//draw the player. At such a low scale, it was impossible to draw a rotating triangle, so its a radius 1 circle instead.
 	// TODO : Replace it for a quick sprite blit, or unwrapped ML_pixel procedure.
+}
+
+//draws the player
+//at first, was supposed to draw an hexagon in the center, plus a triangle to show the player,
+//but the hexagon was not visible, and it was a pixel mess, so we're showing a circle instead.
+//there is still for code to calculate the vertices of the hexagon, in case we want to change that again
+static void drawPlayer(Camera *cam, int player_angle)
+{
 	ML_filled_circle((9. + cam->zoom)*cos( PI*(player_angle + cam->angle)/180) + cam->cX, (9. + cam->zoom)*sin( PI*(player_angle+cam->angle)/180) + cam->cY, 1, BLACK);
 
 }
@@ -185,8 +194,8 @@ static void drawDiagonals(Camera cam, int nb_lines, Line_Transition line_transit
 	do{
 		x1 = fmul(FIX(9) + ftofix(cam.zoom), fcos(tmp_angle));
 		y1 = fmul(FIX(9) + ftofix(cam.zoom), fsin(tmp_angle));
-		x2 = fmul(fcos(tmp_angle), FIX(64));
-		y2 = fmul(fsin(tmp_angle), FIX(64));
+		x2 = fmul(fcos(tmp_angle), FIX(128));
+		y2 = fmul(fsin(tmp_angle), FIX(128));
 		ML_line(UNFIX(x1) + cam.cX, UNFIX(y1) + cam.cY, UNFIX(x2) + cam.cX, UNFIX(y2) + cam.cY, BLACK);
 
 		i++;

+ 1 - 1
hexagon.c

@@ -17,7 +17,7 @@ int AddIn_main(int isAppli, unsigned short OptionNum)
 	//rand initialisation
     srand(RTC_GetTicks());
 
-    switch_to_state(GAME, &data);
+    switch_to_state(TITLE, &data);
 
 
     while(KeyUp(K_EXIT)){ //main loop

+ 29 - 0
init_states.c

@@ -34,6 +34,7 @@ void init_game(Game_Data *data)
 	data->cam.cY = 32;
 	data->cam.angle = 0;
 	data->cam.speed = 0.0;
+	data->cam.zoom = 0.0;
 
 	data->nb_lines = 6;
 	data->line_transition.counter = 0;
@@ -42,12 +43,40 @@ void init_game(Game_Data *data)
 }
 void init_title(Game_Data *data)
 {
+	data->start_time = RTC_GetTicks(); //1 tick == 1/128 second
+	data->last_time = 0;
+	data->current_time = RTC_GetTicks();
+	data->chrono_time = 0;
 
+	data->cam.cX = 96;
+	data->cam.cY = 32;
+	data->cam.angle = 0;
+	data->cam.speed = 1;
+	data->cam.zoom = 32;
+
+	data->nb_lines = 6;
+	data->line_transition.counter = 0;
+	data->line_transition.counter_start = 0;
+	data->line_transition.delta_nb_lines = 0;
 
 }
 void init_menu(Game_Data *data)
 {
+	data->start_time = RTC_GetTicks(); //1 tick == 1/128 second
+	data->last_time = 0;
+	data->current_time = RTC_GetTicks();
+	data->chrono_time = 0;
 
+	data->cam.cX = 64;
+	data->cam.cY = 64;
+	data->cam.angle = 0;
+	data->cam.speed = 0;
+	data->cam.zoom = 16;
+
+	data->nb_lines = 6;
+	data->line_transition.counter = 0;
+	data->line_transition.counter_start = 0;
+	data->line_transition.delta_nb_lines = 0;
 }
 void init_game_over(Game_Data *data)
 {

BIN
sprites/Title.bmp


BIN
sprites/Title.xcf


+ 1 - 0
states.c

@@ -18,6 +18,7 @@ void switch_to_state(State new_state, Game_Data *data)
 			init_game_over(data);
 		break;
 	}
+	current_state = new_state;
 }
 void update(Game_Data *data)
 {

+ 44 - 24
update_states.c

@@ -1,8 +1,18 @@
 #include "update_states.h"
+#include "fixed.h"
 
 void update_title(Game_Data *data)
 {
-//TODO
+	data->last_time = data->current_time;
+	data->current_time = RTC_GetTicks();
+	data->chrono_time += (data->current_time - data->last_time)/ 128.;
+
+	if(KeyDown(K_SHIFT)) {
+		switch_to_state(MENU, data);
+	}
+
+	updateCamera(&(data->cam), data->current_time - data->last_time);
+
 }
 
 #define min(a, b) ((a) < (b) ? (a) : (b))
@@ -13,25 +23,31 @@ void update_game(Game_Data *data)
 	data->current_time = RTC_GetTicks();
 	data->chrono_time += (data->current_time - data->last_time)/ 128.;
 
-	if(data->list != NULL){ //if the linked list is not empty
-		updateWalls(data->list, min(data->current_time - data->last_time, 2)); //update the linked list
+	if(data->list != NULL) {
+	//if the linked list is not empty
+		updateWalls(data->list, min(data->current_time - data->last_time, 2));
+		//update the linked list
 
-	if(isColliding(data->list, data->player_angle, data->nb_lines) == true){ //if the player and a wall collide
-		PrintMini(50, 0, "TOUCHE", MINI_OVER); //death handling
-	}
-	data->list = removeWall(data->list, 8); //remove every wall whose distance to the center equals zero
+		//if the player and a wall collide
+		if(isColliding(data->list, data->player_angle, data->nb_lines) == true) {
+			//death handling
+			PrintMini(50, 0, "TOUCHE", MINI_OVER);
+		}
+	//remove every wall whose distance to the center equals zero
+		data->list = removeWall(data->list, 8);
 	}
 	//level generation
 	//TODO: something else than pure randomness
-	if(rand() % 40 == 1){
+	if(rand() % 40 == 1) {
 		data->list = addWall(data->list, 128, 5, 1, rand()%data->nb_lines);
-	}else if(rand() % 70 == 1){
+	} else if(rand() % 70 == 1) {
 		int emptyRow = rand()%data->nb_lines;
 		int i = 0;
-		for(i = 0; i < data->nb_lines; i++)
+		for(i = 0; i < data->nb_lines; i++){
 			if(i != emptyRow)
 				data->list = addWall(data->list, 128, 5, 1, i);
-    }
+		}
+	}
 	if(KeyDown(K_LEFT)){
 		data->player_angle-=15;
 	}
@@ -58,17 +74,27 @@ void update_game(Game_Data *data)
 		}
 	}
 
-	while(data->player_angle < 0)
-		data->player_angle += 360;
-	while(data->player_angle > 360)
-		data->player_angle -= 360;
-		//data->player_angle = data->player_angle % 360;
+
+	data->player_angle = MOD(data->player_angle, 360);
 
 	updateCamera(&(data->cam), data->current_time - data->last_time);
 }
+
 void update_menu(Game_Data *data)
 {
-//TODO
+	data->last_time = data->current_time;
+	data->current_time = RTC_GetTicks();
+	data->chrono_time += (data->current_time - data->last_time)/ 128.;
+
+	if(KeyDown(K_SHIFT)) {
+		switch_to_state(GAME, data);
+	}
+	if(KeyDown(K_ALPHA)) {
+		switch_to_state(TITLE, data);
+	}
+
+
+	updateCamera(&(data->cam), data->current_time - data->last_time);
 }
 void update_game_over(Game_Data *data)
 {
@@ -76,15 +102,9 @@ void update_game_over(Game_Data *data)
 }
 
 void updateCamera(Camera *cam, unsigned int delta_time){
-	cam->speed = 1; //to change
 	cam->angle += cam->speed * delta_time / 2.;
 
 	if(cam->angle >= 360)
 		cam->angle = cam->angle % 360;
-	if(cam->zoom == 1)
-		cam->zoom = 3;
-	else
-		cam->zoom -= 0.5 * delta_time * FRAME_TIME;
-	if(cam->zoom < 1)
-		cam->zoom = 1;
+
 }