public void Update(GameTime gameTime) { if (CanSpawnCoins && _scoreBoard.Score - _lastSpawnScore >= _currentTargetDistance) { _currentTargetDistance = _random.NextDouble() * (MAX_COIN_DISTANCE - MIN_COIN_DISTANCE) + MIN_COIN_DISTANCE; _currentTargetDistance += (_ball.Speed - BallEntity.START_SPEED) / (BallEntity.MAX_SPEED - BallEntity.START_SPEED) * COIN_DISTANCE_SPEED_TOLERANCE; _lastSpawnScore = _scoreBoard.Score; SpawnCoin(); } foreach (CoinEntity coin in _entityManager.GetEntitiesOfType <CoinEntity>()) { if (coin.Position.X < COIN_DESPAWN_POS_X) { _entityManager.RemoveEntity(coin); } CheckCollisions(coin); } _rotatingCoinAnimation.Update(gameTime); }
public void Update(GameTime gameTime) { // Update tiles. for (int i = 0; i < surroundingTiles.Length; i++) { if (surroundingTiles[i].HasPoint(position.Location)) { currentTile = surroundingTiles[i]; surroundingTiles[(int)Direction.Up] = tiles[currentTile.Index - 28]; surroundingTiles[(int)Direction.Down] = tiles[currentTile.Index + 28]; surroundingTiles[(int)Direction.Left] = tiles[currentTile.Index - 1]; surroundingTiles[(int)Direction.Right] = tiles[currentTile.Index + 1]; } } if (surroundingTiles[(int)Direction.Left].Line != currentTile.Line) { surroundingTiles[(int)Direction.Left] = tiles[currentTile.Index + 27]; } if (surroundingTiles[(int)Direction.Right].Line != currentTile.Line) { surroundingTiles[(int)Direction.Right] = tiles[currentTile.Index - 27]; } position.Tile = currentTile.Center.ToPoint(); // Distance that the player can travel this frame. distance = (int)(speed * gameTime.ElapsedGameTime.TotalSeconds); // Change directions. if (nextDirection != Direction.None && nextDirection != direction) { if (!surroundingTiles[(int)nextDirection].IsWall && (position.DeltaPixel == 0 || (direction == Direction.None && position.DeltaPixel != 0))) { direction = nextDirection; } } // Move player in current direction. if ((direction != Direction.None && !game.DevMode) || (game.DevMode && direction != Direction.None && nextDirection != Direction.None)) { nextTile = surroundingTiles[(int)direction]; if (!nextTile.IsWall || position.DeltaPixel > 0) { position.Location = Move(direction, distance, position.Location); } else { direction = Direction.None; } } drawLocation = new Vector2(position.Location.X - 8, position.Location.Y - 8); Bounds = new Rectangle((int)drawLocation.X + 1, (int)drawLocation.Y + 1, 13, 13); MiniBounds = new Rectangle(Bounds.X + 4, Bounds.Y + 4, 5, 5); // Go through tunnel if (Bounds.Right <= 0) { position.Location = new Point(position.Location.X + 224, position.Location.Y); } else if (Bounds.Left >= 224) { position.Location = new Point(position.Location.X - 224, position.Location.Y); } drawLocation = new Vector2(position.Location.X - 8, position.Location.Y - 8); drawTunnelLocationLeft = new Vector2(drawLocation.X + 224, drawLocation.Y); drawTunnelLocationRight = new Vector2(drawLocation.X - 224, drawLocation.Y); // Update animation animation.Update(gameTime); // Debugging if (game.DevMode) { util.DevMsg("current tile is ", currentTile.Index); } }