From 2c22dabeae5a52924ab03be123902e0ce9454779 Mon Sep 17 00:00:00 2001 From: Strangedusk Date: Thu, 14 Jul 2022 15:22:40 +0200 Subject: [PATCH] Horizontal repetition WIP --- src/Game.zig | 69 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 66 insertions(+), 3 deletions(-) diff --git a/src/Game.zig b/src/Game.zig index 45713c4..1942bfd 100644 --- a/src/Game.zig +++ b/src/Game.zig @@ -54,6 +54,10 @@ action_list: [7]Action = .{ }, timer_down: Timer, +timer_left_arr: Timer, +timer_left_das: Timer, +timer_right_arr: Timer, +timer_right_das: Timer, pub fn init(_renderer: *SDL.SDL_Renderer) Self { var ret = Self{ @@ -68,7 +72,11 @@ pub fn init(_renderer: *SDL.SDL_Renderer) Self { .held = null, .renderer = _renderer, - .timer_down = Timer.init(33), + .timer_down = Timer.init(50), + .timer_left_arr = Timer.init(50), + .timer_left_das = Timer.init(200), + .timer_right_arr = Timer.init(50), + .timer_right_das = Timer.init(200), }; // Calculate positions @@ -82,20 +90,75 @@ pub fn init(_renderer: *SDL.SDL_Renderer) Self { ret.grid_pos_x = @divFloor(aux_w, 2) - (ret.grid_cell_size * @divFloor(Grid.ncolumns, 2)); ret.grid_pos_y = @divFloor(aux_h, 2) - (ret.grid_cell_size * @divFloor(Grid.nrows + Grid.buffer, 2)); - - ret.piece = ret.bag.pop(); } + // Get a piece from the bag + ret.piece = ret.bag.pop(); + return ret; } pub fn tick(self: *Self) State { // TIMERS + // Dropping a piece if (self.piece.timer_dropped.finished()) { self.piece.timer_dropped.stop(); self.piece.dropped = true; } + // Repeat Right + + // DAS + if (self.action_list[@enumToInt(Action.Offset.right)].holding) { + if (!self.timer_right_das.started) { + self.timer_right_das.start(); + std.debug.print("Starting DAS\n", .{}); + } + } else { + // Stop both + self.timer_right_das.stop(); + self.timer_right_arr.stop(); + std.debug.print("Stopping\n", .{}); + } + + // ARR + if (self.timer_right_das.finished()) { + if (!self.timer_right_arr.started) { + self.timer_right_arr.start(); + std.debug.print("Starting ARR\n", .{}); + } else if (self.timer_right_arr.finished()) { + self.timer_right_arr.stop(); + self.action_list[@enumToInt(Action.Offset.right)].holding = false; + } + } + + // Repeat Left + + // DAS + if (self.action_list[@enumToInt(Action.Offset.left)].holding) { + if (!self.timer_left_das.started) { + self.timer_left_das.start(); + std.debug.print("Starting DAS\n", .{}); + } + } else { + // Stop both + self.timer_left_das.stop(); + self.timer_left_arr.stop(); + std.debug.print("Stopping\n", .{}); + } + + // ARR + if (self.timer_left_das.finished()) { + if (!self.timer_left_arr.started) { + self.timer_left_arr.start(); + std.debug.print("Starting ARR\n", .{}); + } else if (self.timer_left_arr.finished()) { + self.timer_left_arr.stop(); + self.action_list[@enumToInt(Action.Offset.left)].holding = false; + } + } + + // Repeat Down if (self.action_list[@enumToInt(Action.Offset.down)].holding) { if (!self.timer_down.started) { self.timer_down.start();