Waphics allows you to easily create video games in C and export them to the web browser. Waphics provides a Javascript runtime enviroment for your C code which allows for:
#define WAPHICS_IMPLEMENTATION
#include "src/waphics.c"
#define WIDTH 1000
#define HEIGHT 600
uint32_t pixels[WIDTH * HEIGHT];
Surface display;
void init(void) {
display = SCREEN(pixels, WIDTH, HEIGHT);
}
static int x;
uint32_t *run(void) {
//fill the display with black
waphics_fill_display(display, RGB(0, 0, 0));
//draw a red rectangle
waphics_draw_rect(display, RECT(0, 0, 50, 50), RGB(255, 0, 0));
//draw a blue circle
waphics_draw_circle(display, CIRCLE(100, 100, 50), RGB(0, 100, 100));
if (get_key(KEY_D)) x+=10;
if (get_key(KEY_A)) x-=10;
return display.pixels;
}
Triangle with mouse input.
Image loading with alpha.
1. git clone https://github.com/ScriptLineStudios/waphics.c
2. cd waphics.c
3. sudo make DESTDIR=/usr/bin/ install
Waphics is simple to use. Once installed simply create a new C file and add an init and run method as follows:
#define WAPHICS_IMPLEMENTATION
#include "waphics.c"
#define WIDTH 1000
#define HEIGHT 600
uint32_t pixels[WIDTH * HEIGHT];
Surface display;
void init(void) {
display = SCREEN(pixels, WIDTH, HEIGHT);
}
uint32_t *run(void) {
// your code will go here...
return display.pixels;
}
From there you are free to use waphics functionaltiy on the web! Once you are ready to compile to the web. Simpliy run:
waphics <your_file>.c <width> <height>
This will generate the following:
index.html
output.wasm
javascript.js
Simpliy run index.html using a web server of your choice, and you will be greeted by your window!
if get_key(KEY_A) {
// the code here will only run when A is pressed
}