public ISprite build(AbsDoodleMoveState mState) { if (mState is DoodleIdleLeftState) { Texture2D texture = content.Load <Texture2D>("bouncy_idle_blue"); product = new SpriteAnimated(texture, 1, 25, 12, false); } else if (mState is DoodleIdleRightState || mState is null) { Texture2D texture = content.Load <Texture2D>("bouncy_idle_blue"); product = new SpriteAnimated(texture, 1, 25, 12, true); } else if (mState is DoodleJumpingState) { //this repeats with above, possible to optimize down the number of elseif branches at a later date Texture2D texture = content.Load <Texture2D>("bouncy_jump_blue"); product = new SpriteAnimated(texture, 1, 3, 12, false); } else if (mState is DoodleFallingState) { Texture2D texture = content.Load <Texture2D>("bouncy_fall_blue"); product = new SpriteAnimated(texture, 1, 3, 12, false); } // mState should only be null during initialization else if (mState is DoodleWalkLeftState) { Texture2D texture = content.Load <Texture2D>("bouncy_run_blue"); product = new SpriteAnimated(texture, 1, 6, 12, false); } else if (mState is DoodleWalkRightState) { Texture2D texture = content.Load <Texture2D>("bouncy_run_blue"); product = new SpriteAnimated(texture, 1, 6, 12, true); } else if (mState is DoodleFlyingState) { Texture2D texture = content.Load <Texture2D>("bouncy_fly_blue"); product = new SpriteAnimated(texture, 1, 3, 12, false); } return(product); }
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(); }
public override void Collide(List <AbsObject> collidedObjects) { bool[] directionsBlocked = new bool[] { false, false, false, false }; Dictionary <AbsObject, Collision.CollisionType> cornerCollidedObjects = new Dictionary <AbsObject, Collision.CollisionType>(); foreach (AbsObject obj in collidedObjects) { if (obj is ItemObject) { if (((ItemObject)obj).State == "speed") { this.powerState.ToFast(); this.audio.PlaySound("potion"); } else if (((ItemObject)obj).State == "jump") { this.powerState.ToDouble(); this.audio.PlaySound("potion"); } else if (((ItemObject)obj).State == "propeller") { this.moveState = new DoodleFlyingState(this); this.audio.PlaySound("copter"); } } Collision.CollisionType type = Collision.GetCollisionType(this, obj); if (type == Collision.CollisionType.TSide) { TopCollide(this, obj, directionsBlocked); } else if (type == Collision.CollisionType.RSide || type == Collision.CollisionType.LSide) { SideCollide(this, obj, directionsBlocked); } else if (type == Collision.CollisionType.BSide) { BottomCollide(this, obj, directionsBlocked); } else { cornerCollidedObjects.Add(obj, type); } } foreach (AbsObject obj in cornerCollidedObjects.Keys) { if (cornerCollidedObjects[obj] == Collision.CollisionType.TRCorner && !directionsBlocked[0] && !directionsBlocked[1]) { SideCollide(this, obj, directionsBlocked); } else if (cornerCollidedObjects[obj] == Collision.CollisionType.TLCorner && !directionsBlocked[0] && !directionsBlocked[3]) { SideCollide(this, obj, directionsBlocked); } else if (cornerCollidedObjects[obj] == Collision.CollisionType.BRCorner && !directionsBlocked[2] && !directionsBlocked[1]) { BottomCollide(this, obj, directionsBlocked); } else if (cornerCollidedObjects[obj] == Collision.CollisionType.BLCorner && !directionsBlocked[2] && !directionsBlocked[3]) { BottomCollide(this, obj, directionsBlocked); } } }
public ISprite build(AbsDoodleMoveState moveState) { product = localFactory.build(moveState); return(product); }