struct.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #ifndef STRUCT_H
  2. #define STRUCT_H
  3. #include "stdlib.h"
  4. //constants
  5. #define FPS 20
  6. #define FRAME_TIME 1/FPS
  7. #define PI 3.14159265
  8. #define SIN_60 0.866025404
  9. #define COS_60 0.5
  10. #define true 1
  11. #define false 0
  12. #define bool unsigned char
  13. //macros
  14. #define abs(x) x>0 ? x : -x
  15. typedef enum {PATTERN} Pattern_Enum;
  16. typedef struct Camera Camera;
  17. typedef struct Wall Wall;
  18. typedef struct Line Line;
  19. typedef struct Level Level;
  20. typedef struct Line_Transition Line_Transition;
  21. typedef struct Game_Data Game_Data;
  22. typedef enum {GAME, MENU, TITLE, GAME_OVER} State;
  23. struct Level{
  24. //for the level generation
  25. Pattern_Enum available_patterns[32][32];
  26. int nb_patterns;
  27. //for the camera rotation
  28. int change_interval; //5 seconds most of the time, but who knows...
  29. int change_precision; //to add a bit of randomness to the intervals
  30. float change_probability; //sometimes, there can be no change at all
  31. float max_speed;
  32. float min_speed;
  33. float fast_spin_probability; //very low, there sometimes is a slightly faster spin for one second, then a normal spin. This is the number that allow us to generate it
  34. };
  35. //the camera is defined by its center
  36. // ! and not by its upper left corner !
  37. //and an angle
  38. struct Camera{
  39. int cX;
  40. int cY;
  41. unsigned int angle;
  42. float zoom;
  43. float speed;
  44. };
  45. //a simple obstacle structure
  46. //d is the distance from the lowest face of the trapeze to the center of the screen
  47. //h is the thickness of the wall
  48. //line indicates the line that contains this obstacle
  49. //id is self explanatory
  50. //nxt is used by the linked list
  51. struct Wall{
  52. float d;
  53. unsigned int h;
  54. unsigned int id;
  55. unsigned int line;
  56. Wall *nxt;
  57. };
  58. struct Line_Transition{
  59. unsigned int counter;
  60. unsigned int counter_start;
  61. int delta_nb_lines;
  62. };
  63. struct Game_Data{
  64. unsigned int start_time;
  65. unsigned int last_time;
  66. unsigned int current_time;
  67. unsigned int player_angle;
  68. unsigned int nb_lines;
  69. Line_Transition line_transition;
  70. Wall *list;
  71. Level *level;
  72. Camera cam;
  73. };
  74. #endif