Giter Site home page Giter Site logo

tetris's Introduction

Tetris

A simple tetris clone written in zig programming language.

Controls

  • Left/Right/Down Arrow - Move piece left/right/down.
  • Up Arrow - Rotate piece clockwise.
  • Shift - Rotate piece counter clockwise.
  • Space - Drop piece immediately.
  • Left Ctrl - Hold piece.
  • R - Start new game.
  • P - Pause and unpause game.
  • Escape - Quit.

Dependencies

Building and Running

zig build play

tetris's People

Contributors

alexpana avatar alichraghi avatar andrewrk avatar danaugrs avatar james-schaefer avatar joachimschmidt557 avatar kavika13 avatar kubkon avatar lordmzte avatar markfirmware avatar marler8997 avatar mrwormhole avatar ominitay avatar paulsmith avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tetris's Issues

error: container 'builtin' has no member called 'Environ'

I would like to refactor to separate the game logic from io in order to add ultibo as a replacement for glfw. Would you be amenable to pull requests for that kind of refactoring?

The first step is to start with a working build:

debian 9 x86/64:

root@localhost:~/github.com/andrewrk/tetris# zig build
/root/github.com/andrewrk/tetris/build.zig:12:71: error: container 'builtin' has no member called 'Environ'
        exe.setTarget(builtin.Arch.x86_64, builtin.Os.windows, builtin.Environ.gnu);
                                                                      ^
root@localhost:~/github.com/andrewrk/tetris# zig version
0.3.0+5469e3e3

LLVM error when building the game

When building the game on linux-x86_64, i get the following LLVM error:

Call parameter type does not match function signature!
%Tetris* @tetris_state
i8* call void @glfwSetWindowUserPointer(i8* %62, %Tetris* @tetris_state), !dbg !12525
LLVM ERROR: Broken module found, compilation aborted!`

To fix this error I had to change the 'const' to a 'var' in main.zig:178.

I'm not sure if this is the correct solution, therefore this issue and not directly a PR.

Maybe this has something to do with this issue: ziglang/zig#2444

Btw, I'm FireFox317 on the IRC

`error: use of undeclared identifier '_'` with zig 0.4.0

I just grabbed the 0.4.0 version of the linux compiler:

± |master ✓| → ~/apps/zig-linux-x86_64-0.4.0/zig version
0.4.0

When trying to build the master branch following the README.md, I get this error:

/home/phtrivier/perso/src/zig/tetris/build.zig:9:60: error: use of undeclared identifier '_'
    exe.addCSourceFile("stb_image-2.22/stb_image_impl.c", [_][]const u8{"-std=c99"});
                                                           ^


Am I missing something, or should I use a "master" version of the compiler ?

Unifying similar code for particles and falling blocks

tetris/src/main.zig

Lines 400 to 424 in c2aa222

for (t.falling_blocks) |*maybe_p| {
if (maybe_p.*) |*p| {
p.pos = p.pos.add(p.vel);
p.vel = p.vel.add(vec3(0, gravity, 0));
p.angle += p.angle_vel;
if (p.pos.data[1] > @intToFloat(f32, t.framebuffer_height)) {
maybe_p.* = null;
}
}
}
for (t.particles) |*maybe_p| {
if (maybe_p.*) |*p| {
p.pos = p.pos.add(p.vel);
p.vel = p.vel.add(vec3(0, gravity, 0));
p.angle += p.angle_vel;
if (p.pos.data[1] > @intToFloat(f32, window_height) + 10.0) {
maybe_p.* = null;
}
}
}

Lines 407 and 420 are similar - one uses framebuffer_height and one uses window_height - should they be the same? Also line 420 adds 10.0 - should that be margin_size:

const margin_size = 10;

and should it also be in line 407?

Regards, Mark

A warning against using trademarked names

The game's name is trademaked, and the rights holders already issued DMCAs to projects on Github that used their name for promotion: https://github.com/search?q=repo%3Agithub%2Fdmca+tetris&type=pullrequests

Since this repo is still being updated and is referenced from time to time as an example of what Zig can do (= promotion) it's going to gather more attention, that said I think it would be safer to change the repo/project's name and any other reference in code, video titles or other promotional articles you may use in the future, to at least reduce the risk of a takedown.

The best thing would be to have a sample game which completely avoids legal gray areas, but the second best thing I guess is just being careful with names and hope for the best. Qt did something similar, of course it's not a bulletproof solution but it's something.

error: no member named 'rand' in '/usr/lib/zig/std/index.zig'

Hi,

I'm using zig version 0.0.0 on 64-bit Arch Linux.

$ zig version
0.0.0

When building tetris, I get the following error:

$ zig build src/main.zig --name tetris --export exe --library c --library m --library glfw --library epoxy --library png --library z            
src/main.zig:2:17: error: no member named 'rand' in '/usr/lib/zig/std/index.zig'
const Rand = std.rand.Rand;

Best regards,
Alexander F Rødseth

build problem

don@oysters:~/src/tetris$ fg
zig build play
Build Dependencies...unwind [2] Compile C Objects [5/8] UnwindLevel1-gcc-ext.c..Build Dependencies...unwind [2] Compile C Objects [7/8] UnwindRegistersRestore.SBuild Dependencies...at_quick_exit [2] Compile C Objects [1/1] at_quick_exit.c..Build Dependencies...pthread_atfork [2] Compile C Objects [1/1] pthread_atfork.cBuild Dependencies...stack_chk_fail_local [2] Compile C Objects [1/1] stack_chk_Error: u8@7ffcfe884080

/home/don/src/tetris/src/main.zig:22:10: 0x22989f in errorCallback (tetris)
    panic("Error: {}\n", .{description});
         ^
The following command terminated unexpectedly:
cd /home/don/src/tetris && /home/don/src/tetris/zig-cache/bin/tetris 

Build failed. The following command failed:
/home/don/src/tetris/zig-cache/o/T43ZyUZTaP-cR0Ny_GS_98VEC-nkbfdu0f2TKyFcPbhrbS2oaCqceqlkSRHZhBey/build /usr/local/bin/zig /home/don/src/tetris /home/don/src/tetris/zig-cache play
don@oysters:~/src/tetris$ zig version
0.5.0+cf38ce970

MIT or CC0 license?

I assume Andrew wants us to use this repo's code to get started on our own projects, but there should be a license to make that intention clear. Could an MIT or CC0 or some other license be added?

Status of this project?

I'm a bit new to zig-lang, and a bit generally confused about things :]

I want to do a zig opengl app https://github.com/bfredl/zigui and it seems I can prototype stuff by copypasting stuff from this repo and just add whatever c dependencies I need. However, is there already a zig opengl app framework lib somewhere I could use instead? If not, I might separate my app in to two layers (opengl initialization lib + the actuall app), so that there is such a library. I guess I also should look though @ifreund stuff like https://github.com/ifreund/river, so to not reinvent anything that is already there there.

Fails building with zig 0.10

I have yet to build my zig hello world, so not quite sure how to fix this build error.

~/s/tetris (master) [1]> zig env
{
 "zig_exe": "/Users/hyiltiz/.asdf/installs/zig/0.10.0/zig",
 "lib_dir": "/Users/hyiltiz/.asdf/installs/zig/0.10.0/lib",
 "std_dir": "/Users/hyiltiz/.asdf/installs/zig/0.10.0/lib/std",
 "global_cache_dir": "/Users/hyiltiz/.cache/zig",
 "version": "0.10.0",
 "target": "x86_64-macos.13...13-none"
}
~/s/tetris (master)> pwd
/Users/hyiltiz/src/tetris
~/s/tetris (master)> zig build play
/Users/hyiltiz/.asdf/installs/zig/0.10.0/lib/std/build.zig:2314:31: error: deprecated; use addIncludePath
    pub const addIncludeDir = @compileError("deprecated; use addIncludePath");
                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
referenced by:
    build: /Users/hyiltiz/src/tetris/build.zig:25:8
    runBuild: /Users/hyiltiz/.asdf/installs/zig/0.10.0/lib/build_runner.zig:230:22
    remaining reference traces hidden; use '-freference-trace' to see all reference traces

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.