Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// Game Motion
- var hud = obj_hud_timer
- var game = obj_mgr_game
- // If death action then to the death movement and disable rest of the step code
- if (action == act_death)
- {
- sound_stop(music_id)
- image_alpha = 1 // set image to 1
- angle = 0 // set the angle to 0
- if play_sound[_die] == 0
- {
- sound_stop(all)
- sound_play(SndDie)
- play_sound[_die]+= 1
- }
- if global.life == 0
- {
- timer[1] -= 1
- if timer[1] > 0
- {
- vspeed-= 1
- //y+= vsp
- }
- else
- {
- vspeed+= 1
- //y+= vsp
- }
- timer[0] -= 1
- if timer[0] <= 0
- {
- room_goto(rm_start) // change this
- global.life = 3
- }
- }
- else
- {
- timer[1] -= 1
- if timer[1] > 0
- {
- //vsp = 8
- y-= 8
- }
- else
- {
- vsp+= 0.3
- y+= vsp
- }
- timer[0] -= 1
- if timer[0] <= 0
- {
- global.life-= 1
- // If we died before hitting checkpt
- if global.checkpt == 0
- {
- hud.minutes = 0
- hud.seconds = 0
- game.time_count = 0
- }
- // If we died of time
- if hud.minutes >= 9 && hud.seconds >= 59
- {
- global.checkpt = 0
- hud.minutes = 0
- hud.seconds = 0
- game.time_count = 0
- }
- timer[0] = 0
- room_restart();
- }
- }
- return 0;
- }
- /*
- vsp += 0.3;
- y += vsp;
- 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)
- {
- if (global.life == 0)
- game_end();
- else
- global.life -= 1
- room_restart();
- }
- return 0;
- }*/
- // Limit the values of the movement
- if (abs(hsp) > hspl) hsp = sign(hsp)*hspl;
- if (abs(vsp) > vspl) vsp = sign(vsp)*vspl;
- //=================================================================
- // 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
- var step_repeat, hstep, vstep, hsign, vsign, hstep_x, hstep_y, rmove, lmove, bmove, tmove;
- step_repeat = ceil(max(abs(hsp), abs(vsp)));
- hsign = sign(hsp);
- vsign = sign(vsp);
- done1 = (hsign == 0); done2 = (vsign == 0);
- rmove = (hsign == +1);
- lmove = (hsign == -1);
- bmove = (vsign == +1);
- tmove = (vsign == -1);
- if (step_repeat != 0)
- {
- hstep = hsp/step_repeat;
- vstep = vsp/step_repeat;
- hstep_x = dcos_val*hstep;
- hstep_y = dsin_val*hstep;
- }
- repeat (step_repeat)
- {
- if (!done1)
- {
- if ((collision_sensor_right(MaskLarge) && rmove) || (collision_sensor_left(MaskLarge) && lmove))
- {
- done1 = true;
- }
- else
- {
- x += hstep_x;
- y -= hstep_y;
- }
- }
- if (!done2)
- {
- if ((collision_sensor_bottom(MaskLarge) && bmove) || (collision_sensor_top(MaskLarge) && tmove))
- {
- done2 = true;
- }
- else
- {
- y += vstep;
- }
- }
- if (done1 && done2) break;
- }
- if (tmove)
- if (collision_sensor_top(MaskLarge))
- vsp = 0; // Stop vsp if hit under wall
- //=================================================================
- // Landing. If we are falling and we landed, if the delimiter lines are colliding, search for new angle.
- if (vsp >= 0 && !ground &&
- collision_sensor_bottom(MaskLarge) &&
- collision_sensor_right_line() &&
- collision_sensor_left_line())
- {
- angle = calculate_angle(0);
- dcos_val = cos(degtorad(angle));
- dsin_val = sin(degtorad(angle));
- if (shield == 4 && shield_action != -1) // If using the water shield then bounce
- {
- hsp = -vsp*dsin_val*0.75;
- vsp = -vsp*dcos_val*0.75;
- angle = 0;
- dcos_val = 1;
- dsin_val = 0;
- jumping = 1;
- }
- else
- {
- hsp -= dsin_val*vsp;
- vsp = 0;
- ground = 1;
- jumping = 0;
- shield_action = -1;
- if (action == act_roll || action == act_spring || action == act_hit)
- action = act_none; // Deactivate the rolling, springing or hit actions
- }
- }
- //=================================================================
- // Wall Collisions, if the side masks are colliding, move the player in order to avoid getting stuck.
- while (collision_sensor_right(MaskLarge))
- {
- x -= dcos_val;
- y += dsin_val;
- }
- while (collision_sensor_left(MaskLarge))
- {
- x += dcos_val;
- y -= dsin_val;
- }
- //=================================================================
- // Do slopes while we're on the ground.
- if (ground)
- {
- // Slopes up: If the main sensor is colliding with the background, push to up
- while (collision_sensor_main())
- {
- x -= dsin_val;
- y -= dcos_val;
- }
- // Slopes down: If the main sensor isn't colliding with the background but the slope sensor does, push to down.
- while (!collision_sensor_main() && collision_sensor_slopes(MaskMedium))
- {
- x += dsin_val;
- y += dcos_val;
- }
- }
- //=================================================================
- if (ground)
- {
- // Check if the delimeter lines aren't colliding while we are on the ground, if that's true, get impulsed to the air
- if (!collision_sensor_left_line() || !collision_sensor_right_line())
- {
- vsp = -dsin_val*hsp;
- hsp = dcos_val*hsp;
- ground = 0;
- angle = 0;
- dcos_val = 1;
- dsin_val = 0;
- }
- // Or if the player is too slow and we're on the roof or on a wall, fall
- if (angle>70 && angle<290 && abs(hsp)<5.5)
- {
- vsp = -dsin_val*hsp;
- hsp = dcos_val*hsp;
- ground = 0;
- angle = 0;
- dcos_val = 1;
- dsin_val = 0;
- if (action != act_roll) // go into roll when falling off a wall
- {
- action = act_roll;
- sound_play(SndSpin);
- }
- }
- // Add momentum when rolling on slopes
- if (action == act_roll)
- {
- if ((angle < 90 && hsp < acc) || (angle > 270 && hsp > -acc)) // Accelerate down hills
- hsp += 1.2*acc*-dsin_val;
- if ((angle > 15 && angle < 165 && hsp > acc) || (angle > 195 && angle < 345 && hsp < -acc)) // Flick up curves
- hsp += abs(hsp)*dsin_val*0.005;
- }
- }
- //=================================================================
- // After moving, get the new angle of the ground while the delimeter lines are colliding
- // and the player is on the ground.
- if (ground && collision_sensor_left_line() && collision_sensor_right_line())
- {
- if (hsp != 0 || vsp != 0) // Only get a new angle if moving
- {
- angle = calculate_angle(angle);
- dcos_val = cos(degtorad(angle));
- dsin_val = sin(degtorad(angle));
- }
- }
- else
- {
- angle = 0;
- dcos_val = 1;
- dsin_val = 0;
- }
- // Now do vertical Movement.
- if (!ground)
- {
- // If we aren't on the ground and we are falling and the bottom sensor is colliding, land
- if (vsp >= 0 && collision_sensor_bottom(MaskLarge))
- {
- ground = 1;
- vsp = 0;
- if (action == act_roll || action == act_spring || action == act_hit) action =act_none; // Deactivate rolling, springing and hit actions
- }
- }
- else
- {
- // Otherwise, if we are on the ground and the bottom sensor isn't colliding, fall.
- if (!collision_sensor_bottom(MaskLarge))
- {
- ground = 0;
- }
- }
- // Grav Code was here: It's been moved to scr_sonic_movement
- if (action == act_roll) // If action is rolling use a smaller square mask
- {
- sprite_index = MaskMain;
- mask_index = MaskSquareSmall;
- }
- else
- {
- sprite_index = MaskMain;
- mask_index = MaskSquareTall;
- }
- if full_vspeed < 0
- {
- if ground
- {
- full_vspeed = 0
- vsp = 0
- }
- }
- // Mushing code goes here.
- // Flickering when hurt code.
- if global.player_control == "player"
- {
- if invincibility > 0 && invincibility <= 200
- {
- timer[3] -= 1
- if timer[3] < 0
- {
- image_alpha = 0.2
- if timer[3] < -8
- {
- timer[3] = q_sec
- }
- }
- else
- {
- if global.player_id == "shadow"
- {
- if chaos_teleport == off
- {
- image_alpha = 1;
- }
- }
- else
- {
- image_alpha = 1;
- }
- }
- }
- else
- {
- if global.player_id == "shadow"
- {
- if chaos_teleport == off
- {
- image_alpha = 1
- }
- }
- else
- {
- image_alpha = 1
- }
- }
- }
- // If sonic is within the canon
- if global.player_control == "canon"
- {
- image_alpha = 0
- }
- // If sonic is super sonic
- if character != supersonic && global.player_control == "player"
- {
- if global.player_id == "sonic"
- {
- scr_sonic_sound_steps()
- }
- }
- clamp(x,12,room_width)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement