/// <summary> /// Makes the ninja slide on a wall associated with the command passed in. /// </summary> public void Action_WallSlide(Command c) { if (c.CollidesWithConnectedPlatforms(DrawFrame()) != null) { actionState = NinjaActionState.WallSliding; } }
/// <summary> /// Makes the ninja climb a ledge associated with the command passed in. /// </summary> /// <param name="c"></param> public void Action_LedgeClimb(Command c) { Platform p = c.CollidesWithConnectedPlatforms(DrawFrame()); if (p == null) return; if (GetDrawFrameY() < p.GetDrawFrameY()) { actionState = NinjaActionState.WallClimbing; //animatedFrameSlide(new Point(NINJA_WIDTH, 0), 15, true); //animatedFrameSlide(new Point(0, GetDrawFrameY() - p.GetDrawFrameY()), 15, false); WorldObjectMove(NINJA_WIDTH, GetDrawFrameY() - p.GetDrawFrameY()); velocity.Y = 0; } }
/// <summary> /// Makes the ninja wall jump. /// </summary> /// <param name="fLeft"></param> public void Action_WallJump(Command c) { if (c.CollidesWithConnectedPlatforms(DrawFrame()) != null) { velocity.Y = NinjaJumpHeight; Action_Move(c.FacesLeft); actionState = NinjaActionState.WallJumping; } }
public override void Update(int gameTime) { if (deathEffectEmitter != null){ deathEffectEmitter.Update(); if (deathEffectEmitter.atMaxParticles()) deathEffectEmitter.isEmitting = false; } //don't update a dead ninja if (ninjaLifeState == LifeState.Dead) return; if (warpEffectEmitter != null) { warpEffectEmitter.Update(); if (warpEffectEmitter.atMaxParticles()) warpEffectEmitter.isEmitting = false; } //turn off spark emission right after every update; it will be turned on again if we are still wall sliding if (wallSlideSparkEmitter != null) { wallSlideSparkEmitter.Update(); wallSlideSparkEmitter.isEmitting = false; } //for (int i = 0; i < 4; i++) { ninjaCrush[i] = false; }//resetting the ninjs's so that collisions from the last upadate are not confused with ones from this update ninjaCrush[0] = ninjaCrush[1] = ninjaCrush[2] = ninjaCrush[3] = false; if (positionMask != PositionState.OnRope) rotationAngle = 0.0f; AnimationComponent deathAnimation = null; // Change the Animation State of the Ninja switch(actionState) { case NinjaActionState.Standing: actionState = NinjaActionState.Running; break; case NinjaActionState.Airborne: //Debug.WriteLine("Air"); airborne.Update(gameTime); if (positionMask == PositionState.OnFloor) { actionState = NinjaActionState.Running; airborne.reset(); } break; case NinjaActionState.Running: velocity.X = NinjaMovement; running.Update(gameTime); if (positionMask == PositionState.InAir) { actionState = NinjaActionState.Airborne; running.reset(); } break; case NinjaActionState.Jumping: //Debug.WriteLine("Jump"); if (jumping.animationComplete()) { jumping.reset(); actionState = NinjaActionState.Airborne; } else jumping.Update(gameTime); velocity.X = NinjaMovement; break; case NinjaActionState.WallJumping: velocity.X = NinjaMovement; //TODO: Temp fix below. Wall jump state should end when animation ends, not when he hits the floor. if (positionMask == PositionState.OnFloor) { wallJumping.reset(); actionState = NinjaActionState.Running; //wallJumping update } else if (wallJumping.animationComplete()) { wallJumping.reset(); actionState = NinjaActionState.Airborne; } else wallJumping.Update(gameTime); break; case NinjaActionState.WallSliding: //if we are wall sliding, turn on the emission again wallSlideSparkEmitter.isEmitting = true; //create rectangle to correct region based on ninja's direction //this will not be necessary if we can anchor the emitter int xvar; if (!wallSlideFacingLeft) xvar = drawRect.Right - 10; else xvar = drawRect.Left; Rectangle b = new Rectangle(xvar, drawRect.Bottom, 10, 10); wallSlideSparkEmitter.AssignRegion(b); velocity.X = 0; velocity.Y = NinjaWallSlideSpeed; if (WallSlidePlatform.GetPatrol() != null) { velocity.X += WallSlidePlatform.velocity.X; velocity.Y += WallSlidePlatform.velocity.Y; } wallSliding.Update(gameTime); if ((drawRect.Top > WallSlidePlatform.drawRect.Top + WallSlidePlatform.drawRect.Height)) { actionState = NinjaActionState.Airborne; } else if(positionMask == PositionState.OnFloor) { actionState = NinjaActionState.Running; } break; case NinjaActionState.WallClimbing: wallClimbing.Update(gameTime); if (wallClimbing.animationComplete()) { wallClimbing.reset(); actionState = NinjaActionState.Rolling; } else if (positionMask == PositionState.OnFloor) { wallClimbing.reset(); actionState = NinjaActionState.Running; } break; case NinjaActionState.Rolling: Rolling.Update(gameTime); if (positionMask == PositionState.OnFloor) { actionState = NinjaActionState.Running; Rolling.reset(); } break; case NinjaActionState.ItemThrowing: ItemThrowing.Update(gameTime); if (ItemThrowing.animationComplete()) { ItemThrowing.reset(); actionState = NinjaActionState.Airborne; } break; case NinjaActionState.SwordSwinging: SwordSwinging.Update(gameTime); if (SwordSwinging.animationComplete()) { SwordSwinging.reset(); actionState = NinjaActionState.Airborne; } break; case NinjaActionState.SwordRunning: velocity.X = NinjaMovement; SwordRunning.Update(gameTime); if (positionMask == PositionState.InAir) { actionState = NinjaActionState.Airborne; running.reset(); } break; case NinjaActionState.ShurikenRunning: velocity.X = NinjaMovement; ShurikenRunning.Update(gameTime); if (positionMask == PositionState.InAir) { actionState = NinjaActionState.Airborne; running.reset(); } break; case NinjaActionState.VictoryPose: VictoryPose.Update(gameTime); break; case NinjaActionState.FallDying: deathAnimation = FallDying; break; case NinjaActionState.FireDying: deathAnimation = FireDying; break; case NinjaActionState.ExplodeDying: deathAnimation = ExplodeDying; break; case NinjaActionState.VillainDying: deathAnimation = VillainDying; break; case NinjaActionState.WarpingIn: UpdateWarpAnimation(); break; } if (deathAnimation != null) { deathAnimation.Update(gameTime); if (deathAnimation.animationComplete()) { deathAnimation.reset(); ninjaLifeState = LifeState.Dead; actionState = NinjaActionState.Airborne; } //stop the ninja's X movement when he dies velocity.X = 0; dialogue.showDialog(true); } if (HeldItem != null && !HeldItem.isFired && ninjaLifeState == LifeState.Alive) { if (positionMask == PositionState.OnFloor) // Animate with item IF he's running. We don't have animations for other fancy schmancy shit { switch (HeldItem.type) { case ItemType.Shuriken: actionState = NinjaActionState.ShurikenRunning; break; case ItemType.Sword: if(actionState != NinjaActionState.SwordSwinging) actionState = NinjaActionState.SwordRunning; break; } } Point itemPos = this.drawRect.Location; itemPos.X = itemPos.X + NINJA_WIDTH / 2; HeldItem.SetPosition(itemPos); } if (tempDelay <= 0) { switch (actionState) { case NinjaActionState.Running: if (facingLeft && velocity.X >= 0) { Action_Move(facingLeft); NinjaMovement = (-1)*NinjaRunSpeed; } if (!facingLeft && velocity.X <= 0) { Action_Move(facingLeft); NinjaMovement = NinjaRunSpeed; } break; case NinjaActionState.ShurikenRunning: goto case NinjaActionState.Running; case NinjaActionState.SwordRunning: goto case NinjaActionState.Running; } base.Update(gameTime); } else { tempDelay--; } }
/// <summary> /// Makes the ninja jump. /// </summary> public void Action_Jump() { if (positionMask == PositionState.OnFloor) { velocity.Y = NinjaJumpHeight; positionMask = PositionState.InAir; actionState = NinjaActionState.Jumping; } else if (positionMask == PositionState.OnRope) { velocity.Y = NinjaJumpHeight; positionMask = PositionState.InAir; onThisRope.ropeRelease(true); actionState = NinjaActionState.Jumping; } }
private void ResetWarpAnimation() { warpAnimationCompleted = false; warpFramesRemaining = warpFramesMaximum; //warpWidth = 1; //warpDrawFrame = Rectangle.Empty; warpDrawColor = Color.Black; actionState = NinjaActionState.WarpingIn; MusicManager.PlaySoundEffect(SoundEffects.warpIn); }
//If the ninja is sandwiched by two platforms, kill him. Called once by WorldObjectManager's collision code. public void squishCheck(bool c1, bool c2, bool c3, bool c4) { if( ( c1 && c3 ) || ( c2 && c4 ) ){ death(); actionState = NinjaActionState.ExplodeDying; return; } }
/// <summary> /// Makes the ninja slide on a wall associated with the command passed in. /// Returns true if wall slide was successful, false otherwise /// </summary> public bool Action_WallSlide(Command c) { if (actionState == NinjaActionState.WallSliding) return false; Platform p = c.CollidesWithConnectedPlatforms(this); //Checks to see if the Ninja collides with Command C's list of tagged platforms if (p != null) { if (velocity.X > 0) wallSlideFacingLeft = false; else wallSlideFacingLeft = true; actionState = NinjaActionState.WallSliding; WallSlidePlatform = p; //create rectangle for emission based on ninja's direction int xvar; if (!wallSlideFacingLeft) xvar = drawRect.Right - 10; else xvar = drawRect.Left; Rectangle b = new Rectangle(xvar, drawRect.Bottom, 10, 10); //create the emitter wallSlideSparkEmitter = new Emitter(b, //bounding box of the emitter //new Vector2((float)(facingLeft ? Math.Tan(Math.PI / 18) * NinjaWallSlideSpeed : Math.Tan(Math.PI / 18) * -NinjaWallSlideSpeed), new Vector2(wallSlideFacingLeft ? 0.6215f : -0.6215f, (float)-NinjaWallSlideSpeed), //starting velocity vector (roughly 100 or 80 degrees depending which way ninja is facing) Math.PI / 18, //maximum angle (in radians) a particle's vector may deviate from the specified one 0.3, 0.01, //intensity (particles are generated at a frequency of 30 frames / thisvalue) 300, //maximum number of particles 30, //particle lifespan, in frames SparkTextures, //Linked list of textures this emitter can use when generating particles new Vector2(0, 1.7f), //A delta vector acting on particles; in this case, it's working as a lighter form of gravity new Vector2(0, 8f), //a delta vector cutoff; in this case, it's the max velocity 0.2); //the fraction of particles generated by this emitter that will employ the above delta vectors to modify their velocity wallSlideSparkEmitter.particlesFade = true; return true; } return false; }
public void EndWarpAnimation() { if (warpAnimationCompleted) return; warpAnimationCompleted = true; actionState = NinjaActionState.Running; }
/// <summary> /// Make the ninja throw its held item /// Returns true if item throw was successful, false otherwise /// </summary> public bool Action_ThrowItem(Command c) { if (HeldItem != null) { MusicManager.PlaySoundEffect(SoundEffects.throwItem); if (actionState != NinjaActionState.WallSliding) actionState = NinjaActionState.ItemThrowing; HeldItem.isFired = true; Point target = c.GetActionTargetLocation(); Point direction = new Point(target.X - c.drawRect.Left, target.Y - c.drawRect.Top); HeldItem.SetCenter(new Point(c.drawRect.Center.X, c.drawRect.Center.Y)); HeldItem.SetDirection(direction); HeldItem = null; return true; } return false; }
/// <summary> /// Makes the ninja wall jump. /// Returns true if wall jump was successful, false otherwise /// </summary> /// <param name="fLeft"></param> public bool Action_WallJump(Command c) { int result = c.WJCollidesWithConnectedPlatforms(this); if (result == 2) { velocity.Y = NinjaJumpHeight; wallJumping.reset(); actionState = NinjaActionState.WallJumping; Action_Move(true); //facingLeft = c.FacesLeft; tempDelay = 10; return true; } else if(result == 4) { velocity.Y = NinjaJumpHeight; wallJumping.reset(); actionState = NinjaActionState.WallJumping; Action_Move(false); //facingLeft = c.FacesLeft; tempDelay = 10; return true; } return false; }
public void Action_SwingSword() { actionState = NinjaActionState.SwordSwinging; }
/// <summary> /// Makes the ninja climb a ledge associated with the command passed in. /// Returns true if ledge climb was successful, false otherwise /// </summary> /// <param name="c"></param> public bool Action_LedgeClimb(Command c, LinkedList<Platform> listOfWorldPlatforms) { LinkedList<Platform> commandConnected = c.ConnectedPlatforms; Rectangle collisionBound = drawRect; collisionBound.Width *= 2; //Player ghost = Copy(); WorldObject ghost = new WorldObject(drawRect); Platform willClimb = null; int collisionState; if (commandConnected == null) return false; //For each connected Platform, check to see if the ninja collides with the side, and then check if its ledge is clear to climb foreach (Platform p in commandConnected) { collisionState = Collision.checkCollisions(this,p); if ((collisionState == 2 && velocity.X > 0) || (collisionState == 4 && velocity.X < 0)) { collisionBound.Y = p.drawRect.Top - collisionBound.Height - 1; // move collision bound to sit on top of the platform. ghost.SetDrawFrame(collisionBound); bool canClimb = true; //check to see if the area where the ninja would ledge climb is clear foreach (Platform p2 in listOfWorldPlatforms) { if (Collision.checkCollisions(ghost, p2) != 0) { canClimb = false; break; } } if (canClimb) { willClimb = p; break; } } } ghost = null; if (willClimb == null) return false; if (drawRect.Top < willClimb.drawRect.Top) { actionState = NinjaActionState.WallClimbing; velocity.Y = (float)NinjaJumpHeight / 1.25f; return true; } return false; }
public Player(Point topLeft) : base(new Rectangle(topLeft.X, topLeft.Y, NINJA_WIDTH, NINJA_HEIGHT), NinjaTexture) { velocity = Vector2.Zero; NinjaMovement = NinjaRunSpeed; ninjaLifeState = LifeState.Alive; hasGravity = true; actionState = NinjaActionState.Standing; resizeRect = ScreenCoordinateDrawFrame(); ResetWarpAnimation(); running = new AnimationComponent(RunTextures, drawRect.Left, drawRect.Top, NINJA_WIDTH, NINJA_HEIGHT, 1); jumping = new AnimationComponent(JumpTextures, drawRect.Left, drawRect.Top, NINJA_WIDTH, NINJA_HEIGHT, 2); airborne = new AnimationComponent(AirborneTextures, drawRect.Left, drawRect.Top, NINJA_WIDTH, NINJA_HEIGHT, 1); wallJumping = new AnimationComponent(WallJumpTextures, drawRect.Left, drawRect.Top, NINJA_WIDTH, NINJA_HEIGHT, 2); wallClimbing = new AnimationComponent(WallClimbTextures, drawRect.Left, drawRect.Top, NINJA_WIDTH, NINJA_HEIGHT, 1); Rolling = new AnimationComponent(RollTextures, drawRect.Left, drawRect.Top, NINJA_WIDTH, NINJA_HEIGHT, 1); wallSliding = new AnimationComponent(WallSlideTextures, drawRect.Left, drawRect.Top, NINJA_WIDTH, NINJA_HEIGHT, 1); ItemThrowing = new AnimationComponent(ItemThrowTextures, drawRect.Left, drawRect.Top, NINJA_WIDTH, NINJA_HEIGHT, 1); SwordSwinging = new AnimationComponent(SwordSwingTextures, drawRect.Left, drawRect.Top, NINJA_WIDTH, NINJA_HEIGHT, 1); SwordRunning = new AnimationComponent(SwordRunTextures, drawRect.Left, drawRect.Top, NINJA_WIDTH, NINJA_HEIGHT, 1); ShurikenRunning= new AnimationComponent(ShurikenRunTextures, drawRect.Left, drawRect.Top, NINJA_WIDTH, NINJA_HEIGHT, 1); VictoryPose= new AnimationComponent(VictoryTextures, drawRect.Left, drawRect.Top, NINJA_WIDTH, NINJA_HEIGHT, 1); SquishDying= new AnimationComponent(SquishDeathTextures, drawRect.Left, drawRect.Top, NINJA_WIDTH, NINJA_HEIGHT, 1); FallDying= new AnimationComponent(FallDeathTextures, drawRect.Left, drawRect.Top, NINJA_WIDTH, NINJA_HEIGHT, 1); FireDying= new AnimationComponent(FireDeathTextures, drawRect.Left, drawRect.Top, NINJA_WIDTH, NINJA_HEIGHT, 1); ExplodeDying = new AnimationComponent(ExplodeDeathTextures, drawRect.Left, drawRect.Top, NINJA_WIDTH, NINJA_HEIGHT, 1); VillainDying = new AnimationComponent(VillainDeathTextures, drawRect.Left, drawRect.Top, NINJA_WIDTH, NINJA_HEIGHT, 1); }
public override void Update(int gameTime) { //only update the ninja if he is not dead if (ninjaLifeState == LifeState.Dead) return; crushStatus = CollisionType.CollisionNone;//resetting crushStatus so that collisions from the last upadate are not confused with ones from this update if (positionMask != PositionState.OnRope) rotationAngle = 0.0f; // Change the Animation State of the Ninja switch(actionState) { case NinjaActionState.Standing: break; case NinjaActionState.Airborne: airborne.Update(gameTime); break; case NinjaActionState.Running: velocity.X = NinjaMovement; running.Update(gameTime); break; case NinjaActionState.Jumping: jumping.Update(gameTime); if (jumping.animationComplete()) { actionState = NinjaActionState.Airborne; jumping.reset(); } velocity.X = NinjaMovement; break; case NinjaActionState.WallJumping: velocity.X = NinjaMovement; break; case NinjaActionState.WallSliding: velocity.X = 0; velocity.Y = NinjaWallSlideSpeed; break; } //If in the air and not jumping, you are airborne if (positionMask == PositionState.InAir && actionState != NinjaActionState.Jumping) { actionState = NinjaActionState.Airborne; } //If you are airborne and then hit ground, you are running else if (positionMask == PositionState.OnFloor) { actionState = NinjaActionState.Running; airborne.reset(); } if (HeldItem!=null && !HeldItem.isFired) { Point itemPos = this.Location(); itemPos.X = itemPos.X + NINJA_WIDTH / 2; HeldItem.SetPosition(itemPos); } base.Update(gameTime); }
public void fireDeath() { if (ninjaLifeState == LifeState.Alive) { Point p = this.drawRect.Location; Metrics.Metrics.writeLine("Level: City"); Metrics.Metrics.writeLine("Death Location: (" + p.X + "," + p.Y + ")"); Metrics.Metrics.writeLine("Death Via Fire"); actionState = NinjaActionState.FireDying; ninjaLifeState = LifeState.Dying; deathEffectEmitter = new Emitter(drawRect, new Vector2(0, -11f), Math.PI / 2, 0.5, 0.001, 80, 120, GoreTextures, new Vector2(0f, 0.75f), new Vector2(0, 15f), 1.0); MusicManager.PlaySoundEffect(SoundEffects.splat1); } // needs to go to some wait state after this }
public Player(Point topLeft) : base(new Rectangle(topLeft.X, topLeft.Y, NINJA_WIDTH, NINJA_HEIGHT), NinjaTexture) { velocity = Vector2.Zero; NinjaMovement = NinjaRunSpeed; ninjaLifeState = LifeState.Alive; hasGravity = true; actionState = NinjaActionState.Standing; running = new AnimationComponent(RunTextures, GetDrawFrameX(), GetDrawFrameY(), NINJA_WIDTH, NINJA_HEIGHT); jumping = new AnimationComponent(JumpTextures, GetDrawFrameX(), GetDrawFrameY(), NINJA_WIDTH, NINJA_HEIGHT); airborne = new AnimationComponent(AirborneTextures, GetDrawFrameX(), GetDrawFrameY(), NINJA_WIDTH, NINJA_HEIGHT); //wallJumping = new AnimationComponent(WallJumpTextures, GetDrawFrameX(), GetDrawFrameY(), NINJA_IMAGE_X, NINJA_IMAGE_Y); //wallClimbing = new AnimationComponent(WallClimbTextures, GetDrawFrameX(), GetDrawFrameY(), NINJA_IMAGE_X, NINJA_IMAGE_Y); }
/// <summary> /// killed by an enemy object /// </summary> public void villainDeath() { if (ninjaLifeState == LifeState.Alive) { Point p = this.drawRect.Location; Metrics.Metrics.writeLine("Level: City"); Metrics.Metrics.writeLine("Death Location: (" + p.X + "," + p.Y + ")"); Metrics.Metrics.writeLine("Death Via Villain"); actionState = NinjaActionState.VillainDying; ninjaLifeState = LifeState.Dying; Rectangle r = drawRect; r.X += 24; r.Y += 37; r.Width = 1; r.Height = 1; deathEffectEmitter = new Emitter(r, new Vector2(facingLeft? 15f: -15f, 0f), Math.PI / 6, 0.5, 0.001, 80, 120, BloodTextures, new Vector2(0f, 0.75f), new Vector2(0, 15f), 1.0); MusicManager.PlaySoundEffect(SoundEffects.splat1); } // needs to go to some wait state after this }