Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function onGameTick(evt:Event) {
- if (!dying) {
- if (!talking) {
- //if we arent dying
- //########################### Movement ################################
- //## Input Handling
- xMove *= RESISTANCE;
- if (KEYLEFTIN) {
- if (!climbing) {
- targetAnimation = "RUN";
- xMove -= SPEED;
- } else {
- if (onLadder) {
- if (!KEYCLIMBUPIN) {
- //canClimb=false
- }
- }
- xMove -= CLIMBSPEED;
- }
- }
- if (KEYRIGHTIN) {
- if (!climbing) {
- targetAnimation = "RUN";
- xMove += SPEED;
- } else {
- if (onLadder) {
- if (!KEYCLIMBUPIN) {
- //canClimb=false
- }
- }
- xMove += CLIMBSPEED;
- }
- }
- if (!canClimb) {
- climbing = false;
- }
- if (KEYCLIMBUPIN && canClimb) {
- if (!KEYJUMPIN) {
- yMove -= CLIMBSPEED;
- climbing = true;
- touchingSlope = "not";
- } else {
- if (yMove>0) {
- yMove -= CLIMBSPEED;
- climbing = true;
- }
- }
- }
- if (KEYCLIMBDOWNIN && canClimb) {
- if (!KEYJUMPIN) {
- yMove += CLIMBSPEED;
- if (!grounded) {
- climbing = true;
- }
- } else {
- if (yMove>0) {
- yMove += CLIMBSPEED;
- climbing = true;
- }
- }
- }
- if (onLadder) {
- xMove = 0;
- }
- //## Gravity and Jumping
- /*
- REPLACE CODE YOU GAVE ME WITH THIS
- */
- if (!grounded) {
- yMove += GRAVITY;
- if (KEYJUMPIN) {
- if (jumpTimer < jumpDelay) {
- jumpTimer++;
- yMove -= HOVERSTRENGTH;
- }
- } else {
- jumpTimer = jumpDelay;
- }
- } else {
- jumpTimer = 0;
- if (KEYJUMPIN) {
- climbing = false;
- grounded = false;
- touchingSlope = "not";
- yMove = -JUMPSTRENGTH;
- }
- }
- if (inUpdraft) {
- yMove -= currentUpdraftStrength;
- }
- //## Movement
- if ( touchingSlope == "not" ) {
- //Move player normally
- mcLevel.mcPlayer.x += xMove;
- mcLevel.mcPlayer.y += yMove;
- } else {
- //move the player at the angle of the slope
- tempPointA = mcLevel.slopeArray[touchingSlope].localToGlobal( mcLevel.slopeArray[touchingSlope].pointA );
- tempPointA = mcLevel.globalToLocal( tempPointA );
- tempPointB = mcLevel.slopeArray[touchingSlope].localToGlobal( mcLevel.slopeArray[touchingSlope].pointB );
- tempPointB = mcLevel.globalToLocal( tempPointB );
- var slopeAngle = Math.atan2( tempPointA.y-tempPointB.y, tempPointA.x-tempPointB.x );
- mcLevel.mcPlayer.x -= xMove * Math.cos( slopeAngle );
- mcLevel.mcPlayer.y -= xMove * Math.sin( slopeAngle );
- }
- //########################### COLLISION DETECTION & RESONSE ##############################
- foundGround = false;//assume we arent touching anything
- inUpdraft = false;//assume we arent in an updraft
- mcLevel.mcPlayer.y += 1;//move the player down a pixel to see if there is ground there
- //## Trampolines
- for (i=0; i<mcLevel.trampArray.length; i++) {
- if (mcLevel.trampArray[i].hitTestObject( mcLevel.mcPlayer.collisionBox )) {
- if (!grounded) {
- if ( lastPos.y < mcLevel.trampArray[i].y ) {
- mcLevel.mcPlayer.y = mcLevel.trampArray[i].y;
- yMove = -mcLevel.trampArray[i].power;
- }
- }
- }
- }
- //## Platforms
- for (i=0; i<mcLevel.platformArray.length; i++) {
- if (mcLevel.platformArray[i].hitTestObject( mcLevel.mcPlayer.collisionBox )) {
- if ( lastPos.y <= mcLevel.platformArray[i].y ) {
- //coming from above
- climbing=false;
- mcLevel.mcPlayer.y = mcLevel.platformArray[i].y;
- foundGround = true;
- grounded = true;
- yMove = 0;
- } else if (lastPos.x <= mcLevel.platformArray[i].x ) {
- //coming from left
- if ( touchingSlope == "not" ) {
- //regular collision
- mcLevel.mcPlayer.x = mcLevel.platformArray[i].x - (mcLevel.mcPlayer.collisionBox.width / 2);
- xMove *= -0.8;
- } else {
- //collision from a slope
- if ( mcLevel.mcPlayer.y < mcLevel.platformArray[i].y + 30 && mcLevel.mcPlayer.y > mcLevel.platformArray[i].y - 5 ) {
- //platform is next to slope so go onto that
- mcLevel.mcPlayer.y = mcLevel.platformArray[i].y;
- foundGround = true;
- grounded = true;
- yMove = 0;
- touchingSlope = "not";
- } else {
- //platform is not next to slope so bounce
- mcLevel.mcPlayer.x = lastPos.x;
- mcLevel.mcPlayer.y = lastPos.y;
- xMove *= -0.8;
- }
- }
- } else if ( lastPos.x >= mcLevel.platformArray[i].x + mcLevel.platformArray[i].width ) {
- //coming from right
- if ( touchingSlope == "not" ) {
- //regular collision
- mcLevel.mcPlayer.x = mcLevel.platformArray[i].x + mcLevel.platformArray[i].width + (mcLevel.mcPlayer.collisionBox.width / 2);
- xMove *= -0.8;
- } else {
- //collision from a slope
- if ( mcLevel.mcPlayer.y < mcLevel.platformArray[i].y + 30 && mcLevel.mcPlayer.y > mcLevel.platformArray[i].y - 5 ) {
- //platform is next to slope so go onto that
- mcLevel.mcPlayer.y = mcLevel.platformArray[i].y - 1;//the -1 fixes a glitch, though it might just have been a wonky slope
- foundGround = true;
- grounded = true;
- yMove = 0;
- touchingSlope = "not";
- } else {
- //platform is not next to slope so bounce
- mcLevel.mcPlayer.x = lastPos.x;
- mcLevel.mcPlayer.y = lastPos.y;
- xMove *= -0.8;
- }
- }
- } else if ( lastPos.y >= mcLevel.platformArray[i].y + mcLevel.platformArray[i].height ) {
- //coming from below
- if ( touchingSlope == "not" ) {
- mcLevel.mcPlayer.y = lastPos.y + 1;
- yMove = 0;
- if (!inUpdraft) {
- mcLevel.mcPlayer.x = lastPos.x;
- } else {
- yMove *= -0.9;
- }
- } else {
- mcLevel.mcPlayer.x = lastPos.x;
- mcLevel.mcPlayer.y = lastPos.y;
- yMove = 0;
- xMove *= -0.8;
- }
- } else {
- //player was inside the platform both this frame and last so bump them
- mcLevel.mcPlayer.y = mcLevel.platformArray[i].y+1;
- lastPos.y = mcLevel.platformArray[i].y;
- //this is usually caused by an overlapping slope
- touchingSlope = "not";
- }
- }
- }
- //## One-Way Platforms
- if ( yMove >= 0 ) {
- for (i=0; i<mcLevel.oneWayPlatformArray.length; i++) {
- if ( lastPos.y <= mcLevel.oneWayPlatformArray[i].y ) {
- if ( mcLevel.oneWayPlatformArray[i].hitTestObject( mcLevel.mcPlayer.collisionBox ) ) {
- climbing=false;
- mcLevel.mcPlayer.y = mcLevel.oneWayPlatformArray[i].y;
- foundGround = true;
- grounded = true;
- yMove = 0;
- }
- }
- }
- }
- //## Climbable surfaces
- canClimb = false;
- for (i=0; i<mcLevel.climbableArray.length; i++) {
- if ( mcLevel.climbableArray[i].hitTestObject( mcLevel.mcPlayer.collisionBox ) ) {
- canClimb = true;
- if (climbing) {
- foundGround = true;
- grounded = true;
- //mcLevel.mcPlayer.y--
- lastClimbX = mcLevel.mcPlayer.x;
- lastClimbY = mcLevel.mcPlayer.y;
- yMove = 0;
- xMove = 0;
- }
- }
- }
- onLadder = false;
- var ClimbIsLadder = false;
- for (i=0; i<mcLevel.ladderArray.length; i++) {
- if ( mcLevel.ladderArray[i].hitTestObject( mcLevel.mcPlayer.collisionBox ) ) {
- canClimb = true;
- ClimbIsLadder = true;
- if (climbing) {
- onLadder = true;
- foundGround = true;
- grounded = true;
- //mcLevel.mcPlayer.y--
- lastClimbX = mcLevel.mcPlayer.x;
- lastClimbY = mcLevel.mcPlayer.y;
- yMove = 0;
- xMove = 0;
- mcLevel.mcPlayer.x = mcLevel.ladderArray[i].x;
- }
- }
- }
- if (climbing && canClimb==false) {
- //if we were climbing but we have gone somewhere we
- //cant climb, put the player back on the climbing surface
- foundGround = true;
- grounded = true;
- yMove = 0;
- xMove = 0;
- canClimb=true
- ;
- if (mcLevel.mcPlayer.y < lastClimbY) {
- //the player climbed off the top into thin air
- mcLevel.mcPlayer.y = lastClimbY + 1;
- }
- //check to see if we are back on ladder,
- //otherwise we have gone off the side or bottom
- canClimb = false;
- for (i=0; i<mcLevel.climbableArray.length; i++) {
- if ( mcLevel.climbableArray[i].hitTestObject( mcLevel.mcPlayer.collisionBox ) ) {
- canClimb = true;
- }
- }
- for (i=0; i<mcLevel.ladderArray.length; i++) {
- if ( mcLevel.ladderArray[i].hitTestObject( mcLevel.mcPlayer.collisionBox ) ) {
- canClimb = true;
- }
- }
- //mcLevel.mcPlayer.x = lastClimbX
- }
- if (climbing && canClimb) {
- mcLevel.mcPlayer.y--;
- }
- if (climbing && onLadder==false && ClimbIsLadder) {
- onLadder=true;
- }
- //## Conveyor belts
- conveying = false;
- if ( yMove >= 0 ) {
- for (i=0; i<mcLevel.conveyorArray.length; i++) {
- if ( lastPos.y <= mcLevel.conveyorArray[i].y ) {
- if ( mcLevel.conveyorArray[i].hitTestObject( mcLevel.mcPlayer.collisionBox ) ) {
- mcLevel.mcPlayer.y = mcLevel.conveyorArray[i].y;
- foundGround = true;
- climbing=false;
- grounded = true;
- yMove = 0;
- if ( touchingSlope == "not" ) {
- if ( mcLevel.conveyorArray[i].pushDirection == "R" ) {
- if ( mcLevel.conveyorArray[i].cSpeed==0 ) {
- mcLevel.mcPlayer.x += CONVEYORSPEED;
- } else {
- mcLevel.mcPlayer.x += mcLevel.conveyorArray[i].cSpeed;
- }
- } else {
- if ( mcLevel.conveyorArray[i].cSpeed==0 ) {
- mcLevel.mcPlayer.x -= CONVEYORSPEED;
- } else {
- mcLevel.mcPlayer.x -= mcLevel.conveyorArray[i].cSpeed;
- }
- }
- }
- conveying = true;
- }
- }
- }
- }
- //## Moving Platforms
- for (i=0; i<mcLevel.movingPlatformArray.length; i++) {
- // do collision
- hitThis = false;
- if ( lastPos.y <= mcLevel.movingPlatformArray[i].y ) {
- if ( mcLevel.movingPlatformArray[i].movingCollision.hitTestObject( mcLevel.mcPlayer.collisionBox ) ) {
- //if ( yMove >= 0 ){
- hitThis = true;
- //}
- }
- }
- // then do platform movement
- for (k=0; k<mcLevel.controlArray.length; k++) {
- if ( mcLevel.movingPlatformArray[i].movingCollision.hitTestObject( mcLevel.controlArray[k] ) ) {
- //change platform direction
- mcLevel.movingPlatformArray[i].moveDirection = mcLevel.controlArray[k].moveDirection;
- }
- }
- mcLevel.movingPlatformArray[i].lastX = mcLevel.movingPlatformArray[i].x;
- mcLevel.movingPlatformArray[i].lastY = mcLevel.movingPlatformArray[i].y;
- if ( mcLevel.movingPlatformArray[i].moveDirection == "RIGHT" ) {
- mcLevel.movingPlatformArray[i].x += mcLevel.movingPlatformArray[i].moveSpeed;
- } else if ( mcLevel.movingPlatformArray[i].moveDirection == "LEFT" ) {
- mcLevel.movingPlatformArray[i].x -= mcLevel.movingPlatformArray[i].moveSpeed;
- } else if ( mcLevel.movingPlatformArray[i].moveDirection == "UP" ) {
- mcLevel.movingPlatformArray[i].y -= mcLevel.movingPlatformArray[i].moveSpeed;
- } else if ( mcLevel.movingPlatformArray[i].moveDirection == "DOWN" ) {
- mcLevel.movingPlatformArray[i].y += mcLevel.movingPlatformArray[i].moveSpeed;
- }
- // double check collision with the new place too
- // otherwise falling onto an upwards moving platform wont register
- if ( lastPos.y <= mcLevel.movingPlatformArray[i].y ) {
- if ( mcLevel.movingPlatformArray[i].movingCollision.hitTestObject( mcLevel.mcPlayer.collisionBox ) ) {
- //if ( yMove >= 0 ){
- hitThis = true;
- //}
- }
- }
- //then if we hit, we move the player to the new position
- if (hitThis) {
- mcLevel.mcPlayer.y = mcLevel.movingPlatformArray[i].y;
- mcLevel.mcPlayer.x += mcLevel.movingPlatformArray[i].x - mcLevel.movingPlatformArray[i].lastX;
- foundGround = true;
- climbing=false;
- grounded = true;
- yMove = 0;
- }
- }
- //## Moving Fryers
- for (i=0; i<mcLevel.movingFryerArray.length; i++) {
- if (mcLevel.movingFryerArray[i].bopped==false) {
- // do collision
- hitThis = false
- ;
- if ( mcLevel.movingFryerArray[i].movingCollision.hitTestObject( mcLevel.mcPlayer.collisionBox ) ) {
- if ( lastPos.y <= mcLevel.movingFryerArray[i].y ) {
- hitThis = true;
- } else {
- xMove = 0;
- yMove = 0;
- grounded = false;
- touchingSlope = "not";
- climbing=false;
- dying = true;
- }
- }
- // then do platform movement
- for (k=0; k<mcLevel.fryerControlArray.length; k++) {
- if ( mcLevel.movingFryerArray[i].movingCollision.hitTestObject( mcLevel.fryerControlArray[k] ) ) {
- //change platform direction
- mcLevel.movingFryerArray[i].moveDirection = mcLevel.fryerControlArray[k].moveDirection;
- }
- }
- mcLevel.movingFryerArray[i].lastX = mcLevel.movingFryerArray[i].x;
- mcLevel.movingFryerArray[i].lastY = mcLevel.movingFryerArray[i].y;
- if ( mcLevel.movingFryerArray[i].moveDirection == "RIGHT" ) {
- mcLevel.movingFryerArray[i].x += mcLevel.movingFryerArray[i].moveSpeed;
- } else if ( mcLevel.movingFryerArray[i].moveDirection == "LEFT" ) {
- mcLevel.movingFryerArray[i].x -= mcLevel.movingFryerArray[i].moveSpeed;
- } else if ( mcLevel.movingFryerArray[i].moveDirection == "UP" ) {
- mcLevel.movingFryerArray[i].y -= mcLevel.movingFryerArray[i].moveSpeed;
- } else if ( mcLevel.movingFryerArray[i].moveDirection == "DOWN" ) {
- mcLevel.movingFryerArray[i].y += mcLevel.movingFryerArray[i].moveSpeed;
- }
- // double check collision with the new place too
- // otherwise falling onto an upwards moving platform wont register
- if ( mcLevel.movingFryerArray[i].movingCollision.hitTestObject( mcLevel.mcPlayer.collisionBox ) ) {
- if ( lastPos.y <= mcLevel.movingFryerArray[i].y ) {
- hitThis = true;
- } else {
- /*xMove = 0;
- yMove = 0;
- grounded = false;
- touchingSlope = "not";
- climbing=false
- dying = true*/
- }
- }
- //then if we hit, we move the player to the new position
- if (hitThis) {
- if (mcLevel.movingFryerArray[i].fryerBehaviour=="KILLER") {
- xMove = 0;
- yMove = 0;
- grounded = false;
- touchingSlope = "not";
- climbing=false;
- dying = true;
- }
- if (mcLevel.movingFryerArray[i].fryerBehaviour=="BOP") {
- mcLevel.movingFryerArray[i].bopped = true;
- /*mcLevel.mcPlayer.y = mcLevel.movingFryerArray[i].y;
- yMove = -JUMPSTRENGTH;*/
- }
- if (mcLevel.movingFryerArray[i].fryerBehaviour=="PLATFORM") {
- mcLevel.mcPlayer.y = mcLevel.movingFryerArray[i].y;
- mcLevel.mcPlayer.x += mcLevel.movingFryerArray[i].x - mcLevel.movingFryerArray[i].lastX;
- foundGround = true;
- climbing=false;
- grounded = true;
- yMove = 0;
- }
- }
- }
- }
- //## Slopes
- for (i=0; i<mcLevel.slopeArray.length; i++) {
- if ( mcLevel.slopeArray[i].hitTestObject( mcLevel.mcPlayer.collisionBox ) ) {
- if ( mcLevel.slopeArray[i].pointA.y == 50 ) {
- //slope wall on right
- if ( lastPos.y > mcLevel.slopeArray[i].y && lastPos.x > mcLevel.slopeArray[i].x + mcLevel.slopeArray[i].width ) {
- //hit the wall
- if ( touchingSlope == "not" ) {
- //regular collision
- if ( mcLevel.mcPlayer.y < mcLevel.slopeArray[i].y + 30 ) {
- mcLevel.mcPlayer.y = mcLevel.slopeArray[i].y;
- foundGround = true;
- grounded = true;
- yMove = 0;
- touchingSlope = "not";
- } else {
- mcLevel.mcPlayer.x = mcLevel.slopeArray[i].x + mcLevel.slopeArray[i].width + (mcLevel.mcPlayer.collisionBox.width / 2) + 2;
- xMove *= -0.8;
- }
- } else {
- //collision from a slope
- if ( mcLevel.mcPlayer.y < mcLevel.slopeArray[i].y + 30 && mcLevel.mcPlayer.y > mcLevel.slopeArray[i].y - 5 ) {
- //platform is next to slope so go onto that
- mcLevel.mcPlayer.y = mcLevel.slopeArray[i].y - 1;//the -1 fixes a glitch, though it might just be a wonky slope
- foundGround = true;
- grounded = true;
- yMove = 0;
- touchingSlope = "not";
- } else {
- //platform is not next to slope so bounce
- mcLevel.mcPlayer.x = lastPos.x;
- mcLevel.mcPlayer.y = lastPos.y;
- xMove *= -0.8;
- }
- }
- } else {
- //slope wall on right, not hitting wall side
- if ( lastPos.x < mcLevel.slopeArray[i].x ) {
- if ( mcLevel.mcPlayer.x >= mcLevel.slopeArray[i].x ) {
- if ( mcLevel.mcPlayer.y > mcLevel.slopeArray[i].y + mcLevel.slopeArray[i].height ) {
- //bubmped into the corner from below
- mcLevel.mcPlayer.x = lastPos.x;
- mcLevel.mcPlayer.y = lastPos.y;
- xMove *= -0.8;
- }
- }
- }
- }
- } else if ( mcLevel.slopeArray[i].pointA.y == 0 ) {
- //slope wall on left
- if ( lastPos.y > mcLevel.slopeArray[i].y && lastPos.x < mcLevel.slopeArray[i].x ) {
- //hit the wall
- if ( touchingSlope == "not" ) {
- //regular collision
- if ( mcLevel.mcPlayer.y < mcLevel.slopeArray[i].y + 30 ) {
- mcLevel.mcPlayer.y = mcLevel.slopeArray[i].y;
- foundGround = true;
- grounded = true;
- yMove = 0;
- touchingSlope = "not";
- } else {
- mcLevel.mcPlayer.x = mcLevel.slopeArray[i].x - (mcLevel.mcPlayer.collisionBox.width / 2) - 2;
- xMove *= -0.8;
- }
- } else {
- //collision from a slope
- if ( mcLevel.mcPlayer.y < mcLevel.slopeArray[i].y + 30 && mcLevel.mcPlayer.y > mcLevel.slopeArray[i].y - 5) {
- //platform is next to slope so go onto that
- mcLevel.mcPlayer.y = mcLevel.slopeArray[i].y;
- foundGround = true;
- grounded = true;
- yMove = 0;
- touchingSlope = "not";
- } else {
- //platform is not next to slope so bounce
- mcLevel.mcPlayer.x = lastPos.x;
- mcLevel.mcPlayer.y = lastPos.y;
- xMove *= -0.8;
- }
- }
- } else {
- //slope wall on left, not hitting wall side
- if ( lastPos.x >= mcLevel.slopeArray[i].x + mcLevel.slopeArray[i].width ) {
- if ( mcLevel.mcPlayer.x <= mcLevel.slopeArray[i].x + mcLevel.slopeArray[i].width ) {
- if ( mcLevel.mcPlayer.y > mcLevel.slopeArray[i].y + mcLevel.slopeArray[i].height ) {
- //bubmped into the corner from below
- mcLevel.mcPlayer.x = lastPos.x;
- mcLevel.mcPlayer.y = lastPos.y;
- xMove *= -0.8;
- }
- }
- }
- }
- }
- if ( lastPos.y-10 > mcLevel.slopeArray[i].y + mcLevel.slopeArray[i].height ) {
- //collision from below
- if ( touchingSlope == "not" ) {
- mcLevel.mcPlayer.y = lastPos.y + 1;
- yMove = 0;
- if (!inUpdraft) {
- mcLevel.mcPlayer.x = lastPos.x;
- } else {
- yMove *= -0.9;
- }
- } else {
- mcLevel.mcPlayer.x = lastPos.x;
- mcLevel.mcPlayer.y = lastPos.y;
- yMove = 0;
- xMove *= -0.8;
- }
- } else {
- //not from below
- if ( mcLevel.mcPlayer.x > mcLevel.slopeArray[i].x && mcLevel.mcPlayer.x < mcLevel.slopeArray[i].x + mcLevel.slopeArray[i].width && mcLevel.mcPlayer.y > mcLevel.slopeArray[i].y && mcLevel.mcPlayer.y < mcLevel.slopeArray[i].y + mcLevel.slopeArray[i].height ) {
- //player co-ordinats overlap slope bounding box
- tempPointA = mcLevel.slopeArray[i].localToGlobal( mcLevel.slopeArray[i].pointA );
- tempPointA = mcLevel.globalToLocal( tempPointA );
- tempPointB = mcLevel.slopeArray[i].localToGlobal( mcLevel.slopeArray[i].pointB );
- tempPointB = mcLevel.globalToLocal( tempPointB );
- var lineAngle = Math.atan2( tempPointA.y-tempPointB.y, tempPointA.x-tempPointB.x );
- var pointAngle = Math.atan2( tempPointA.y-mcLevel.mcPlayer.y, tempPointA.x-mcLevel.mcPlayer.x );
- if ( pointAngle < lineAngle ) {
- //no slope collision
- } else {
- //slope collision
- if ( mcLevel.mcPlayer.x > mcLevel.slopeArray[i].x && mcLevel.mcPlayer.x < mcLevel.slopeArray[i].x + mcLevel.slopeArray[i].width ) {
- foundGround = true;
- grounded = true;
- yMove = 0;
- mcLevel.mcPlayer.y -= 1;
- if ( touchingSlope != i ) {
- tempPointC = lineIntersectLine( tempPointA, tempPointB, new Point(mcLevel.mcPlayer.x, mcLevel.mcPlayer.y), lastPos );
- mcLevel.mcPlayer.y = tempPointC.y;
- mcLevel.mcPlayer.x = tempPointC.x;
- touchingSlope = i;
- climbing=false;
- }
- }
- }
- }
- }
- }
- }
- //## One-Way Ceilings
- for (i=0; i<mcLevel.oneWayCeilingArray.length; i++) {
- if ( mcLevel.oneWayCeilingArray[i].hitTestObject( mcLevel.mcPlayer.collisionBox ) ) {
- if ( touchingSlope == "not" ) {
- if ( yMove < 0 ) {
- if ( lastPos.y - mcLevel.mcPlayer.collisionBox.height > mcLevel.oneWayCeilingArray[i].y + mcLevel.oneWayCeilingArray[i].height ) {
- mcLevel.mcPlayer.y = mcLevel.oneWayCeilingArray[i].y + mcLevel.oneWayCeilingArray[i].height + mcLevel.mcPlayer.collisionBox.height + 3;
- yMove = 0;
- if (!inUpdraft) {
- mcLevel.mcPlayer.x = lastPos.x;
- } else {
- yMove *= -0.9;
- }
- }
- }
- } else {
- if ( mcLevel.mcPlayer.y < lastPos.y ) {
- mcLevel.mcPlayer.x = lastPos.x;
- mcLevel.mcPlayer.y = lastPos.y;
- yMove = 0;
- xMove *= -0.8;
- }
- }
- }
- }
- //## updrafts
- currentUpdraftStrength = 0;
- for (i=0; i<mcLevel.updraftArray.length; i++) {
- if ( mcLevel.updraftArray[i].hitTestObject( mcLevel.mcPlayer.collisionBox ) ) {
- inUpdraft = true;
- if ( mcLevel.updraftArray[i].power == 0 ) {
- if ( UPDRAFTSTRENGTH > currentUpdraftStrength ) {
- currentUpdraftStrength = UPDRAFTSTRENGTH;
- }
- } else {
- if ( mcLevel.updraftArray[i].power > currentUpdraftStrength ) {
- currentUpdraftStrength = mcLevel.updraftArray[i].power;
- }
- }
- if (grounded) {
- mcLevel.mcPlayer.y -= 2;
- }
- }
- }
- //## Checkpoints
- for (i=0; i<mcLevel.checkPointArray.length; i++) {
- if ( mcLevel.checkPointArray[i].hitTestObject( mcLevel.mcPlayer.collisionBox ) ) {
- safeSpot.x = mcLevel.checkPointArray[i].x;
- safeSpot.y = mcLevel.checkPointArray[i].y;
- }
- }
- //## Messages
- for (i=0; i<mcLevel.messageArray.length; i++) {
- if ( mcLevel.messageArray[i].hitTestObject( mcLevel.mcPlayer.collisionBox ) ) {
- if (mcLevel.messageArray[i].talkType=="CONTACT") {
- mcLevel.messageArray[i].Talk();
- } else {
- if (KEYACTIONIN) {
- mcLevel.messageArray[i].Talk();
- }
- }
- }
- }
- //## Dangerous surfaces
- for (i=0; i<mcLevel.fryArray.length; i++) {
- if ( mcLevel.fryArray[i].hitTestObject( mcLevel.mcPlayer.collisionBox ) ) {
- //mcLevel.mcPlayer.x = safeSpot.x;
- //mcLevel.mcPlayer.y = safeSpot.y;
- xMove = 0;
- yMove = 0;
- grounded = false;
- touchingSlope = "not";
- climbing=false;
- dying = true;
- }
- }
- //## Keys
- for (i=0; i<mcLevel.keyArray.length; i++) {
- for (k=0; k<keysOwned.length; k++) {
- if ( keysOwned[i] == mcLevel.keyArray[i].keyName.text ) {
- mcLevel.keyArray[i].visible = false;
- }
- }
- if ( mcLevel.keyArray[i].hitTestObject( mcLevel.mcPlayer.collisionBox ) ) {
- keysOwned.push( mcLevel.keyArray[i].keyName.text );
- mcLevel.keyArray[i].visible = false;
- }
- }
- //## Collectables
- for (i=0; i<mcLevel.collectablesArray.length; i++) {
- if (mcLevel.collectablesArray[i].collected==false) {
- if ( mcLevel.collectablesArray[i].hitTestObject( mcLevel.mcPlayer.collisionBox ) ) {
- var knownType = false;
- for (k=0; k<collectedStuff.length; k++) {
- if (collectedStuff[k][0] == mcLevel.collectablesArray[i].collectableName.text) {
- knownType = true;
- collectedStuff[k][1] += Number(mcLevel.collectablesArray[i].collectableValue.text);
- mcLevel.collectablesArray[i].collected = true;
- }
- }
- if (!knownType) {
- collectedStuff.push( [String(mcLevel.collectablesArray[i].collectableName.text), Number(mcLevel.collectablesArray[i].collectableValue.text) ] );
- mcLevel.collectablesArray[i].collected = true;
- }
- }
- }
- }
- //##Animations
- for (i=0; i<mcLevel.animationsArray.length; i++) {
- if ( mcLevel.animationsArray[i].collisionBox.hitTestObject( mcLevel.mcPlayer.collisionBox ) ) {
- if (String(mcLevel.animationsArray[i].triggerType.text)=="TOUCH") {
- if (mcLevel.animationsArray[i].animationKey.text == "NONE") {
- mcLevel.animationsArray[i].triggered = true;
- } else {
- for (k=0; k<keysOwned.length; k++) {
- if ( keysOwned[i] == mcLevel.animationsArray[i].animationKey.text ) {
- mcLevel.animationsArray[i].triggered = true;
- }
- }
- }
- } else {
- if (KEYACTIONIN) {
- if (mcLevel.animationsArray[i].animationKey.text == "NONE") {
- mcLevel.animationsArray[i].triggered = true;
- } else {
- for (k=0; k<keysOwned.length; k++) {
- if ( keysOwned[i] == mcLevel.animationsArray[i].animationKey.text ) {
- mcLevel.animationsArray[i].triggered = true;
- }
- }
- }
- } else {
- mcLevel.animationsArray[i].triggered = false;
- }
- }
- } else {
- mcLevel.animationsArray[i].triggered = false;
- }
- }
- //## Teleports
- for (i=0; i<mcLevel.teleportArray.length; i++) {
- if ( mcLevel.teleportArray[i].hitTestObject( mcLevel.mcPlayer.collisionBox ) ) {
- if ( mcLevel.teleportArray[i].teleportType.text == "INSTANT" ) {
- if ( mcLevel.teleportArray[i].teleportKey.text != "NONE" ) {
- for (k=0; k<keysOwned.length; k++) {
- if ( keysOwned[i] == mcLevel.teleportArray[i].teleportKey.text ) {
- teleporting = true;
- }
- }
- } else {
- teleporting = true;
- }
- } else {
- if ( mcLevel.teleportArray[i].teleportKey.text != "NONE" ) {
- for (k=0; k<keysOwned.length; k++) {
- if ( keysOwned[i] == mcLevel.teleportArray[i].teleportKey.text ) {
- if (KEYACTIONIN) {
- teleporting = true;
- }
- }
- }
- } else {
- if (KEYACTIONIN) {
- teleporting = true;
- }
- }
- }
- teleportFrame = Number( mcLevel.teleportArray[i].targetLevel.text );
- teleportX = mcLevel.teleportArray[i].targetX.text;
- teleportY = mcLevel.teleportArray[i].targetY.text;
- }
- }
- if (!foundGround) {
- //We didnt collide
- grounded = false;
- touchingSlope = "not";
- //put the player back to where it was before collision tests
- mcLevel.mcPlayer.y -= 1;
- }
- //## make a record of the players position for next frames collision tests
- lastPos.x = mcLevel.mcPlayer.x;
- lastPos.y = mcLevel.mcPlayer.y;
- } else {
- //talking
- }
- }
- //############################# Player Animation ################################
- targetAnimation = "IDLE";
- if (KEYRIGHTIN) {
- if (!onLadder) {
- facingDirection = "R";
- }
- } else if (KEYLEFTIN) {
- if (!onLadder) {
- facingDirection = "L";
- }
- }
- if (grounded) {
- if (KEYRIGHTIN || KEYLEFTIN) {
- targetAnimation = "RUN";
- } else {
- tempVar = Math.sqrt(xMove*xMove);
- if (tempVar > 0.5) {
- targetAnimation = "SLIDE";
- }
- }
- } else {
- //not grounded
- if ( yMove < 0 ) {
- targetAnimation = "RISE";
- } else {
- targetAnimation = "FALL";
- }
- }
- if (facingDirection == "R") {
- mcLevel.mcPlayer.scaleX = 1;
- } else {
- mcLevel.mcPlayer.scaleX = -1;
- }
- if (dying) {
- targetAnimation = "DIE";
- }
- if (climbing) {
- targetAnimation = "CLIMB";
- }
- if (targetAnimation != "FALL") {
- //prevent slope spazing glitch
- targetAnimationB = targetAnimation;
- }
- if ( targetAnimation != currentAnimation && targetAnimation == targetAnimationB ) {
- switch (targetAnimation) {
- case "IDLE" :
- mcLevel.mcPlayer.gotoAndStop(1);
- break;
- case "RUN" :
- mcLevel.mcPlayer.gotoAndStop(2);
- break;
- case "SLIDE" :
- mcLevel.mcPlayer.gotoAndStop(3);
- break;
- case "RISE" :
- mcLevel.mcPlayer.gotoAndStop(4);
- break;
- case "FALL" :
- mcLevel.mcPlayer.gotoAndStop(5);
- break;
- case "DIE" :
- mcLevel.mcPlayer.gotoAndStop(6);
- break;
- case "CLIMB" :
- //sort out the animations below
- //should work if I put it here but it doesent
- //I'll figure it out later ^___^
- break;
- }
- currentAnimation = targetAnimation;
- }
- if (climbing) {
- if (KEYLEFTIN && !onLadder) {
- if (!onLadder) {
- if (mcLevel.mcPlayer.currentFrame!=9) {
- mcLevel.mcPlayer.gotoAndStop(9);
- }
- }
- } else if (KEYRIGHTIN && !onLadder) {
- if (!onLadder) {
- if (mcLevel.mcPlayer.currentFrame!=9) {
- mcLevel.mcPlayer.gotoAndStop(9);
- }
- }
- } else if (KEYCLIMBUPIN) {
- if (mcLevel.mcPlayer.currentFrame!=8) {
- mcLevel.mcPlayer.gotoAndStop(8);
- }
- } else if (KEYCLIMBDOWNIN) {
- if (mcLevel.mcPlayer.currentFrame!=10) {
- mcLevel.mcPlayer.gotoAndStop(10);
- }
- } else {
- if (mcLevel.mcPlayer.currentFrame!=7) {
- mcLevel.mcPlayer.gotoAndStop(7);
- }
- }
- }
- //prevent slope spazing glitch
- targetAnimationB = targetAnimation;
- if (conveying) {
- if (targetAnimationB == "SLIDE") {
- targetAnimationB = "IDLE";
- targetAnimation = "IDLE";
- mcLevel.mcPlayer.gotoAndStop(1);
- }
- }
- //respawn after dying
- if (targetAnimation == "DIE") {
- if (mcLevel.mcPlayer.deathAnim != null && mcLevel.mcPlayer.deathAnim.currentFrame == mcLevel.mcPlayer.deathAnim.totalFrames) {
- dying = false;
- mcLevel.mcPlayer.x = safeSpot.x;
- mcLevel.mcPlayer.y = safeSpot.y;
- }
- }
- //############################# Level Positioning ################################
- //## Center player in screen
- if (scrollingMode) {
- mcLevel.x = -mcLevel.mcPlayer.x + (STAGEWIDTH / 2);
- mcLevel.y = -mcLevel.mcPlayer.y + (STAGEHEIGHT / 2);
- //# parralax Scrolling
- for (i=0; i<parralaxArray.length; i++) {
- parralaxArray[i][0].x = -(mcLevel.mcPlayer.x*parralaxArray[i][1]);
- parralaxArray[i][0].y = -(mcLevel.mcPlayer.y*parralaxArray[i][1]);
- }
- if (ScrollLimitLeft.x!=0) {
- if (mcLevel.x > -ScrollLimitLeft.x) {
- mcLevel.x = -ScrollLimitLeft.x;
- }
- }
- if (ScrollLimitTop.y!=0) {
- if (mcLevel.y > -ScrollLimitTop.y) {
- mcLevel.y = -ScrollLimitTop.y;
- }
- }
- if (ScrollLimitBottom.y!=0) {
- if (mcLevel.y < stage.stageHeight - ScrollLimitBottom.y) {
- mcLevel.y = stage.stageHeight - ScrollLimitBottom.y;
- }
- }
- if (ScrollLimitRight.x!=0) {
- if (mcLevel.x < stage.stageWidth - ScrollLimitRight.x) {
- mcLevel.x = stage.stageWidth - ScrollLimitRight.x;
- }
- }
- }
- //############################# Level Teleporting ################################
- if (teleporting) {
- if ( teleportFrame != currentFrame ) {
- //teleport to different level
- ScrollLimitLeft = new MovieClip();
- ScrollLimitRight = new MovieClip();
- ScrollLimitBottom = new MovieClip();
- ScrollLimitTop = new MovieClip();
- KEYLEFTIN = false;
- KEYRIGHTIN = false;
- KEYJUMPIN = false;
- KEYACTIONIN = false;
- KEYCLIMBUPIN = false;
- KEYCLIMBDOWNIN = false;
- stage.removeEventListener( Event.ENTER_FRAME, onGameTick );
- gotoAndStop( teleportFrame );
- } else {
- //teleport to somewhere in current level
- if ( teleportX != "-" ) {
- mcLevel.mcPlayer.x = Number(teleportX);
- lastPos.x = mcLevel.mcPlayer.x;
- }
- if ( teleportY != "-" ) {
- mcLevel.mcPlayer.y = Number(teleportY);
- lastPos.y = mcLevel.mcPlayer.y;
- }
- }
- //reset some variables
- grounded = false;
- touchingSlope = "not";
- teleporting = false;
- }
- }
Add Comment
Please, Sign In to add comment