Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Commit

Permalink
Started tracking the playtime
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanlangston committed Nov 28, 2023
1 parent f9cab85 commit 01f79ee
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/ViewModels/ScaleViewModel.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ const WorldModel = @import("../Models/World.zig").World;
const RndGen = std.rand.DefaultPrng;

pub const ScaleViewModel = ViewModel.Create(
struct {},
struct {
pub var elapsedSeconds: f64 = undefined;
},
.{
.Init = init,
.DeInit = deinit,
},
);

fn init() void {
ScaleViewModel.GetVM().elapsedSeconds = 0;

WorldModel.Init() catch {
Logger.Error("Failed to Init World!");
};
Expand Down
10 changes: 9 additions & 1 deletion src/Views/ScaleView.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ const ScaleViewModel = @import("../ViewModels/ScaleViewModel.zig").ScaleViewMode
const PlayerModel = @import("../Models/Player.zig").Player;
const WorldModel = @import("../Models/World.zig").World;

const vm: type = ScaleViewModel.GetVM();
const moveModifier: f32 = 32;

pub fn DrawFunction() Views {
const current_screen = WorldModel.GetCurrentScreenSize();

const scroll_speed: f32 = 20 * raylib.getFrameTime();
vm.elapsedSeconds += raylib.getFrameTime();

WorldModel.Platforms = WorldModel.UpdatePlatforms(scroll_speed, current_screen);
WorldModel.Player = WorldModel.Player.UpdatePosition(scroll_speed - 0.001, current_screen);
Expand Down Expand Up @@ -68,6 +69,13 @@ pub fn DrawFunction() Views {
WorldModel.Player = WorldModel.Player.MoveRight();
}

const duration = std.fmt.fmtDuration(@as(u64, @intFromFloat(vm.elapsedSeconds * 1000000000)));
var buf: [13]u8 = undefined;
const timestamp = std.fmt.bufPrintZ(&buf, "{s:^12}", .{duration}) catch "Unknown!!";
const timestampSize = raylib.measureText(timestamp, 15);
raylib.drawText(timestamp, @as(i32, @intFromFloat(current_screen.width)) - timestampSize - 5, 5, 15, Colors.Miyazaki.Black);

// Ensure this is last, otherwise the pause screen won't display all the content
if (Inputs.Start_Pressed()) {
return Shared.Pause(Views.Scale);
}
Expand Down

0 comments on commit 01f79ee

Please sign in to comment.