public Player(ContentManager Content, ParticleTools particleTools, GameUnit x, GameUnit y) : base(CollisionType.StickyCollision) { sprites = new Dictionary <SpriteState, Sprite>(); InitializeSprites(Content); this.particleTools = particleTools; kinematicsX = new Kinematics(x, 0); kinematicsY = new Kinematics(y, 0); accelerationX = 0; horizontalFacing = SpriteState.HorizontalFacing.Left; intendedVerticalFacing = SpriteState.VerticalFacing.Horizontal; walkingAnimation = new WalkingAnimation(); maybeGroundTile = null; jumpActive = false; playerHealth = new PlayerHealth(Content); interacting = false; invincibleTimer = new Timer(InvincibleTime); damageText = new FloatingNumber(Content, FloatingNumber.NumberType.Damage); experienceText = new FloatingNumber(Content, FloatingNumber.NumberType.Experience); gunExperienceHud = new GunExperienceHud(Content); polarStar = new PolarStar(Content); collisionRectangle = new CompositeCollisionRectangle(new Rectangle((int)Math.Round(CollisionTopLeft), (int)Math.Round(CollisionYTop), (int)Math.Round(CollisionTopWidth), (int)Math.Round(CollisionYHeight / 2)), new Rectangle((int)Math.Round(CollisionBottomLeft), (int)Math.Round(CollisionYTop + CollisionYHeight / 2), (int)Math.Round(CollisionBottomWidth), (int)Math.Round(CollisionYHeight / 2)), new Rectangle(6, 10, 10, 12), new Rectangle(16, 10, 10, 12)); }
public Player(ContentManager Content, ParticleTools particleTools, GameUnit x, GameUnit y) : base(CollisionType.StickyCollision) { sprites = new Dictionary<SpriteState, Sprite>(); InitializeSprites(Content); this.particleTools = particleTools; kinematicsX = new Kinematics(x, 0); kinematicsY = new Kinematics(y, 0); accelerationX = 0; horizontalFacing = SpriteState.HorizontalFacing.Left; intendedVerticalFacing = SpriteState.VerticalFacing.Horizontal; walkingAnimation = new WalkingAnimation(); maybeGroundTile = null; jumpActive = false; playerHealth = new PlayerHealth(Content); interacting = false; invincibleTimer = new Timer(InvincibleTime); damageText = new FloatingNumber(Content, FloatingNumber.NumberType.Damage); experienceText = new FloatingNumber(Content, FloatingNumber.NumberType.Experience); gunExperienceHud = new GunExperienceHud(Content); polarStar = new PolarStar(Content); collisionRectangle = new CompositeCollisionRectangle(new Rectangle((int)Math.Round(CollisionTopLeft), (int)Math.Round(CollisionYTop), (int)Math.Round(CollisionTopWidth), (int)Math.Round(CollisionYHeight / 2)), new Rectangle((int)Math.Round(CollisionBottomLeft), (int)Math.Round(CollisionYTop + CollisionYHeight / 2), (int)Math.Round(CollisionBottomWidth), (int)Math.Round(CollisionYHeight / 2)), new Rectangle(6, 10, 10, 12), new Rectangle(16, 10, 10, 12)); }
protected void UpdateX(ICollisionRectangle collisionRectangle, IAccelerator accelerator, Kinematics kinematicsX, Kinematics kinematicsY, GameTime gameTime, Map map) { Update(collisionRectangle, accelerator, kinematicsX, kinematicsY, gameTime, map, null, kinematicsX, AxisType.XAxis); }
public void UpdateVelocity(Kinematics kinematics, GameTime gameTime) { if (acceleration < 0) { kinematics.velocity = Math.Max(kinematics.velocity + acceleration * (float)gameTime.ElapsedGameTime.TotalMilliseconds, maxVelocity); } else { kinematics.velocity = Math.Min(kinematics.velocity + acceleration * (float)gameTime.ElapsedGameTime.TotalMilliseconds, maxVelocity); } }
public PowerDoritoPickup(ContentManager Content, GameUnit centerX, GameUnit centerY, SizeType size) : base(CollisionType.BouncingCollision) { kinematicsX = new Kinematics(centerX - Units.HalfTile, (Game1.Random.Next(0, 11) - 5) * 0.025f); kinematicsY = new Kinematics(centerY - Units.HalfTile, (Game1.Random.Next(0, 11) - 5) * 0.025f); sprite = new AnimatedSprite(Content, SpriteName, Units.TileToPixel(SourceX), Units.TileToPixel(SourceYs[(int)size]), Units.TileToPixel(SourceWidth), Units.TileToPixel(SourceHeight), Fps, NumFrames); this.size = size; timer = new Timer(LifeTime, true); }
protected void UpdateY(ICollisionRectangle collisionRectangle, IAccelerator accelerator, Kinematics kinematicsX, Kinematics kinematicsY, GameTime gameTime, Map map, BitArray maybeGroundTile) { Update(collisionRectangle, accelerator, kinematicsX, kinematicsY, gameTime, map, maybeGroundTile, kinematicsY, AxisType.YAxis); }
private void Update(ICollisionRectangle collisionRectangle, IAccelerator accelerator, Kinematics kinematicsX, Kinematics kinematicsY, GameTime gameTime, Map map, BitArray maybeGroundTile, Kinematics kinematics, AxisType axis) { Func <Map, Rectangle, TileInfo.SideType, BitArray, CollisionInfo?> testMapCollisionFunc; if (collisionType == CollisionType.BouncingCollision) { testMapCollisionFunc = TestMapBouncingCollision; } else { testMapCollisionFunc = TestMapStickyCollision; } accelerator.UpdateVelocity(kinematics, gameTime); GameUnit delta = kinematics.velocity * (float)gameTime.ElapsedGameTime.TotalMilliseconds; TileInfo.SideType direction = axis == AxisType.XAxis ? (delta > 0 ? TileInfo.SideType.RightSide : TileInfo.SideType.LeftSide) : (delta > 0 ? TileInfo.SideType.BottomSide : TileInfo.SideType.TopSide); CollisionInfo?maybeInfo = testMapCollisionFunc(map, collisionRectangle.Collision(direction, kinematicsX.position, kinematicsY.position, delta), direction, maybeGroundTile); if (maybeInfo.HasValue) { kinematics.position = maybeInfo.Value.position - collisionRectangle.BoundingBox.Side(direction); debugCollidingTiles.Add(maybeInfo.Value.tilePosition); OnCollision(direction, true, maybeInfo.Value.tileType); } else { kinematics.position += delta; OnDelta(direction); } maybeInfo = null; TileInfo.SideType oppositeDirection = TileInfo.OppositeSide(direction); maybeInfo = testMapCollisionFunc(map, collisionRectangle.Collision(oppositeDirection, kinematicsX.position, kinematicsY.position, 0), oppositeDirection, null); if (maybeInfo.HasValue) { kinematics.position = maybeInfo.Value.position - collisionRectangle.BoundingBox.Side(oppositeDirection); debugOppositeCollidingTiles.Add(maybeInfo.Value.tilePosition); OnCollision(oppositeDirection, false, maybeInfo.Value.tileType); } }
private void Update(ICollisionRectangle collisionRectangle, IAccelerator accelerator, Kinematics kinematicsX, Kinematics kinematicsY, GameTime gameTime, Map map, BitArray maybeGroundTile, Kinematics kinematics, AxisType axis) { Func<Map, Rectangle, TileInfo.SideType, BitArray, CollisionInfo?> testMapCollisionFunc; if (collisionType == CollisionType.BouncingCollision) { testMapCollisionFunc = TestMapBouncingCollision; } else { testMapCollisionFunc = TestMapStickyCollision; } accelerator.UpdateVelocity(kinematics, gameTime); GameUnit delta = kinematics.velocity * (float)gameTime.ElapsedGameTime.TotalMilliseconds; TileInfo.SideType direction = axis == AxisType.XAxis ? (delta > 0 ? TileInfo.SideType.RightSide : TileInfo.SideType.LeftSide) : (delta > 0 ? TileInfo.SideType.BottomSide : TileInfo.SideType.TopSide); CollisionInfo? maybeInfo = testMapCollisionFunc(map, collisionRectangle.Collision(direction, kinematicsX.position, kinematicsY.position, delta), direction, maybeGroundTile); if (maybeInfo.HasValue) { kinematics.position = maybeInfo.Value.position - collisionRectangle.BoundingBox.Side(direction); debugCollidingTiles.Add(maybeInfo.Value.tilePosition); OnCollision(direction, true, maybeInfo.Value.tileType); } else { kinematics.position += delta; OnDelta(direction); } maybeInfo = null; TileInfo.SideType oppositeDirection = TileInfo.OppositeSide(direction); maybeInfo = testMapCollisionFunc(map, collisionRectangle.Collision(oppositeDirection, kinematicsX.position, kinematicsY.position, 0), oppositeDirection, null); if (maybeInfo.HasValue) { kinematics.position = maybeInfo.Value.position - collisionRectangle.BoundingBox.Side(oppositeDirection); debugOppositeCollidingTiles.Add(maybeInfo.Value.tilePosition); OnCollision(oppositeDirection, false, maybeInfo.Value.tileType); } }
public void UpdateVelocity(Kinematics kinematics, GameTime gameTime) { kinematics.velocity = kinematics.velocity > 0.0f ? (float)Math.Max(0.0f, kinematics.velocity - friction * gameTime.ElapsedGameTime.TotalMilliseconds) : (float)Math.Min(0.0f, kinematics.velocity + friction * gameTime.ElapsedGameTime.TotalMilliseconds); }
public Kinematics2D(Kinematics x, Kinematics y) { this.x = x; this.y = y; }
public void UpdateVelocity(Kinematics kinematics, GameTime gameTime) { }