forked from tsoding/zozlib.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d300c4e
Showing
9 changed files
with
8,919 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
all: wasm/game.wasm | ||
|
||
wasm/game.wasm: game.c | ||
clang --target=wasm32 -I./include --no-standard-libraries -Wl,--no-entry -Wl,--allow-undefined -Wl,--export=game_init -Wl,--export=game_frame -Wl,--export=game_over -o wasm/game.wasm game.c -DPLATFORM_WEB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#include <raylib.h> | ||
#include <raymath.h> | ||
|
||
#define BALL_RADIUS 100.0 | ||
#define GRAVITY 1000.0 | ||
|
||
static Vector2 ball_position = {0}; | ||
static Vector2 ball_velocity = {200, 200}; | ||
|
||
void game_frame() | ||
{ | ||
BeginDrawing(); | ||
ClearBackground((Color){20, 20, 20, 255}); | ||
float dt = GetFrameTime(); | ||
ball_velocity.y += GRAVITY*dt; | ||
float x = ball_position.x + ball_velocity.x*dt; | ||
if (x - BALL_RADIUS < 0.0 || x + BALL_RADIUS >= GetScreenWidth()) { | ||
ball_velocity.x *= -1.0f; | ||
} else { | ||
ball_position.x = x; | ||
} | ||
float y = ball_position.y + ball_velocity.y*dt; | ||
if (y - BALL_RADIUS < 0.0 || y + BALL_RADIUS >= GetScreenHeight()) { | ||
ball_velocity.y *= -1.0f; | ||
} else { | ||
ball_position.y = y; | ||
} | ||
DrawCircleV(ball_position, BALL_RADIUS, RED); | ||
EndDrawing(); | ||
} | ||
|
||
void game_init() | ||
{ | ||
InitWindow(800, 600, "Hello, from WebAssembly"); | ||
SetTargetFPS(60); | ||
|
||
int w = GetScreenWidth(); | ||
int h = GetScreenHeight(); | ||
ball_position.x = w/2; | ||
ball_position.y = h/2; | ||
} | ||
|
||
void game_over() | ||
{ | ||
CloseWindow(); | ||
} | ||
|
||
#ifndef PLATFORM_WEB | ||
int main() | ||
{ | ||
game_init(); | ||
while (!WindowShouldClose()) { | ||
game_frame(); | ||
} | ||
game_over(); | ||
return 0; | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Phony math.h. Since we are compiling with --no-standard-libraries we raymath.h can't find math.h. | ||
// But it only needs it for few function definitions. So we've put those definitions here. | ||
#ifndef MATH_H_ | ||
#define MATH_H_ | ||
float floorf(float); | ||
float fabsf(float); | ||
double fabs(double); | ||
float fmaxf(float, float); | ||
float fminf(float, float); | ||
float sqrtf(float); | ||
float atan2f(float, float); | ||
float cosf(float); | ||
float sinf(float); | ||
float acosf(float); | ||
float asinf(float); | ||
double tan(double); | ||
#endif // MATH_H_ |
Oops, something went wrong.