Compare commits
2 Commits
e9b070ff35
...
84b908ef51
Author | SHA1 | Date | |
---|---|---|---|
84b908ef51 | |||
c078204e60 |
@@ -5,7 +5,11 @@ namespace AceFieldNewHorizon.Scripts.Entities;
|
||||
|
||||
public partial class Player : CharacterBody2D
|
||||
{
|
||||
[Export] public float Speed = 400.0f;
|
||||
[Export] public float MaxSpeed = 400.0f;
|
||||
[Export] public float SprintMultiplier = 1.8f; // 80% faster when sprinting
|
||||
[Export] public float Acceleration = 1500.0f;
|
||||
[Export] public float SprintAcceleration = 1800.0f; // Slightly faster acceleration when sprinting
|
||||
[Export] public float Deceleration = 1200.0f;
|
||||
[Export] public float RotationSpeed = 3.0f;
|
||||
|
||||
public override void _Process(double delta)
|
||||
@@ -20,10 +24,43 @@ public partial class Player : CharacterBody2D
|
||||
{
|
||||
// Get movement input
|
||||
var moveForward = Input.GetActionStrength("move_up") - Input.GetActionStrength("move_down");
|
||||
var moveHorizontal = Input.GetActionStrength("move_right") - Input.GetActionStrength("move_left");
|
||||
var isSprinting = Input.IsActionPressed("move_sprint");
|
||||
|
||||
// Calculate movement direction based on rotation
|
||||
Velocity = Vector2.Right.Rotated(Rotation) * moveForward * Speed;
|
||||
// Calculate movement parameters based on sprint state
|
||||
var currentMaxSpeed = isSprinting ? MaxSpeed * SprintMultiplier : MaxSpeed;
|
||||
var currentAcceleration = isSprinting ? SprintAcceleration : Acceleration;
|
||||
|
||||
// Calculate desired movement direction
|
||||
var forwardVector = Vector2.Right.Rotated(Rotation);
|
||||
var rightVector = new Vector2(-forwardVector.Y, forwardVector.X);
|
||||
|
||||
// Calculate target velocity based on input
|
||||
var targetVelocity = (forwardVector * moveForward + rightVector * moveHorizontal).Normalized() * currentMaxSpeed;
|
||||
|
||||
// Apply acceleration or deceleration
|
||||
var currentSpeed = Velocity.Length();
|
||||
var isAccelerating = targetVelocity != Vector2.Zero;
|
||||
|
||||
if (isAccelerating)
|
||||
{
|
||||
// Accelerate towards target velocity
|
||||
Velocity = Velocity.MoveToward(targetVelocity, (float)(currentAcceleration * delta));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Apply deceleration when no input
|
||||
if (currentSpeed > 0)
|
||||
{
|
||||
var decelAmount = (float)(Deceleration * delta);
|
||||
if (currentSpeed <= decelAmount)
|
||||
Velocity = Vector2.Zero;
|
||||
else
|
||||
Velocity = Velocity.Normalized() * (currentSpeed - decelAmount);
|
||||
}
|
||||
}
|
||||
|
||||
// Apply the movement
|
||||
MoveAndSlide();
|
||||
}
|
||||
}
|
@@ -23,12 +23,31 @@ public partial class PlacementManager : Node2D
|
||||
_ghostBuilding = null;
|
||||
}
|
||||
|
||||
// Add this field to PlacementManager
|
||||
private float _currentRotation = 0f;
|
||||
|
||||
// Add this method to handle rotation
|
||||
private void RotateGhost(bool reverse = false)
|
||||
{
|
||||
if (_ghostBuilding == null) return;
|
||||
if (reverse)
|
||||
_currentRotation = (_currentRotation - 90f) % 360f;
|
||||
else
|
||||
_currentRotation = (_currentRotation + 90f) % 360f;
|
||||
_ghostBuilding.RotationDegrees = _currentRotation;
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
// Snap mouse to grid
|
||||
var mousePos = GetGlobalMousePosition();
|
||||
_hoveredCell = GridUtils.WorldToGrid(mousePos);
|
||||
|
||||
if (Input.IsActionJustPressed("rotate_tile_reverse"))
|
||||
RotateGhost(reverse: true);
|
||||
else if (Input.IsActionJustPressed("rotate_tile"))
|
||||
RotateGhost();
|
||||
|
||||
if (_ghostBuilding == null)
|
||||
{
|
||||
var scene = Registry.GetBuilding(_currentBuildingId)?.Scene;
|
||||
@@ -36,6 +55,7 @@ public partial class PlacementManager : Node2D
|
||||
|
||||
_ghostBuilding = (BaseTile)scene.Instantiate();
|
||||
_ghostBuilding.SetGhostMode(true);
|
||||
_ghostBuilding.RotationDegrees = _currentRotation;
|
||||
AddChild(_ghostBuilding);
|
||||
}
|
||||
|
||||
@@ -58,6 +78,7 @@ public partial class PlacementManager : Node2D
|
||||
_ghostBuilding.Position = placementPos;
|
||||
_ghostBuilding.SetGhostMode(canPlace);
|
||||
|
||||
|
||||
// Left click to place
|
||||
if (Input.IsActionPressed("build_tile") && canPlace)
|
||||
{
|
||||
@@ -65,6 +86,7 @@ public partial class PlacementManager : Node2D
|
||||
if (scene == null) return;
|
||||
|
||||
_ghostBuilding.FinalizePlacement();
|
||||
_ghostBuilding.RotationDegrees = _currentRotation;
|
||||
|
||||
var buildingData = Registry.GetBuilding(_currentBuildingId);
|
||||
Grid.OccupyCell(_hoveredCell, _ghostBuilding);
|
||||
@@ -74,6 +96,7 @@ public partial class PlacementManager : Node2D
|
||||
|
||||
_ghostBuilding = (BaseTile)scene.Instantiate();
|
||||
_ghostBuilding.SetGhostMode(true);
|
||||
_ghostBuilding.RotationDegrees = _currentRotation;
|
||||
AddChild(_ghostBuilding);
|
||||
}
|
||||
|
||||
|
@@ -55,6 +55,21 @@ destroy_tile={
|
||||
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":2,"position":Vector2(481, 42),"global_position":Vector2(500, 138),"factor":1.0,"button_index":2,"canceled":false,"pressed":true,"double_click":false,"script":null)
|
||||
]
|
||||
}
|
||||
rotate_tile={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":79,"key_label":0,"unicode":111,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
rotate_tile_reverse={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":true,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":79,"key_label":0,"unicode":79,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
move_sprint={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194325,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[rendering]
|
||||
|
||||
|
Reference in New Issue
Block a user