draw_states.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #include "draw_states.h"
  2. void draw_game(Game_Data *data)
  3. {
  4. //draw the player and the lines
  5. drawPlayer(&(data->cam), data->player_angle, data->nb_lines, data->line_transition);
  6. drawDiagonals(data->cam, data->nb_lines, data->line_transition);
  7. //showing the walls
  8. //if(data->list != NULL)
  9. // drawWalls(data->list, &(data->cam), data->nb_lines);
  10. }
  11. void draw_title(Game_Data *data)
  12. {
  13. }
  14. void draw_menu(Game_Data *data)
  15. {
  16. }
  17. void draw_game_over(Game_Data *data)
  18. {
  19. }
  20. //draws the player
  21. //at first, was supposed to draw an hexagon in the center, plus a triangle to show the player,
  22. //but the hexagon was not visible, and it was a pixel mess, so we're showing a circle instead.
  23. //there is still for code to calculate the vertices of the hexagon, in case we want to change that again
  24. void drawPlayer(Camera *cam, int player_angle, int nb_lines, Line_Transition line_transition)
  25. {
  26. int x[32];
  27. int y[32];
  28. int i = 0;
  29. int angle = 0;
  30. for(i = 0; i < nb_lines; ++i)
  31. {
  32. angle = i * 360/nb_lines;
  33. x[i] = (8. + cam->zoom)*cos(PI * (angle + cam->angle)/180.) + cam->cX;
  34. y[i] = (8. + cam->zoom)*sin(PI * (angle + cam->angle)/180.) + cam->cY;
  35. }
  36. //draw the aforementionned circle, depending on the camera's center
  37. //ML_filled_circle(cam.cX, cam.cY, 6, BLACK);
  38. ML_polygone(x, y, nb_lines, BLACK);
  39. //draw the player. At such a low scale, it was impossible to draw a rotating triangle, so its a radius 1 circle instead.
  40. 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);
  41. }
  42. //draws one of the three rotating lines
  43. void drawDiagonals(Camera cam, int nb_lines, Line_Transition line_transition)
  44. {
  45. int tmp_angle = cam.angle;
  46. float tmp_angle_rad = 0.0f;
  47. int i = 0;
  48. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  49. float delta_angle = 0.0;
  50. float coeff = 0.0;
  51. float transition_angle = 0.0;
  52. delta_angle = 360.0 / nb_lines;
  53. if(line_transition.delta_nb_lines == 1)
  54. nb_lines ++;
  55. if(line_transition.counter_start != 0)
  56. coeff = (float)line_transition.counter / (float)line_transition.counter_start;
  57. transition_angle = delta_angle * coeff;
  58. do{
  59. tmp_angle_rad = tmp_angle * PI / 180.0f;
  60. x1 = 9.0f * cos(tmp_angle_rad);
  61. y1 = 9.0f * sin(tmp_angle_rad);
  62. x2 = 64.0f * cos(tmp_angle_rad);
  63. y2 = 64.0f * sin(tmp_angle_rad);
  64. ML_line(x1 + cam.cX, y1 + cam.cY, x2 + cam.cX, y2 + cam.cY, BLACK);
  65. i++;
  66. switch(line_transition.delta_nb_lines){
  67. case 0:
  68. tmp_angle += 360/nb_lines;
  69. break;
  70. case 1:
  71. if(i < nb_lines - 1)
  72. {
  73. tmp_angle += (360 - (delta_angle - transition_angle)) / (nb_lines - 1);
  74. }else{
  75. tmp_angle += delta_angle - transition_angle;
  76. }
  77. break;
  78. case -1:
  79. if(i < nb_lines - 1)
  80. {
  81. tmp_angle += (360 - transition_angle) / (nb_lines - 1);
  82. }else{
  83. tmp_angle += transition_angle;
  84. }
  85. break;
  86. }
  87. if(tmp_angle >= 360)tmp_angle = tmp_angle - 359;
  88. }while(i < nb_lines);
  89. }