draw_states.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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);
  6. drawDiagonal(1, data->cam);
  7. drawDiagonal(2, data->cam);
  8. drawDiagonal(3, data->cam);
  9. //showing the walls
  10. if(data->list != NULL)
  11. drawWalls(data->list, &(data->cam));
  12. }
  13. void draw_title(Game_Data *data)
  14. {
  15. }
  16. void draw_menu(Game_Data *data)
  17. {
  18. }
  19. void draw_game_over(Game_Data *data)
  20. {
  21. }
  22. //draws the player
  23. //at first, was supposed to draw an hexagon in the center, plus a triangle to show the player,
  24. //but the hexagon was not visible, and it was a pixel mess, so we're showing a circle instead.
  25. //there is still for code to calculate the vertices of the hexagon, in case we want to change that again
  26. void drawPlayer(Camera *cam, int player_angle, int nb_lines)
  27. {
  28. int x[6];
  29. int y[6];
  30. int i = 0;
  31. int angle = 0;
  32. for(i = 0; i<6; ++i)
  33. {
  34. angle = i * 360 / nb_lines;
  35. x[i] = (8. + cam->zoom)*cos(PI * (angle + cam->angle)/180.) + cam->cX;
  36. y[i] = (8. + cam->zoom)*sin(PI * (angle + cam->angle)/180.) + cam->cY;
  37. }
  38. //draw the aforementionned circle, depending on the camera's center
  39. //ML_filled_circle(cam.cX, cam.cY, 6, BLACK);
  40. ML_polygone(x, y, 6, BLACK);
  41. //draw the player. At such a low scale, it was impossible to draw a rotating triangle, so its a radius 1 circle instead.
  42. 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);
  43. }
  44. //draws one of the three rotating lines
  45. void drawDiagonal(int nb, Camera cam, int nb_lines)
  46. {
  47. int tmp_angle = 0;
  48. float coeff = 0;
  49. int x1 = 0, y1 = 0, x2 = 0, y2 = 0;
  50. //defining the angle between the line and the horizontal axis
  51. if(nb == 1)
  52. tmp_angle = cam.angle + 60;
  53. else if(nb == 2)
  54. tmp_angle = cam.angle;
  55. else if(nb == 3)
  56. tmp_angle = 300 + cam.angle;
  57. if(tmp_angle >= 360)tmp_angle = tmp_angle - 359;
  58. //defining the slope coefficient
  59. coeff = sin(PI*tmp_angle / 180)/cos(PI * tmp_angle / 180);
  60. //ML needs four coordinates in order to draw a line
  61. x1 = -32/coeff;
  62. y1 = -32;
  63. x2 = 32/coeff;
  64. y2 = 32;
  65. if(abs(x1) > 64){
  66. x1 = -64;
  67. y1 = -64*coeff;
  68. x2 = 64;
  69. y2 = 64*coeff;
  70. }
  71. //drawing the line
  72. ML_line(x1 + cam.cX, y1 + cam.cY, x2 + cam.cX, y2 + cam.cY, BLACK);
  73. }