public void HandleInput(InputState inputState, InputBindings bindings) { if (bindings.JustPressed("attack")) { ReplacedSelf?.Invoke(this, new ScreenEventArgs(new GameScreen(_game, _game.JungleTemplate, new PlayerData { Prologue = false }))); } else if (bindings.JustPressed("restart")) { ReplacedSelf?.Invoke(this, new ScreenEventArgs(new GameScreen(_game, _game.EntranceTemplate, new PlayerData()))); } }
public void Update(Entity entity, Level level, float deltaTime) { if (!level.PhysicsWorld.TryGetBody(entity.BodyID, out Body? body)) { return; } if (level.EntityWorld.TryGetEntity(_torchEntityID, out Entity? torchEntity)) { if (torchEntity.IsPutOut) { entity.HasLostAllHope = true; body.Velocity = body.Velocity.SetX(0f); return; } } float speedModifier = 1f; float waterHeight = level.TileMap.Height * PhysicsConstants.TileSize - level.WaterLevel; if (body.Position.Y + body.Bounds.Center.Y > waterHeight) { body.Position = body.Position.SetY(waterHeight - body.Bounds.Center.Y); if (body.Velocity.Y > 0f) { body.Velocity = body.Velocity.SetY(0f); } speedModifier = 0.5f; _jumpsLeft = _maxJumps; } float speed = body.Velocity.Length(); body.IgnoresPlatforms = _bindings.IsPressed(Bindings.Drop); if (_graceTimer > 0f) { _graceTimer -= deltaTime; } if (speed < entity.DangerSpeed && entity.DashTimer <= 0f) { if (_bindings.IsPressed(Bindings.MoveRight)) { body.Velocity = body.Velocity.SetX(_movementSpeed * speedModifier); } if (_bindings.IsPressed(Bindings.MoveLeft)) { body.Velocity = body.Velocity.SetX(-_movementSpeed * speedModifier); } if (!_bindings.IsPressed(Bindings.MoveRight) && !_bindings.IsPressed(Bindings.MoveLeft)) { body.Velocity = body.Velocity.SetX(0f); } } if (body.Contact.Y > 0f) { _jumpsLeft = _maxJumps; _graceTimer = _gracePeriod; } if (_dashCooldownTimer > 0f) { _dashCooldownTimer -= deltaTime; } if (entity.DashTimer <= 0f) { _hasBumped = false; if (_bindings.JustPressed(Bindings.Dash) && _jumpsLeft > 0 && _dashCooldownTimer <= 0f) { _dashDir = new Vector2(); if (_bindings.IsPressed(Bindings.MoveRight)) { _dashDir.X++; } if (_bindings.IsPressed(Bindings.MoveLeft)) { _dashDir.X--; } if (_dashDir.X != 0f) { entity.DashTimer = _dashTime; _jumpsLeft--; _dashCooldownTimer = _dashCooldown; } } } if (entity.KickTimer <= 0f) { _hasKicked = false; } if (_bindings.JustPressed(Bindings.Jump) && _jumpsLeft > 0) { body.Velocity = body.Velocity.SetY(0f); body.Impulse += new Vector2(0f, -_jumpImpulse * Math.Min(Math.Max(_jumpTime - _jumpTimer, 0f), deltaTime) / _jumpTime); _jumpTimer = deltaTime; _isJumping = true; _jumpsLeft--; BeginKick(entity, body, level); } if (_bindings.IsPressed(Bindings.Jump) && _isJumping && _jumpTimer < _jumpTime) { body.Impulse += new Vector2(0f, -_jumpImpulse * Math.Min(Math.Max(_jumpTime - _jumpTimer, 0f), deltaTime) / _jumpTime); _jumpTimer += deltaTime; } if (_jumpTimer >= _jumpTime) { _isJumping = false; } if (!_bindings.IsPressed(Bindings.Jump)) { if (body.Velocity.Y < 0f) { body.Velocity = body.Velocity.SetY(0f); } _jumpTimer = 0f; } if (entity.DashTimer > 0f) { entity.DashTimer -= deltaTime; body.Velocity = _dashDir * _dashSpeed; BumpTorch(entity, body, level); } if (entity.KickTimer > 0f) { entity.KickTimer -= deltaTime; KickTorch(entity, body, level); } }
public void Update(GameTime gameTime) { if (_bindings.JustPressed(Bindings.Restart)) { if (_winnerIsYou) { _screens.TransitionTo <LevelScreen, LevelSettings>(LD46Game.Level0Settings !); } else { _screens.TransitionTo <LevelScreen, LevelSettings>(_settings); } } if (_toot && _bindings.JustPressed(Bindings.Skip)) { _screens.TransitionTo <LevelScreen, LevelSettings>(_settings.NextLevel); } if (_levelView.HasFadedOut && _settings.NextLevel != null) { _screens.TransitionTo <LevelScreen, LevelSettings>(_settings.NextLevel); } float deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds; if (Level.SlowMoTimer > 0f) { deltaTime /= 2f; } Level.Update(deltaTime); if (Level.PhysicsWorld.TryGetBody(_torchEntity.BodyID, out Body? torchBody)) { if (!_hasWon && torchBody.Position.Y + torchBody.Bounds.Center.Y <= Level.FinishHeight) { _hasWon = true; Level.SlowMoTimer = float.MaxValue; } if (_hasWon) { Level.CameraCenter += (torchBody.Position + torchBody.Bounds.Center - Level.CameraCenter) * 5f * (float)gameTime.ElapsedGameTime.TotalSeconds; if (_winTimer < 1f) { _winTimer += deltaTime; if (_winTimer >= 1f) { _levelView.FadeOut(); } } } } float waterSpeedModifier = 1f; if (Level.PhysicsWorld.TryGetBody(_playerEntity.BodyID, out Body? playerBody)) { if (!_hasWon) { Level.CameraCenter = playerBody.Position + playerBody.Bounds.Center; } float yDistance = Math.Abs(playerBody.Position.Y - (Level.TileMap.Height * PhysicsConstants.TileSize - Level.WaterLevel)); waterSpeedModifier *= Math.Max(yDistance * yDistance / 100000f, 1f); } Level.WaterLevel += _settings.WaterSpeed * waterSpeedModifier * deltaTime; if (_playerEntity.HasLostAllHope) { _levelView.ShowLoseScreen(); } _levelView.Update(Level, deltaTime); }