add pause menu
This commit is contained in:
parent
f7e3698cb1
commit
79905b3546
@ -202,6 +202,7 @@ player: Player,
|
||||
rope: Rope,
|
||||
ui: UI,
|
||||
should_close: bool = false,
|
||||
paused: bool = false,
|
||||
|
||||
camera: rl.Camera2D,
|
||||
|
||||
@ -505,6 +506,41 @@ fn tickUI(self: *Self) !void {
|
||||
if (self.ui.button("Exit?", content.left(), content.top() + 120, content.width, 30)) {
|
||||
self.should_close = true;
|
||||
}
|
||||
} else if (self.paused) {
|
||||
const modal_size = rl.Vector2{ .x = 200, .y = 200 };
|
||||
const modal = screen_box.box(
|
||||
screen_box.center() - modal_size.x/2,
|
||||
screen_box.middle() - modal_size.y/2,
|
||||
modal_size.x,
|
||||
modal_size.y
|
||||
);
|
||||
const content = modal.margin(10);
|
||||
|
||||
rl.DrawRectangleRec(modal.rect(), rl.RAYWHITE);
|
||||
UI.drawTextAligned(
|
||||
font,
|
||||
"Paused",
|
||||
content.center_top().add(.{ .x = 0, .y = 30 }),
|
||||
30,
|
||||
rl.BLACK
|
||||
);
|
||||
|
||||
if (self.ui.button("Continue?", content.left(), content.top() + 70, content.width, 30)) {
|
||||
self.togglePaused();
|
||||
}
|
||||
|
||||
if (self.ui.button("Exit?", content.left(), content.top() + 120, content.width, 30)) {
|
||||
self.should_close = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn togglePaused(self: *Self) void {
|
||||
self.paused = !self.paused;
|
||||
if (self.paused) {
|
||||
self.player.input.deactivate();
|
||||
} else {
|
||||
self.player.input.activate();
|
||||
}
|
||||
}
|
||||
|
||||
@ -521,11 +557,17 @@ pub fn tick(self: *Self) !void {
|
||||
var enemies = &self.enemies;
|
||||
var rope = &self.rope;
|
||||
|
||||
self.tickPlayer();
|
||||
try self.tickEnemies();
|
||||
if (self.player.input.isPausePressed()) {
|
||||
self.togglePaused();
|
||||
}
|
||||
|
||||
if (self.player.alive()) {
|
||||
self.timePassed += rl.GetFrameTime();
|
||||
if (!self.paused) {
|
||||
self.tickPlayer();
|
||||
try self.tickEnemies();
|
||||
|
||||
if (self.player.alive()) {
|
||||
self.timePassed += rl.GetFrameTime();
|
||||
}
|
||||
}
|
||||
|
||||
const deathBallPosition = rope.nodePositions.get(rope.nodePositions.len-1);
|
||||
|
@ -104,6 +104,18 @@ pub fn getHandPosition(self: *@This()) rl.Vector2 {
|
||||
return hand_position;
|
||||
}
|
||||
|
||||
pub fn isPausePressed(self: *@This()) bool {
|
||||
if (rl.IsKeyPressed(rl.KeyboardKey.KEY_ESCAPE)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (rl.IsGamepadAvailable(self.gamepad) and rl.IsGamepadButtonPressed(self.gamepad, .GAMEPAD_BUTTON_MIDDLE_RIGHT)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
pub fn activate(self: *@This()) void {
|
||||
if (self.active) return;
|
||||
rl.DisableCursor();
|
||||
|
Loading…
Reference in New Issue
Block a user