void InitAffectedObjectsIfNeeded(FPGameProtocol game) { if (affectedObjects == null) { affectedObjects = new List<FPGameObject>(); RectangleF selfRect = this.Rect; foreach (var gameObject in game.GameObjects) { if (gameObject == this) continue; RectangleF gameObjectRect = gameObject.Rect; gameObjectRect.Height += FPPlayer.tolerance; if (gameObjectRect.IntersectsWith(selfRect)) affectedObjects.Add(gameObject); } foreach (var gameObject in game.GameObjects) { if (gameObject == this) continue; if (affectedObjects.Contains(gameObject)) continue; RectangleF gameObjectRect = gameObject.Rect; gameObjectRect.Height += FPPlayer.tolerance; foreach (var affectedObject in affectedObjects) { if (gameObjectRect.IntersectsWith(affectedObject.Rect)) affectedObjects.Add(gameObject); } } } }
public void Update(FPGameProtocol game) { }
public void ElevatorCollision(FPGameProtocol game, float diffX, float diffY) { FPPlayer player = (FPPlayer)game.Player; RectangleF playerRect = player.Rect; RectangleF moveRect = this.Rect.WithMove(diffX, diffY); if (diffY > 0.0f) { if (playerRect.IntersectsWithTolerance(moveRect)) diffY = 0.0f; else { foreach (var gameObject in game.GameObjects) { if (gameObject.IsMovable) { if (gameObject.Rect.IntersectsWithTolerance(moveRect)) { diffY = 0.0f; break; } } } } } if (Math.Abs(diffX) > 0.0f) { if (playerRect.IntersectsWithTolerance(moveRect)) diffX = 0.0f; else { foreach (var gameObject in game.GameObjects) { if (gameObject.IsMovable) { if (gameObject.Rect.IntersectsWithTolerance(moveRect)) { diffX = 0.0f; break; } } } } } playerRect.Height += FPPlayer.tolerance; if (playerRect.IntersectsWithTolerance(moveRect)) { game.MoveWorld(-diffX, 0.0f); player.CollisionLeftRight(game); game.MoveWorld(0.0f, -diffY); } else { foreach (var gameObject in affectedObjects) { moveRect = gameObject.Rect.WithMove(diffX, diffY); if (playerRect.IntersectsWithTolerance(moveRect)) { game.MoveWorld(-diffX, 0.0f); player.CollisionLeftRight(game); game.MoveWorld(0.0f, -diffY); break; } } } FPGameObject movableOnElevator = null; RectangleF movableRect; foreach (var movable in game.GameObjects) { if (movable.IsMovable) { moveRect = this.Rect.WithMove(diffX, diffY); movableRect = movable.Rect; movableRect.Height += FPPlayer.tolerance; if (movableRect.Bottom < moveRect.Bottom && movableRect.IntersectsWithTolerance(moveRect)) { movableOnElevator = movable; break; } else { foreach (var gameObject in affectedObjects) { moveRect = gameObject.Rect.WithMove(diffX, diffY); if (movableRect.Bottom < moveRect.Bottom && movableRect.IntersectsWithTolerance(moveRect)) { movableOnElevator = movable; break; } } } } } if (movableOnElevator != null) { movableRect = movableOnElevator.Rect.WithMove(diffX, diffY); movableOnElevator.Move(diffX, 0.0f); if (playerRect.IntersectsWithTolerance(movableRect)) { game.MoveWorld(-diffX, 0.0f); player.CollisionLeftRight(game); } movableOnElevator.Move(0.0f, diffY); if (playerRect.IntersectsWithTolerance(movableRect)) { game.MoveWorld(0.0f, -diffY); } } X += diffX; Y += diffY; foreach (var gameObject in affectedObjects) gameObject.Move(diffX, diffY); }
public void Update(FPGameProtocol game) { const float speed = 2.0f; float diffX, diffY; if (movingToEnd) { diffX = EndX - X; diffY = EndY - Y; } else { diffX = StartX - X; diffY = StartY - Y; } diffX = FPMath.fabsminf(diffX, speed); diffY = FPMath.fabsminf(diffY, speed); if (Math.Abs(diffX) < 0.1f && Math.Abs(diffY) < 0.1f) { movingToEnd = !movingToEnd; } InitAffectedObjectsIfNeeded(game); ElevatorCollision(game, diffX, diffY); if (textureIndex > 2) textureIndex = 2; if (textureIndex < 0) textureIndex = 0; if (diffY < 0.0f) { if (++animationCounter > 2) { animationCounter = 0; if (++textureIndex >= 2) textureIndex = 2; } } else if (diffY > 0.0f) { if (++animationCounter > 2) { animationCounter = 0; if (--textureIndex < 0) textureIndex = 0; } } else { textureIndex = 1; } }
public void Update(FPGameProtocol game) { FPPlayer player = (FPPlayer)game.Player; RectangleF playerRect = player.Rect; RectangleF selfRect = this.Rect; selfRect.Y += 32.0f; selfRect.Height += 32.0f * 4; selfRect.X += 18.0f; selfRect.Width -= 18.0f * 2.0f; if (selfRect.IntersectsWith(playerRect)) { if (player.MoveY < 5.0f) player.MoveY = FPMath.flerpf(player.MoveY, 5.0f, 0.3f); } }
public void Update(FPGameProtocol game) { FPPlayer player = (FPPlayer)game.Player; RectangleF playerRect = player.Rect; if (speedUpCounter > 0) { speedUpCounter++; if (speedUpCounter > FPPlayer.maxSpeedUpCount) { speedUpCounter = 0; IsVisible = true; } } else if (playerRect.IntersectsWith(this.Rect)) { speedUpCounter = 1; player.SpeedUpCounter = 1; IsVisible = false; } }
public bool CollisionUpDown(FPGameProtocol game) { bool isColliding = false; foreach (var platform in game.GameObjects) { if (platform.IsPlatform) { RectangleF intersection = RectangleF.Intersect(platform.Rect, this.Rect); if (intersection.IsEmptyWithTolerance()) continue; if (platform.Rect.Bottom < this.Rect.Bottom) { if (MoveY > 0.0f) MoveY = 0.0f; game.MoveWorld(0.0f, -intersection.Height); isColliding = true; } else if (MoveY < 0.0f) { if (platform.Rect.Top > this.Rect.Bottom - tolerance + MoveY) { MoveY = 0.0f; jumping = false; game.MoveWorld(0.0f, intersection.Height); isColliding = true; } } else if (platform.Rect.Top > this.Rect.Bottom - tolerance + MoveY) { jumping = false; game.MoveWorld(0.0f, intersection.Height); isColliding = true; } } } return isColliding; }
public void Update(FPGameProtocol game) { PointF inputAcceleration = game.InputAcceleration; bool moveLeftOrRight = false; if (SpeedUpCounter > 0) { if (++SpeedUpCounter > maxSpeedUpCount) { SpeedUpCounter = 0; } } float currentMaxSpeed = SpeedUpCounter > 0 ? maxSpeed * speedPowerUp : maxSpeed; if (inputAcceleration.X < 0.0f) { if (MoveX < 0.0f) MoveX += Math.Abs(inputAcceleration.X) * acceleration * changeDirectionSpeed; MoveX += Math.Abs(inputAcceleration.X) * acceleration; if (MoveX > currentMaxSpeed) MoveX = currentMaxSpeed; moveLeftOrRight = true; } else if (inputAcceleration.X > 0.0f) { if (MoveX > 0.0f) MoveX -= Math.Abs(inputAcceleration.X) * acceleration * changeDirectionSpeed; MoveX -= Math.Abs(inputAcceleration.X) * acceleration; if (MoveX < -currentMaxSpeed) MoveX = -currentMaxSpeed; moveLeftOrRight = true; } if (!jumping && inputAcceleration.Y > 0.0f) { if (MoveY < upSpeed) MoveY = upSpeed; jumping = true; } if (!moveLeftOrRight) { if (Math.Abs(MoveX) < deceleration) MoveX = 0.0f; else if (MoveX > 0.0f) MoveX -= deceleration; else if (MoveX < 0.0f) MoveX += deceleration; } MoveY -= deceleration; if (MoveY < maxFallSpeed) MoveY = maxFallSpeed; jumping = true; game.MoveWorld(MoveX, 0.0f); if (CollisionLeftRight(game)) MoveX = 0.0f; game.MoveWorld(0.0f, MoveY); CollisionUpDown(game); Rotation -= MoveX * 3.0f; Alpha += 0.07f; if (Alpha > (float)Math.PI) Alpha -= (float)Math.PI; }
public bool CollisionLeftRight(FPGameProtocol game) { bool isColliding = false; foreach (var platform in game.GameObjects) { if (platform.IsPlatform) { RectangleF intersection = RectangleF.Intersect(platform.Rect, this.Rect); if (intersection.IsEmptyWithTolerance()) continue; if (platform.Rect.Left > this.Rect.Left) { if (platform.IsMovable) { var movable = (FPMovablePlatform)platform; platform.Move(intersection.Width, 0.0f); if (movable.CollisionLeftRight(game)) { platform.Move(-intersection.Width, 0.0f); game.MoveWorld(intersection.Width, 0.0f); isColliding = true; } } else { game.MoveWorld(intersection.Width, 0.0f); isColliding = true; } } else if (platform.Rect.Right < this.Rect.Right) { if (platform.IsMovable) { var movable = (FPMovablePlatform)platform; platform.Move(-intersection.Width, 0.0f); if (movable.CollisionLeftRight(game)) { platform.Move(intersection.Width, 0.0f); game.MoveWorld(-intersection.Width, 0.0f); isColliding = true; } } else { game.MoveWorld(-intersection.Width, 0.0f); isColliding = true; } } } } return isColliding; }
public void Update(FPGameProtocol game) { if (!IsVisible) return; var playerRect = game.Player.Rect; if (playerRect.IntersectsWith(this.Rect)) IsVisible = false; }
public void Update(FPGameProtocol game) { FPPlayer player = (FPPlayer)game.Player; RectangleF playerRect = player.Rect; MoveY -= FPPlayer.deceleration; if (MoveY < FPPlayer.maxFallSpeed) MoveY = FPPlayer.maxFallSpeed; RectangleF moveRect = this.Rect.WithMove(0.0f, -MoveY); if (playerRect.IntersectsWithTolerance(moveRect)) MoveY = 0.0f; Y -= MoveY; CollisionUpDown(game); }
public bool CollisionLeftRight(FPGameProtocol game) { foreach (var platform in game.GameObjects) { if (platform != this && platform.IsPlatform) { RectangleF intersection = RectangleF.Intersect(platform.Rect, this.Rect); if (intersection.IsEmptyWithTolerance()) continue; if (platform.Rect.Left > this.Rect.Left) return true; if (platform.Rect.Right < this.Rect.Right) return true; } } return false; }
public void Update(FPGameProtocol game) { FPPlayer player = (FPPlayer)game.Player; RectangleF playerRect = player.Rect; if (!playerRect.IntersectsWith(this.Rect)) { playerRect.Height += FPPlayer.tolerance; if (playerRect.IntersectsWith(this.Rect)) player.MoveY = 9.5f; } foreach (var gameObject in game.GameObjects) { if (gameObject.IsMovable) { FPMovablePlatform movable = (FPMovablePlatform)gameObject; RectangleF movableRect = movable.Rect; movableRect.Height += FPPlayer.tolerance; RectangleF intersection = RectangleF.Intersect(movableRect, this.Rect); if (!intersection.IsEmpty && intersection.Width > 30.0f) { movable.MoveY = 8.0f; } } } if (++animationCounter > 5) { textureIndex += textureDirection; if (textureIndex < 0 || textureIndex >= 2) { textureIndex -= textureDirection; textureDirection = -textureDirection; } animationCounter = 0; } }