public override void CollideWithObject(GameObject obj, Room room, BBox collision) { if (obj is Player && obj.Color == Color && !Symbolizing) { if (this != room.CorrectPortal) { Unlocked = true; room.Failed = true; room.Finish(); } else { if (type != RoomType.Acceptance) { curSymAnimation = animations.Find((set) => set.IsCalled(SYM + "1")); Symbolizing = true; } else { Unlocked = true; } } } base.CollideWithObject(obj, room, collision); }
public Section(Room room, Rectangle box, float zoomLevel) { this.room = room; this.box = box; centered = false; this.zoomLevel = zoomLevel; }
/// <summary> /// Make a new section. /// </summary> /// <param name="room">The room this section is dividing up.</param> /// <param name="box">The position and size of this section.</param> /// <param name="centered">Whether or not the camera should be centered on this section.</param> public Section(Room room, Rectangle box, bool centered) { this.room = room; this.box = box; this.centered = centered; if (!centered) zoomLevel = DefaultZoom; }
public MiniMap(Room room, Vector2 position) { this.position = position; roomWidth = room.Width; roomHeight = room.Height; mapWidth = (int)MathHelper.Lerp(0, roomWidth, SCALE_X_FACTOR); mapHeight = (int)MathHelper.Lerp(0, roomHeight, SCALE_Y_FACTOR); }
public override void Update(Room room, GameTime gameTime) { reloadTimer++; if (CanGenerate(room)) { room.Add(Generate()); reloadTimer = 0; } base.Update(room, gameTime); }
public override void CollideWithObject(GameObject obj, Room room, BBox collision) { base.CollideWithObject(obj, room, collision); // ink blobs should smash into each other, but avoid awkward behavior with ink blobs // coming out of the same generator if (obj is InkBlob && !(obj is WaterBlob) && (obj.Color != Color)) room.Add(new InkBlob(Position, Vector2.Lerp(Velocity, obj.Velocity, 0.5f), Color.Combine(obj.Color), Vector2.Lerp(Size, obj.Size, 0.5f), shouldBounce)); room.Remove(this); }
public override void Update(Room room, GameTime gameTime) { lastPosition = Position; base.Update(room, gameTime); //Position = new Vector2(Position.X, maxHeightPos + (maxHeight - size.Y)); Move(room, Velocity); if ((Velocity.Y > 1 || Math.Abs(Vector2.Distance(lastPosition, Position)) < Math.Abs(Velocity.X / 2)) && !curAnimation.IsCalled("Disappear")) ChangeAnimation("Disappear"); if (curAnimation.IsCalled("Disappear") && curAnimation.IsDonePlaying()) room.Remove(this); }
public override void CollideWithWall(Room room) { ChangeAnimation(EXPLODE); Vector2 splatPosition = Position.ShoveToSide(size, velocity); if (!(this is WaterBlob)) // room.Splat(splatPosition, size, color, velocity); base.CollideWithWall(room); if (shouldBounce) { velocity *= -1; velocity = velocity.PushBack(BOUNCE_FRICTION * Vector2.One); size = size.PushBack(BOUNCE_SIZE_REDUCTION * Vector2.One); if (size == Vector2.Zero) room.Remove(this); } else room.Remove(this); }
public void Update(Room room, GameTime gameTime) { // if not panning, just follow our target, otherwise pan if (!InPan) { // but we might just be centered on a point, so check that we have a target. if (target != null) position = target.Position; } else { // to avoid a jarring jump, we need to update the pan position to match up with the // target's position if we have one. if (target != null) nextPos = target.Position; position = position.PushTowards(nextPos, PAN_SPEED*Vector2.One); if (position == nextPos) nextPos = Vector2.Zero; } // if we are still in the middle of zooming to a spot if (InZoomTransition) { Zoom = nextZoom > Zoom ? Math.Min(Zoom + ZOOM_SPEED, nextZoom) : Math.Max(Zoom - ZOOM_SPEED, nextZoom); // done zooming? if (Zoom == nextZoom) nextZoom = 0; } }
protected override void CollideWithCeiling(Room room) { if (UnderReverseGravity()) { maxSpeed = new Vector2(MAX_SPEED_X, MAX_SPEED_Y); velocity.Y = 0; onGround = true; canJump = true; } base.CollideWithCeiling(room); }
protected virtual bool CanGenerate(Room room) { Debug.Assert(room.CanHaveMoreBlobs(), "Uh oh, we're getting too many blobs. (is garbage collection working?)"); return reloadTimer >= interval; }
public virtual void CollideWithObject(GameObject obj, Room room, BBox collision) { }
public override void Update(Room room, GameTime gameTime) { if (curAnimation.IsCalled("Appear") && curAnimation.IsDonePlaying()) ChangeAnimation("Main"); else if (curAnimation.IsCalled("Main") && curAnimation.IsDonePlaying()) ChangeAnimation("Disappear"); else if (curAnimation.IsCalled("Disappear") && curAnimation.IsDonePlaying()) room.Remove(this); Move(room, Vector2.Zero); if (direction.X < 0) box = new BBox((int)(Position.X - SIZE_Y / 8 + 40), (int)(Position.Y - SIZE_X / 2), (int)SIZE_Y - 40, (int)SIZE_X); if (direction.X > 0) { box = new BBox((int)(Position.X - 50), (int)Position.Y, (int)SIZE_Y - 140, (int)SIZE_X); } base.Update(room, gameTime); }
public override void Update(Room room, GameTime gameTime) { base.Update(room, gameTime); }
internal override void Move(Room room, Vector2 direction) { if (direction.X == 0 && curAnimation.IsCalled(WALK)) ChangeAnimation(IDLE); if (direction.X < 0) { if (curAnimation.IsCalled(SLIDE)) { velocity.X = -2; ChangeAnimation(JUMP); Position = new Vector2(Position.X - size.X / 8, Position.Y); } facing = LEFT; } else if (direction.X > 0) { if (curAnimation.IsCalled(SLIDE)) { velocity.X = 2; ChangeAnimation(JUMP); Position = new Vector2(Position.X + size.X / 8, Position.Y); } facing = RIGHT; } if (TookStep && !(Color == Color.Black)) room.Splat(facing == RIGHT ? new Vector2(box.Left, box.Bottom) : new Vector2(box.Right, box.Bottom), STEP_SPLATTER_SIZE * Vector2.One, color, room.Gravity * Vector2.One * 0.0001f); base.Move(room, direction); }
/// <summary> /// Jumps the player. /// </summary> private void DoJump(Room room) { velocity.Y = -JUMP_SPEED; if (curAnimation.IsCalled(SLIDE)) velocity.X = ((facing == RIGHT && velocity.X > 0) ? -WALL_JUMP_PUSH : WALL_JUMP_PUSH); maxSpeed = new Vector2(MAX_JUMP_SPEED_X, MAX_JUMP_SPEED_Y); ChangeAnimation(JUMP); canJump = false; if (!(Color == Color.Black)) room.Splat(Center, Vector2.One * JUMP_SPLATTER_SIZE*2.5f, color, velocity); }
private void ChangeYPosition(Room room) { bool shouldCollideWithGround = false; bool shouldCollideWithCeiling = false; // check for colliding against a wall if (Box.Position.Y + velocity.Y < minPosition.Y) shouldCollideWithCeiling = true; else if (Box.Position.Y + velocity.Y > maxPosition.Y) { // if we're falling off-stage, die if (maxPosition.Y + Box.Height*2 >= room.Height) { room.Remove(this); return; } // handle the ground collision after we've moved, to prevent weirdness when player is moving too fast shouldCollideWithGround = true; } Position = new Vector2(Position.X, MathHelper.Clamp(Box.Position.Y + velocity.Y, minPosition.Y, maxPosition.Y) + BoxOffset.Y); if (shouldCollideWithGround) { hasCollidedWithGround = true; CollideWithWall(room); CollideWithGround(room); } if (shouldCollideWithCeiling) { hasCollidedWithCeiling = true; CollideWithWall(room); CollideWithCeiling(room); } }
/// <summary> /// Applies gravity to the object. /// </summary> /// <param name="room">The room that the object is in.</param> protected virtual void ApplyGravity(Room room) { velocity.Y += room.Gravity; }
protected virtual void CollideWithCeiling(Room room) { hasCollidedWithCeiling = true; }
/// <summary> /// Moves in the specified direction. /// </summary> /// <param name="room">The room that this object is moving around in.</param> /// <param name="direction">The direction to move in.</param> internal virtual void Move(Room room, Vector2 direction) { if (direction != Vector2.Zero) direction.Normalize(); if (!(this is Spout)) ApplyGravity(room); Accelerate(direction); // TODO: Figure out a way to resolve collisions and do only one function call. // resolve collisions on x-axis first UpdateBounds(room); ChangeXPosition(room); // then resolve any remaining on the y-axis UpdateBounds(room); ChangeYPosition(room); }
/// <summary> /// Update the object. /// </summary> /// <param name="gameTime">The current time of the game.</param> public virtual void Update(Room room, GameTime gameTime) { hasCollidedWithWall = false; hasCollidedWithGround = false; if (velocity.Y > 0 && hasCollidedWithCeiling) { hasCollidedWithCeiling = false; Console.WriteLine("Done ceiling colliding!"); } curAnimation.Update(); }
/// <summary> /// Collides with a wall. /// </summary> /// <param name="room">The room containing the wall.</param> public virtual void CollideWithWall(Room room) { hasCollidedWithWall = true; }
public override void CollideWithWall(Room room) { base.CollideWithWall(room); }
private void UpdateBounds(Room room, bool collidable=true) { minPosition = room.GetMinPosition(box.Position, box.Size, color, collidable); maxPosition = room.GetMaxPosition(box.Position, box.Size, color, collidable); }
protected override void ApplyGravity(Room room) { //if (Color.Contains(Color.Yellow)) // velocity.Y -= room.Gravity; //else base.ApplyGravity(room); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) Exit(); Input.Update(); if (!ShouldFade) { GameState oldState = state; state = GetNextState(); // handle state transition if (state != oldState) { if (state == GameState.Exit) Exit(); else SetupState(); } if (controller is Room && controller.Finished) { Room oldRoom = curRoom; controller = curRoom = NextRoom(); if (oldRoom == null || curRoom.Type != oldRoom.Type) { ResourceManager.Stop(); curRoom.ShouldPlayMusic = true; } } if (controller != null) controller.Update(gameTime); } else fade = fade.PushTowards(nextFade, fadeSpeed); base.Update(gameTime); }
public override void Update(Room room, GameTime gameTime) { // keep moving along Move(room, Vector2.Zero); if (curAnimation.IsCalled(EXPLODE) && curAnimation.IsDonePlaying()) ChangeAnimation(FALL); base.Update(room, gameTime); }
/// <summary> /// Set up the state of the game. /// </summary> private void SetupState() { switch (state) { case GameState.Intro: intro = new Intro(); intro.Play(); controller = intro; break; case GameState.TitleScreen: titleScreen = new TitleScreen(); controller = titleScreen; break; case GameState.Room: Room oldRoom = curRoom; curRoom = NextRoom(); if (oldRoom == null || curRoom.Type != oldRoom.Type) { ResourceManager.Stop(); curRoom.ShouldPlayMusic = true; } controller = curRoom; break; case GameState.GameMenu: controller = gameMenu; break; case GameState.Credits: credits = new Credits(); controller = credits; break; default: throw new InvalidOperationException("Can't setup this state."); } }
private void ChangeXPosition(Room room) { // check for colliding against a wall if (Box.Position.X + velocity.X < minPosition.X || Box.Position.X + velocity.X > maxPosition.X) CollideWithWall(room); Position = new Vector2(MathHelper.Clamp(Box.Position.X + velocity.X, minPosition.X, maxPosition.X) - BoxOffset.X, Position.Y); }
/// <summary> /// Collides with the ground. Should be called alongside CollideWithWall. /// </summary> /// <param name="room">The room containing the ground.</param> public virtual void CollideWithGround(Room room) { velocity.Y = 0; }