2D Run-and-gun shooter inspired by One Man's Doomsday, Counter-Strike, and Metal Slug.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

131 lines
3.5 KiB

  1. #include "IZ_app_video.h"
  2. void IZ_VideoUpdateForDebugTicks(IZ_VideoState* video_state, uint64_t ticks) {
  3. SDL_SetRenderDrawColor(video_state->renderer, 0x00, 0xff, 0xff, 0xff);
  4. u64 the_ticks = ticks;
  5. u8 column;
  6. u8 row;
  7. const u8 size = 4;
  8. u8 bit_index;
  9. for (bit_index = 0; bit_index < 64; bit_index += 1) {
  10. column = bit_index % 32;
  11. row = bit_index / 32;
  12. if (the_ticks & 0x1) {
  13. SDL_RenderFillRectF(video_state->renderer, &(SDL_FRect) {
  14. (f32) (video_state->config.width - ((column + 1) * size)),
  15. (f32) (video_state->config.height - ((row + 1) * size)),
  16. size,
  17. size
  18. });
  19. }
  20. the_ticks >>= 1;
  21. }
  22. }
  23. void IZ_VideoUpdateForDebugInput(IZ_VideoState* video_state, IZ_InputState* input_state) {
  24. SDL_SetRenderDrawColor(video_state->renderer, 0xff, 0xff, 0x00, 0xff);
  25. const u8 size = 4;
  26. u8 column;
  27. u8 row;
  28. u8 player_index;
  29. u8 control_index;
  30. for (player_index = 0; player_index < IZ_PLAYERS; player_index += 1) {
  31. IZ_Action the_action = input_state->action[player_index];
  32. for (control_index = 0; control_index < CONTROLS; control_index += 1) {
  33. column = (control_index % 4) + (player_index * 4);
  34. row = control_index / 4;
  35. if (the_action & 0x1) {
  36. SDL_RenderFillRectF(video_state->renderer, &(SDL_FRect) {
  37. (f32) (column * size),
  38. (f32) (row * size),
  39. size,
  40. size
  41. });
  42. }
  43. the_action >>= 1;
  44. }
  45. }
  46. }
  47. void IZ_VideoUpdateForDebugNet(IZ_VideoState* video_state, IZ_NetClientState* net_state) {
  48. const u8 size = 4;
  49. switch (net_state->status) {
  50. default:
  51. return;
  52. case IZ_NET_CLIENT_STATUS_ERROR:
  53. SDL_SetRenderDrawColor(video_state->renderer, 0xff, 0x00, 0x00, 0xff);
  54. break;
  55. case IZ_NET_CLIENT_STATUS_CONNECTING:
  56. SDL_SetRenderDrawColor(video_state->renderer, 0xff, 0xff, 0x00, 0xff);
  57. break;
  58. case IZ_NET_CLIENT_STATUS_CONNECTED:
  59. SDL_SetRenderDrawColor(video_state->renderer, 0x00, 0xff, 0x00, 0xff);
  60. break;
  61. }
  62. SDL_RenderFillRectF(video_state->renderer, &(SDL_FRect) {
  63. 0,
  64. (f32) (video_state->config.height - size),
  65. size,
  66. size,
  67. });
  68. if (!net_state->binding.connection) {
  69. return;
  70. }
  71. u8 column;
  72. u8 row;
  73. u8 player_index;
  74. u8 control_index;
  75. for (player_index = 0; player_index < IZ_PLAYERS; player_index += 1) {
  76. IZ_Action the_action = net_state->action[player_index];
  77. for (control_index = 0; control_index < CONTROLS; control_index += 1) {
  78. column = (control_index % 4) + (player_index * 4);
  79. row = control_index / 4;
  80. if (the_action & 0x1) {
  81. SDL_RenderFillRectF(video_state->renderer, &(SDL_FRect) {
  82. (f32) (column * size),
  83. (f32) ((row * size) + (video_state->config.height - (size * 5))),
  84. size,
  85. size
  86. });
  87. }
  88. the_action >>= 1;
  89. }
  90. }
  91. }
  92. void IZ_VideoUpdate(IZ_VideoState* video_state) {
  93. struct IZ_App* app = video_state->user_data;
  94. u64 ticks = IZ_AppGetTicks(app);
  95. IZ_InputState* input_state = IZ_AppGetInputState(app);
  96. IZ_NetClientState* net_state = IZ_AppGetNetState(app);
  97. if (ticks - video_state->last_update_at > 1000 / video_state->config.max_fps) {
  98. // Update window
  99. SDL_SetRenderDrawColor(video_state->renderer, 0x00, 0x00, 0x00, 0xff);
  100. SDL_RenderClear(video_state->renderer);
  101. u8 sprite_index;
  102. for (sprite_index = 0; sprite_index < MAX_ACTIVE_SPRITES; sprite_index += 1) {
  103. if (!video_state->active_sprites[sprite_index]) {
  104. continue;
  105. }
  106. // TODO draw sprites
  107. }
  108. IZ_VideoUpdateForDebugTicks(video_state, ticks);
  109. IZ_VideoUpdateForDebugInput(video_state, input_state);
  110. IZ_VideoUpdateForDebugNet(video_state, net_state);
  111. SDL_RenderPresent(video_state->renderer);
  112. video_state->last_update_at = ticks;
  113. }
  114. }