draw_states.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. #include "draw_states.h"
  2. #include "fxlib.h"
  3. #include <stdio.h>
  4. // static functions
  5. static void drawPlayer(Camera *cam, int player_angle, int nb_lines, Line_Transition line_transition);
  6. static void drawDiagonals(Camera cam, int nb_lines, Line_Transition line_transition);
  7. static void drawHud(Game_Data *data);
  8. void draw_game(Game_Data *data)
  9. {
  10. //draw the player and the lines
  11. drawPlayer(&(data->cam), data->player_angle, data->nb_lines, data->line_transition);
  12. drawDiagonals(data->cam, data->nb_lines, data->line_transition);
  13. drawHud(data);
  14. //showing the walls
  15. if(data->list != NULL)
  16. drawWalls(data->list, &(data->cam), data->nb_lines, data->line_transition);
  17. }
  18. void draw_title(Game_Data *data)
  19. {
  20. }
  21. void draw_menu(Game_Data *data)
  22. {
  23. }
  24. void draw_game_over(Game_Data *data)
  25. {
  26. }
  27. static void drawHud(Game_Data *data) {
  28. unsigned char time_text[8] = "";
  29. unsigned char *step_text[6] = {
  30. "Point",
  31. "Line",
  32. "Triangle",
  33. "Square",
  34. "Pentagon",
  35. "Hexagon"
  36. };
  37. unsigned short step_time[5] = {
  38. 10,
  39. 20,
  40. 30,
  41. 45,
  42. 60
  43. };
  44. unsigned char time_hud_border[8] = {0xF0, 0xF0, 0xE0, 0xE0, 0xC0, 0xC0, 0x80, 0x80};
  45. unsigned char step_hud_border[8] ={0x1F, 0x1F, 0x0F, 0x0F, 0x07, 0x07, 0x01, 0x01};
  46. unsigned short length_of_time, length_of_time_line;
  47. unsigned short length_of_step, current_step, i;
  48. current_step = 5;
  49. for(i = 0; i < 5; i++) {
  50. if(data->chrono_time < step_time[i]) {
  51. current_step = i;
  52. break;
  53. }
  54. }
  55. sprintf(time_text, "%.2f", data->chrono_time);
  56. length_of_time = strlen(time_text);
  57. length_of_time_line = 4 * length_of_time;
  58. length_of_step = 4 * strlen(step_text[current_step]) + 1;
  59. // Little patch because the font is not fixed width and 'n' chars are annoying me.
  60. ML_vertical_line(125,0,5, BLACK);
  61. ML_vertical_line(126,0,5, BLACK);
  62. ML_vertical_line(127,0,5, BLACK);
  63. PrintMini(127 - length_of_step, 1, step_text[current_step], MINI_REV);
  64. ML_bmp_8_or(step_hud_border, 127 - length_of_step - 8, 0);
  65. ML_horizontal_line(6, 127 - length_of_step - 2, 127, BLACK);
  66. ML_horizontal_line(7, 127 - length_of_step - 2, 127, BLACK);
  67. if(data->chrono_time < 60) {
  68. PrintMini(0, 0, time_text, MINI_REV);
  69. ML_horizontal_line(6, 0, (data->chrono_time/60.) * (length_of_time_line - 2), BLACK);
  70. ML_horizontal_line(7, 0, length_of_time_line - 1, BLACK);
  71. }
  72. else {
  73. PrintMini(0, 1, time_text, MINI_REV);
  74. ML_horizontal_line(6, 0, length_of_time_line - 1, BLACK);
  75. ML_horizontal_line(7, 0, length_of_time_line - 1, BLACK);
  76. }
  77. ML_bmp_8_or(time_hud_border, length_of_time_line, 0);
  78. }
  79. //draws the player
  80. //at first, was supposed to draw an hexagon in the center, plus a triangle to show the player,
  81. //but the hexagon was not visible, and it was a pixel mess, so we're showing a circle instead.
  82. //there is still for code to calculate the vertices of the hexagon, in case we want to change that again
  83. static void drawPlayer(Camera *cam, int player_angle, int nb_lines, Line_Transition line_transition)
  84. {
  85. int x[32];
  86. int y[32];
  87. int i = 0;
  88. int angle = 0;
  89. float tmp_angle = 0.0;
  90. float transition_angle = 0.0;
  91. float delta_angle = 0.0;
  92. if(line_transition.delta_nb_lines == 1)
  93. nb_lines ++;
  94. if(line_transition.counter_start != 0)
  95. transition_angle = (360.0 / (float)nb_lines) * ((float)line_transition.counter / (float)line_transition.counter_start);
  96. delta_angle = 360.0/nb_lines;
  97. do
  98. {
  99. x[i] = (8. + cam->zoom)*cos(PI * (tmp_angle + cam->angle)/180.) + cam->cX;
  100. y[i] = (8. + cam->zoom)*sin(PI * (tmp_angle + cam->angle)/180.) + cam->cY;
  101. i++;
  102. switch(line_transition.delta_nb_lines)
  103. {
  104. case 0:
  105. tmp_angle += delta_angle;
  106. break;
  107. case 1:
  108. if(i < nb_lines)
  109. tmp_angle += (360 - (delta_angle - transition_angle)) / (nb_lines - 1);
  110. else
  111. tmp_angle += delta_angle - transition_angle;
  112. break;
  113. case -1:
  114. if(i < nb_lines)
  115. tmp_angle += (360 - transition_angle) / (nb_lines - 1);
  116. else
  117. tmp_angle = transition_angle;
  118. break;
  119. }
  120. }while(i <= nb_lines);
  121. //draw the aforementionned circle, depending on the camera's center
  122. //ML_filled_circle(cam.cX, cam.cY, 6, BLACK);
  123. ML_polygone(x, y, nb_lines, BLACK);
  124. //draw the player. At such a low scale, it was impossible to draw a rotating triangle, so its a radius 1 circle instead.
  125. 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);
  126. }
  127. //draws one of the three rotating lines
  128. static void drawDiagonals(Camera cam, int nb_lines, Line_Transition line_transition)
  129. {
  130. int tmp_angle = cam.angle;
  131. float tmp_angle_rad = 0.0f;
  132. int i = 0;
  133. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  134. float delta_angle = 0.0;
  135. float coeff = 0.0;
  136. float transition_angle = 0.0;
  137. delta_angle = 360.0 / nb_lines;
  138. if(line_transition.delta_nb_lines == 1)
  139. nb_lines ++;
  140. if(line_transition.counter_start != 0)
  141. coeff = (float)line_transition.counter / (float)line_transition.counter_start;
  142. transition_angle = delta_angle * coeff;
  143. do{
  144. tmp_angle_rad = tmp_angle * PI / 180.0f;
  145. x1 = 9.0f * cos(tmp_angle_rad);
  146. y1 = 9.0f * sin(tmp_angle_rad);
  147. x2 = 64.0f * cos(tmp_angle_rad);
  148. y2 = 64.0f * sin(tmp_angle_rad);
  149. ML_line(x1 + cam.cX, y1 + cam.cY, x2 + cam.cX, y2 + cam.cY, BLACK);
  150. i++;
  151. switch(line_transition.delta_nb_lines){
  152. case 0:
  153. tmp_angle += 360/nb_lines;
  154. break;
  155. case 1:
  156. if(i < nb_lines - 1)
  157. {
  158. tmp_angle += (360 - (delta_angle - transition_angle)) / (nb_lines - 1);
  159. }else{
  160. tmp_angle += delta_angle - transition_angle;
  161. }
  162. break;
  163. case -1:
  164. if(i < nb_lines - 1)
  165. {
  166. tmp_angle += (360 - transition_angle) / (nb_lines - 1);
  167. }else{
  168. tmp_angle += transition_angle;
  169. }
  170. break;
  171. }
  172. if(tmp_angle >= 360)tmp_angle = tmp_angle - 359;
  173. }while(i < nb_lines);
  174. }