Tetris in C + Raylib (and WEB using emscripten and wasm)
I personally use Clang on both Linux and Macos (i'm pretty sure you can substitute clang with gcc in the nob.c and still compile)
Clone the repo and enter:
$ git clone https://github.com/lmarzocchetti/cetris
$ cd cetris
Build the nob:
$ clang -o nob nob.c
Compile the executable dynamic
$ <install raylib with homebrew or apt/dnf/pacman>
$ ./nob Debug|Release
or if you want to link statically
$ ./nob Static <path-to-libraylib.a>
Play:
$ ./cetris
- Download and compile raylib targeting the web following the raylib guide (https://github.com/raysan5/raylib/wiki/Working-for-Web-(HTML5)) in a folder called raylib-5.5
- Uncomment the line "// #define EMSCRIPTEN" in nob.c
- In cetris folder:
$ ./nob
$ python -m http.server 8080
- Go in your browser to: "http://localhost:8080/cetris.html"
- Play!
To play the music you need to click on the canvas!
By default emscripten generate an html file which is not centered, if you interested copy this:
<style>
body {
margin: 0;
overflow: hidden;
background-color: #000;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
canvas.emscripten {
border: 0 none;
background-color: #000;
}
</style>
and substitute to the <style> generated automatically by emscripten.
- z -> Rotate the piece Clockwise
- x -> Rotate the piece Anticlockwise
- Left and Right key -> Move the piece
- Down key -> Speed up the piece
- m -> Mute/Unmute the music
- r -> Restart the game
- l -> Select another level
- Separate next piece from score (maybe generate 4/5 pieces aot?)
- Destroy animation
- Level selection
- Next level after some deleted blocks
- OpenGL Shaders
- Web support (emscripten)
If you want to add windows support you can do push request. Need to add some preprocessor on nob.c and os independent path in main.c