public override void HandleCollision(Vector2 vector, AABB collision, Entity collider) { Side side = AABB.SideHit(BoundingBox, collision); if (side == Side.BOTTOM && collider is PlayerChar) { if (item != null) { item.EmergingTransition(); item = null; } PlayerChar colliderChar = (PlayerChar)collider; if ((colliderChar.IsSmall() && Velocity.Equals(Vector2.Zero))) { this.HitTransition(); } else if (!colliderChar.IsSmall()) { this.BigHitTransition(); } } // Bounce any entities off except for an emerging or inactive item if (collider is ItemEntity) { if (!(((ItemEntity)collider).CurrentItemState is InactiveItemState) && !(((ItemEntity)collider).CurrentItemState is EmergingItemState)) { Bounce(side, collision, collider); } } else if ((collider is EnemyEntity) || (collider is PlayerChar && Velocity.Y == 0)) { Bounce(side, collision, collider); } }
public override bool Equals(object obj) { return(obj is Point3 point && X == point.X && Y == point.Y && Z == point.Z && (Velocity?.Equals(point.Velocity) ?? true)); }
public override void Update(GameTime gameTime) { if (EnemyState is PiranhaPlantDownState) { if (Position.Y >= anchor.Y) { Velocity = Vector2.Zero; Collidable = false; } } else { if (Position.Y <= anchor.Y - SourceRectangle.Height) { EnemyState = new PiranhaPlantDownState(this); EnemyState.Enter(); } } Position += Velocity; if (!Velocity.Equals(Vector2.Zero))//then it isn't hidden { if (Frame <= lastUpdate) { if (SourceRectangle.X != 0) { SourceRectangle = new Rectangle(new Point(0, 0), SourceRectangle.Size); } else { SourceRectangle = new Rectangle(new Point(Texture.Width / 2, 0), SourceRectangle.Size); } lastUpdate = 0; } else { lastUpdate += (int)gameTime.ElapsedGameTime.TotalMilliseconds; } } else { if (SourceRectangle.X != 0) { SourceRectangle = new Rectangle(new Point(0, 0), SourceRectangle.Size); } } }
private void MoveGoriya() { if (movementTimer == EnemyConstants.GoriyaMovementTimer) { Velocity = Vector2.UnitX * Constant.RNG.Next(-1, 2) * EnemyConstants.GoriyaSpeed; if (Velocity.X.Equals(0f)) { while (Velocity.Equals(Vector2.Zero)) { Velocity = Vector2.UnitY * Constant.RNG.Next(-1, 2) * EnemyConstants.GoriyaSpeed; } if (Velocity.Y > 0) { facingDirection = Enumerations.Direction.Down; Sprite = EnemySpriteFactory.Instance.CreateSpriteEnemyGoriyaWalkDown(); } else { facingDirection = Enumerations.Direction.Up; Sprite = EnemySpriteFactory.Instance.CreateSpriteEnemyGoriyaWalkUp(); } } else { if (Velocity.X > 0) { facingDirection = Enumerations.Direction.Right; Sprite = EnemySpriteFactory.Instance.CreateSpriteEnemyGoriyaWalkRight(); } else { facingDirection = Enumerations.Direction.Left; Sprite = EnemySpriteFactory.Instance.CreateSpriteEnemyGoriyaWalkLeft(); } } movementTimer = 0; } if (HasHitWall) { HasHitWall = false; TurnRight(EnemyConstants.GoriyaSpeed); } Position += Velocity; movementTimer++; }
public Stalfos() { Sprite = EnemySpriteFactory.Instance.CreateSpriteEnemyStalfos(); Position = Constant.EnemyStartPosition; DamageAmount = EnemyConstants.StalfosDamageAmount; MaxHP = EnemyConstants.StalfosHP; CurrentHP = MaxHP; Velocity = Vector2.UnitX * Constant.RNG.Next(-1, 2) * EnemyConstants.StalfosSpeed; if (Velocity.X.Equals(0f)) { while (Velocity.Equals(Vector2.Zero)) { Velocity = Vector2.UnitY * Constant.RNG.Next(-1, 2) * EnemyConstants.StalfosSpeed; } } }
public bool Equals(ParticleType p) { // If parameter is null return false: if (p == null) { return(false); } // Return true if the fields match: return(Position.Equals(p.Position) && Velocity.Equals(p.Velocity) && Acceleration.Equals(p.Acceleration) && Lifespan.Equals(p.Lifespan) && Mass.Equals(p.Mass) && BodySize.Equals(p.BodySize) && HistoryLength.Equals(p.HistoryLength) && InitialVelocitySet.Equals(p.InitialVelocitySet) && Orientation.Equals(Orientation)); }
static void Main(string[] args) { /* a) Easy creation of and operation on quantities */ Length macroscopic = Length.Si <Kilo, Metre>(6378.16); Length microscopic = Length.Si <Micro, Metre>(0.89); Length nonSiUnit = Length.Imperial <Foot>(1737.1); Length sum = macroscopic + microscopic + nonSiUnit; Console.WriteLine($"{macroscopic} + {microscopic} + {nonSiUnit} = {sum:g8}"); // Writes: 6378.16 Km + 0.89 μm + 1737.1 ft = 6378.6895 Km /* b) Combine quantities to form other quantities */ /* b.i) Length -> Volume */ Length width = Length.Si <Deci, Metre>(3.1415); Length height = Length.Imperial <Mile>(27.18); Length depth = Length.Si <Kilo, Metre>(33); Volume volume = width * height * depth; Console.WriteLine($"{width} * {height} * {depth} = {volume:g4}"); // Writes: 3.1415 dm * 27.18 mi * 33 Km = 0.4535 Km³ /* b.ii) Length & Time -> Velocity */ // indirect (computation) of velocity Length distance = Length.Si <Kilo, Metre>(160.9344); Time duration = Time.Seconds(7200); Velocity velocity = distance / duration; // direct (creation) of velocity Velocity otherVelocity = Velocity.Imperial <Mile>(50).Per <Hour>(); // which represent the same linear velocity String comparison = velocity.Equals(otherVelocity) ? "yes" : "no"; Console.WriteLine($"Is {velocity} equal to {otherVelocity}? -> {comparison}"); // Writes: Is 0.022352 Km/s equal to 50 mi/h? -> yes /* c) Transform quantities to other representations */ Velocity velInKmph = velocity.To <Kilo, Metre>().Per <Hour>(); Velocity velInMiph = velocity.ToImperial <Mile>().Per <Hour>(); Console.WriteLine($"{velInKmph} and {velInMiph} are equal velocities"); // Writes: 80.4672 Km/h and 50 mi/h are equal velocities }
private void MoveStalfos() { if (movementTimer == EnemyConstants.StalfosMovementTimer) { Velocity = Vector2.UnitX * Constant.RNG.Next(-1, 2) * EnemyConstants.StalfosSpeed; if (Velocity.X.Equals(0f)) { while (Velocity.Equals(Vector2.Zero)) { Velocity = Vector2.UnitY * Constant.RNG.Next(-1, 2) * EnemyConstants.StalfosSpeed; } } movementTimer = 0; } if (HasHitWall) { HasHitWall = false; TurnRight(EnemyConstants.StalfosSpeed); } Position += Velocity; movementTimer++; }
public override bool Equals(object obj) { if (obj == null) { return(false); } PositionPlayerState other = (PositionPlayerState)obj; if (!Position.Equals(other.Position)) { return(false); } if (ViewOffsetZ != other.ViewOffsetZ) { return(false); } if (!Velocity.Equals(other.Velocity)) { return(false); } if (ViewDirectionX != other.ViewDirectionX) { return(false); } if (ViewDirectionY != other.ViewDirectionY) { return(false); } return(true); }
public override bool Equals(object obj) { var moon = obj as Moon; return(moon != null && Velocity.Equals(moon.Velocity) && Position.Equals(moon.Position)); }
public override void Update(GameTime gameTime) { mapBottomHit = false; gunTimer.Update(gameTime); if (!IsCharging && Position.Y < -GameDevice.Instance().DisplayModify.Y) { if (!IsMenu) { sound.PlaySE("wall_hit"); } Position = new Vector2(Position.X, -GameDevice.Instance().DisplayModify.Y + 1); var rotation = Rotation; Rotation = 180 - rotation; new DestroyParticle(HitParticle, Position, new Point(16, 16), DestroyParticle.DestroyOption.Down); } IsCharging = false; Velocity = Front * Speed; Speed -= Deceleration; if (Speed < 0) { Speed = 0; } if (Input.GetKeyTrigger(Keys.Space) && !IsTitle) { Speed = 0; if (!IsMenu) { sound.StoppedSE("shoot", 0); sound.RemoveSE("shoot", 0); sound.CreateSEInstance("charge"); sound.CreateSEInstance("charging"); sound.PlaySEInstances("charge", 0); haveSound = true; } } if (Input.GetKeyRelease(Keys.Space) && !IsTitle && !IsMenu) { sound.StoppedSE("charge", 0); sound.RemoveSE("charge", 0); sound.StoppedSE("charging", 0); sound.RemoveSE("charging", 0); haveSound = false; if (Speed > MaxSpeed / 2) { sound.CreateSEInstance("shoot"); sound.PlaySEInstances("shoot", 0); } } if (Input.GetKeyState(Keys.Space) && !IsTitle) { if (haveSound) { if (sound.IsStoppedSEInstance("charge", 0)) { sound.PlaySEInstances("charging", 0, true); } } Velocity = Vector2.Zero; Rotation += RotaionSpeed; Speed += ChargeSpeed; if (Speed > MaxSpeed) { Speed = MaxSpeed; } IsCharging = true; } BladeRotation -= (Speed - MaxSpeed / 2) * 2; //if (Speed <= MaxSpeed / 2 && gunTimer.Location >= (BulletRate + Speed / (MaxSpeed / 2) / (1 + BulletRate))) if (!Velocity.Equals(Vector2.Zero) && Speed <= MaxSpeed / 2 && gunTimer.Location >= BulletRate && !IsMenu) { gunTimer.Reset(); //GameObjectManager.Instance.Add(new PlayerBullet(Position + Size.ToVector2() / 2 - new Vector2(8, 8 + Math.Sign(Front.Y) * Size.Y / 2), -Math.Sign(Front.Y))); GameObjectManager.Instance.Add(new PlayerBullet(Position + Size.ToVector2() / 2 - new Vector2(8, 8 + Size.Y / 2), -1)); sound.PlaySE("gun"); } if (!IsTitle && !IsMenu) { if (LifeWall.AllIsDead()) { new DestroyParticle(Name, Position, Size, DestroyParticle.DestroyOption.Center); sound.StoppedSE("charge", 0); sound.StoppedSE("charging", 0); IsDead = true; } } new TailParticle(Position + new Vector2(16, 16)); base.Update(gameTime); if (Position.X < Block.BlockSize) { HitWall(true); } else if (Position.X > Screen.Width - Block.BlockSize - Size.X) { HitWall(false); } }
protected bool Equals(Limit other) { return(Lower.Equals(other.Lower) && Upper.Equals(other.Upper) && Effort.Equals(other.Effort) && Velocity.Equals(other.Velocity)); }