public DoodleObject(Vector2 startingPosition, ContentManager cont, AudioManager audio) { propellerUpdates = 0; powerUpdates = 0; score = 0; isMoving = false; _opacity = 1.0f; _objectsToNotCollide = new List <AbsObject>(); _objectsToAdd = new List <AbsObject>(); isVisible = true; deleteThis = false; _position = startingPosition; content = cont; _velocity = new Vector2(0); _acceleration = new Vector2(0, 0.03f); powerState = new StandardDoodleState(this); moveState = new DoodleIdleRightState(this); isGrounded = false; groundVelocity = Vector2.Zero; tookDamage = false; this.audio = audio; }
public override void Update(GameTime gameTime) { if (moveState is DoodleFlyingState) { _velocity.Y = -5f; if (propellerUpdates < 400) { propellerUpdates++; } else { propellerUpdates = 0; moveState = new DoodleFallingState(this); } } if (!(powerState is StandardDoodleState)) { if (powerUpdates < 500) { powerUpdates++; } else { powerUpdates = 0; powerState = new StandardDoodleState(this); } } _velocity = _velocity + _acceleration; if (!isMoving) { if (isGrounded && _velocity.X != groundVelocity.X) { if (_velocity.X - groundVelocity.X < -0.5) { _velocity.X += 0.1f; } else if (_velocity.X - groundVelocity.X > 0.5) { _velocity.X -= 0.1f; } else { _velocity.X = groundVelocity.X; } } else if (!isGrounded && _velocity.X != 0) { if (_velocity.X < -0.5f) { _velocity.X += 0.05f; } else if (_velocity.X > 0.5f) { _velocity.X -= 0.05f; } else { _velocity.X = 0; } } } if (!isGrounded) { if (_velocity.Y > 0) { moveState = new DoodleFallingState(this); } } else { moveState = new DoodleIdleRightState(this); } if (tookDamage) { damageCounter++; if (damageCounter >= 10) { tookDamage = false; } } Sprite.Update(gameTime); isGrounded = false; isMoving = false; _objectsToNotCollide.Clear(); }