2D Run-and-gun shooter inspired by One Man's Doomsday, Counter-Strike, and Metal Slug.
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

158 рядки
4.3 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 < IZ_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 < IZ_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. static f32 degrees = 0;
  93. void IZ_VideoUpdate(IZ_VideoState* video_state) {
  94. struct IZ_App* app = video_state->user_data;
  95. u64 ticks = IZ_AppGetTicks(app);
  96. IZ_InputState* input_state = IZ_AppGetInputState(app);
  97. IZ_NetClientState* net_state = IZ_AppGetNetState(app);
  98. if (ticks - video_state->last_update_at > 1000 / video_state->config.max_fps) {
  99. // Update window
  100. SDL_SetRenderDrawColor(video_state->renderer, 0x00, 0x00, 0x00, 0xff);
  101. SDL_RenderClear(video_state->renderer);
  102. u16 sprite_index;
  103. for (sprite_index = 0; sprite_index < MAX_ACTIVE_SPRITES; sprite_index += 1) {
  104. if (!video_state->active_sprites[sprite_index]) {
  105. continue;
  106. }
  107. // TODO draw sprites
  108. }
  109. IZ_LoadedSprite loaded_sprite = {
  110. .texture = NULL,
  111. .original_width = 0,
  112. .original_height = 0,
  113. };
  114. IZ_VideoLoadTexture(video_state, "assets/default/weapon-servant", "sprite.svg", &loaded_sprite);
  115. if (loaded_sprite.texture) {
  116. f32 draw_width = loaded_sprite.original_width / 2;
  117. f32 draw_height = loaded_sprite.original_height / 2;
  118. SDL_RenderCopyExF(video_state->renderer, loaded_sprite.texture, NULL, &(SDL_FRect) {
  119. .x = 160,
  120. .y = 120,
  121. .w = draw_width,
  122. .h = draw_height,
  123. }, degrees++, &(SDL_FPoint) {
  124. .x = draw_width / 2,
  125. .y = draw_height / 2,
  126. }, SDL_FLIP_NONE);
  127. IZ_VideoTeardownTexture(&loaded_sprite);
  128. // our goal is to render the svg files and apply custom transforms to some SVG groups if ever.
  129. // TODO perhaps we can parse the SVG for easier transforms?
  130. }
  131. IZ_VideoUpdateForDebugTicks(video_state, ticks);
  132. IZ_VideoUpdateForDebugInput(video_state, input_state);
  133. IZ_VideoUpdateForDebugNet(video_state, net_state);
  134. SDL_RenderPresent(video_state->renderer);
  135. video_state->last_update_at = ticks;
  136. }
  137. }