diff options
Diffstat (limited to 'src/main.c')
| -rw-r--r-- | src/main.c | 272 |
1 files changed, 31 insertions, 241 deletions
@@ -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); -} |
