add moving of hand

This commit is contained in:
Rokas Puzonas 2024-02-11 01:01:58 +02:00
parent ee42ccc8f3
commit 7c73d5436d

View File

@ -160,34 +160,45 @@ pub fn tick(self: *Self) !void {
});
}
var inputDx: f32 = 0;
var inputDy: f32 = 0;
var moveDx: f32 = 0;
var moveDy: f32 = 0;
if (rl.IsKeyDown(rl.KeyboardKey.KEY_W)) {
inputDy -= 1;
moveDy -= 1;
}
if (rl.IsKeyDown(rl.KeyboardKey.KEY_S)) {
inputDy += 1;
moveDy += 1;
}
if (rl.IsKeyDown(rl.KeyboardKey.KEY_A)) {
inputDx -= 1;
moveDx -= 1;
}
if (rl.IsKeyDown(rl.KeyboardKey.KEY_D)) {
inputDx += 1;
moveDx += 1;
}
var handDx: f32 = 0;
var handDy: f32 = 0;
var gamepad: i32 = 0;
if (rl.IsGamepadAvailable(gamepad)) {
inputDx += rl.GetGamepadAxisMovement(gamepad, rl.GamepadAxis.GAMEPAD_AXIS_LEFT_X);
inputDy += rl.GetGamepadAxisMovement(gamepad, rl.GamepadAxis.GAMEPAD_AXIS_LEFT_Y);
moveDx += rl.GetGamepadAxisMovement(gamepad, rl.GamepadAxis.GAMEPAD_AXIS_LEFT_X);
moveDy += rl.GetGamepadAxisMovement(gamepad, rl.GamepadAxis.GAMEPAD_AXIS_LEFT_Y);
handDx = rl.GetGamepadAxisMovement(gamepad, rl.GamepadAxis.GAMEPAD_AXIS_RIGHT_X);
handDy = rl.GetGamepadAxisMovement(gamepad, rl.GamepadAxis.GAMEPAD_AXIS_RIGHT_Y);
}
var input_dir = rl.Vector2{ .x = inputDx, .y = inputDy };
input_dir = rl.Vector2Normalize(input_dir);
if (input_dir.x != 0 or input_dir.y != 0) {
player.handDirection = input_dir;
var moveDir = rl.Vector2{ .x = moveDx, .y = moveDy };
moveDir = rl.Vector2Normalize(moveDir);
if (moveDir.x != 0 or moveDir.y != 0) {
player.handDirection = moveDir;
}
if (handDx != 0 or handDy != 0) {
player.handDirection.x = handDx;
player.handDirection.y = handDy;
player.handDirection = player.handDirection.normalize();
}
player.acceleration = input_dir;
player.acceleration = moveDir;
player.acceleration = rl.Vector2Scale(player.acceleration, walkForce);
player.velocity = rl.Vector2Add(player.velocity, rl.Vector2Scale(player.acceleration, dt));
@ -249,8 +260,8 @@ pub fn tick(self: *Self) !void {
);
rl.DrawCircle(
@intFromFloat(player.position.x + input_dir.x * maxSpeed),
@intFromFloat(player.position.y + input_dir.y * maxSpeed),
@intFromFloat(player.position.x + moveDir.x * maxSpeed),
@intFromFloat(player.position.y + moveDir.y * maxSpeed),
5,
rl.GREEN
);