暂无描述

cutscene_meteor.c 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. #include "cutscene_meteor.h"
  2. #define CLOUD_THROTTLE 4
  3. #define PALETTE_BG 0
  4. #define PALETTE_SKY 1
  5. #define PALETTE_CLOUD 2
  6. #define PALETTE_FG 3
  7. #define TAG_METEOR 0x2000
  8. struct meteor_memory{
  9. void* bg_gfx;
  10. void* bg_map;
  11. void* sky_gfx;
  12. void* sky_map;
  13. void* cloud_gfx;
  14. void* cloud_map;
  15. void* fg_gfx;
  16. void* fg_map;
  17. u8 animate_clouds;
  18. u8 cloud_animation_state;
  19. u8 meteor_moving;
  20. u16 delay;
  21. u16 delay_end;
  22. };
  23. static struct meteor_memory* memory = (struct meteor_memory*)(0x0203FFC0);
  24. static struct sprite sprite_meteor = {0, 0x8000, 0x800, 0x0};
  25. static struct frame meteor_frames [4] = {
  26. {0, 10},
  27. {16, 10},
  28. {32, 10},
  29. {0xFFFE, 0}
  30. };
  31. static struct frame* meteor_frames_a [1] = {
  32. meteor_frames
  33. };
  34. static struct template template_meteor = {
  35. TAG_METEOR,
  36. TAG_METEOR,
  37. &sprite_meteor,
  38. meteor_frames_a,
  39. 0,
  40. (rotscale_frame **) 0x08231CFC,
  41. meteor_callback
  42. };
  43. void meteor_callback(object* self)
  44. {
  45. if(memory->meteor_moving > 0)
  46. {
  47. self->x--;
  48. self->y++;
  49. if(self->y > 130)
  50. {
  51. memory->meteor_moving = 0;
  52. m4aSongNumStart(0xAB);
  53. }
  54. }
  55. }
  56. void play_meteor()
  57. {
  58. memory->animate_clouds = 0;
  59. memory->cloud_animation_state = 0;
  60. memory-> meteor_moving = 0;
  61. superstate.multi_purpose_state_tracker = 0;
  62. vblank_handler_set(update_screen);
  63. set_callback2(cutscene);
  64. }
  65. void cutscene()
  66. {
  67. if(superstate.multi_purpose_state_tracker == 0)
  68. {
  69. fade_screen(0xFFFFFFFF, 0, 0, 0x10, 0x0000);
  70. superstate.multi_purpose_state_tracker++;
  71. }
  72. else if(superstate.multi_purpose_state_tracker == 1)
  73. {
  74. if((fade_controller.mix_color & 0x8000) == 0)
  75. {
  76. setup_vram();
  77. fade_screen(0xFFFFFFFF,0,0x10,0,0x0000);
  78. memory->delay = 60*3;
  79. memory->delay_end = 90;
  80. superstate.multi_purpose_state_tracker++;
  81. }
  82. }
  83. else if(superstate.multi_purpose_state_tracker == 2)
  84. {
  85. if((fade_controller.mix_color & 0x8000) == 0)
  86. {
  87. if(memory->delay == 0)
  88. {
  89. //tint screen
  90. fade_screen(0xE, 28,0,0x6, 0x015C);
  91. //play sound
  92. m4aSongNumStart(0x64);
  93. superstate.multi_purpose_state_tracker++;
  94. }
  95. else
  96. memory->delay--;
  97. }
  98. }
  99. else if (superstate.multi_purpose_state_tracker == 3)
  100. {
  101. superstate.multi_purpose_state_tracker++;
  102. }
  103. else if(superstate.multi_purpose_state_tracker == 4)
  104. {
  105. if((fade_controller.mix_color & 0x8000) == 0)
  106. {
  107. memory->meteor_moving = 1;
  108. superstate.multi_purpose_state_tracker++;
  109. }
  110. }
  111. else if(superstate.multi_purpose_state_tracker == 5)
  112. {
  113. if(memory->meteor_moving == 0)
  114. {
  115. superstate.multi_purpose_state_tracker++;
  116. }
  117. }
  118. else if(superstate.multi_purpose_state_tracker == 6)
  119. {
  120. if(memory->delay_end == 0)
  121. end_playback();
  122. else
  123. memory->delay_end--;
  124. }
  125. memory->cloud_animation_state++;
  126. if(memory->cloud_animation_state >= CLOUD_THROTTLE)
  127. memory->cloud_animation_state=0;
  128. }
  129. void end_playback()
  130. {
  131. set_callback2(callback_overworld);
  132. free(memory->bg_gfx);
  133. free(memory->bg_map);
  134. free(memory->fg_gfx);
  135. free(memory->fg_map);
  136. free(memory->sky_gfx);
  137. free(memory->sky_map);
  138. free(memory->cloud_gfx);
  139. free(memory->cloud_map);
  140. }
  141. void setup_scrolling()
  142. {
  143. lcd_io_set_func(0x14, 0x0);
  144. lcd_io_set_func(0x16, 0x0);
  145. lcd_io_set_func(0x18, 0x0);
  146. lcd_io_set_func(0x1A, 0x0);
  147. lcd_io_set_func(0x1C, 0x0);
  148. lcd_io_set_func(0x1E, 0x0);
  149. }
  150. void setup_palettes()
  151. {
  152. wram_decompress((void*)met_skyPal, palette_unfaded_buffer + PALETTE_SKY*32);
  153. wram_decompress((void*)met_cloudsPal, palette_unfaded_buffer + PALETTE_CLOUD*32);
  154. wram_decompress((void*)met_foregroundPal, palette_unfaded_buffer + PALETTE_FG*32);
  155. wram_decompress((void*)met_backgroundPal, palette_unfaded_buffer + PALETTE_BG*32);
  156. }
  157. void setup_vram()
  158. {
  159. gpu_tile_bg_drop_all_sets(0);
  160. gpu_tile_bg_drop_all_sets(1);
  161. gpu_tile_bg_drop_all_sets(2);
  162. gpu_tile_bg_drop_all_sets(3);
  163. bg_vram_setup(0, standard_bg, 4);
  164. gpu_bg_show(0);
  165. gpu_bg_show(1);
  166. gpu_bg_show(2);
  167. gpu_bg_show(3);
  168. gpu_sync_bg_visibility_and_mode();
  169. setup_scrolling();
  170. //copy tilesets
  171. memory->bg_gfx = malloc(0x40);
  172. wram_decompress((void*)met_backgroundTiles, memory->bg_gfx);
  173. gpu_copy_to_vram_by_bgid(0, memory->bg_gfx, 0x40, 0, 1);
  174. memory->fg_gfx = malloc(0x1180);
  175. wram_decompress((void*)met_foregroundTiles, memory->fg_gfx);
  176. gpu_copy_to_vram_by_bgid(1, memory->fg_gfx, 0x1180, 0, 1);
  177. memory->cloud_gfx = malloc(0x5E0);
  178. wram_decompress((void*)met_cloudsTiles, memory->cloud_gfx);
  179. gpu_copy_to_vram_by_bgid(2, memory->cloud_gfx, 0x5E0,0,1);
  180. memory->sky_gfx = malloc(0x7A0);
  181. wram_decompress((void*)met_skyTiles, memory->sky_gfx);
  182. gpu_copy_to_vram_by_bgid(3, memory->sky_gfx,0x7A0,0,1);
  183. //copy tilemaps
  184. memory->bg_map = malloc(0x500);
  185. wram_decompress((void*)met_backgroundMap, memory->bg_map);
  186. gpu_copy_to_vram_by_bgid(0, memory->bg_map,0x500,0,2);
  187. memory->fg_map = malloc(0x500);
  188. wram_decompress((void*)met_foregroundMap, memory->fg_map);
  189. gpu_copy_to_vram_by_bgid(1, memory->fg_map,0x500,0,2);
  190. memory->cloud_map = malloc(0x500);
  191. wram_decompress((void*)met_cloudsMap, memory->cloud_map);
  192. gpu_copy_to_vram_by_bgid(2, memory->cloud_map,0x500,0,2);
  193. memory->sky_map = malloc(0x500);
  194. wram_decompress((void*)met_skyMap, memory->sky_map);
  195. gpu_copy_to_vram_by_bgid(3, memory->sky_map,0x500,0,2);
  196. //copy palettes
  197. //pal_decompress_slice_to_faded_and_unfaded((void*)met_skyPal, 16, 32);
  198. //pal_decompress_slice_to_faded_and_unfaded((void*)met_foregroundPal, 48, 32);
  199. //pal_decompress_slice_to_faded_and_unfaded((void*)met_cloudsPal, 32, 32);
  200. setup_palettes();
  201. //setup oam
  202. obj_delete_all();
  203. resource gfx_meteor = {(void*)met_meteorTiles, 0x1C00, TAG_METEOR};
  204. resource pal_meteor = {(void*)met_meteorPal, TAG_METEOR};
  205. gpu_pal_obj_alloc_tag_and_apply(&pal_meteor);
  206. gpu_tile_obj_decompress_alloc_tag_and_upload(&gfx_meteor);
  207. u8 meteor_id = template_instanciate_forward_search(&template_meteor, 0, 100, 1);
  208. objects[meteor_id].x = 200;
  209. objects[meteor_id].y = 0;
  210. memory->animate_clouds = 1;
  211. }
  212. void update_screen()
  213. {
  214. fade_update();
  215. task_exec();
  216. objc_exec();
  217. obj_sync();
  218. gpu_pal_upload();
  219. gpu_sprites_upload();
  220. if(memory->cloud_animation_state == 0 && memory->animate_clouds != 0)
  221. {
  222. u16 sky_h = lcd_io_get(0x18);
  223. lcd_io_set_func(0x18, sky_h + 1);
  224. }
  225. }