struct.h 3.1 KB

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