struct.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 {PATTERN1, PATTERN2, PATTERN3, END_PATTERNS} 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 struct Pattern_Stage Pattern_Stage;
  23. typedef enum {GAME, MENU, TITLE, GAME_OVER} State;
  24. typedef struct Pattern Pattern;
  25. struct Pattern_Stage{
  26. bool walls[6];
  27. };
  28. struct Pattern{
  29. Pattern_Stage *stages;
  30. int num_stages;
  31. int nb_lines; //so that we don't load a 5-lines pattern when we have 6 lines to fill
  32. float prob; //some patterns are more common than some others
  33. };
  34. struct Level{
  35. int id; //1 to 6
  36. //for the level generation
  37. Pattern_Enum available_patterns[32];
  38. int nb_patterns;
  39. //for the camera rotation
  40. int cam_change_interval; //5 seconds most of the time, but who knows...
  41. int cam_change_precision; //to add a bit of randomness to the intervals
  42. float cam_change_probability; //sometimes, there can be no change at all
  43. //camera speed
  44. float cam_max_speed;
  45. float cam_min_speed;
  46. 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
  47. //for the line number changes (lc prefix):
  48. int lc_min_score; //minimum score in seconds to reach before any line number change occurs
  49. float lc_probability;
  50. int lc_duration;
  51. };
  52. //the camera is defined by its center
  53. // ! and not by its upper left corner !
  54. //and an angle
  55. struct Camera{
  56. int cX;
  57. int cY;
  58. unsigned int angle;
  59. float zoom;
  60. float speed;
  61. };
  62. //a simple obstacle structure
  63. //d is the distance from the lowest face of the trapeze to the center of the screen
  64. //h is the thickness of the wall
  65. //line indicates the line that contains this obstacle
  66. //id is self explanatory
  67. //nxt is used by the linked list
  68. struct Wall{
  69. float d;
  70. unsigned int h;
  71. unsigned int id;
  72. unsigned int line;
  73. Wall *nxt;
  74. };
  75. struct Line_Transition{
  76. unsigned int counter;
  77. unsigned int counter_start;
  78. int delta_nb_lines;
  79. };
  80. struct Game_Data{
  81. //Main game data
  82. unsigned int start_time;
  83. unsigned int last_time;
  84. unsigned int current_time;
  85. unsigned int player_angle;
  86. unsigned int nb_lines;
  87. Line_Transition line_transition;
  88. Wall *list;
  89. Level *level;
  90. Camera cam;
  91. //Start menu data
  92. unsigned int nb_entries;
  93. unsigned int current_entry; //from 1 to 6
  94. unsigned int current_entry_high_score;
  95. char **entry_difficulties; //a table of null-terminated strings
  96. unsigned int keypress_delay;
  97. Pattern patterns[END_PATTERNS];
  98. };
  99. #endif