Skip to content

Commit 0c4b6b7

Browse files
committed
remove stdlib dependency and add raymath implementation
1 parent 78a5253 commit 0c4b6b7

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

examples/2d_camera_platformer.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
********************************************************************************************/
1515

1616
#include "raylib.h"
17+
#define RAYMATH_IMPLEMENTATION
1718
#include "raymath.h"
1819

1920
void raylib_js_set_entry(void (*entry)(void));
@@ -81,6 +82,16 @@ void UpdateCameraPlayerBoundsPush(Camera2D *camera, Player *player, EnvItem *env
8182
"Follow player center horizontally; update player center vertically after landing",
8283
"Player push camera on getting too close to screen edge"
8384
};
85+
86+
//custom MATH funcitons
87+
float myfminf(float a, float b) {
88+
if (b < a ) return b;
89+
return a;
90+
}
91+
float myfmaxf(float a, float b) {
92+
if (b > a ) return b;
93+
return a;
94+
}
8495

8596
void GameFrame() {
8697

@@ -232,10 +243,10 @@ void UpdateCameraCenterInsideMap(Camera2D *camera, Player *player, EnvItem *envI
232243
for (int i = 0; i < envItemsLength; i++)
233244
{
234245
EnvItem *ei = envItems + i;
235-
minX = fminf(ei->rect.x, minX);
236-
maxX = fmaxf(ei->rect.x + ei->rect.width, maxX);
237-
minY = fminf(ei->rect.y, minY);
238-
maxY = fmaxf(ei->rect.y + ei->rect.height, maxY);
246+
minX = myfminf(ei->rect.x, minX);
247+
maxX = myfmaxf(ei->rect.x + ei->rect.width, maxX);
248+
minY = myfminf(ei->rect.y, minY);
249+
maxY = myfmaxf(ei->rect.y + ei->rect.height, maxY);
239250
}
240251

241252
Vector2 max = GetWorldToScreen2D((Vector2){ maxX, maxY }, *camera);
@@ -259,7 +270,7 @@ void UpdateCameraCenterSmoothFollow(Camera2D *camera, Player *player, EnvItem *e
259270

260271
if (length > minEffectLength)
261272
{
262-
float speed = fmaxf(fractionSpeed*length, minSpeed);
273+
float speed = myfmaxf(fractionSpeed*length, minSpeed);
263274
camera->target = Vector2Add(camera->target, Vector2Scale(diff, speed*delta/length));
264275
}
265276
}

raylib.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ class RaylibJs {
4545
this.images = [];
4646
this.quit = false;
4747

48-
this.camera2DOffset = undefined;
48+
this.cameraOffset2D = undefined;
4949
}
5050

5151
applyCameraOffset(x, y) {
52-
if (this.camera2DOffset) {
53-
x += this.camera2DOffset.x;
54-
y += this.camera2DOffset.y;
52+
if (this.cameraOffset2D) {
53+
x += this.cameraOffset2D.x;
54+
y += this.cameraOffset2D.y;
5555
}
5656
return [x, y];
5757
}
@@ -370,11 +370,9 @@ class RaylibJs {
370370
if (rotation !== 0) throw Error("Rotation not yet supported");
371371
if (zoom !== 1) throw Error("Zoom not yet supported");
372372

373-
this.camera2DOffset = { x: offsetX - targetX, y: offsetY - targetY };
374-
375-
373+
this.cameraOffset2D = { x: offsetX - targetX, y: offsetY - targetY };
376374
}
377-
EndMode2D() {this.camera2DOffset = undefined;}
375+
EndMode2D() {this.cameraOffset2D = undefined;}
378376
DrawCircle(posX, posY, radius, color_ptr)
379377
{
380378
const buffer = this.wasm.instance.exports.memory.buffer;
@@ -387,6 +385,9 @@ class RaylibJs {
387385
this.ctx.fill();
388386

389387
}
388+
GetWorldToScreen2D() {}
389+
GetScreenToWorld2D() {}
390+
//End newly added
390391

391392
raylib_js_set_entry(entry) {
392393
this.entryFunction = this.wasm.instance.exports.__indirect_function_table.get(entry);

0 commit comments

Comments
 (0)