Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Information about object: objLink
- Sprite: sprLink0ID
- Solid: false
- Visible: true
- Depth: 0
- Persistent: true
- Parent:
- Children:
- Mask: sprLinkM
- No Physics Object
- Create Event:
- execute code:
- moveable=true; //Is Link ABLE to move?
- moving=false; //Is Link moving?
- spd=1; //How fast, in pixels, does Link increase his movement speed?
- maxspd=2; //Maximum amount of speed Link can achieve.
- //Which direction is Link facing? D=Down, U=Up, L=Left, R=Right.
- dir='D';
- /*
- Which direction has the player pressed? This will be used for
- double tapping a directional key.
- */
- doublekeytapdir='';
- doublekeytapdly=0; //Frames left before double tapping interval ends.
- xoff=0; //The x offset of which to draw Link's sprite.
- yoff=0; //The y offset of which to draw Link's sprite.
- jumping=false; //Is Link jumping?
- z=0; //How high off of the ground, in pixels, Link is.
- zmax=0; //How high off of the ground, in pixels, Link needs to reach.
- //Has Link peaked at his needed height during the jump?
- zreached=false;
- zspd=0; //How fast is Link rising/falling, in pixels?
- /*
- How long, in frames, must Link wait in the air before the next
- z motion?
- */
- zdly=0;
- pushing=false; //Is Link pushing?
- //How long, in frames, has Link been pushing?
- pushtmr=0;
- digging=false; //Is Link digging?
- //Is Link holding up an item? 0 for 1 hand, 1 for 2 hands.
- holding=0;
- slashing=false; //Is Link slashing?
- charge=0; //How long, in frames, has Link been charging.
- tap=false; //Is Link tapping his sword against something?
- tapreverse=false; //Is Link recovering from tapping the sword?
- tapdly=0; //How long, in frames, Link has to wait before tapping again.
- spin=0; //How many spin attacks has Link done.
- defend=false; //Is Link using the shield?
- shieldspr=sprInvis; //The shield sprite to draw.
- rolling=false; //Is Link rolling?
- smokedly=0; //Delay before another smoke object is made.
- cliff=false; //Is Link jumping down a cliff or not?
- cliffdir=''; //Which direction is Link jumping in?
- cliffspd=2; //How fast Link is moving for the cliff jump.
- hvel=0; //Conserve horizontal velocity when against a solid.
- vvel=0; //Conserve vertical velocity when against a solid.
- myfriction=.5; //Amount of friction used to slow movement to a halt.
- lhspeed=0; //Conserve horizontal speed when the game is paused.
- lvspeed=0; //Conserve vertical speed when the game is paused.
- gravity_direction=270; //Gravity should point down in sideview areas.
- mygravity=.5; //How much gravity Link has.
- climbing=false; //Is Link climbing on a ladder?
- Step Event:
- execute code:
- /*********************************************************************
- GAME PAUSED SECTION
- *********************************************************************/
- if (scr_pause_chk())
- {
- //Conserve vertical speed.
- if (vspeed!=0)
- {
- lvspeed=vspeed;
- vspeed=0;
- }
- //Conserve horizontal speed.
- if (hspeed!=0)
- {
- lhspeed=hspeed;
- hspeed=0;
- }
- image_speed=0; //Stop animating.
- exit; //Get out of this script.
- }
- //Restore conserved vertical speed.
- if (lvspeed!=0)
- {
- vspeed=lvspeed;
- lvspeed=0;
- }
- //Restore conserved horizontal speed.
- if (lhspeed!=0)
- {
- hspeed=lhspeed;
- lhspeed=0;
- }
- //Flag Link as visible.
- visible=true;
- //Keyboard Key variables.
- var; down=false; up=false; left=false; right=false;
- //Restore any conserved movement force, if possible.
- if (vvel!=0)
- {
- if ((vvel>0 && place_free(x,y+1)) || (vvel<0 && place_free(x,y-1)))
- {
- vspeed=vvel;
- vvel=0;
- scr_link_collide();
- }
- }
- if (hvel!=0)
- {
- if ((hvel>0 && place_free(x+1,y)) || (hvel<0 && place_free(x-1,y)))
- {
- hspeed=hvel;
- hvel=0;
- scr_link_collide();
- }
- }
- /*******************************************************************
- ARROW KEY CHECKING SECTION
- *******************************************************************/
- /*
- This block of code checks for the corresponding directional keys,
- while considering the opposite. If both up and down are held
- together, for example, then they cancel out.
- */
- down=(keyboard_check(vk_down) && !keyboard_check(vk_up));
- up=(keyboard_check(vk_up) && !keyboard_check(vk_down));
- left=(keyboard_check(vk_left) && !keyboard_check(vk_right));
- right=(keyboard_check(vk_right) && !keyboard_check(vk_left));
- /*
- This section checks for double tapping a directional key.
- */
- /*
- If there was an interval for double tapping an arrow key, subtract
- a frame now. If it becomes 0 (or smaller, somehow) reset the double
- tap checking direction, because it's no longer valid.
- */
- if (doublekeytapdly)
- {
- doublekeytapdly-=1;
- if (doublekeytapdly<=0)
- {
- doublekeytapdir='';
- }
- }
- //Temporary variable to see if Link is told to roll.
- var; tempcanroll=false;
- //If the player presses down...
- if (keyboard_check_pressed(vk_down) && !global.sideview)
- {
- scr_link_doubletap('D') //Check for down double tapping.
- }
- //If the player presses up...
- if (keyboard_check_pressed(vk_up) && !global.sideview)
- {
- scr_link_doubletap('U') //Check for up double tapping.
- }
- //If the player presses left...
- if (keyboard_check_pressed(vk_left))
- {
- scr_link_doubletap('L') //Check for left double tapping.
- }
- //If the player presses right...
- if (keyboard_check_pressed(vk_right))
- {
- scr_link_doubletap('R') //Check for right double tapping.
- }
- /*
- If Link was told to roll, we will allow for it, if he's able to.
- */
- if (tempcanroll && moveable && !rolling && !charge && !slashing && !jumping && !tap && !cliff && !spin && !digging)
- {
- /*
- This block of if statements just assigns Link velocity based on
- which direction he's facing.
- */
- if (dir=='D'){vspeed=maxspd*2.5;}
- else if (dir=='U'){vspeed=-maxspd*2.5;}
- else if (dir=='L'){hspeed=-maxspd*2.5;}
- else if (dir=='R'){hspeed=maxspd*2.5;}
- scr_link_collide(); //Check for collision.
- doublekeytapdir=''; //Reset the double key tap check direction.
- doublekeytapdly=0; //Reset the interval for double key tapping.
- moving=false; //Unflag him as moving.
- pushing=false; //And don't flag him as pushing either.
- pushtmr=0; //And reset the pushing frame counter.
- defend=false; //Unflag Link as defending.
- image_index=0; //Reset his animation frame.
- rolling=true; //Flag Link as rolling.
- sound_play(sndRoll) //Play the rolling sound effect.
- scr_link_sprite_change(); //Update Link's sprite.
- }
- /*******************************************************************
- MOVEMENT SPEED AND FRICTION ALTERATION SECTION
- *******************************************************************/
- //If Link is STANDING on a slow-walking tile...
- if (scr_link_foot_check(objSlowWalk) && !jumping)
- {
- //Temporary variable to store the calculated slow-walk speed.
- var; walkspd=1-(.5*defend);
- maxspd=walkspd; //Assign the slow walking speed.
- }
- else
- {
- //Temporary variable for the calculated normal movement speed.
- var; walkspd=2-(1*defend);
- maxspd=walkspd; //Assign standard walking speed.
- }
- //If Link is rolling...
- if (rolling)
- {
- myfriction=.25; //Less friction during rolling.
- }
- else
- {
- myfriciton=.5; //Regular friction.
- }
- /*********************************************************************
- JUMPING IN THE AIR SECTION
- *********************************************************************/
- if (jumping && moveable && !global.sideview)
- {
- /*
- If the Link hasn't peaked yet, the zspd should be smaller the
- closer he gets to his peak. Otherwise it should be larger as
- he approaches the ground.
- */
- zspd=max(abs(round((zmax-z) div 3)),1);
- /*
- If Link hasn't peaked in height yet, subtract the zspd
- from the z value. Otherwise, add it.
- */
- if (!zpeak)
- {
- if (z-zspd>=zmax)
- {
- z-=zspd;
- }
- else
- {
- z=zmax;
- zpeak=true;
- }
- }
- else
- {
- /*
- Link shouldn't come down if he's jumping off a cliff,
- unless he's already made it down the cliff.
- */
- if (!cliff || (cliff && place_free(x,y)))
- {
- if (z+zspd<=0)
- {
- z+=zspd;
- }
- else
- {
- z=0;
- zpeak=false;
- zmax=0;
- cliff=false;
- jumping=false;
- sound_play(sndLand);
- }
- }
- }
- }
- else
- {
- zpeak=false; //Reset Link peaking at his jump.
- }
- /********************************************************************
- SIDEVIEW GRAVITY SECTION
- ********************************************************************/
- if (global.sideview)
- {
- //If Link is in the air...
- if (place_free(x,y+1))
- {
- //If Link is hugging the ceiling...
- if (vvel<0)
- {
- vvel+=mygravity; //Add the gravity to it.
- //Then make sure Link isn't considered hugging the floor.
- if (vvel>0)
- {
- vvel=0;
- }
- }
- else
- {
- gravity=mygravity; //Otherwise, apply gravity.
- }
- //If he wasn't jumping or rolling, reset his frame of animation.
- if (!jumping && !rolling)
- {
- image_index=0;
- }
- jumping=true; //Flag him as jumping.
- rolling=false; //Unflag him as rolling.
- scr_link_collide(); //Check for collision.
- }
- else
- {
- gravity=0; //Otherwise, unapply gravity.
- //If he was jumping, play the landing sound.
- if (jumping)
- {
- sound_play(sndLand);
- }
- jumping=false; //Unflag him as jumping.
- }
- //Cap his vertical velocity at a max of 4 pixels per frame.
- if (vspeed>4)
- {
- vspeed=4;
- }
- }
- else
- {
- gravity=0; //Otherwise, no gravity.
- }
- /********************************************************************
- MOVEMENT SECTION
- *********************************************************************/
- //If Link is in a proper state to move...
- if (moveable && !digging && (!slashing or jumping) && !tap && !rolling && !cliff && (!spin || spin>1))
- {
- /*
- Store the direction Link was just facing in a temporary variable.
- */
- var; lastdir=dir;
- //If any directional key held...
- if ((down && !global.sideview) || (up && !global.sideview) || left || right)
- {
- moving=true; //Flag Link as moving.
- //Apply friction to the plane he's not moving in.
- scr_link_friction(false);
- scr_link_collide(); //Check for collision with a wall.
- }
- else
- {
- //Otherwise, unflag Link as moving and pushing.
- moving=false;
- pushing=false;
- scr_link_friction(true); //Apply friction in all planes.
- scr_link_collide(); //Check for collision with a wall.
- }
- /*
- Change the direction Link is facing based on which directional
- keys are held down. Link's facing is locked depending on which
- direction he was facing before moving diagonally. So you won't
- have that problem some engines have where Link will always face
- down when holding down and left for example. He'll stay facing
- left if he was facing left to begin with, or down. No, Link
- cannot moonwalk in this engine =P. No directional change if
- Link is charging, using the spin attack or jumping.
- */
- if (!charge && !spin && !jumping && !defend)
- {
- if (down && ((!left && !right) || (left && dir!='L') || (right && dir!='R')))
- {
- dir='D';
- }
- if (up && ((!left && !right) || (left && dir!='L') || (right && dir!='R')))
- {
- dir='U';
- }
- if (left && ((!down && !up) || (down && dir!='D') || (up && dir!='U')))
- {
- dir='L';
- }
- if (right && ((!down && !up) || (down && dir!='D') || (up && dir!='U')))
- {
- dir='R';
- }
- }
- /*
- If Link changed directions, the pushing frame counter needs to
- be reset, since he is no longer pushing in the same direction.
- */
- if (dir!=lastdir)
- {
- pushtmr=0;
- }
- /*
- Movement for DOWN.
- */
- if (down && !global.sideview)
- {
- //If there's no wall below link...
- if (place_free(x,y+spd))
- {
- /*
- If he's not hugging the wall vertically, then add the
- momentem to his vertical motion. Otherwise, add it to
- his wall-hugging momentum.
- */
- if (vvel==0)
- {
- scr_link_add_vspeed(spd-((spd/2)*jumping));
- }
- else
- {
- scr_link_add_vvel(spd-((spd/2)*jumping));
- }
- scr_link_collide(); //Check for collision.
- pushing=false; //Unflag Link as pushing.
- pushtmr=0; //Reset the pushing timer.
- }
- else if (place_free(x-6,y+spd) && !left && !right && dir=='D')
- {
- /*
- Otherwise, try to add momentum to the left, to try and
- cut around the corner of a wall.
- */
- if (hvel==0)
- {
- scr_link_add_hspeed(-spd+((spd/2)*jumping));
- }
- else
- {
- scr_link_add_hvel(-spd+((spd/2)*jumping));
- }
- scr_link_collide(); //Check for collision.
- pushing=false; //Unflag Link as pushing.
- pushtmr=0; //Reset the pushing timer.
- }
- else if (place_free(x+6,y+spd) && !left && !right && dir=='D')
- {
- /*
- Otherwise, try to add momentum to the right, to try and
- cut around the corner of a wall.
- */
- if (hvel==0)
- {
- scr_link_add_hspeed(spd-((spd/2)*jumping));
- }
- else
- {
- scr_link_add_hvel(spd-((spd/2)*jumping));
- }
- scr_link_collide(); //Check for collision.
- pushing=false; //Unflag Link as pushing.
- pushtmr=0; //Reset the pushing timer.
- }
- else
- {
- scr_link_collide(); //Check for collision.
- if (dir=='D' && !defend && !jumping)
- {
- /*
- Flag Link as pushing if he isn't charging the sword,
- otherwise, make him perform a sword tap.
- */
- if (!charge)
- {
- pushing=true;
- }
- else if (!tapdly)
- {
- tap=true;
- }
- }
- }
- }
- /*
- Movement for UP.
- */
- if (up && !global.sideview)
- {
- /*
- If Link can go directly UP without running into a solid,
- then make him move UP, and unflag him as pushing. Otherwise,
- check to see if he can slide around a corner, and isn't
- already holding that directional key. If so, do that, unflag
- him as pushing and reset the pushing frame counter. Otherwise,
- get as close to the wall as possible and go no further, and
- flag him as pushing if he is facing in this direction.
- */
- if (place_free(x,y-spd))
- {
- /*
- If he's not hugging the wall vertically, then add the
- momentem to his vertical motion. Otherwise, add it to
- his wall-hugging momentum.
- */
- if (vvel==0)
- {
- scr_link_add_vspeed(-spd+((spd/2)*jumping));
- }
- else
- {
- scr_link_add_vvel(-spd+((spd/2)*jumping));
- }
- scr_link_collide(); //Check for collision.
- pushing=false; //Unflag Link as pushing.
- pushtmr=0; //Reset the pushing timer.
- }
- else if (place_free(x-6,y-spd) && !left && !right && dir=='U')
- {
- /*
- Otherwise, try to add momentum to the left, to try and
- cut around the corner of a wall.
- */
- if (hvel==0)
- {
- scr_link_add_hspeed(-spd+((spd/2)*jumping));
- }
- else
- {
- scr_link_add_hvel(-spd+((spd/2)*jumping));
- }
- scr_link_collide(); //Check for collision.
- pushing=false; //Unflag Link as pushing.
- pushtmr=0; //Reset the pushing timer.
- }
- else if (place_free(x+6,y-spd) && !left && !right && dir=='U')
- {
- /*
- Otherwise, try to add momentum to the right, to try and
- cut around the corner of a wall.
- */
- if (hvel==0)
- {
- scr_link_add_hspeed(spd-((spd/2)*jumping));
- }
- else
- {
- scr_link_add_hvel(spd-((spd/2)*jumping));
- }
- scr_link_collide(); //Check for collision.
- pushing=false; //Unflag Link as pushing.
- pushtmr=0; //Reset the pushing timer.
- }
- else
- {
- scr_link_collide(); //Check for collision.
- if (dir=='U' && !defend && !jumping)
- {
- /*
- Flag Link as pushing if he isn't charging the sword,
- otherwise, make him perform a sword tap.
- */
- if (!charge)
- {
- pushing=true;
- }
- else if (!tapdly)
- {
- tap=true;
- }
- }
- }
- }
- /*
- Movement for LEFT.
- */
- if (left)
- {
- /*
- If Link can go directly LEFT without running into a solid,
- then make him move LEFT, and unflag him as pushing. Otherwise,
- check to see if he can slide around a corner, and isn't
- already holding that directional key. If so, do that, unflag
- him as pushing and reset the pushing frame counter. Otherwise,
- get as close to the wall as possible and go no further, and
- flag him as pushing if he is facing in this direction.
- */
- if (place_free(x-spd,y))
- {
- /*
- If he's not hugging the wall horizontally, then add the
- momentem to his horizontal motion. Otherwise, add it to
- his wall-hugging momentum.
- */
- if (hvel==0)
- {
- scr_link_add_hspeed(-spd+((spd/2)*jumping));
- }
- else
- {
- scr_link_add_hvel(-spd+((spd/2)*jumping));
- }
- scr_link_collide(); //Check for collision.
- pushing=false; //Unflag Link as pushing.
- pushtmr=0; //Reset the pushing timer.
- }
- else if (place_free(x-spd,y-6) && !global.sideview && !down && !up && dir=='L')
- {
- /*
- Otherwise, try to add momentum to the north, to try and
- cut around the corner of a wall.
- */
- if (vvel==0)
- {
- scr_link_add_vspeed(-spd+((spd/2)*jumping));
- }
- else
- {
- scr_link_add_vvel(-spd+((spd/2)*jumping));
- }
- scr_link_collide(); //Check for collision.
- pushing=false; //Unflag Link as pushing.
- pushtmr=0; //Reset the pushing timer.
- }
- else if (place_free(x-spd,y+6) && !global.sideview && !down && !up && dir=='L')
- {
- /*
- Otherwise, try to add momentum to the south, to try and
- cut around the corner of a wall.
- */
- if (vvel==0)
- {
- scr_link_add_vspeed(spd-((spd/2)*jumping));
- }
- else
- {
- scr_link_add_vvel(spd-((spd/2)*jumping));
- }
- scr_link_collide(); //Check for collision.
- pushing=false; //Unflag Link as pushing.
- pushtmr=0; //Reset the pushing timer.
- }
- else
- {
- scr_link_collide(); //Check for collision.
- if (dir=='L' && !defend && !jumping)
- {
- /*
- Flag Link as pushing if he isn't charging the sword,
- otherwise, make him perform a sword tap.
- */
- if (!charge)
- {
- pushing=true;
- }
- else if (!tapdly)
- {
- tap=true;
- }
- }
- }
- }
- /*
- Movement for RIGHT.
- */
- if (right)
- {
- /*
- If Link can go directly RIGHT without running into a solid,
- then make him move RIGHT, and unflag him as pushing. Otherwise,
- check to see if he can slide around a corner, and isn't
- already holding that directional key. If so, do that, unflag
- him as pushing and reset the pushing frame counter. Otherwise,
- get as close to the wall as possible and go no further, and
- flag him as pushing if he is facing in this direction.
- */
- if (place_free(x+spd,y))
- {
- /*
- If he's not hugging the wall horizontally, then add the
- momentem to his horizontal motion. Otherwise, add it to
- his wall-hugging momentum.
- */
- if (hvel==0)
- {
- scr_link_add_hspeed(spd-((spd/2)*jumping));
- }
- else
- {
- scr_link_add_hvel(spd-((spd/2)*jumping));
- }
- scr_link_collide(); //Check for collision.
- pushing=false; //Unflag Link as pushing.
- pushtmr=0; //Reset the pushing timer.
- }
- else if (place_free(x+spd,y-6) && !global.sideview && !down && !up && dir=='R')
- {
- /*
- Otherwise, try to add momentum to the north, to try and
- cut around the corner of a wall.
- */
- if (vvel==0)
- {
- scr_link_add_vspeed(-spd+((spd/2)*jumping));
- }
- else
- {
- scr_link_add_vvel(-spd+((spd/2)*jumping));
- }
- scr_link_collide(); //Check for collision.
- pushing=false; //Unflag Link as pushing.
- pushtmr=0; //Reset the pushing timer.
- }
- else if (place_free(x+spd,y+6) && !global.sideview && !down && !up && dir=='R')
- {
- /*
- Otherwise, try to add momentum to the south, to try and
- cut around the corner of a wall.
- */
- if (vvel==0)
- {
- scr_link_add_vspeed(spd-((spd/2)*jumping));
- }
- else
- {
- scr_link_add_vvel(spd-((spd/2)*jumping));
- }
- scr_link_collide(); //Check for collision.
- pushing=false; //Unflag Link as pushing.
- pushtmr=0; //Reset the pushing timer.
- }
- else
- {
- scr_link_collide(); //Check for collision.
- if (dir=='R' && !defend && !jumping)
- {
- /*
- Flag Link as pushing if he isn't charging the sword,
- otherwise, make him perform a sword tap.
- */
- if (!charge)
- {
- pushing=true;
- }
- else if (!tapdly)
- {
- tap=true;
- }
- }
- }
- }
- /*
- Pushing Segment
- */
- if (pushing){
- /*
- If Link has been pushing for about 1/4 of a second...
- */
- if (pushtmr>=7)
- {
- //Temporary variable for a possible cliff ahead of Link.
- var; cliffobj=scr_link_ahead_chk(objCliff,1);
- /*
- If there is a cliff, and Link is in a state to jump
- down...
- */
- if (cliffobj!=-1 && !cliff && !jumping && dir==cliffobj.dir)
- {
- hspeed=0; //Reset his horizontal speed.
- vspeed=0; //Reset his vertical speed.
- pushing=false; //Unflag Link as pushing.
- zmax=-16; //Have Link leave the ground a full tile.
- jumping=true; //Flag Link as jumping.
- //Jump in the direction the cliff wants.
- cliffdir=cliffobj.dir;
- sound_play(sndCliff); //Play the cliff jumping sound.
- cliff=true; //Flag Link as jumping off of a cliff.
- image_index=0; //Reset Link's animation frame.
- scr_link_sprite_change(); //Update Link's sprite.
- /*
- Move Link forward a bit depending on which direction he's
- jumping down.
- */
- if (cliffdir=='D')
- {
- y+=2;
- }
- else if (cliffdir=='U')
- {
- y-=2;
- }
- else if (cliffdir=='L')
- {
- x-=2;
- }
- else
- {
- x+=2;
- }
- }
- }
- /*
- If Link hasn't been pushing for 15 frames (1/2 second), add this
- frame to the timer. Otherwise, check for other things.
- */
- if (pushtmr<15)
- {
- pushtmr+=1;
- }
- else
- {
- /*
- Define a temporary variable for checking if a pushable
- object is in front of Link.
- */
- var; pushobjchk=scr_link_ahead_chk(objPushable,1);
- /*
- If there was a pushable object in front of Link, then we
- can do things with it.
- */
- if (pushobjchk!=-1)
- {
- /*
- If the object can still be pushed, and Link is trying
- to push the object in the right direction, if
- applicable...
- */
- if (pushobjchk.pushes!=0 && pushobjchk.pushx==0 && pushobjchk.pushy==0 && (pushobjchk.pushdir=='' || (pushobjchk.pushdir==dir)))
- {
- /*
- Then set it's pushing distance to one tile ahead,
- if the object can move forward and isn't at the edge
- of the room, and play the pushing sound effect.
- */
- if (dir=='D')
- {
- if (place_free(pushobjchk.x,pushobjchk.y+16) && pushobjchk.y+16<room_height)
- {
- pushobjchk.pushy=16;
- sound_play(sndPush);
- }
- }
- else if (dir=='U')
- {
- if (place_free(pushobjchk.x,pushobjchk.y-16) && pushobjchk.y-16>=0)
- {
- pushobjchk.pushy=-16;
- sound_play(sndPush);
- }
- }
- else if (dir=='L')
- {
- if (place_free(pushobjchk.x-16,pushobjchk.y) && pushobjchk.x-16>=0)
- {
- pushobjchk.pushx=-16;
- sound_play(sndPush);
- }
- }
- else
- {
- if (place_free(pushobjchk.x+16,pushobjchk.y) && pushobjchk.x+16<room_width)
- {
- pushobjchk.pushx=16;
- sound_play(sndPush);
- }
- }
- }
- }
- }
- }
- else
- {
- //Reset the pushing frame counter if he's not pushing.
- pushtmr=0;
- }
- }
- else if (rolling)
- {
- //Otherwise if Link is rolling...
- //If there is a delay on the next smoke object...
- if (smokedly)
- {
- smokedly-=1; //Subtract a frame from the delay.
- }
- else
- {
- //Otherwise, make a new smoke object here.
- s=instance_create(x,y,objRollSmoke);
- /*
- If Link is facing down, the smoke should appear behind
- him. Otherwise, it should be above him.
- */
- if (dir=='D')
- {
- s.depth=depth+2;
- }
- else
- {
- s.depth=depth-2;
- }
- smokedly=4; //Set the delay to 4 frames away.
- }
- doublekeytapdir=''; //Reset the double key tap check direction.
- doublekeytapdly=0; //Reset the interval for double key tapping.
- scr_link_friction(true); //Apply friction in all planes.
- scr_link_collide(); //Check for wall collission.
- }
- else
- {
- /*
- If Link isn't able to move at all or is using an item that locks
- his movement, don't flag him as moving.
- */
- moving=false;
- doublekeytapdir=''; //Reset the double key tap check direction.
- doublekeytapdly=0; //Reset the interval for double key tapping.
- pushing=false; //And don't flag him as pushing either.
- pushtmr=0; //And reset the pushing frame counter.
- defend=false; //Unflag him as defending.
- hspeed=0; //Reset his horizontal speed.
- vspeed=0; //Reset his vertical speed.
- }
- /*********************************************************************
- ACTION/ITEM KEY PRESS SECTION
- *********************************************************************/
- /*
- This section of code is for the item button checks. When these buttons
- are pressed, Link needs to use the items that are equipped. That is,
- if he is able to at all.
- */
- //If the player presses Z...
- if keyboard_check_pressed(ord('Z'))
- {
- //Temporary variable for a possible interaction in front of Link.
- var; interactchk=scr_link_ahead_chk(objInteractable,4);
- //If there isn't an interaction in front of Link, use what's on Z.
- if (interactchk==-1 || jumping)
- {
- scr_use_item(global.Z);
- }
- else if (!rolling)
- {
- /*
- Otherwise, if Link is facing in the right direction,
- flag the object as interacted.
- */
- if (dir==interactchk.interactdir || interactchk.interactdir=='')
- {
- interactchk.interacted=true;
- }
- }
- }
- //If the player presses X, use what's on X.
- if keyboard_check_pressed(ord('X'))
- {
- scr_use_item(global.X);
- }
- //If the player releases Z, do what needs to be done.
- if keyboard_check_released(ord('Z'))
- {
- scr_release_button(global.Z);
- }
- //If the player releases X, do what needs to be done.
- if keyboard_check_released(ord('X'))
- {
- scr_release_button(global.X);
- }
- /********************************************************************
- SWORD CHARGING SECTION
- ********************************************************************/
- if (charge)
- {
- //If there is still a delay on the next tap, subtract a frame.
- if (tapdly)
- {
- tapdly-=1;
- }
- //If the charge isn't fully done, add a frame to the counter.
- if (charge<30 && !tap)
- {
- charge+=1;
- /*
- If the charging has just reached maximum, play the charge
- sound.
- */
- if (charge>=30)
- {
- sound_play(sndCharge);
- }
- }
- }
- else
- {
- tapdly=0;
- }
- /*
- Call Link's sprite changing script. This will change his sprite
- depending on the current actions he is performing. It should be
- called after the keychecks and movement, so his sprite can change
- immediately after the flags for such actions are set.
- */
- scr_link_sprite_change();
- /*********************************************************************
- ANIMATION SPEED SECTION
- *********************************************************************/
- /*
- This section is for Link's animation speed. He should animate at
- various speeds depending on what actions he is performing. Otherwise
- he'll slowly animate for his idle pose, letting him blink, and not
- stare into space infinitely.
- */
- //If Link is moving or using an item that requires animation...
- if (moving || digging || slashing || jumping || rolling || tap)
- {
- if (tap)
- {
- //2nd frame for tapping.
- image_index=1;
- }
- else if (digging)
- {
- //Standard Digging Animation Speed.
- image_speed=.25;
- }
- else if (slashing)
- {
- //Standard Slashing Animation Speed.
- image_speed=.5;
- }
- else if (jumping)
- {
- //Standard Jumping Animation Speed.
- image_speed=.5;
- }
- else if (rolling)
- {
- //Standard Rolling Animation Speed.
- image_speed=.5;
- }
- else{
- //Standard Walking Animation Speed.
- image_speed=.5;
- }
- }
- else
- {
- //If Link isn't charging, go in here.
- if (!charge)
- {
- /*
- Store the current image of animation to see if he's on the
- blinking frames. If he is, he should animate faster, to finish
- blinking faster. Otherwise, it should slow to a crawl, at a
- purely random speed, so his intervals of not blinking aren't
- consistent.
- */
- var; img=floor(image_index);
- if (img==0)
- {
- //Standard First Frame Blinking Animation Speed.
- image_speed=.0125+random(.00625);
- }
- else
- {
- //Standard After-First Frame Blinking Animation Speed.
- image_speed=.25;
- }
- }
- else
- {
- //Otherwise, freeze his animation entirely.
- image_speed=0;
- image_index=0;
- }
- }
- /*********************************************************************
- SLASHING AND SWORD TAPPING SECTION
- *********************************************************************/
- /*
- This is for offsetting Link's sprite when he is attacking.
- */
- if (slashing)
- {
- //Store which image Link's animation is on.
- var; img=floor(image_index);
- //If he's facing Down or Up, the sprite offset is all vertical.
- if (dir=='D' or dir=='U')
- {
- xoff=0;
- yoff=img*2-(4*(img==3));
- if (dir=='U')
- {
- yoff*=-1;
- }
- }
- else
- {
- //Otherwise, the offset is all horizontal.
- xoff=img*2-(4*(img==3));
- yoff=0;
- if (dir=='L')
- {
- xoff*=-1;
- }
- }
- }
- else if (tap)
- {
- /*
- This section is for things revolving around Link tapping
- the sword against a wall.
- */
- charge=1; //Reset the charging.
- //Make his sprite move a pixel.
- if (dir=='D')
- {
- yoff+=2-(4*tapreverse);
- }
- else if (dir=='U'){
- yoff-=2-(4*tapreverse);
- }
- else if (dir=='L'){
- xoff-=2-(4*tapreverse);
- }
- else if (dir=='R'){
- xoff+=2-(4*tapreverse);
- }
- //If Link's sprite is forward by a quarter tile, do tapping stuff.
- if (!tapreverse && (yoff==4 || yoff==-4 || xoff==-4 || xoff==4))
- {
- //Temp. variable for bush checking.
- var; bushchk=scr_link_ahead_chk(objBush,8);
- tapreverse=true; //Flag the tapping for the second phase.
- /*
- If there is a bush in front of Link, apply an appropriate
- force based on which direction Link is facing, and then get rid
- of the bush.
- */
- if (bushchk!=-1)
- {
- var; global.hspeedgive=0; global.vspeedgive=0;
- if (dir=='D')
- {
- global.vspeedgive=3;
- }
- else if (dir=='U')
- {
- global.vspeedgive=-3;
- }
- else if (dir=='L')
- {
- global.hspeedgive=-3;
- }
- else
- {
- global.hspeedgive=3;
- }
- with bushchk
- {
- hspeed=global.hspeedgive;
- vspeed=global.vspeedgive;
- instance_destroy();
- }
- }
- else
- {
- //Otherwise, play the clanking sound effect.
- sound_play(sndClank);
- }
- }
- //If Link's sprite made it back after tapping, go in here.
- if (tapreverse && xoff==0 && yoff==0)
- {
- tap=false; //Unflag the tapping.
- tapreverse=false; //Unflag the finishing of the tapping.
- tapdly=6; //Make Link wait for a bit before the next tap.
- //Get rid of the sword if the key is no longer held.
- if (!scr_held_button_chk("sword"))
- {
- charge=0;
- if instance_exists(objSword)
- {
- with objSword
- {
- instance_destroy();
- }
- }
- }
- scr_link_sprite_change(); //Finally, have Link update his sprite.
- }
- }
- else
- {
- //Reset the sprite offset.
- xoff=0;
- yoff=0;
- }
- /*
- if (place_meeting(x,y,objEnemy))
- {
- var; e=-1;
- e=instance_place(x,y,objEnemy);
- direction=point_direction(e.x,e.y,x,y);
- speed=4;
- }
- */
- Begin Step Event:
- execute code:
- //If the game is paused, get out of here.
- if (scr_pause_chk())
- {
- exit;
- }
- /*
- If Link is jumping down a cliff and he's still not at a free space,
- do what's in here.
- */
- if (cliff && !place_free(x,y))
- {
- /*
- Move forward, depending on which way Link is jumping down a
- cliff.
- */
- if (cliffdir=='D')
- {
- y+=cliffspd;
- }
- else if (cliffdir=='U')
- {
- y-=cliffspd;
- }
- else if (cliffdir=='L')
- {
- x-=cliffspd;
- }
- else
- {
- x+=cliffspd;
- }
- }
- else
- {
- cliffspd=2; //Reset the cliff jumping speed.
- }
- //Get the camera moving to where it needs to be.
- scr_align_view(false);
- End Step Event:
- execute code:
- /*
- This section of code checks for when Link steps outside of the screen.
- As soon as he does, if there is a room in that direction, a scrolling
- transition should happen. Otherwise, he should be locked into the
- screen, as if an invisible barrier were holding him in.
- */
- //If Link steps off of the north boundary of the screen...
- if (y<0)
- {
- //If there is a room north of this one...
- if (global.northroom!=-1)
- {
- //Set the next transition to the scrolling up transition.
- transition_kind=17
- //Flag Link as invisible, so he won't show up on the surface.
- visible=false;
- //Flag the Control as invisible as well for the same reason.
- objControl.visible=false;
- //Flag the Weather as invisible as well for the same reason.
- objWeather.visible=false;
- //Flag any of Link's weapons as invisible as well.
- objLinkWeapon.visible=false;
- scr_reset_weather(); //Reset the weather.
- //If Link is jumping down a cliff, reset his animation.
- if (cliff && image_index>=3)
- {
- image_index=0;
- }
- scr_align_view(true); //Orient the screen just right.
- room_goto(global.northroom); //Go to the northern room.
- //Now place Link at the bottom of the room.
- y=room_height-sprite_height;
- //And get out of this code for this frame.
- exit;
- }
- else
- {
- //Otherwise, place Link back at the south edge of the screen.
- y=0;
- }
- }
- //If Link steps off of the south boundary of the screen...
- if (y+16>room_height)
- {
- //If there is a room south of this one...
- if (global.southroom!=-1)
- {
- //Set the next transition to the scrolling down transition.
- transition_kind=16;
- //Flag Link as invisible, so he won't show up on the surface.
- visible=false;
- //Flag the Control as invisible as well for the same reason.
- objControl.visible=false;
- //Flag the Weather as invisible as well for the same reason.
- objWeather.visible=false;
- //Flag any of Link's weapons as invisible as well.
- objLinkWeapon.visible=false;
- scr_reset_weather(); //Reset the weather.
- //If Link is jumping down a cliff, reset his animation.
- if (cliff && image_index>=3)
- {
- image_index=0;
- }
- scr_align_view(true); //Orient the screen just right.
- room_goto(global.southroom); //Go to the southern room.
- y=0; //Place Link at the top of the room now.
- //And get out of this code for this frame.
- exit;
- }
- else
- {
- //Otherwise, place Link back at the south edge of the screen.
- y=room_height-16;
- }
- }
- //If Link steps off of the west boundary of the screen...
- if (x<0)
- {
- //If there is a room west of this one...
- if (global.westroom!=-1)
- {
- //Set the next transition to the scrolling left transition.
- transition_kind=15;
- //Flag Link as invisible, so he won't show up on the surface.
- visible=false;
- //Flag the Control as invisible as well for the same reason.
- objControl.visible=false;
- //Flag the Weather as invisible as well for the same reason.
- objWeather.visible=false;
- //Flag any of Link's weapons as invisible as well.
- objLinkWeapon.visible=false;
- scr_reset_weather(); //Reset the weather.
- //If Link is jumping down a cliff, reset his animation.
- if (cliff && image_index>=3)
- {
- image_index=0;
- }
- scr_align_view(true); //Orient the screen just right.
- room_goto(global.westroom); //Go to the western room.
- //Now place Link at the right of the room.
- x=room_width-sprite_width;
- //And get out of this code for this frame.
- exit;
- }
- else
- {
- //Otherwise, place Link back at the west edge of the screen.
- x=0;
- }
- }
- //If Link steps off of the east boundary of the screen...
- if (x+16>room_width)
- {
- //If there is a room east of this one...
- if (global.eastroom!=-1)
- {
- //Set the next transition to the scrolling right transition.
- transition_kind=14;
- //Flag Link as invisible, so he won't show up on the surface.
- visible=false;
- //Flag the Control as invisible as well for the same reason.
- objControl.visible=false;
- //Flag the Weather as invisible as well for the same reason.
- objWeather.visible=false;
- //Flag any of Link's weapons as invisible as well.
- objLinkWeapon.visible=false;
- scr_reset_weather(); //Reset the weather.
- //If Link is jumping down a cliff, reset his animation.
- if (cliff && image_index>=3)
- {
- image_index=0;
- }
- scr_align_view(true); //Orient the screen just right.
- room_goto(global.eastroom); //Go to the eastern room.
- x=0; //Place Link at the left of the room now.
- //And get out of this code for this frame.
- exit;
- }
- else
- {
- //Otherwise, place Link back at the east edge of the screen.
- x=room_width-16;
- }
- }
- Other Event: Room Start:
- execute code:
- scr_align_view(true); //Align the view instantly.
- doublekeytapdir=''; //Reset the double key tap check direction.
- doublekeytapdly=0; //Reset the interval for double key tapping.
- Other Event: Animation End:
- execute code:
- /*
- If Link was digging when his animation finished, he shouldn't
- be now.
- */
- if (digging)
- {
- digging=false;
- image_index=0; //Reset his animation frame.
- scr_link_sprite_change(); //And have Link update his sprite.
- }
- else if (slashing)
- {
- /*
- If Link was slashing...
- */
- //Temp. variable for bush checking.
- var; bushchk=scr_link_ahead_chk(objBush,8);
- /*
- If there is a bush in front of Link, apply an appropriate
- force based on which direction Link is facing, and then get rid
- of the bush.
- */
- if (bushchk!=-1)
- {
- var; global.hspeedgive=0; global.vspeedgive=0;
- if (dir=='D')
- {
- global.vspeedgive=3;
- }
- else if (dir=='U')
- {
- global.vspeedgive=-3;
- }
- else if (dir=='L')
- {
- global.hspeedgive=-3;
- }
- else
- {
- global.hspeedgive=3;
- }
- with bushchk
- {
- hspeed=global.hspeedgive;
- vspeed=global.vspeedgive;
- instance_destroy();
- }
- }
- /*
- If Link is at full health, has at least the Master Sword,
- and there isn't a sword beam already on the screen...
- */
- if (global.hearts==global.heartmax && global.sword>=2 && !instance_exists(objSwordBeam))
- {
- //Create a Sword Beam right on the sword.
- beam=instance_create(x+objSword.xoff,y+objSword.yoff,objSwordBeam);
- //Give the beam the same sprite as the sword.
- beam.sprite_index=objSword.sprite_index;
- //The beam should travel in the direction Link is facing.
- beam.dir=dir;
- //Play the sword beam sound effect.
- sound_play(sndSwordBeam);
- }
- slashing=false; //Unflag him as slashing.
- /*
- If the player is still holding the sword button, flag Link
- as charging.
- */
- if (scr_held_button_chk("sword"))
- {
- charge=1;
- }
- else{
- //Otherwise delete the sword.
- if instance_exists(objSword)
- {
- with objSword
- {
- instance_destroy();
- }
- }
- }
- image_index=0; //Reset his animation frame.
- scr_link_sprite_change(); //Finally, have Link update his sprite.
- }
- else if (jumping)
- {
- //If Link was jumping...
- image_index=7; //Stay on the final frame.
- }
- else if (rolling)
- {
- //If Link was rolling...
- rolling=false; //He's not now.
- image_index=0; //Reset his animation frame.
- scr_link_sprite_change(); //Finally, have Link update his sprite.
- }
- Draw Event:
- execute code:
- /*
- Temporary variables for having drawn the shield or not, and Link's
- current frame of animation.
- */
- var; drewshield=false; img=floor(image_index);
- /*
- Draw the shadow below Link's sprite, 1 pixel further down, if he's
- not in a sideview area.
- */
- if (!global.sideview)
- {
- draw_sprite_ext(sprShadow,-1,round(x),round(y)+1,image_xscale,image_yscale,image_angle,image_blend,image_alpha-.125);
- }
- /*
- If Link isn't defending, the shield should be drawn under him
- only if he's facing left. Otherwise, it should be under him if he's
- facing Left, Up or Right.
- */
- if (holding!=1 && ((!defend && ((dir=='L') || (dir=='D' && img>=1 && img<=3) || (dir=='U' && img>=5 && img<=7))) || (defend && dir!='D')))
- {
- //Draw the shield sprite.
- draw_sprite_ext(shieldspr,-1,round(x)+xoff,round(y)+yoff+z,image_xscale,image_yscale,image_angle,image_blend,image_alpha);
- drewshield=true; //Flag as having already drawn the shield.
- }
- //Draw Link's sprite.
- draw_sprite_ext(sprite_index,-1,round(x)+xoff,round(y)+yoff+z,image_xscale,image_yscale,image_angle,image_blend,image_alpha);
- //If the shield hasn't been drawn yet...
- if (!drewshield)
- {
- //Draw the shield sprite.
- draw_sprite_ext(shieldspr,-1,round(x)+xoff,round(y)+yoff+z,image_xscale,image_yscale,image_angle,image_blend,image_alpha);
- }
- //If Link is digging, he needs to draw his shovel item sprite above him.
- if (digging)
- {
- var; shovelspr=sprInvis;
- script_execute('shovelspr=sprShovel'+string(global.shovel)+dir);
- draw_sprite_ext(shovelspr,-1,round(x)+xoff,round(y)+yoff+z,image_xscale,image_yscale,image_angle,image_blend,image_alpha);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement