struct.h 2.5 KB

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