설명 없음

cutscene_meteor.c.old 9.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. /****************************************************************************
  2. * Copyright (C) 2015-2016 by the SotS Team *
  3. * *
  4. * This file is part of Sovereign of the Skies. *
  5. * *
  6. * Sovereign of the Skies is free software: you can redistribute it *
  7. * and/or modify it *
  8. * under the terms of the GNU Lesser General Public License as published *
  9. * by the Free Software Foundation, either version 3 of the License, or *
  10. * (at your option) any later version provided you include a copy of the *
  11. * licence and this header. *
  12. * *
  13. * Sovereign of the Skies is distributed in the hope that it will be *
  14. * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of *
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  16. * GNU Lesser General Public License for more details. *
  17. * *
  18. * You should have received a copy of the GNU Lesser General Public *
  19. * License along with Sovereign of the Skies. *
  20. * If not, see <http://www.gnu.org/licenses/>. *
  21. ****************************************************************************/
  22. /**
  23. * @file cutscene_meteor.c
  24. * @author Sturmvogel
  25. * @date 15 dec 2016
  26. * @brief Cutscene to play "crashing meteor"
  27. *
  28. * This source is able to play a cutscene, a meteor crashing on earth.
  29. */
  30. /* === INCLUDES === */
  31. #include <cutscene_meteor/met_background.h>
  32. #include <cutscene_meteor/met_clouds.h>
  33. #include <cutscene_meteor/met_foreground.h>
  34. #include <cutscene_meteor/met_sky.h>
  35. #include <cutscene_meteor/met_meteor.h>
  36. #include <callback.h>
  37. #include <lcd.h>
  38. #include <fade.h>
  39. #include <sound.h>
  40. #include <memory.h>
  41. /* === MACROS & DEFINES === */
  42. #define CLOUD_THROTTLE 4
  43. #define PALETTE_BG 0
  44. #define PALETTE_SKY 1
  45. #define PALETTE_CLOUD 2
  46. #define PALETTE_FG 3
  47. #define TAG_METEOR 0x2000
  48. /* === STRUCTURES === */
  49. struct meteor_memory{
  50. void* bg_gfx;
  51. void* bg_map;
  52. void* sky_gfx;
  53. void* sky_map;
  54. void* cloud_gfx;
  55. void* cloud_map;
  56. void* fg_gfx;
  57. void* fg_map;
  58. u8 animate_clouds;
  59. u8 cloud_animation_state;
  60. u8 meteor_moving;
  61. u16 delay;
  62. u16 delay_end;
  63. };
  64. /* === STATIC STRUCTURES === */
  65. static struct bg_config met_bg_config[4] = {
  66. {0, 0, 0x19, 0, 0, 0},
  67. {1, 1, 0x1A, 0, 0, 1},
  68. {2, 2, 0x1B, 0, 0, 2},
  69. {3, 3, 0x1C, 0, 0, 3}
  70. };
  71. /* === PROTOTYPES === */
  72. /**
  73. * @brief readies VRAM for our graphic setup
  74. */
  75. void met_setup_vram();
  76. /**
  77. * @brief callback for doing the actual animation
  78. */
  79. void met_cutscene_cb();
  80. /**
  81. * @brief callback to update the screen elements
  82. */
  83. void met_update_screen();
  84. /**
  85. * @brief callback for the meteor object entity
  86. * @param self pointer to the meteor object entity
  87. */
  88. void met_entity_cb(struct obj_entity* self);
  89. /**
  90. * @brief finish the animation and free memory
  91. */
  92. void met_free_end();
  93. /**
  94. * @brief disable overworld scrolling in scrolling controller
  95. */
  96. void met_setup_scrolling();
  97. /**
  98. * @brief setup palettes for cutscene environment
  99. */
  100. void met_setup_palettes();
  101. /* === STATIC ELEMENTS === */
  102. /*static memory block pointer for used structure*/
  103. static struct meteor_memory* memory = (struct meteor_memory*)(0x0203FFC0);
  104. /*oam attributes for the meteor object entity*/
  105. static struct obj_oam_attributes sprite_meteor = {0, 0x8000, 0x800, 0x0};
  106. /*frame list for the meteor object entity*/
  107. static struct obj_frame meteor_frames [4] = {
  108. {0, 10},
  109. {16, 10},
  110. {32, 10},
  111. {0xFFFE, 0}
  112. };
  113. /*pointer to the frame list*/
  114. static struct obj_frame* meteor_frames_a [1] = {
  115. meteor_frames
  116. };
  117. /*template for the meteor object entity*/
  118. static struct obj_template template_meteor = {
  119. TAG_METEOR,
  120. TAG_METEOR,
  121. &sprite_meteor,
  122. meteor_frames_a,
  123. 0,
  124. (struct obj_rotscale_frame **) 0x08231CFC,
  125. met_entity_cb
  126. };
  127. void met_entity_cb(struct obj_entity* self)
  128. {
  129. if(memory->meteor_moving > 0)
  130. {
  131. self->x--;
  132. self->y++;
  133. if(self->y > 130)
  134. {
  135. memory->meteor_moving = 0;
  136. m4aSongNumStart(0xAB);
  137. }
  138. }
  139. }
  140. void met_play()
  141. {
  142. memory->animate_clouds = 0;
  143. memory->cloud_animation_state = 0;
  144. memory-> meteor_moving = 0;
  145. superstate.multi_purpose_state_tracker = 0;
  146. vblank_handler_set(met_update_screen);
  147. set_callback2(met_cutscene_cb);
  148. }
  149. void met_cutscene_cb()
  150. {
  151. if(superstate.multi_purpose_state_tracker == 0)
  152. {
  153. fade_screen(0xFFFFFFFF, 0, 0, 0x10, 0x0000);
  154. superstate.multi_purpose_state_tracker++;
  155. }
  156. else if(superstate.multi_purpose_state_tracker == 1)
  157. {
  158. if((fade_controller.mix_color & 0x8000) == 0)
  159. {
  160. met_setup_vram();
  161. fade_screen(0xFFFFFFFF,0,0x10,0,0x0000);
  162. memory->delay = 60*3;
  163. memory->delay_end = 90;
  164. superstate.multi_purpose_state_tracker++;
  165. }
  166. }
  167. else if(superstate.multi_purpose_state_tracker == 2)
  168. {
  169. if((fade_controller.mix_color & 0x8000) == 0)
  170. {
  171. if(memory->delay == 0)
  172. {
  173. //tint screen
  174. fade_screen(0xE, 28,0,0x6, 0x015C);
  175. //play sound
  176. m4aSongNumStart(0x64);
  177. superstate.multi_purpose_state_tracker++;
  178. }
  179. else
  180. memory->delay--;
  181. }
  182. }
  183. else if (superstate.multi_purpose_state_tracker == 3)
  184. {
  185. superstate.multi_purpose_state_tracker++;
  186. }
  187. else if(superstate.multi_purpose_state_tracker == 4)
  188. {
  189. if((fade_controller.mix_color & 0x8000) == 0)
  190. {
  191. memory->meteor_moving = 1;
  192. superstate.multi_purpose_state_tracker++;
  193. }
  194. }
  195. else if(superstate.multi_purpose_state_tracker == 5)
  196. {
  197. if(memory->meteor_moving == 0)
  198. {
  199. superstate.multi_purpose_state_tracker++;
  200. }
  201. }
  202. else if(superstate.multi_purpose_state_tracker == 6)
  203. {
  204. if(memory->delay_end == 0)
  205. met_free_end();
  206. else
  207. memory->delay_end--;
  208. }
  209. memory->cloud_animation_state++;
  210. if(memory->cloud_animation_state >= CLOUD_THROTTLE)
  211. memory->cloud_animation_state=0;
  212. }
  213. void met_free_end()
  214. {
  215. set_callback2(callback_overworld);
  216. free(memory->bg_gfx);
  217. free(memory->bg_map);
  218. free(memory->fg_gfx);
  219. free(memory->fg_map);
  220. free(memory->sky_gfx);
  221. free(memory->sky_map);
  222. free(memory->cloud_gfx);
  223. free(memory->cloud_map);
  224. }
  225. void met_setup_scrolling()
  226. {
  227. lcd_io_set_func(0x14, 0x0);
  228. lcd_io_set_func(0x16, 0x0);
  229. lcd_io_set_func(0x18, 0x0);
  230. lcd_io_set_func(0x1A, 0x0);
  231. lcd_io_set_func(0x1C, 0x0);
  232. lcd_io_set_func(0x1E, 0x0);
  233. }
  234. void met_setup_palettes()
  235. {
  236. wram_decompress((void*)met_skyPal, palette_unfaded_buffer + PALETTE_SKY*16);
  237. wram_decompress((void*)met_cloudsPal, palette_unfaded_buffer + PALETTE_CLOUD*16);
  238. wram_decompress((void*)met_foregroundPal, palette_unfaded_buffer + PALETTE_FG*16);
  239. wram_decompress((void*)met_backgroundPal, palette_unfaded_buffer + PALETTE_BG*16);
  240. }
  241. void met_setup_vram()
  242. {
  243. gpu_tile_bg_drop_all_sets(0);
  244. gpu_tile_bg_drop_all_sets(1);
  245. gpu_tile_bg_drop_all_sets(2);
  246. gpu_tile_bg_drop_all_sets(3);
  247. gpu_bg_vram_setup(0, met_bg_config, 4);
  248. gpu_bg_show(0);
  249. gpu_bg_show(1);
  250. gpu_bg_show(2);
  251. gpu_bg_show(3);
  252. gpu_sync_bg_visibility_and_mode();
  253. met_setup_scrolling();
  254. //copy tilesets
  255. memory->bg_gfx = malloc(0x40);
  256. wram_decompress((void*)met_backgroundTiles, memory->bg_gfx);
  257. gpu_copy_to_vram_by_bgid(0, memory->bg_gfx, 0x40, 0, 1);
  258. memory->fg_gfx = malloc(0x1180);
  259. wram_decompress((void*)met_foregroundTiles, memory->fg_gfx);
  260. gpu_copy_to_vram_by_bgid(1, memory->fg_gfx, 0x1180, 0, 1);
  261. memory->cloud_gfx = malloc(0x5E0);
  262. wram_decompress((void*)met_cloudsTiles, memory->cloud_gfx);
  263. gpu_copy_to_vram_by_bgid(2, memory->cloud_gfx, 0x5E0,0,1);
  264. memory->sky_gfx = malloc(0x7A0);
  265. wram_decompress((void*)met_skyTiles, memory->sky_gfx);
  266. gpu_copy_to_vram_by_bgid(3, memory->sky_gfx,0x7A0,0,1);
  267. //copy tilemaps
  268. memory->bg_map = malloc(0x500);
  269. wram_decompress((void*)met_backgroundMap, memory->bg_map);
  270. gpu_copy_to_vram_by_bgid(0, memory->bg_map,0x500,0,2);
  271. memory->fg_map = malloc(0x500);
  272. wram_decompress((void*)met_foregroundMap, memory->fg_map);
  273. gpu_copy_to_vram_by_bgid(1, memory->fg_map,0x500,0,2);
  274. memory->cloud_map = malloc(0x500);
  275. wram_decompress((void*)met_cloudsMap, memory->cloud_map);
  276. gpu_copy_to_vram_by_bgid(2, memory->cloud_map,0x500,0,2);
  277. memory->sky_map = malloc(0x500);
  278. wram_decompress((void*)met_skyMap, memory->sky_map);
  279. gpu_copy_to_vram_by_bgid(3, memory->sky_map,0x500,0,2);
  280. met_setup_palettes();
  281. //setup oam
  282. obj_delete_all();
  283. struct obj_resource gfx_meteor = {(void*)met_meteorTiles, 0x1C00, TAG_METEOR};
  284. struct obj_resource pal_meteor = {(void*)met_meteorPal, TAG_METEOR};
  285. obj_gpu_pal_alloc_tag_and_apply(&pal_meteor);
  286. obj_gpu_tile_decompress_alloc_tag_and_upload(&gfx_meteor);
  287. u8 meteor_id = obj_template_instanciate_forward_search(&template_meteor, 0, 100, 1);
  288. objects[meteor_id].x = 200;
  289. objects[meteor_id].y = 0;
  290. memory->animate_clouds = 1;
  291. }
  292. void met_update_screen()
  293. {
  294. fade_update();
  295. task_exec();
  296. objc_exec();
  297. obj_sync();
  298. gpu_pal_upload();
  299. obj_gpu_sprites_upload();
  300. if(memory->cloud_animation_state == 0 && memory->animate_clouds != 0)
  301. {
  302. u16 sky_h = lcd_io_get(0x18);
  303. lcd_io_set_func(0x18, sky_h + 1);
  304. }
  305. }