v/examples/2048
Eliyaan (Nopana) bbb61ab368
Some checks failed
Graphics CI / gg-regressions (push) Waiting to run
vlib modules CI / build-module-docs (push) Waiting to run
native backend CI / native-backend-ubuntu (push) Waiting to run
vab CI / v-compiles-os-android (push) Waiting to run
native backend CI / native-backend-windows (push) Waiting to run
Shy and PV CI / v-compiles-puzzle-vibes (push) Waiting to run
Sanitized CI / sanitize-undefined-clang (push) Waiting to run
Sanitized CI / sanitize-undefined-gcc (push) Waiting to run
Sanitized CI / tests-sanitize-address-clang (push) Waiting to run
Sanitized CI / sanitize-address-msvc (push) Waiting to run
Sanitized CI / sanitize-address-gcc (push) Waiting to run
Sanitized CI / sanitize-memory-clang (push) Waiting to run
sdl CI / v-compiles-sdl-examples (push) Waiting to run
Time CI / time-linux (push) Waiting to run
Time CI / time-macos (push) Waiting to run
Time CI / time-windows (push) Waiting to run
toml CI / toml-module-pass-external-test-suites (push) Waiting to run
Tools CI / tools-linux (clang) (push) Waiting to run
Tools CI / tools-linux (gcc) (push) Waiting to run
Tools CI / tools-linux (tcc) (push) Waiting to run
Tools CI / tools-macos (clang) (push) Waiting to run
Tools CI / tools-windows (gcc) (push) Waiting to run
Tools CI / tools-windows (msvc) (push) Waiting to run
Tools CI / tools-windows (tcc) (push) Waiting to run
Tools CI / tools-docker-ubuntu-musl (push) Waiting to run
vab CI / vab-compiles-v-examples (push) Waiting to run
wasm backend CI / wasm-backend (ubuntu-22.04) (push) Waiting to run
wasm backend CI / wasm-backend (windows-2022) (push) Waiting to run
Workflow Lint / lint-yml-workflows (push) Has been cancelled
gg, gx: deprecate gx and replace all occurences with gg (which now contains all the functionality of gx) (#24966)
2025-08-14 19:53:56 +03:00
..
.gitignore v.pref: allow for -os wasm32_emscripten and filtering _d_wasm32_emscripten.c.v and _notd_wasm32_emscripten.c.v files. (#23797) 2025-02-24 11:23:37 +02:00
2048.v gg, gx: deprecate gx and replace all occurences with gg (which now contains all the functionality of gx) (#24966) 2025-08-14 19:53:56 +03:00
demo.png all: optimize png images (#6860) 2020-11-17 17:42:21 +01:00
index.html examples/2048: add instructions, on how to compile the game through Emscripten and v -os wasm32_emscripten 2023-08-13 11:13:17 +03:00
LICENSE examples: add 2048 game 2020-08-18 09:29:43 +03:00
README.md examples: show how to use a v file server for the wasm version of 2048, instead of emrun 2025-02-24 15:25:16 +02:00
v.mod examples: add 2048 game 2020-08-18 09:29:43 +03:00

V 2048

This is a simple 2048 game, written in the V programming language.

WebAssembly demo: https://v2048.vercel.app

screenshot

Description

Merge tiles by moving them. After each move, a new random tile is added (2 or 4). The goal of the game is to create a tile with a value of 2048.

Keys

Escape - exit the game Backspace - undo last move n - restart the game t - toggle the UI theme Enter - toggle the tile text format

UP,LEFT,DOWN,RIGHT / W,A,S,D / touchscreen swipes - move the tiles

Running instructions

Compile & run the game with ./v run examples/2048

Compiling to WASM

  1. Install Emscripten from: https://emscripten.org/docs/getting_started/downloads.html

  2. Make sure that the environment in your shell is setup correctly, i.e. that emcc --version works.

    . /opt/emsdk/emsdk_env.sh
    emcc --version
    
  3. Compile the game to WASM: (the JS file contains a loader for the .wasm file, without the extension):

    v -prod -os wasm32_emscripten -o examples/2048/index.js examples/2048/
    
  4. Run/test the game:

    emrun examples/2048/index.html
    

    If you prefer, instead of emrun, you can start a simple V http file server:

    v -e 'import net.http.file; file.serve(folder: "examples/2048")'   
    

    and then open http://127.0.0.1:4001/ in your browser.

Once you have opened the game in your browser, you can make changes to the V source, then recompile (step 3), and refresh the browser window with the game, to see their effect.