https://github.com/scriptlinestudios/waphics.c
A web browser video game library for C.
https://github.com/scriptlinestudios/waphics.c
c game-development webassembly
Last synced: 7 months ago
JSON representation
A web browser video game library for C.
- Host: GitHub
- URL: https://github.com/scriptlinestudios/waphics.c
- Owner: ScriptLineStudios
- License: mit
- Created: 2023-02-05T17:25:38.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-31T09:17:43.000Z (8 months ago)
- Last Synced: 2024-10-31T10:21:07.588Z (8 months ago)
- Topics: c, game-development, webassembly
- Language: C
- Homepage: https://waphicsc.readthedocs.io/en/latest/index.html
- Size: 669 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# waphics.c - WebAssembly Graphics
## A web browser based video game library for C.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:
- Keyboard input (mouse input to come)
- Playing sounds
- Rendering primitimes (circles, rectangles, triangles)
- Image rendering (with scaling using uv coordinates)
- Alpha blending
```C
#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;
}
```
# Examples

Triangle with mouse input.

Image loading with alpha.
# Using the Library
## Building from source
```bash
1. git clone https://github.com/ScriptLineStudios/waphics.c
2. cd waphics.c
3. sudo make DESTDIR=/usr/bin/ install
```
# Getting started
Waphics is simple to use. Once installed simply create a new C file and add an init and run method as follows:
```C
#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:
```bash
waphics .c
```
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!
# Keyboard Inputs
```C
if get_key(KEY_A) {
// the code here will only run when A is pressed
}
```