Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Screen Shake when you land from stomp #256

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion Scripts/Entities/Level/LevelCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,35 @@ public partial class LevelCamera : Camera2D
{
private Player Player { get; set; }

private double shakingTime = 0;
private int intensity = 24;

private Random random = new Random();

public override void _Ready()
{
Player = GetNode<Player>("../Player");
Current = true;
}

public override void _Process(double delta) => Position = Player.Position;
//public override void _Process(double delta) => Position = Player.Position;
public override void _Process(double delta){
Position = Player.Position;

if(Player.ShakeWhenIHitTheGround && Player.IsOnFloor()) //idk how you want me to do this i just make everything public because i am hardcore
{
shakingTime = 0.25;
Player.ShakeWhenIHitTheGround = false;
}
if(shakingTime > 0){
Offset = new Vector2(random.Next(0, 2 * intensity) - intensity,random.Next(0, 2 * intensity) - intensity);
shakingTime -= delta;
}
else{
Offset = new Vector2();
shakingTime = 0;
}
}

public void StopFollowingPlayer() => SetProcess(false);
public void StartFollowingPlayer() => SetProcess(true);
Expand Down
6 changes: 5 additions & 1 deletion Scripts/Entities/Player/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public partial class Player : MovingEntity<Player>

private int JumpCount { get; set; }
private int StompForce { get; set; } = 600;
public bool ShakeWhenIHitTheGround { get; set; } = false;

public override int HalfHearts
{
Expand Down Expand Up @@ -157,8 +158,11 @@ public override void UpdatePhysicsAir()
{
if (PlayerInput.IsFastFall)
Velocity = Velocity + new Vector2(0, 10);
if (PlayerInput.IsStomp)
if (PlayerInput.IsStomp){
Velocity = new Vector2(0, StompForce);
ShakeWhenIHitTheGround = true;
}

}

/// <summary>
Expand Down