Horizontal repetition WIP

This commit is contained in:
Dusk 2022-07-14 15:22:40 +02:00
parent 276016cdf7
commit 2c22dabeae
1 changed files with 66 additions and 3 deletions

View File

@ -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();