Implement timers

This commit is contained in:
Dusk 2023-09-22 20:30:19 +02:00
parent 4f3599fa42
commit fb9968c19f
4 changed files with 21 additions and 17 deletions

View File

@ -65,12 +65,12 @@ pub fn init(renderer: *Renderer.Renderer) Self {
.held = null, .held = null,
.renderer = Renderer.init(renderer), .renderer = Renderer.init(renderer),
.timer_down = Timer.init(50), .timer_down = Timer.init(0.05),
.timer_left_arr = Timer.init(50), .timer_left_arr = Timer.init(0.05),
.timer_left_das = Timer.init(200), .timer_left_das = Timer.init(0.2),
.timer_right_arr = Timer.init(50), .timer_right_arr = Timer.init(0.05),
.timer_right_das = Timer.init(200), .timer_right_das = Timer.init(0.2),
.timer_gravity = Timer.init(200), .timer_gravity = Timer.init(0.2),
}; };
// Get a piece from the bag // Get a piece from the bag

View File

@ -58,7 +58,7 @@ pub fn init(piece_type: Type) Self {
.col = (Grid.ncolumns / 2) - (ncols / 2), .col = (Grid.ncolumns / 2) - (ncols / 2),
.piece_type = piece_type, .piece_type = piece_type,
.timer_dropped = Timer.init(500), .timer_dropped = Timer.init(0.5),
.structure = switch (piece_type) { .structure = switch (piece_type) {
Type.o => .{ Type.o => .{

View File

@ -1,13 +1,13 @@
//const SDL = @import("sdl2");
const Self = @This(); const Self = @This();
started: bool, const getTime = @import("raylib.zig").getTime;
initial: u64,
progress: u64,
target: u64,
pub fn init(target: u64) Self { started: bool,
initial: f64,
progress: f64,
target: f64,
pub fn init(target: f64) Self {
return Self{ return Self{
.started = false, .started = false,
.initial = 0, .initial = 0,
@ -19,12 +19,12 @@ pub fn init(target: u64) Self {
pub fn start(self: *Self) void { pub fn start(self: *Self) void {
self.started = true; self.started = true;
self.progress = 0; self.progress = 0;
//self.initial = SDL.getTicks64(); self.initial = getTime();
} }
pub fn finished(self: *Self) bool { pub fn finished(self: *Self) bool {
if (self.started) { if (self.started) {
//self.progress = SDL.getTicks64() - self.initial; self.progress = getTime() - self.initial;
if (self.progress >= self.target) { if (self.progress >= self.target) {
return true; return true;
} else return false; } else return false;
@ -35,7 +35,7 @@ pub fn finished(self: *Self) bool {
pub fn reset(self: *Self) void { pub fn reset(self: *Self) void {
self.progress = 0; self.progress = 0;
//self.initial = SDL.getTicks64(); self.initial = getTime();
} }
pub fn stop(self: *Self) void { pub fn stop(self: *Self) void {

View File

@ -73,3 +73,7 @@ pub fn getScreenWidth() i32 {
pub fn getScreenHeight() i32 { pub fn getScreenHeight() i32 {
return c.GetScreenHeight(); return c.GetScreenHeight();
} }
pub fn getTime() f64 {
return c.GetTime();
}