game_map.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #ifndef _GAME_MAP_H_
  2. #define _GAME_MAP_H_
  3. #include "SDL2/SDL.h"
  4. /* the map
  5. * describes a horizontal array of "platforms"
  6. * each platform has a number, showing its height
  7. * currently all platforms have the same width
  8. */
  9. struct game_map {
  10. // background
  11. SDL_Texture *bg_tex;
  12. // platforms's texture and rect
  13. SDL_Texture *tex_top;
  14. SDL_Texture *tex_mid;
  15. SDL_Rect rect;
  16. // array with platforms and their width
  17. float grid[10];
  18. float grid_width;
  19. float grid_height;
  20. /* actual height of all platforms,
  21. * platforms follow that height constantly
  22. */
  23. float grid_actual[10];
  24. // water
  25. SDL_Rect water_rect;
  26. int water_delay;
  27. int water_actual;
  28. float water_speed;
  29. int offset_x;
  30. int offset_y;
  31. };
  32. /* init update and draw
  33. */
  34. void game_map_init(struct game_map*);
  35. void game_map_update(struct game_map*);
  36. void game_map_draw(struct game_map*);
  37. void game_map_draw_front(struct game_map *m);
  38. /* returns the height of the platform with a given index
  39. * returns a value out of bounds when index is -1 or >= array size
  40. */
  41. int game_map_platform_y(struct game_map*, int index);
  42. int game_map_platform_x(struct game_map*, int index);
  43. int game_map_platform_width(struct game_map *);
  44. // returns number of platforms
  45. int game_map_platform_number(struct game_map *);
  46. /* returns the index of the platform on given location
  47. * returns -1 when location is on the left of the leftmost platform
  48. * or array's max value if location is on the right of it
  49. */
  50. int game_map_platform_id(struct game_map*, int loc);
  51. // offsets the map
  52. void game_map_offset(struct game_map *, int x, int y);
  53. // control the platform's position
  54. void game_map_platform_rise(struct game_map *, int index, int amount);
  55. // get water position
  56. int game_map_water_y(struct game_map *);
  57. #endif