public void Die(Level level) { level.PlaySoundEffect(mDeathEffect); level.PlayerDeath(); }
public void Update(GameTime theGameTime, Level level, InputState inputState) { Acceleration = Vector2.Zero; var curstate = mCurrentState; CheckCollisions(level, inputState.IsInteracting(null)); if (curstate == State.Air && (mCurrentState == State.Ground || mCurrentState == State.Platform)) level.PlaySoundEffect(mLandingEffect); UpdateMovement(inputState); if (UpdateJump(inputState)) level.PlaySoundEffect(mJumpEffect); UpdateDuck(inputState); Acceleration.Y = (mCurrentState == State.Air || mCurrentState == State.GravityPortal || mCurrentState == State.Portal ? 1 : 0) * level.Gravity * Level.METERS_TO_UNITS; if (Angle != 0) { if(Angle > 0) Angle = (float)Math.Max(0, Angle - Math.PI * theGameTime.ElapsedGameTime.TotalSeconds / 2); else Angle = (float)Math.Min(0, Angle + Math.PI * theGameTime.ElapsedGameTime.TotalSeconds / 2); } base.Update(theGameTime); mFlip = mGunhand.Update(inputState.CurrentMouseState, mIsDucking, this, level.Position); UpdateProjectile(theGameTime, inputState, level); }
public void Fire(Vector2 startPosition, Vector2 direction, Vector2 acceleration, Level lvl) { if(mFireSound != null) lvl.PlaySoundEffect(mFireSound); Position = startPosition; Velocity = direction * mSpeed; Acceleration = acceleration; Visible = true; }
public void Open(Vector2 position, Orientation orientation, int portalNumber, Vector2 movement, Level lvl) { Sprite chosenOne = portalNumber == 1 ? Portal2 : Portal1; chosenOne.Visible = true; chosenOne.Angle = (int)orientation % 2== 0 ? MathHelper.PiOver2 : 0; chosenOne.Position = position; chosenOne.Oriented = orientation; chosenOne.FrameVelocity = movement; if (Portal1.Visible == Portal2.Visible) { if (!Rectangle.Intersect(Portal1.CollisionSurface, Portal2.CollisionSurface).IsEmpty) { Close(portalNumber); return; } mState = PortalState.Open; lvl.PlaySoundEffect(mOpenPortalEffect); } lvl.LevelStatistics.PortalsOpened++; }
private bool HandleStandardCollision(Rectangle result, Rectangle obj, Surface type, float friction, Level level) { if(type == Surface.Antiportal) //no physical interaction with antiportal surfaces { //reset portals if(level.Portals.Portal1.Visible || level.Portals.Portal2.Visible) { level.Portals.Reset(); level.PlaySoundEffect(antiportalEffect); } } else if (3 >= result.Height || result.Width >= this.CollisionSurface.Width - 1 || result.Height / (float)CollisionSurface.Height < result.Width / (float)CollisionSurface.Width) { if (CollisionSurface.Center.Y < obj.Center.Y) { mCurrentFriction = friction * MASS; mCurrentState = (mCurrentState == State.Portal || mCurrentState == State.GravityPortal) ? mCurrentState : State.Ground; Velocity.Y = 0; Position = new Vector2(Position.X, obj.Top - Center.Y + 1); mCollisions[(int)Orientation.Down] = obj; } else { Velocity.Y = Math.Max(Velocity.Y, 5); Position = new Vector2(Position.X, obj.Bottom + Center.Y *1.41f); mCollisions[(int)Orientation.Up] = obj; } stillJumping = false; stillWallJumpingLeft = false; stillWallJumpingRight = false; } else { if (Position.X > result.X) { mCollisions[(int)Orientation.Left] = obj; wallJumpRight = true; //walljump from left wall to right direction is available to player if (Velocity.X < 0) Velocity.X = 0; } else if (Position.X < result.X) { mCollisions[(int)Orientation.Right] = obj; wallJumpLeft = true; //walljump from right wall to left direction is available to player if (Velocity.X > 0) Velocity.X = 0; } Position = new Vector2(result.X - (Position.X - result.X < 0 ? CollisionSurface.Width - Center.X - 1 : -result.Width + 1 - Center.X), Position.Y); } return type == Surface.Death; }
public void Die(Level level) { //animator.PlayAnimation(deathAnimation); level.PlaySoundEffect(mDeathEffect); level.PlayerDeath(); }
public void Open(Vector2 position, Orientation orientation, int portalNumber, Vector2 movement, Level lvl, object targetObject) { Sprite chosenOne = mPortals[portalNumber]; try { mPortalHolders[portalNumber] = targetObject; chosenOne.Visible = true; chosenOne.Angle = (int)orientation % 2== 0 ? MathHelper.PiOver2 : 0; chosenOne.Position = position; chosenOne.Oriented = orientation; chosenOne.FrameVelocity = movement; int count = 0; foreach (Tile t in lvl.Tiles) if (!Rectangle.Intersect(chosenOne.CollisionSurface, t.Dimensions).IsEmpty) ++count; if (count > 1) throw new Exception("Invalid Portal Location"); } catch { mPortalHolders[portalNumber] = null; chosenOne.Visible = false; return; } if (Portal1.Visible == Portal2.Visible) { if (!Rectangle.Intersect(Portal1.CollisionSurface, Portal2.CollisionSurface).IsEmpty) { Close(1 - portalNumber); return; } mState = PortalState.Open; lvl.PlaySoundEffect(mOpenPortalEffect); } lvl.LevelStatistics.PortalsOpened++; }