Advertisement
Guest User

Untitled

a guest
Jul 6th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. /// Game Motion
  3.     var hud = obj_hud_timer
  4.     var game = obj_mgr_game
  5.  
  6.     // If death action then to the death movement and disable rest of the step code
  7.     if (action == act_death)
  8.     {
  9.         sound_stop(music_id)
  10.         image_alpha = 1 // set image to 1
  11.         angle = 0   // set the angle to 0
  12.         if play_sound[_die] == 0
  13.         {
  14.             sound_stop(all)
  15.             sound_play(SndDie)
  16.             play_sound[_die]+= 1
  17.         }
  18.         if global.life == 0
  19.         {
  20.             timer[1] -= 1
  21.             if timer[1] > 0
  22.             {
  23.                 vspeed-= 1
  24.                 //y+= vsp
  25.             }
  26.             else
  27.             {
  28.                 vspeed+= 1
  29.                 //y+= vsp
  30.             }
  31.             timer[0] -= 1
  32.             if timer[0] <= 0
  33.             {
  34.                 room_goto(rm_start) // change this
  35.                 global.life = 3
  36.             }
  37.         }
  38.         else
  39.         {
  40.            
  41.             timer[1] -= 1
  42.             if timer[1] > 0
  43.             {
  44.                 //vsp = 8
  45.                 y-= 8
  46.             }
  47.             else
  48.             {
  49.                 vsp+= 0.3
  50.                 y+= vsp
  51.             }
  52.             timer[0] -= 1
  53.             if timer[0] <= 0
  54.             {
  55.                 global.life-= 1
  56.                 // If we died before hitting checkpt
  57.                 if global.checkpt == 0
  58.                 {
  59.                     hud.minutes = 0
  60.                     hud.seconds = 0
  61.                     game.time_count = 0
  62.                 }
  63.                 // If we died of time
  64.                 if hud.minutes >= 9 && hud.seconds >= 59
  65.                 {
  66.                     global.checkpt = 0
  67.                     hud.minutes = 0
  68.                     hud.seconds = 0
  69.                     game.time_count = 0
  70.                 }
  71.                 timer[0] = 0
  72.                 room_restart();
  73.  
  74.             }
  75.  
  76.         }
  77.         return 0;
  78.     }
  79.                
  80.         /*
  81.         vsp += 0.3;
  82.         y += vsp;
  83.         if (y > __view_get( e__VW.XView, 0 ) + __view_get( e__VW.HView, 0 ) + 250)   // Once player falls out below the view then restart the room (you can set lifes -= 1 here)
  84.         {
  85.             if (global.life == 0)
  86.                 game_end();
  87.             else
  88.                 global.life -= 1
  89.                 room_restart();
  90.         }
  91.         return 0;
  92.     }*/
  93.  
  94.  
  95.     // Limit the values of the movement
  96.     if (abs(hsp) > hspl)    hsp = sign(hsp)*hspl;
  97.     if (abs(vsp) > vspl)    vsp = sign(vsp)*vspl;
  98.  
  99.     //=================================================================
  100.     // Main horizontal and vertical movement, done by moving the player forward in increments of the hsp and vsp and checking if there is a collision
  101.  
  102.     var step_repeat, hstep, vstep, hsign, vsign, hstep_x, hstep_y, rmove, lmove, bmove, tmove;
  103.  
  104.     step_repeat = ceil(max(abs(hsp), abs(vsp)));
  105.  
  106.     hsign = sign(hsp);
  107.     vsign = sign(vsp);
  108.     done1 = (hsign == 0); done2 = (vsign == 0);
  109.     rmove = (hsign == +1);
  110.     lmove = (hsign == -1);
  111.     bmove = (vsign == +1);
  112.     tmove = (vsign == -1);
  113.  
  114.     if (step_repeat != 0)
  115.     {
  116.         hstep = hsp/step_repeat;
  117.         vstep = vsp/step_repeat;
  118.         hstep_x = dcos_val*hstep;
  119.         hstep_y = dsin_val*hstep;
  120.     }
  121.  
  122.     repeat (step_repeat)
  123.     {
  124.        if (!done1)
  125.        {        
  126.             if ((collision_sensor_right(MaskLarge) && rmove) || (collision_sensor_left(MaskLarge) && lmove))
  127.             {
  128.                 done1 = true;
  129.             }
  130.             else
  131.             {
  132.                 x += hstep_x;
  133.                 y -= hstep_y;
  134.             }
  135.         }
  136.         if (!done2)
  137.         {        
  138.             if ((collision_sensor_bottom(MaskLarge) && bmove) || (collision_sensor_top(MaskLarge) && tmove))
  139.             {
  140.                 done2 = true;
  141.             }
  142.             else
  143.             {
  144.                 y += vstep;
  145.             }
  146.         }
  147.  
  148.         if (done1 && done2) break;
  149.     }
  150.  
  151.     if (tmove)
  152.         if (collision_sensor_top(MaskLarge))
  153.             vsp = 0;   // Stop vsp if hit under wall
  154.  
  155.     //=================================================================      
  156.     // Landing. If we are falling and we landed, if the delimiter lines are colliding, search for new angle.
  157.     if (vsp >= 0 && !ground &&
  158.        collision_sensor_bottom(MaskLarge) &&
  159.        collision_sensor_right_line() &&
  160.        collision_sensor_left_line())
  161.     {
  162.         angle = calculate_angle(0);
  163.         dcos_val = cos(degtorad(angle));
  164.         dsin_val = sin(degtorad(angle));
  165.         if (shield == 4 && shield_action != -1)     // If using the water shield then bounce
  166.         {
  167.             hsp = -vsp*dsin_val*0.75;
  168.             vsp = -vsp*dcos_val*0.75;
  169.             angle = 0;
  170.             dcos_val = 1;
  171.             dsin_val = 0;
  172.             jumping = 1;
  173.         }
  174.         else
  175.         {    
  176.             hsp -= dsin_val*vsp;
  177.             vsp = 0;
  178.             ground = 1;
  179.  
  180.             jumping = 0;
  181.             shield_action = -1;
  182.  
  183.              if (action == act_roll || action == act_spring || action == act_hit)
  184.                 action = act_none;       // Deactivate the rolling, springing or hit actions
  185.         }
  186.     }
  187.  
  188.     //=================================================================
  189.     // Wall Collisions, if the side masks are colliding, move the player in order to avoid getting stuck.
  190.     while (collision_sensor_right(MaskLarge))
  191.     {
  192.         x -= dcos_val;
  193.         y += dsin_val;                                                                                        
  194.     }
  195.  
  196.     while (collision_sensor_left(MaskLarge))
  197.     {
  198.         x += dcos_val;
  199.         y -= dsin_val;                                                                                        
  200.     }
  201.  
  202.     //=================================================================  
  203.     // Do slopes while we're on the ground.
  204.     if (ground)
  205.     {
  206.         // Slopes up: If the main sensor is colliding with the background, push to up
  207.         while (collision_sensor_main())
  208.         {
  209.             x -= dsin_val;
  210.             y -= dcos_val;  
  211.         }
  212.  
  213.         // Slopes down: If the main sensor isn't colliding with the background but the slope sensor does, push to down.
  214.         while (!collision_sensor_main() && collision_sensor_slopes(MaskMedium))
  215.         {
  216.             x += dsin_val;
  217.             y += dcos_val;  
  218.         }
  219.     }
  220.  
  221.     //=================================================================    
  222.     if (ground)
  223.     {
  224.         // Check if the delimeter lines aren't colliding while we are on the ground, if that's true, get impulsed to the air
  225.         if (!collision_sensor_left_line() || !collision_sensor_right_line())
  226.         {
  227.             vsp = -dsin_val*hsp;
  228.             hsp = dcos_val*hsp;
  229.             ground = 0;
  230.             angle = 0;
  231.             dcos_val = 1;
  232.             dsin_val = 0;
  233.         }
  234.  
  235.        // Or if the player is too slow and we're on the roof or on a wall, fall
  236.        if (angle>70 && angle<290 && abs(hsp)<5.5)
  237.        {
  238.             vsp = -dsin_val*hsp;
  239.             hsp = dcos_val*hsp;
  240.             ground = 0;
  241.             angle = 0;
  242.             dcos_val = 1;
  243.             dsin_val = 0;
  244.  
  245.             if (action != act_roll)     // go into roll when falling off a wall
  246.             {
  247.                 action = act_roll;
  248.                 sound_play(SndSpin);
  249.             }
  250.         }
  251.  
  252.         // Add momentum when rolling on slopes
  253.         if (action == act_roll)
  254.         {
  255.             if ((angle < 90 && hsp < acc) || (angle > 270 && hsp > -acc)) // Accelerate down hills
  256.                hsp += 1.2*acc*-dsin_val;
  257.             if ((angle > 15 && angle < 165 && hsp > acc) || (angle > 195 && angle < 345 && hsp < -acc)) // Flick up curves
  258.                hsp += abs(hsp)*dsin_val*0.005;
  259.         }
  260.     }
  261.  
  262.     //=================================================================  
  263.     // After moving, get the new angle of the ground while the delimeter lines are colliding
  264.     // and the player is on the ground.
  265.     if (ground && collision_sensor_left_line() && collision_sensor_right_line())
  266.     {
  267.         if (hsp != 0 || vsp != 0)       // Only get a new angle if moving
  268.         {
  269.             angle = calculate_angle(angle);
  270.             dcos_val = cos(degtorad(angle));
  271.             dsin_val = sin(degtorad(angle));
  272.         }
  273.     }
  274.     else
  275.     {
  276.         angle = 0;
  277.         dcos_val = 1;
  278.         dsin_val = 0;
  279.     }
  280.  
  281.     // Now do vertical Movement.
  282.     if (!ground)
  283.     {
  284.         // If we aren't on the ground and we are falling and the bottom sensor is colliding, land
  285.         if (vsp >= 0 && collision_sensor_bottom(MaskLarge))
  286.         {
  287.             ground = 1;
  288.             vsp = 0;
  289.             if (action == act_roll || action == act_spring || action == act_hit) action =act_none;   // Deactivate rolling, springing and hit actions
  290.         }
  291.     }
  292.     else
  293.     {
  294.         // Otherwise, if we are on the ground and the bottom sensor isn't colliding, fall.
  295.         if (!collision_sensor_bottom(MaskLarge))    
  296.         {
  297.             ground = 0;
  298.         }
  299.     }
  300.  
  301.     // Grav Code was here: It's been moved to scr_sonic_movement
  302.    
  303.  
  304.     if (action == act_roll)  // If action is rolling use a smaller square mask
  305.     {
  306.         sprite_index = MaskMain;
  307.         mask_index = MaskSquareSmall;
  308.     }
  309.     else
  310.     {
  311.         sprite_index = MaskMain;
  312.         mask_index = MaskSquareTall;
  313.     }
  314.  
  315.  
  316. if full_vspeed < 0
  317. {
  318.     if ground
  319.     {
  320.         full_vspeed = 0
  321.         vsp = 0
  322.     }
  323. }
  324.  
  325. // Mushing code goes here.
  326.  
  327. // Flickering when hurt code.
  328. if global.player_control == "player"
  329. {
  330.     if invincibility > 0 && invincibility <= 200
  331.     {
  332.         timer[3] -= 1
  333.         if timer[3] < 0
  334.         {
  335.             image_alpha = 0.2
  336.             if timer[3] < -8
  337.             {
  338.                 timer[3] = q_sec
  339.             }
  340.         }
  341.         else
  342.         {
  343.             if global.player_id == "shadow"
  344.             {
  345.                 if chaos_teleport == off
  346.                 {
  347.                     image_alpha = 1;
  348.                 }
  349.             }
  350.             else
  351.             {
  352.                 image_alpha = 1;
  353.             }
  354.         }
  355.     }
  356.     else
  357.     {
  358.         if global.player_id == "shadow"
  359.         {
  360.             if chaos_teleport == off
  361.             {
  362.                 image_alpha = 1
  363.             }
  364.         }
  365.         else
  366.         {
  367.             image_alpha = 1
  368.         }
  369.     }
  370. }
  371. // If sonic is within the canon
  372. if global.player_control == "canon"
  373. {
  374.     image_alpha = 0
  375. }
  376. // If sonic is super sonic
  377. if character != supersonic && global.player_control == "player"
  378. {
  379.     if global.player_id == "sonic"
  380.     {
  381.         scr_sonic_sound_steps()
  382.     }
  383. }
  384.  
  385.  
  386.  
  387.  
  388.  
  389.    
  390.  
  391. clamp(x,12,room_width)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement