NoahJosephHall

Saturn Homebrew Menu v0.2

Dec 21st, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 8.01 KB | None | 0 0
  1. #include <jo/jo.h>
  2.  
  3. #define LEV_ID      (0)
  4. #define HITBOX_POS_X        (JO_TV_WIDTH_2)
  5. #define HITBOX_POS_Y        (JO_TV_HEIGHT_2)
  6. #define HITBOX_WIDTH        (32)
  7. #define HITBOX_HEIGHT       (32)
  8.  
  9. int selection = 0;
  10. int selections = 6;
  11.  
  12. int mode = 0;
  13.  
  14. int animspeed = 3;
  15.  
  16. float sscale = 1;
  17. int rot = 0;
  18.  
  19. static int map_pos_x = 0;
  20. static int map_pos_y = -160;
  21. static int hitbox_sprite_id;
  22.  
  23. bool togtil = true;
  24. bool togpar = true;
  25.  
  26. /*static int walk_width = 48;
  27. static int walk_height = 48;*/
  28.  
  29. static int walk_id = 0;
  30.  
  31. static const jo_tile SonicWalk[] =
  32. {
  33.     {48 * 0, 0, 48, 48},
  34.     {48 * 1, 0, 48, 48},
  35.     {48 * 2, 0, 48, 48},
  36.     {48 * 3, 0, 48, 48},
  37.     {48 * 4, 0, 48, 48},
  38.     {48 * 5, 0, 48, 48},
  39.     {48 * 6, 0, 48, 48},   
  40.     {48 * 7, 0, 48, 48},
  41.     {48 * 8, 0, 48, 48},
  42.     {48 * 9, 0, 48, 48},
  43.     {48 * 10, 0, 48, 48},
  44.     {48 * 11, 0, 48, 48},
  45. };
  46.  
  47. static const items[] =
  48. {
  49.     {"Input Test"},
  50.     {"Animation Demo"},
  51.     {"Scaling and Rotation"},
  52.     {"Parallax & Collision"},
  53.     {"Mode 7"},
  54.     {"Sounds"},
  55.     {"Input-based Animation (Timeline)"},
  56.     {"Saturn Sonic (Unavailable)"},
  57. };
  58.  
  59. void menu(void)
  60. {
  61.     if(mode == 0){
  62.        
  63.     //If UP? Erase cursor -> Handle Overflow
  64.     if(jo_is_pad1_key_down(JO_KEY_UP)){
  65.         jo_printf(1, selection + 3, " ");
  66.         if(selection == 0){
  67.             selection = selections;
  68.         } else{
  69.             selection--;
  70.         }
  71.         draw();
  72.     }
  73.    
  74.     //If DOWN? Erase cursor -> Handle Overflow
  75.     if(jo_is_pad1_key_down(JO_KEY_DOWN)){
  76.         jo_printf(1, selection + 3, " ");
  77.         if(selection == selections){
  78.             selection = 0;
  79.         } else{
  80.             selection++;
  81.         }
  82.         draw();
  83.     }
  84.    
  85.     if(jo_is_pad1_key_down(JO_KEY_A)){
  86.         if(selection == 0){
  87.             mode = 1;
  88.         }
  89.         if(selection == 1){
  90.             mode = 2;
  91.         }
  92.         if(selection == 2){
  93.             mode = 3;
  94.         }
  95.         if(selection == 3){
  96.             mode = 4;
  97.             draw();
  98.         }
  99.         if(selection == 4){
  100.             mode = 5;
  101.         }
  102.         if(selection == 5){
  103.             mode = 6;
  104.         }
  105.         if(selection == 6){
  106.             mode = 7;
  107.         }
  108.         if(selection == 7){
  109.             mode = 8;
  110.         }
  111.     }
  112.    
  113.     }
  114.    
  115.     //Input
  116.     if(mode == 1){
  117.         jo_clear_screen();
  118.         input();
  119.     }
  120.    
  121.     //Sprite Animation
  122.     if(mode == 2){
  123.         jo_clear_screen();
  124.         animation();
  125.     }
  126.    
  127.     //Scale/Rotation
  128.     if(mode == 3){
  129.         jo_clear_screen();
  130.         scalerot();
  131.     }
  132.    
  133.     //Tiles and Parallax
  134.     if(mode == 4){
  135.         jo_map_draw(LEV_ID, map_pos_x, map_pos_y);
  136.         parallax();
  137.     }
  138. }
  139.  
  140. void    draw(void)
  141. {
  142.     if(mode == 0){
  143.    
  144.     jo_clear_background(JO_COLOR_Black);
  145.    
  146.     jo_clear_screen();
  147.    
  148.     //Main
  149.     jo_printf(1, 1, "Saturn Sonic V.0.0.0.0.1");
  150.    
  151.     //Cursor
  152.     jo_printf(1, selection + 3, ">");
  153.    
  154.     //Display items
  155.     jo_printf(2, 3, items[0]);
  156.     jo_printf(2, 3 + 1, items[1]);
  157.     jo_printf(2, 3 + 2, items[2]);
  158.     jo_printf(2, 3 + 3, items[3]);
  159.     jo_printf(2, 3 + 4, items[4]);
  160.     jo_printf(2, 3 + 5, items[5]);
  161.     jo_printf(2, 3 + 6, items[6]);
  162.     jo_printf(2, 3 + 7, items[7]);
  163.     }
  164.    
  165.     if(mode == 1){
  166.         //NULL
  167.     }
  168.    
  169.     if(mode == 2){
  170.         sonic_setup();
  171.     }
  172.    
  173.     if(mode == 3){
  174.         sonic_setup();
  175.     }
  176.    
  177.     if(mode == 4){
  178.         map_load();
  179.     }
  180.    
  181. }
  182.  
  183. void    input(void)
  184. {
  185.     if (!jo_is_pad1_available()){
  186.         return;
  187.     }
  188.    
  189.     jo_clear_background(JO_COLOR_SemiBlue);
  190.    
  191.     jo_printf(1, 1, "Hold A, B, and C to return");
  192.    
  193.     //Inputs
  194.     jo_printf(30, 1, "INPUTS:");
  195.     jo_printf(30, 3, "A:");
  196.     jo_printf(30, 5, "B:");
  197.     jo_printf(30, 7, "C:");
  198.     jo_printf(30, 9, "L:");
  199.     jo_printf(30, 11, "R:");
  200.     jo_printf(30, 13, "U:");
  201.     jo_printf(30, 15, "D:");
  202.     jo_printf(30, 17, "<:");
  203.     jo_printf(30, 19, ">:");
  204.    
  205.     if(jo_is_pad1_key_pressed(JO_KEY_A) && jo_is_pad1_key_pressed(JO_KEY_B) && jo_is_pad1_key_pressed(JO_KEY_C)){
  206.         back();
  207.         return;
  208.     }
  209.        
  210.     //A
  211.     if(jo_is_pad1_key_pressed(JO_KEY_A)){
  212.         jo_printf(32, 3, "TRUE ");
  213.     }
  214.     if(!jo_is_pad1_key_pressed(JO_KEY_A)){
  215.         jo_printf(32, 3, "FALSE");
  216.     }
  217.    
  218.     //B
  219.     if(jo_is_pad1_key_pressed(JO_KEY_B)){
  220.         jo_printf(32, 5, "TRUE ");
  221.     }
  222.     if(!jo_is_pad1_key_pressed(JO_KEY_B)){
  223.         jo_printf(32, 5, "FALSE");
  224.     }
  225.    
  226.     //C
  227.     if(jo_is_pad1_key_pressed(JO_KEY_C)){
  228.         jo_printf(32, 7, "TRUE ");
  229.     }
  230.     if(!jo_is_pad1_key_pressed(JO_KEY_C)){
  231.         jo_printf(32, 7, "FALSE");
  232.     }
  233.    
  234.     //L
  235.     if(jo_is_pad1_key_pressed(JO_KEY_L)){
  236.         jo_printf(32, 9, "TRUE ");
  237.     }
  238.     if(!jo_is_pad1_key_pressed(JO_KEY_L)){
  239.         jo_printf(32, 9, "FALSE");
  240.     }
  241.    
  242.     //R
  243.     if(jo_is_pad1_key_pressed(JO_KEY_R)){
  244.         jo_printf(32, 11, "TRUE ");
  245.     }
  246.     if(!jo_is_pad1_key_pressed(JO_KEY_R)){
  247.         jo_printf(32, 11, "FALSE");
  248.     }
  249.    
  250.     //UP
  251.     if(jo_is_pad1_key_pressed(JO_KEY_UP)){
  252.         jo_printf(32, 13, "TRUE ");
  253.         draw();
  254.     }
  255.     if(!jo_is_pad1_key_pressed(JO_KEY_UP)){
  256.         jo_printf(32, 13, "FALSE");
  257.     }
  258.    
  259.     //DOWN
  260.     if(jo_is_pad1_key_pressed(JO_KEY_DOWN)){
  261.         jo_printf(32, 15, "TRUE ");
  262.         draw();
  263.     }
  264.     if(!jo_is_pad1_key_pressed(JO_KEY_DOWN)){
  265.         jo_printf(32, 15, "FALSE");
  266.     }
  267.    
  268.     //LEFT 
  269.     if(jo_is_pad1_key_pressed(JO_KEY_LEFT)){
  270.         jo_printf(32, 17, "TRUE ");
  271.     }
  272.     if(!jo_is_pad1_key_pressed(JO_KEY_LEFT)){
  273.         jo_printf(32, 17, "FALSE");
  274.     }
  275.    
  276.     //RIGHT
  277.     if(jo_is_pad1_key_pressed(JO_KEY_RIGHT)){
  278.         jo_printf(32, 19, "TRUE ");
  279.     }
  280.     if(!jo_is_pad1_key_pressed(JO_KEY_RIGHT)){
  281.         jo_printf(32, 19, "FALSE");
  282.     }
  283.    
  284.    
  285. }
  286.  
  287. void    animation(void)
  288. {
  289.    
  290.     jo_clear_background(JO_COLOR_SemiPurple);
  291.  
  292.     jo_printf(1, 1, "Animation Demo");
  293.     jo_printf(1, 2, "Press B to return");
  294.     jo_printf(1, 4, "<: Decrease Animation Speed");
  295.     jo_printf(1, 5, ">: Increase Animation Speed");
  296.     jo_printf(1, 20, "I'm not sure why, but");
  297.     jo_printf(1, 21, "animation framerates can only be");
  298.     jo_printf(1, 22, "displayed at whole-integer");
  299.     jo_printf(1, 23, "intervals. The difference in speeds");
  300.     jo_printf(1, 24, "will be noticeable. This can be");
  301.     jo_printf(1, 25, "fixed with timeline-based animation.");
  302.    
  303.    
  304.     jo_sprite_draw3D(jo_get_anim_sprite(walk_id), -15, -15, 490);
  305.    
  306.     jo_set_sprite_anim_frame_rate(walk_id, animspeed);
  307.    
  308.     if(animspeed < 0){
  309.         animspeed = 0;
  310.     }
  311.    
  312.     if(jo_is_pad1_key_down(JO_KEY_RIGHT)){
  313.         animspeed--;
  314.     }
  315.     if(jo_is_pad1_key_down(JO_KEY_LEFT)){
  316.         animspeed++;
  317.     }
  318.    
  319.     if(jo_is_pad1_key_pressed(JO_KEY_B)){
  320.         back();
  321.         return;
  322.     }
  323.        
  324. }
  325.  
  326. void scalerot(void)
  327. {
  328.     jo_clear_background(JO_COLOR_SemiGreen);
  329.    
  330.     jo_printf(1, 1, "Scale and Rotation Demo");
  331.     jo_printf(1, 2, "Press B to return");
  332.     jo_printf(1, 4, "</>: Rotate Left/Right");
  333.     jo_printf(1, 5, "U/D: Inc/Dec Scale");
  334.     jo_printf(1, 7, "A: Reset");
  335.    
  336.     jo_sprite_draw3D_and_rotate(jo_get_anim_sprite(walk_id), -15, -15, 490, rot);
  337.     jo_set_sprite_anim_frame_rate(walk_id, 3);
  338.     jo_sprite_change_sprite_scale(sscale);
  339.    
  340.     if(jo_is_pad1_key_pressed(JO_KEY_RIGHT)){
  341.             rot--;
  342.     }
  343.     if(jo_is_pad1_key_pressed(JO_KEY_LEFT)){
  344.             rot++;
  345.     }
  346.     if(jo_is_pad1_key_pressed(JO_KEY_DOWN)){
  347.             sscale-=0.02;
  348.     }
  349.     if(jo_is_pad1_key_pressed(JO_KEY_UP)){
  350.             sscale+=0.02;
  351.     }
  352.    
  353.     if(jo_is_pad1_key_pressed(JO_KEY_A)){
  354.             sscale = 1;
  355.             rot = 0;
  356.     }
  357.    
  358.     if(jo_is_pad1_key_pressed(JO_KEY_B)){
  359.         back();
  360.         return;
  361.     }
  362. }
  363.  
  364. void    parallax(void)
  365. {  
  366.     jo_clear_background(JO_COLOR_DarkRed);
  367.    
  368.     jo_clear_screen();
  369.    
  370.     jo_printf(1, 1, "Tiles, Parallax, & Sprite Collision");
  371.     jo_printf(1, 2, "Press B to return");
  372.     jo_printf(1, 4, "(Just tiles for now.");
  373.     jo_printf(1, 5, "Parallax comes tomorrow.)");
  374.    
  375.     if (!jo_is_pad1_available())
  376.         return ;
  377.     if (jo_is_pad1_key_pressed(JO_KEY_LEFT))
  378.         map_pos_x -= 2;
  379.     if (jo_is_pad1_key_pressed(JO_KEY_RIGHT))
  380.         map_pos_x += 2;
  381.     if (jo_is_pad1_key_pressed(JO_KEY_UP))
  382.         map_pos_y -= 2;
  383.     if (jo_is_pad1_key_pressed(JO_KEY_DOWN))
  384.         map_pos_y += 2;
  385.    
  386.     if(jo_is_pad1_key_pressed(JO_KEY_B)){
  387.         back();
  388.         return;
  389.     }
  390.  
  391.        
  392. }
  393.  
  394. void    back(void)
  395. {
  396.     mode = 0;
  397.     menu();
  398.     draw();
  399. }
  400.  
  401. void    sonic_setup(void)
  402. {
  403.     int sprite_id = jo_sprite_add_bin_tileset("SONIC", "WALK.BIN", JO_COLOR_Green, SonicWalk, JO_TILE_COUNT(SonicWalk));   
  404.     walk_id = jo_create_sprite_anim(sprite_id, JO_TILE_COUNT(SonicWalk), animspeed);
  405.     jo_start_sprite_anim_loop(walk_id);
  406. }
  407.  
  408. void    map_load(void)
  409. {
  410.     jo_map_load_from_file(LEV_ID, 450, "LEV", "LEV.MAP");
  411.    
  412.     jo_sprite_add_image_pack("BLK", "BLK.TEX", JO_COLOR_Red);
  413. }
  414.  
  415. void    jo_main(void)
  416. {
  417.     jo_core_init(JO_COLOR_Black);
  418.     draw();
  419.     map_load();
  420.     jo_core_add_callback(menu);
  421.     sonic_setup();
  422.     jo_core_run();
  423. }
  424.  
  425. /*
  426. ** END OF FILE
  427. */
Advertisement
Add Comment
Please, Sign In to add comment