diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/customBeginMode3D | 38 | ||||
| -rw-r--r-- | src/input.c | 146 | ||||
| -rw-r--r-- | src/input.h | 22 | ||||
| -rw-r--r-- | src/main.c | 272 | ||||
| -rw-r--r-- | src/player.c | 16 | ||||
| -rw-r--r-- | src/render.c | 30 |
6 files changed, 221 insertions, 303 deletions
diff --git a/src/customBeginMode3D b/src/customBeginMode3D new file mode 100644 index 0000000..7be9b9f --- /dev/null +++ b/src/customBeginMode3D @@ -0,0 +1,38 @@ +// place this code into raylib/src/rcore.c +void customBeginMode3D(Camera camera) +{ + rlDrawRenderBatchActive(); // Update and draw internal render batch + + rlMatrixMode(RL_PROJECTION); // Switch to projection matrix + rlPushMatrix(); // Save previous matrix, which contains the settings for the 2d ortho projection + rlLoadIdentity(); // Reset current matrix (projection) + + float aspect = ((float)CORE.Window.currentFbo.width / 2.0f)/(float)CORE.Window.currentFbo.height; + + // NOTE: zNear and zFar values are important when computing depth buffer values + if (camera.projection == CAMERA_PERSPECTIVE) + { + // Setup perspective projection + double top = RL_CULL_DISTANCE_NEAR*tan(camera.fovy*0.5*DEG2RAD); + double right = top*aspect; + + rlFrustum(-right, right, -top, top, RL_CULL_DISTANCE_NEAR, RL_CULL_DISTANCE_FAR); + } + else if (camera.projection == CAMERA_ORTHOGRAPHIC) + { + // Setup orthographic projection + double top = camera.fovy/2.0; + double right = top*aspect; + + rlOrtho(-right, right, -top,top, RL_CULL_DISTANCE_NEAR, RL_CULL_DISTANCE_FAR); + } + + rlMatrixMode(RL_MODELVIEW); // Switch back to modelview matrix + rlLoadIdentity(); // Reset current matrix (modelview) + + // Setup Camera view + Matrix matView = MatrixLookAt(camera.position, camera.target, camera.up); + rlMultMatrixf(MatrixToFloat(matView)); // Multiply modelview matrix by view matrix (camera) + + rlEnableDepthTest(); // Enable DEPTH_TEST for 3D +} diff --git a/src/input.c b/src/input.c index 3661492..f1c5280 100644 --- a/src/input.c +++ b/src/input.c @@ -1,15 +1,123 @@ #include "input.h" +#ifdef PLATFORM_WEB +#include "raylib.h" +#include <stdio.h> +#else +#endif -joypad_buttons_t pressed_p1; -joypad_buttons_t held_p1; -joypad_inputs_t inputs_p1; +joypad_buttons_t pressed_p1 = {0}; +joypad_buttons_t held_p1 = {0}; +joypad_inputs_t inputs_p1 = {0}; -joypad_buttons_t pressed_p2; -joypad_buttons_t held_p2; -joypad_inputs_t inputs_p2; +joypad_buttons_t pressed_p2 = {0}; +joypad_buttons_t held_p2 = {0}; +joypad_inputs_t inputs_p2 = {0}; void updateController() { +#ifdef PLATFORM_WEB + static int previous_x_p1 = 0; + static int previous_y_p1 = 0; + static int previous_x_p2 = 0; + static int previous_y_p2 = 0; + + pressed_p1.z = IsKeyPressed(KEY_V); + pressed_p1.r = IsKeyPressed(KEY_Q); + pressed_p2.z = IsKeyPressed(KEY_K); + pressed_p2.r = IsKeyPressed(KEY_L); + + static int turn_speed = 5; + + if(IsKeyDown(KEY_W)) + { + previous_y_p1 += turn_speed; + if(previous_y_p1 > 100) + { + previous_y_p1 = 100; + } + } + if(IsKeyDown(KEY_A)) + { + previous_x_p1 -= turn_speed; + if(previous_x_p1 < -100) + { + previous_x_p1 = -100; + } + } + if(IsKeyDown(KEY_S)) + { + previous_y_p1 -= turn_speed; + if(previous_y_p1 < -100) + { + previous_y_p1 = -100; + } + } + if(IsKeyDown(KEY_D)) + { + previous_x_p1 += turn_speed; + if(previous_x_p1 > 100) + { + previous_x_p1 = 100; + } + } + + if(!IsKeyDown(KEY_W) && !IsKeyDown(KEY_S)) + { + previous_y_p1 *= 2.0f/3.0f; + } + if(!IsKeyDown(KEY_A) && !IsKeyDown(KEY_D)) + { + previous_x_p1 *= 2.0f/3.0f; + } + + if(IsKeyDown(KEY_UP)) + { + previous_y_p2 += turn_speed; + if(previous_y_p2 > 100) + { + previous_y_p2 = 100; + } + } + if(IsKeyDown(KEY_LEFT)) + { + previous_x_p2 -= turn_speed; + if(previous_x_p2 < -100) + { + previous_x_p2 = -100; + } + } + if(IsKeyDown(KEY_DOWN)) + { + previous_y_p2 -= turn_speed; + if(previous_y_p2 < -100) + { + previous_y_p2 = -100; + } + } + if(IsKeyDown(KEY_RIGHT)) + { + previous_x_p2 += turn_speed; + if(previous_x_p2 > 100) + { + previous_x_p2 = 100; + } + } + + if(!IsKeyDown(KEY_UP) && !IsKeyDown(KEY_DOWN)) + { + previous_y_p2 *= 2.0f/3.0f; + } + if(!IsKeyDown(KEY_LEFT) && !IsKeyDown(KEY_RIGHT)) + { + previous_x_p2 *= 2.0f/3.0f; + } + + inputs_p1.stick_y = previous_y_p1; + inputs_p1.stick_x = previous_x_p1; + + inputs_p2.stick_y = previous_y_p2; + inputs_p2.stick_x = previous_x_p2; +#else joypad_poll(); pressed_p1 = joypad_get_buttons_pressed(JOYPAD_PORT_1); held_p1 = joypad_get_buttons_held(JOYPAD_PORT_1); @@ -17,10 +125,12 @@ void updateController() pressed_p2 = joypad_get_buttons_pressed(JOYPAD_PORT_2); held_p2 = joypad_get_buttons_held(JOYPAD_PORT_2); inputs_p2 = joypad_get_inputs(JOYPAD_PORT_2); +#endif float x = inputs_p1.stick_x; float y = inputs_p1.stick_y; + if(x > 60) { x = 60.0f; @@ -65,29 +175,12 @@ void updateController() y += 5; } - //float distance = sqrtf((x * x) + (y * y)); - - //char text[500]; - //char text2[500]; - //char text3[500]; - //sprintf(text, "x %f", x); - //sprintf(text2, "y %f", y); - //sprintf(text3, "d %f", distance); - //DrawText(text, 100, 10, 12, GREEN); - //DrawText(text2, 100, 30, 12, GREEN); - //DrawText(text3, 100, 60, 12, GREEN); - - /* - if(distance != 0) - { - inputs_p1.stick_x = (x / distance) * 127.0f; - inputs_p1.stick_y = (y / distance) * 127.0f; - } - */ - inputs_p1.stick_x = x / 55.0f * 127.0f; inputs_p1.stick_y = y / 55.0f * 127.0f; + printf("Input %f\n", x); + printf("Input %d\n", inputs_p1.stick_x); + x = inputs_p2.stick_x; y = inputs_p2.stick_y; @@ -137,5 +230,4 @@ void updateController() inputs_p2.stick_x = x / 55.0f * 127.0f; inputs_p2.stick_y = y / 55.0f * 127.0f; - } diff --git a/src/input.h b/src/input.h index 8913e35..083a377 100644 --- a/src/input.h +++ b/src/input.h @@ -1,7 +1,29 @@ #ifndef GAME_INPUT_H #define GAME_INPUT_H + +#ifdef PLATFORM_WEB + +typedef +struct +{ + char r; + char z; +} +joypad_buttons_t; +typedef +struct +{ + char stick_x; + char stick_y; +} +joypad_inputs_t; + +#else + #include <libdragon.h> +#endif + extern joypad_buttons_t pressed_p1; extern joypad_buttons_t held_p1; extern joypad_inputs_t inputs_p1; @@ -1,25 +1,20 @@ -/******************************************************************************************* - * - * raylib [models] example - Draw textured cube - * - * Example originally created with raylib 4.5, last time updated with raylib 4.5 - * - * Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, - * BSD-like license that allows static linking with closed source software - * - * Copyright (c) 2022-2024 Ramon Santamaria (@raysan5) - * - ********************************************************************************************/ - - +#ifdef PLATFORM_WEB +#include <stdio.h> +#else #include <libdragon.h> - #include <GL/gl.h> #include <GL/glu.h> +#endif + #include <raylib.h> #include <rlgl.h> + +#ifdef PLATFORM_WEB +#include <math.h> +#else #include <fmath.h> -//#include "raylib_font_RGBA16_5551.h" +#endif + #define ATTR_NINTENDO64_WIDTH 320 #define ATTR_NINTENDO64_HEIGHT 240 bool flag=true; @@ -34,11 +29,9 @@ bool xflag=false; Camera camera = { 0 }; Camera camera2 = { 0 }; -void DrawCubeTexture(Texture2D texture, Vector3 position, float width, float height, float length, Color color); // Draw cube textured -void DrawCubeTextureRec(Texture2D texture, Rectangle source, Vector3 position, float width, float height, float length, Color color); // Draw cube with a region of a texture - - +#ifdef PLATFORM_WEB +#else bool initApp() { return true; @@ -48,10 +41,10 @@ void finishApp() } -extern Texture2D getFontGLTextureId(char *text); + Rectangle src={0.0f,0.0f,5.0f,10.0f}; Rectangle dst={0.0f,0.0f,32.0f,32.0f}; - +#endif World world = { .players = { @@ -73,54 +66,38 @@ World world = { }; -//------------------------------------------------------------------------------------ -// Program main entry point -//------------------------------------------------------------------------------------ int main(void) { - // Initialization - //-------------------------------------------------------------------------------------- const int screenWidth = ATTR_NINTENDO64_WIDTH; const int screenHeight = ATTR_NINTENDO64_HEIGHT; - InitWindow(screenWidth, screenHeight, "raylib [shapes] example - basic shapes"); + InitWindow(screenWidth, screenHeight, "CubeSpace64"); - // Define the camera to look into our 3d world camera.position = (Vector3){ 0.0f, 10.0f, 10.0f }; camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; camera.fovy = 45.0f; camera.projection = CAMERA_PERSPECTIVE; - // Define the camera to look into our 3d world camera2.position = (Vector3){ 1.0f, -10.0f, 5.0f }; camera2.target = (Vector3){ 0.0f, 0.0f, 0.0f }; camera2.up = (Vector3){ 0.0f, 1.0f, 0.0f }; camera2.fovy = 35.0f; camera2.projection = CAMERA_PERSPECTIVE; + SetTargetFPS(60); - Texture2D texture = LoadTexture("rom:/cubicmap_atlas32x32.png"); // Load map texture - //Model model = LoadModel("rom:/plane.m3d"); - - - //BoundingBox bounds = GetMeshBoundingBox(model.meshes[0]); // Set model bounds - - - - SetTargetFPS(60); // Set our game to run at 60 frames-per-second - //---------------------------------------------------------- - - // Main game loop - while (flag) // Detect window close with Start button + while (!WindowShouldClose()) { - // Update - //----------------------------------------------------- - //controller_read(&controllers); updateController(); - if(pressed_p1.r) + char p1_cam = pressed_p1.r; + char p2_cam = pressed_p2.r; + char p1_shoot = pressed_p1.z; + char p2_shoot = pressed_p2.z; + + if(p1_cam) { if(world.players[0].camera_mode == 0) { @@ -132,7 +109,7 @@ int main(void) } } - if(pressed_p2.r) + if(p2_cam) { if(world.players[1].camera_mode == 0) { @@ -144,11 +121,11 @@ int main(void) } } - if(pressed_p1.z) + if(p1_shoot) { spawn_bullet(1, world.players[0].position, world.players[0].direction); } - if(pressed_p2.z) + if(p2_shoot) { spawn_bullet(2, world.players[1].position, world.players[1].direction); } @@ -158,17 +135,9 @@ int main(void) camera = lookThroughPlayer(camera, world.players[0]); camera2 = lookThroughPlayer(camera2, world.players[1]); - // Update - //---------------------------------------------------------------------------------- - //UpdateCamera(&camera, CAMERA_ORBITAL); - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(BLACK); - BeginScissorMode(0, 0, 320/2, 240); rlViewport(0, 0, 320/2, 240); renderWorld(&world, camera); @@ -178,202 +147,23 @@ int main(void) renderWorld(&world, camera2); EndScissorMode(); rlViewport(0, 0, 320, 240); - DrawRectangle((320/2)-4, 0, 2, 240, DARKGRAY); // split screen line - // Draw cube with an applied texture - //test(); - // Draw cube with an applied texture, but only a defined rectangle piece of the texture - //DrawCubeTextureRec(texture, (Rectangle){ 0, texture.height/2, texture.width/2, texture.height/2 }, - // (Vector3){ 2.0f, 1.0f, 0.0f }, 2.0f, 2.0f, 2.0f, WHITE); - - char text[50]; - //sprintf(text, "Joystick %d,%d", inputs_p1.stick_x, inputs_p1.stick_y); - //DrawText(text, 10, 30, 12, GREEN); sprintf(text, "Player1: %d", world.players[0].points); DrawText(text, 50, 30, 12, BLUE); sprintf(text, "Player2: %d", world.players[1].points); DrawText(text, 210, 30, 12, VIOLET); - /* - DrawText("Position", 150, 30, 12, GREEN); - DrawText(text, 150, 45, 12, GREEN); - sprintf(text, "y: %f", camera.position.y); - DrawText(text, 150, 60, 12, GREEN); - sprintf(text, "z: %f", camera.position.z); - DrawText(text, 150, 75, 12, GREEN); - DrawText("Target", 220, 30, 12, GREEN); - sprintf(text, "%f", camera.target.x); - DrawText(text, 220, 45, 12, GREEN); - sprintf(text, "%f", camera.target.y); - DrawText(text, 220, 60, 12, GREEN); - sprintf(text, "%f", camera.target.z); - DrawText(text, 220, 75, 12, GREEN); - */ DrawFPS(10, 10); EndDrawing(); - - - - //----------------------------------------------------- } + CloseWindow(); - // De-Initialization - //-------------------------------------------------------------------------------------- - UnloadTexture(texture); // Unload map texture - - CloseWindow(); // Close window and OpenGL context - //---------------------------------------------------------- +#ifdef PLATFORM_WEB +#else finishApp(); +#endif return 0; } -void DrawCubeTexture(Texture2D texture, Vector3 position, float width, float height, float length, Color color) -{ - float x = position.x; - float y = position.y; - float z = position.z; - - // Set desired texture to be enabled while drawing following vertex data - rlSetTexture(texture.id); - - // Vertex data transformation can be defined with the commented lines, - // but in this example we calculate the transformed vertex data directly when calling rlVertex3f() - //rlPushMatrix(); - // NOTE: Transformation is applied in inverse order (scale -> rotate -> translate) - //rlTranslatef(2.0f, 0.0f, 0.0f); - //rlRotatef(45, 0, 1, 0); - //rlScalef(2.0f, 2.0f, 2.0f); - - rlBegin(RL_QUADS); - rlColor4ub(color.r, color.g, color.b, color.a); - // Front Face - rlNormal3f(0.0f, 0.0f, 1.0f); // Normal Pointing Towards Viewer - rlTexCoord2f(0.0f, 0.0f); rlVertex3f(x - width/2, y - height/2, z + length/2); // Bottom Left Of The Texture and Quad - rlTexCoord2f(1.0f, 0.0f); rlVertex3f(x + width/2, y - height/2, z + length/2); // Bottom Right Of The Texture and Quad - rlTexCoord2f(1.0f, 1.0f); rlVertex3f(x + width/2, y + height/2, z + length/2); // Top Right Of The Texture and Quad - rlTexCoord2f(0.0f, 1.0f); rlVertex3f(x - width/2, y + height/2, z + length/2); // Top Left Of The Texture and Quad - // Back Face - rlNormal3f(0.0f, 0.0f, - 1.0f); // Normal Pointing Away From Viewer - rlTexCoord2f(1.0f, 0.0f); rlVertex3f(x - width/2, y - height/2, z - length/2); // Bottom Right Of The Texture and Quad - rlTexCoord2f(1.0f, 1.0f); rlVertex3f(x - width/2, y + height/2, z - length/2); // Top Right Of The Texture and Quad - rlTexCoord2f(0.0f, 1.0f); rlVertex3f(x + width/2, y + height/2, z - length/2); // Top Left Of The Texture and Quad - rlTexCoord2f(0.0f, 0.0f); rlVertex3f(x + width/2, y - height/2, z - length/2); // Bottom Left Of The Texture and Quad - // Top Face - rlNormal3f(0.0f, 1.0f, 0.0f); // Normal Pointing Up - rlTexCoord2f(0.0f, 1.0f); rlVertex3f(x - width/2, y + height/2, z - length/2); // Top Left Of The Texture and Quad - rlTexCoord2f(0.0f, 0.0f); rlVertex3f(x - width/2, y + height/2, z + length/2); // Bottom Left Of The Texture and Quad - rlTexCoord2f(1.0f, 0.0f); rlVertex3f(x + width/2, y + height/2, z + length/2); // Bottom Right Of The Texture and Quad - rlTexCoord2f(1.0f, 1.0f); rlVertex3f(x + width/2, y + height/2, z - length/2); // Top Right Of The Texture and Quad - // Bottom Face - rlNormal3f(0.0f, - 1.0f, 0.0f); // Normal Pointing Down - rlTexCoord2f(1.0f, 1.0f); rlVertex3f(x - width/2, y - height/2, z - length/2); // Top Right Of The Texture and Quad - rlTexCoord2f(0.0f, 1.0f); rlVertex3f(x + width/2, y - height/2, z - length/2); // Top Left Of The Texture and Quad - rlTexCoord2f(0.0f, 0.0f); rlVertex3f(x + width/2, y - height/2, z + length/2); // Bottom Left Of The Texture and Quad - rlTexCoord2f(1.0f, 0.0f); rlVertex3f(x - width/2, y - height/2, z + length/2); // Bottom Right Of The Texture and Quad - // Right face - rlNormal3f(1.0f, 0.0f, 0.0f); // Normal Pointing Right - rlTexCoord2f(1.0f, 0.0f); rlVertex3f(x + width/2, y - height/2, z - length/2); // Bottom Right Of The Texture and Quad - rlTexCoord2f(1.0f, 1.0f); rlVertex3f(x + width/2, y + height/2, z - length/2); // Top Right Of The Texture and Quad - rlTexCoord2f(0.0f, 1.0f); rlVertex3f(x + width/2, y + height/2, z + length/2); // Top Left Of The Texture and Quad - rlTexCoord2f(0.0f, 0.0f); rlVertex3f(x + width/2, y - height/2, z + length/2); // Bottom Left Of The Texture and Quad - // Left Face - rlNormal3f( - 1.0f, 0.0f, 0.0f); // Normal Pointing Left - rlTexCoord2f(0.0f, 0.0f); rlVertex3f(x - width/2, y - height/2, z - length/2); // Bottom Left Of The Texture and Quad - rlTexCoord2f(1.0f, 0.0f); rlVertex3f(x - width/2, y - height/2, z + length/2); // Bottom Right Of The Texture and Quad - rlTexCoord2f(1.0f, 1.0f); rlVertex3f(x - width/2, y + height/2, z + length/2); // Top Right Of The Texture and Quad - rlTexCoord2f(0.0f, 1.0f); rlVertex3f(x - width/2, y + height/2, z - length/2); // Top Left Of The Texture and Quad - rlEnd(); - //rlPopMatrix(); - - rlSetTexture(0); -} - -// Draw cube with texture piece applied to all faces -void DrawCubeTextureRec(Texture2D texture, Rectangle source, Vector3 position, float width, float height, float length, Color color) -{ - float x = position.x; - float y = position.y; - float z = position.z; - float texWidth = (float)texture.width; - float texHeight = (float)texture.height; - - // Set desired texture to be enabled while drawing following vertex data - rlSetTexture(texture.id); - - // We calculate the normalized texture coordinates for the desired texture-source-rectangle - // It means converting from (tex.width, tex.height) coordinates to [0.0f, 1.0f] equivalent - rlBegin(RL_QUADS); - rlColor4ub(color.r, color.g, color.b, color.a); - - // Front face - rlNormal3f(0.0f, 0.0f, 1.0f); - rlTexCoord2f(source.x/texWidth, (source.y + source.height)/texHeight); - rlVertex3f(x - width/2, y - height/2, z + length/2); - rlTexCoord2f((source.x + source.width)/texWidth, (source.y + source.height)/texHeight); - rlVertex3f(x + width/2, y - height/2, z + length/2); - rlTexCoord2f((source.x + source.width)/texWidth, source.y/texHeight); - rlVertex3f(x + width/2, y + height/2, z + length/2); - rlTexCoord2f(source.x/texWidth, source.y/texHeight); - rlVertex3f(x - width/2, y + height/2, z + length/2); - - // Back face - rlNormal3f(0.0f, 0.0f, - 1.0f); - rlTexCoord2f((source.x + source.width)/texWidth, (source.y + source.height)/texHeight); - rlVertex3f(x - width/2, y - height/2, z - length/2); - rlTexCoord2f((source.x + source.width)/texWidth, source.y/texHeight); - rlVertex3f(x - width/2, y + height/2, z - length/2); - rlTexCoord2f(source.x/texWidth, source.y/texHeight); - rlVertex3f(x + width/2, y + height/2, z - length/2); - rlTexCoord2f(source.x/texWidth, (source.y + source.height)/texHeight); - rlVertex3f(x + width/2, y - height/2, z - length/2); - - // Top face - rlNormal3f(0.0f, 1.0f, 0.0f); - rlTexCoord2f(source.x/texWidth, source.y/texHeight); - rlVertex3f(x - width/2, y + height/2, z - length/2); - rlTexCoord2f(source.x/texWidth, (source.y + source.height)/texHeight); - rlVertex3f(x - width/2, y + height/2, z + length/2); - rlTexCoord2f((source.x + source.width)/texWidth, (source.y + source.height)/texHeight); - rlVertex3f(x + width/2, y + height/2, z + length/2); - rlTexCoord2f((source.x + source.width)/texWidth, source.y/texHeight); - rlVertex3f(x + width/2, y + height/2, z - length/2); - - // Bottom face - rlNormal3f(0.0f, - 1.0f, 0.0f); - rlTexCoord2f((source.x + source.width)/texWidth, source.y/texHeight); - rlVertex3f(x - width/2, y - height/2, z - length/2); - rlTexCoord2f(source.x/texWidth, source.y/texHeight); - rlVertex3f(x + width/2, y - height/2, z - length/2); - rlTexCoord2f(source.x/texWidth, (source.y + source.height)/texHeight); - rlVertex3f(x + width/2, y - height/2, z + length/2); - rlTexCoord2f((source.x + source.width)/texWidth, (source.y + source.height)/texHeight); - rlVertex3f(x - width/2, y - height/2, z + length/2); - - // Right face - rlNormal3f(1.0f, 0.0f, 0.0f); - rlTexCoord2f((source.x + source.width)/texWidth, (source.y + source.height)/texHeight); - rlVertex3f(x + width/2, y - height/2, z - length/2); - rlTexCoord2f((source.x + source.width)/texWidth, source.y/texHeight); - rlVertex3f(x + width/2, y + height/2, z - length/2); - rlTexCoord2f(source.x/texWidth, source.y/texHeight); - rlVertex3f(x + width/2, y + height/2, z + length/2); - rlTexCoord2f(source.x/texWidth, (source.y + source.height)/texHeight); - rlVertex3f(x + width/2, y - height/2, z + length/2); - - // Left face - rlNormal3f( - 1.0f, 0.0f, 0.0f); - rlTexCoord2f(source.x/texWidth, (source.y + source.height)/texHeight); - rlVertex3f(x - width/2, y - height/2, z - length/2); - rlTexCoord2f((source.x + source.width)/texWidth, (source.y + source.height)/texHeight); - rlVertex3f(x - width/2, y - height/2, z + length/2); - rlTexCoord2f((source.x + source.width)/texWidth, source.y/texHeight); - rlVertex3f(x - width/2, y + height/2, z + length/2); - rlTexCoord2f(source.x/texWidth, source.y/texHeight); - rlVertex3f(x - width/2, y + height/2, z - length/2); - - rlEnd(); - - rlSetTexture(0); -} diff --git a/src/player.c b/src/player.c index 4e02b78..fd7c7b5 100644 --- a/src/player.c +++ b/src/player.c @@ -1,13 +1,20 @@ #include "player.h" #include "world.h" +#ifdef PLATFORM_WEB + +#include <math.h> + +#else + #include <fmath.h> + +#endif + #include "raymath.h" void drawPlayer(Player *player) { - //DrawCube(player->position, 1.0f, 1.0f, 1.0f, BLUE); - //DrawSphereEx(player->position, 0.5f, 3, 3, player->color); DrawCube(player->position, 0.5f, 0.5f, 0.5f, player->color); } @@ -31,7 +38,6 @@ lookThroughPlayer(Camera camera, Player player) } else if(player.camera_mode == 1) { - //camera.position = player.position; camera.position.x = player.position.x - (player.direction.x * 2); camera.position.y = player.position.y - (player.direction.y * 2); camera.position.z = player.position.z - (player.direction.z * 2) + player.camera_mode; @@ -40,10 +46,6 @@ lookThroughPlayer(Camera camera, Player player) camera.target.z = player.position.z; } camera.up = (Vector3){ 0.0f, 0.0f, 1.0f }; - //camera.target = player2.position; - //camera.target = (Vector3){ - // 0, 0, 0 - //}; camera.fovy = 90.0f; camera.projection = CAMERA_PERSPECTIVE; return camera; diff --git a/src/render.c b/src/render.c index b6efa34..1501814 100644 --- a/src/render.c +++ b/src/render.c @@ -2,6 +2,8 @@ #include "rlgl.h" #include "bullet.h" +void customBeginMode3D(Camera camera); + void drawLine(Vector3 start, Vector3 end, float width, int up, Color color) { @@ -115,37 +117,12 @@ drawGrid(Vector3 position, int lines, int size, Color color) void renderWorld(World* world, Camera camera) { - //Vector3 lookat = camera.target; - //camera.target = (Vector3){0}; - //camera.position.x -= lookat.x; - //camera.position.y -= lookat.y; - //camera.position.z -= lookat.z; customBeginMode3D(camera); - //rlPushMatrix(); - //rlTranslatef( - // -lookat.x, - // -lookat.y, - // -lookat.z - // ); drawPlayer(&world->players[0]); drawPlayer(&world->players[1]); render_bullets(); - //drawGrid((Vector3){0}, 10, 1); - - for(int i = -3; i <= 3; ++i){ - //DrawCube((Vector3){i,3,3}, 0.5f, 0.5f, 0.5f, YELLOW); - //DrawCube((Vector3){i,4,3}, 0.5f, 0.5f, 0.5f, DARKPURPLE); - //DrawCube((Vector3){i,5,3}, 0.5f, 0.5f, 0.5f, YELLOW); - //DrawCube((Vector3){i,3,4}, 0.5f, 0.5f, 0.5f, MAGENTA); - //DrawCube((Vector3){i,4,4}, 0.5f, 0.5f, 0.5f, GREEN); - //DrawCube((Vector3){i,5,4}, 0.5f, 0.5f, 0.5f, MAGENTA); - //DrawLineEx((Vector2){i, 3},(Vector2){i, -3}, 5, BLACK); - //DrawLineEx((Vector2){3, i},(Vector2){-3, i}, 5, BLACK); - } - //drawLine((Vector3){0}, (Vector3){10,0,0}, 2.0f, 2, BLACK); - int space = 3; rlPushMatrix(); @@ -171,8 +148,5 @@ renderWorld(World* world, Camera camera) drawGrid((Vector3){0}, 5, 1, ORANGE); rlPopMatrix(); - - - //rlPopMatrix(); EndMode3D(); } |
