add controller support

This commit is contained in:
Rokas Puzonas 2024-02-11 00:50:24 +02:00
parent be6be4390b
commit ee42ccc8f3

View File

@ -146,20 +146,19 @@ pub fn tick(self: *Self) !void {
const dt = rl.GetFrameTime();
var rng = self.prng.random();
_ = rng;
var player = &self.player;
var enemies = &self.enemies;
var rope = &self.rope;
var allocator = self.allocator;
self.enemyTimer -= dt;
// if (self.enemyTimer <= 0) {
// self.enemyTimer = 0.5 + rng.float(f32) * 2;
// self.spawnedEnemiesCount += 1;
// try enemies.append(Enemy{
// .position = rl.Vector2.randomOnUnitCircle(rng).scale(100)
// });
// }
if (self.enemyTimer <= 0) {
self.enemyTimer = 0.5 + rng.float(f32) * 2;
self.spawnedEnemiesCount += 1;
try enemies.append(Enemy{
.position = rl.Vector2.randomOnUnitCircle(rng).scale(100)
});
}
var inputDx: f32 = 0;
var inputDy: f32 = 0;
@ -176,6 +175,12 @@ pub fn tick(self: *Self) !void {
inputDx += 1;
}
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);
}
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) {