struct.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 struct Camera Camera;
  16. typedef struct Wall Wall;
  17. typedef struct Line Line;
  18. typedef struct Level Level;
  19. typedef struct Line_Transition Line_Transition;
  20. typedef struct Game_Data Game_Data;
  21. typedef struct Pattern Pattern;
  22. typedef enum {GAME, MENU, TITLE, GAME_OVER} State;
  23. struct Level{
  24. int id; //1 to 6
  25. //for the level generation
  26. Pattern* patterns;
  27. int nb_patterns;
  28. // Rotation spped. Different levels have different speed.
  29. // Just compare Hexagon and Hexagonest in the original game
  30. float player_rotation_speed;
  31. //for the camera rotation
  32. int cam_change_interval; //5 seconds most of the time, but who knows...
  33. int cam_change_precision; //to add a bit of randomness to the intervals
  34. float cam_change_probability; //sometimes, there can be no change at all
  35. //camera speed
  36. float cam_max_speed;
  37. float cam_min_speed;
  38. 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
  39. //for the line number changes (lc prefix):
  40. int lc_min_score; //minimum score in seconds to reach before any line number change occurs
  41. float lc_probability;
  42. int lc_duration;
  43. };
  44. //the camera is defined by its center
  45. // ! and not by its upper left corner !
  46. //and an angle
  47. struct Camera{
  48. int cX;
  49. int cY;
  50. unsigned int angle;
  51. float zoom;
  52. float speed;
  53. };
  54. //a simple obstacle structure
  55. //d is the distance from the lowest face of the trapeze to the center of the screen
  56. //h is the thickness of the wall
  57. //line indicates the line that contains this obstacle
  58. //id is self explanatory
  59. //nxt is used by the linked list
  60. struct Wall{
  61. float d;
  62. unsigned int h;
  63. unsigned int id;
  64. unsigned int line;
  65. Wall *nxt;
  66. };
  67. struct Line_Transition{
  68. unsigned int counter;
  69. unsigned int counter_start;
  70. int delta_nb_lines;
  71. };
  72. struct Game_Data{
  73. unsigned int start_time;
  74. unsigned int last_time;
  75. unsigned int current_time;
  76. float chrono_time;
  77. int player_angle;
  78. unsigned int nb_lines;
  79. Line_Transition line_transition;
  80. Wall *list;
  81. unsigned char are_colors_reversed;
  82. Level *level;
  83. Camera cam;
  84. unsigned char shift_latch_value;
  85. unsigned char alpha_latch_value;
  86. unsigned short cooldown_timer;
  87. };
  88. struct Pattern{
  89. unsigned char length;
  90. unsigned char cooldown;
  91. // Should be dynamically allocated
  92. unsigned char* side;
  93. unsigned short* distance;
  94. unsigned short* wall_length;
  95. };
  96. #endif