refine gameplay
This commit is contained in:
20
src/main.zig
20
src/main.zig
@@ -21,7 +21,8 @@ pub fn main() !void {
|
||||
|
||||
const tickInterval: f32 = 0.5;
|
||||
const fastTickInterval: f32 = tickInterval / 3.0;
|
||||
var tickTimer: f32 = 0;
|
||||
var timer: f32 = 0;
|
||||
var isFast = false;
|
||||
|
||||
const fontSize = 50;
|
||||
const gameOverText = "Game Over!";
|
||||
@@ -31,7 +32,7 @@ pub fn main() !void {
|
||||
|
||||
while (!rl.windowShouldClose()) {
|
||||
const deltaTime = rl.getFrameTime();
|
||||
tickTimer += deltaTime;
|
||||
timer += deltaTime;
|
||||
|
||||
if (rl.isKeyPressed(.up)) {
|
||||
game.setDirection(g.Direction.up);
|
||||
@@ -45,10 +46,17 @@ pub fn main() !void {
|
||||
if (rl.isKeyPressed(.left)) {
|
||||
game.setDirection(g.Direction.left);
|
||||
}
|
||||
|
||||
const currentInterval = if (rl.isKeyDown(.s)) fastTickInterval else tickInterval;
|
||||
if (tickTimer >= currentInterval) {
|
||||
tickTimer -= currentInterval;
|
||||
if (rl.isKeyDown(.s)) {
|
||||
if (!isFast) {
|
||||
isFast = true;
|
||||
timer = 0;
|
||||
}
|
||||
} else {
|
||||
isFast = false;
|
||||
}
|
||||
const interval = if (isFast) fastTickInterval else tickInterval;
|
||||
if (timer >= interval) {
|
||||
timer -= interval;
|
||||
try game.tick();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user