Basic rotation
This commit is contained in:
parent
4f6a010564
commit
8d2259b6c7
|
@ -88,3 +88,4 @@ tags
|
|||
zig
|
||||
zig-out
|
||||
zig-cache
|
||||
zig-cache/*
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
const std = @import("std");
|
||||
const SDL = @import("sdl2");
|
||||
|
||||
const Color = @import("color.zig");
|
||||
|
||||
const Self = @This();
|
||||
|
||||
free: bool,
|
||||
|
@ -9,11 +11,6 @@ color: SDL.SDL_Color,
|
|||
pub fn init() Self {
|
||||
return Self{
|
||||
.free = true,
|
||||
.color = SDL.SDL_Color{
|
||||
.r = 0x00,
|
||||
.g = 0x00,
|
||||
.b = 0x00,
|
||||
.a = 0xFF,
|
||||
},
|
||||
.color = Color.dark_grey,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -42,3 +42,15 @@ pub const purple = SDL.SDL_Color{
|
|||
.b = 203,
|
||||
.a = 255,
|
||||
};
|
||||
pub const dark_grey = SDL.SDL_Color{
|
||||
.r = 40,
|
||||
.g = 40,
|
||||
.b = 40,
|
||||
.a = 255,
|
||||
};
|
||||
pub const light_grey = SDL.SDL_Color{
|
||||
.r = 80,
|
||||
.g = 80,
|
||||
.b = 80,
|
||||
.a = 255,
|
||||
};
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
const std = @import("std");
|
||||
const SDL = @import("sdl2");
|
||||
|
||||
const Color = @import("color.zig");
|
||||
const Cell = @import("cell.zig");
|
||||
const utils = @import("utils.zig");
|
||||
|
||||
|
@ -71,7 +72,7 @@ pub fn render(self: Self, renderer: *SDL.SDL_Renderer, cell_size: i32, pos_x: i3
|
|||
|
||||
_ = SDL.SDL_SetRenderDrawColor(renderer, r, g, b, a);
|
||||
_ = SDL.SDL_RenderFillRect(renderer, &rect);
|
||||
_ = SDL.SDL_SetRenderDrawColor(renderer, 0x33, 0x33, 0x33, 0xFF);
|
||||
_ = SDL.SDL_SetRenderDrawColor(renderer, Color.light_grey.r, Color.light_grey.g, Color.light_grey.b, Color.light_grey.a);
|
||||
_ = SDL.SDL_RenderDrawRect(renderer, &rect);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,9 +6,9 @@ const Grid = @import("grid.zig");
|
|||
|
||||
const Self = @This();
|
||||
|
||||
pub const Rot = enum(u2) {
|
||||
right = 0,
|
||||
left = 2,
|
||||
pub const Rot = enum {
|
||||
right,
|
||||
left,
|
||||
};
|
||||
|
||||
pub const Type = enum {
|
||||
|
@ -112,7 +112,13 @@ pub fn rotate(self: Self, dir: Rot) Self {
|
|||
|
||||
inline for (sequences) |seq| {
|
||||
inline for (seq) |_, i| {
|
||||
new_piece.structure[seq[i][0]][seq[i][1]] = self.structure[seq[(i + @enumToInt(dir) - 1) % 4][0]][seq[(i + @enumToInt(dir) - 1) % 4][1]];
|
||||
if (dir == Rot.right) {
|
||||
const refi = @mod((@intCast(i32, i) - 1), 4);
|
||||
new_piece.structure[seq[i][0]][seq[i][1]] = self.structure[seq[refi][0]][seq[refi][1]];
|
||||
} else {
|
||||
const refi = @mod((@intCast(i32, i) + 1), 4);
|
||||
new_piece.structure[seq[i][0]][seq[i][1]] = self.structure[seq[refi][0]][seq[refi][1]];
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -120,7 +126,13 @@ pub fn rotate(self: Self, dir: Rot) Self {
|
|||
|
||||
inline for (sequences) |seq| {
|
||||
inline for (seq) |_, i| {
|
||||
new_piece.structure[seq[i][0]][seq[i][1]] = self.structure[seq[(i + @enumToInt(dir) - 1) % 4][0]][seq[(i + @enumToInt(dir) - 1) % 4][1]];
|
||||
if (dir == Rot.right) {
|
||||
const refi = @mod((@intCast(i32, i) - 1), 4);
|
||||
new_piece.structure[seq[i][0]][seq[i][1]] = self.structure[seq[refi][0]][seq[refi][1]];
|
||||
} else {
|
||||
const refi = @mod((@intCast(i32, i) + 1), 4);
|
||||
new_piece.structure[seq[i][0]][seq[i][1]] = self.structure[seq[refi][0]][seq[refi][1]];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
1361 36569768 1657038271710135652 e361ab3d1987688681b5db7b52fd5cba /home/strange/Documentos/Projectes/Programació/usg/src/main.zig
|
||||
1361 36569768 1657038271710135652 e361ab3d1987688681b5db7b52fd5cba /home/strange/Documentos/Projectes/Programació/usg/src/main.zig
|
||||
135300 36570392 1655299923670057346 b4c2d851673df5aab566633b89bdaa84 /home/strange/Documentos/Projectes/Programació/usg/lib/SDL.zig/src/binding/sdl.zig
|
||||
32 36570080 1657053720550249757 91a8da097c7c1645ba2a6217a5171c4e /home/strange/Documentos/Projectes/Programació/usg/zig-cache/options/kh59p23UXKId3bWMadeQ0Yp6cv2kATA4qPk2nBQ2q_3IsG9JTjKRYS1YxdIMHL6s
|
||||
32 36570080 1657057884680280513 91a8da097c7c1645ba2a6217a5171c4e /home/strange/Documentos/Projectes/Programació/usg/zig-cache/options/kh59p23UXKId3bWMadeQ0Yp6cv2kATA4qPk2nBQ2q_3IsG9JTjKRYS1YxdIMHL6s
|
||||
5621 36968525 1655270162000000000 66001e1a55f68e4681c1f32a69223647 /home/strange/Documentos/Projectes/Programació/usg/zig/lib/std/std.zig
|
||||
5621 36968525 1655270162000000000 66001e1a55f68e4681c1f32a69223647 /home/strange/Documentos/Projectes/Programació/usg/zig/lib/std/std.zig
|
||||
29901 36968437 1655270162000000000 5c441d88acbf5e7fe2a26137df2b5376 /home/strange/Documentos/Projectes/Programació/usg/zig/lib/std/builtin.zig
|
||||
|
@ -21,15 +21,15 @@
|
|||
121502 36968568 1655270162000000000 4bad05f05e4a10364e515a13d2fa2b3f /home/strange/Documentos/Projectes/Programació/usg/zig/lib/std/os/linux/io_uring.zig
|
||||
135300 36570392 1655299923670057346 b4c2d851673df5aab566633b89bdaa84 /home/strange/Documentos/Projectes/Programació/usg/lib/SDL.zig/src/binding/sdl.zig
|
||||
1640 36570393 1655299923670057346 c3d50ea43c9e10688a521a9ac927ded4 /home/strange/Documentos/Projectes/Programació/usg/lib/SDL.zig/src/binding/sdl_image.zig
|
||||
32 36570080 1657053720550249757 91a8da097c7c1645ba2a6217a5171c4e /home/strange/Documentos/Projectes/Programació/usg/zig-cache/options/kh59p23UXKId3bWMadeQ0Yp6cv2kATA4qPk2nBQ2q_3IsG9JTjKRYS1YxdIMHL6s
|
||||
32 36570080 1657057884680280513 91a8da097c7c1645ba2a6217a5171c4e /home/strange/Documentos/Projectes/Programació/usg/zig-cache/options/kh59p23UXKId3bWMadeQ0Yp6cv2kATA4qPk2nBQ2q_3IsG9JTjKRYS1YxdIMHL6s
|
||||
7338 36968289 1655270162000000000 ee4fd6c02929ff52d99a8faa2539dce8 /home/strange/Documentos/Projectes/Programació/usg/zig/lib/std/zig.zig
|
||||
21121 36968483 1655270162000000000 669c911cf26ce07c5f5516d896b30e33 /home/strange/Documentos/Projectes/Programació/usg/zig/lib/std/zig/c_translation.zig
|
||||
113573 36968636 1655270162000000000 2c3980264c753ba754322c7c8c4f2634 /home/strange/Documentos/Projectes/Programació/usg/zig/lib/std/mem.zig
|
||||
4399 36570427 1657050625270226896 5a5f1095331817ca2935aae8f1c887ef /home/strange/Documentos/Projectes/Programació/usg/src/game.zig
|
||||
1985 36569864 1657040654430153251 a4190b51e743c069b95bce0368e169d7 /home/strange/Documentos/Projectes/Programació/usg/src/grid.zig
|
||||
320 36569823 1657026237740046769 9c0018b94509c3c3f7e8edd793177de6 /home/strange/Documentos/Projectes/Programació/usg/src/cell.zig
|
||||
2077 36569864 1657057506010277717 a18ae95a6705d7982e23251e180871b3 /home/strange/Documentos/Projectes/Programació/usg/src/grid.zig
|
||||
256 36569823 1657057405170276972 a69ae39529d33ff9e7623523a1e0dbe9 /home/strange/Documentos/Projectes/Programació/usg/src/cell.zig
|
||||
1708 36569840 1657038395020136563 151ce67aaf4e36de54f56be701bc0b66 /home/strange/Documentos/Projectes/Programació/usg/src/bag.zig
|
||||
4796 36569846 1657053719270249748 1273e72a46280cdcf35d48a94d969800 /home/strange/Documentos/Projectes/Programació/usg/src/piece.zig
|
||||
5393 36569846 1657057045880274318 1150e3c04cfc9dfab11e84e9393b3c7f /home/strange/Documentos/Projectes/Programació/usg/src/piece.zig
|
||||
16192 36968506 1655270162000000000 744a2bb13e662f350a196780c9fbcad2 /home/strange/Documentos/Projectes/Programació/usg/zig/lib/std/rand.zig
|
||||
3105 36968346 1655270162000000000 412e5ff0bcf84571f173caa8acab5393 /home/strange/Documentos/Projectes/Programació/usg/zig/lib/std/rand/Xoshiro256.zig
|
||||
45023 36968356 1655270162000000000 c30e605ecc099ad6f5498460429756fa /home/strange/Documentos/Projectes/Programació/usg/zig/lib/std/elf.zig
|
||||
|
@ -65,7 +65,7 @@
|
|||
68808 36968298 1655270162000000000 1428e5a8bcb96a47d038d40214331d68 /home/strange/Documentos/Projectes/Programació/usg/zig/lib/std/event/loop.zig
|
||||
32411 36968509 1655270162000000000 a25cf125aa2af22a7263d8104b549cb9 /home/strange/Documentos/Projectes/Programació/usg/zig/lib/std/unicode.zig
|
||||
44495 36968491 1655270162000000000 bfcc36624c8f3cb045fc58558f6aa79d /home/strange/Documentos/Projectes/Programació/usg/zig/lib/std/process.zig
|
||||
663 36569831 1656078583710029346 74acba9445f0ebf3147733e83d02a6d1 /home/strange/Documentos/Projectes/Programació/usg/src/color.zig
|
||||
850 36569831 1657057860690280336 b9ebfb0b293930640bc22ebdf6acab54 /home/strange/Documentos/Projectes/Programació/usg/src/color.zig
|
||||
76200 36968550 1655270162000000000 35261e8277652ce34bf8d0d6761b4bab /home/strange/Documentos/Projectes/Programació/usg/zig/lib/std/os/linux/syscalls.zig
|
||||
1174 36968430 1655270162000000000 1a71f479a0d0d95f1b0d960381e246ee /home/strange/Documentos/Projectes/Programació/usg/zig/lib/std/hash.zig
|
||||
10122 36968518 1655270162000000000 6372ee29c64a8e176138e879d43eb625 /home/strange/Documentos/Projectes/Programació/usg/zig/lib/std/hash/wyhash.zig
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue