public override void _PhysicsProcess(float delta) { Vector2 velocity = Vector2.Zero; if (CanMove()) { if (Input.IsActionPressed("move_left")) { velocity.x += moveSpeed; direction = 1; playerAnim.Play("Running"); playerAnim.FlipH = false; punchRay.CastTo = new Vector2(5f, 0f); } if (Input.IsActionPressed("move_right")) { velocity.x -= moveSpeed; direction = -1; playerAnim.Play("Running"); playerAnim.FlipH = true; punchRay.CastTo = new Vector2(-7f, 0f); } if (velocity.x == 0f) { playerAnim.Play("Idle"); } } if (IsOnFloor()) { if (CanMove()) { if (Input.IsActionPressed("power1")) { playerAnim.Play("Punching"); } if (Input.IsActionJustPressed("power3")) { velocity = Vector2.Zero; dashing = true; } if (Input.IsActionJustPressed("jump")) { yVel = jumpForce; } } if (dying) { playerAnim.Play("Dying"); dyingTimer++; } } if (!IsOnFloor()) { if (yVel <= 0) { playerAnim.Play("Jumping"); } if (yVel > 0) { playerAnim.Play("Falling"); } if (yVel < maxGravity) { yVel += gravity; } if (dying) { playerAnim.Play("FallingDying"); yVel = 15f; } } velocity.y = yVel; if (dashing) { dashTimer++; playerAnim.Stop(); if (dashTimer >= 80) { GlobalPosition += new Vector2(60f * direction, 0f); if (dashRay.IsColliding()) { var target = dashRay.GetCollider(); for (int i = 0; i < GameData.enemyTypes.Length; i++) { if (target.GetType().ToString() == GameData.enemyTypes[i]) { switch (GameData.enemyTypes[i]) { case "Enemy": //didn't really know how else to do this { Enemy enemy = target as Enemy; enemy.Hit(damage * 8); break; } case "RangedEnemy": { RangedEnemy rangedEnemy = target as RangedEnemy; rangedEnemy.Hit(damage * 8); break; } default: break; } } } } dashing = false; dashTimer = 0; } } MoveAndSlide(velocity, new Vector2(0, -1)); }
public override void _Process(float delta) { healthRect.RectScale = new Vector2(GameData.playerHealth / 3.846f, 7f); manaRect.RectScale = new Vector2(GameData.playerMana / 3.846f, 7f); score.Text = "Score: " + GameData.score; if (Input.IsActionPressed("power1") && punchRay.IsColliding()) { var target = punchRay.GetCollider(); for (int i = 0; i < GameData.enemyTypes.Length; i++) { if (target.GetType().ToString() == GameData.enemyTypes[i]) { switch (GameData.enemyTypes[i]) { case "Enemy": //didn't really know how else to do this { Enemy enemy = target as Enemy; enemy.Hit(damage); break; } case "RangedEnemy": { RangedEnemy rangedEnemy = target as RangedEnemy; rangedEnemy.Hit(damage); break; } default: break; } } } } if (Input.IsActionJustPressed("power2") && GameData.playerMana >= 25) //Time dash { GameData.playerMana -= 25; } if (Input.IsActionJustPressed("power3") && GameData.playerMana >= 50) //Time Evasion (evade all attacks for a few seconds) { timeEvasion = true; } if (Input.IsActionJustPressed("power4") && GameData.playerMana >= 100) //Timestop { GameData.playerMana -= 100; GameData.timeStopped = true; } if (Input.IsActionJustPressed("ui_cancel")) { GameData.gamePaused = true; } if (GameData.playerHealth <= 0) { if (!dying) { dying = true; } if (dyingTimer >= 120 && dyingTimer <= 240) { darkening.Visible = true; darkening.Modulate = new Color(0f, 0f, 0f, (dyingTimer - 120f) / 120f); } if (dyingTimer >= 360) { GetTree().ChangeScene("res://Scenes/TitleScreen.tscn"); } } }