draw_states.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. drawDiagonals(data->cam, data->nb_lines);
  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)
  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)
  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. do{
  50. tmp_angle_rad = tmp_angle * PI / 180.0f;
  51. x1 = 9.0f * cos(tmp_angle_rad);
  52. y1 = 9.0f * sin(tmp_angle_rad);
  53. x2 = 64.0f * cos(tmp_angle_rad);
  54. y2 = 64.0f * sin(tmp_angle_rad);
  55. ML_line(x1 + cam.cX, y1 + cam.cY, x2 + cam.cX, y2 + cam.cY, BLACK);
  56. tmp_angle += (360 / nb_lines);
  57. if(tmp_angle >= 360)tmp_angle = tmp_angle - 359;
  58. i++;
  59. }while(i < nb_lines);
  60. }