summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/input.c85
-rw-r--r--src/input.h12
-rw-r--r--src/main.c472
-rw-r--r--src/player.c4
-rw-r--r--src/player.h8
-rw-r--r--src/render.c11
-rw-r--r--src/render.h12
-rw-r--r--src/second.c17
-rw-r--r--src/second.h1
-rw-r--r--src/world.h13
10 files changed, 390 insertions, 245 deletions
diff --git a/src/input.c b/src/input.c
new file mode 100644
index 0000000..6ac092f
--- /dev/null
+++ b/src/input.c
@@ -0,0 +1,85 @@
+#include "input.h"
+
+joypad_buttons_t pressed_p1;
+joypad_buttons_t held_p1;
+joypad_inputs_t inputs_p1;
+
+void updateController()
+{
+ joypad_poll();
+ pressed_p1 = joypad_get_buttons_pressed(JOYPAD_PORT_1);
+ held_p1 = joypad_get_buttons_held(JOYPAD_PORT_1);
+ inputs_p1 = joypad_get_inputs(JOYPAD_PORT_1);
+
+
+ float x = inputs_p1.stick_x;
+ float y = inputs_p1.stick_y;
+
+ if(x > 60)
+ {
+ x = 60.0f;
+ }
+ else if(x < -60)
+ {
+ x = -60.0f;
+ }
+ else if((x > -5) && (x < 5))
+ {
+ x = 0.0f;
+ }
+
+ if(y > 60)
+ {
+ y = 60;
+ }
+ else if(y < -60)
+ {
+ y = -60;
+ }
+ else if((y > -5) && (y < 5))
+ {
+ y = 0;
+ }
+
+ if(x > 0)
+ {
+ x -= 5;
+ }
+ else if(x < 0)
+ {
+ x += 5;
+ }
+
+ if(y > 0)
+ {
+ y -= 5;
+ }
+ else if(y < 0)
+ {
+ 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;
+
+}
diff --git a/src/input.h b/src/input.h
new file mode 100644
index 0000000..5fa4d1a
--- /dev/null
+++ b/src/input.h
@@ -0,0 +1,12 @@
+#ifndef GAME_INPUT_H
+#define GAME_INPUT_H
+
+#include <libdragon.h>
+
+extern joypad_buttons_t pressed_p1;
+extern joypad_buttons_t held_p1;
+extern joypad_inputs_t inputs_p1;
+
+void updateController(void);
+
+#endif
diff --git a/src/main.c b/src/main.c
index ccde73d..3a93df2 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,15 +1,15 @@
/*******************************************************************************************
-*
-* 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)
-*
-********************************************************************************************/
+ *
+ * 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)
+ *
+ ********************************************************************************************/
#include <libdragon.h>
@@ -18,281 +18,303 @@
#include <GL/glu.h>
#include <raylib.h>
#include <rlgl.h>
+#include <fmath.h>
//#include "raylib_font_RGBA16_5551.h"
#define ATTR_NINTENDO64_WIDTH 320
#define ATTR_NINTENDO64_HEIGHT 240
bool flag=true;
bool xflag=false;
-#include "second.h"
#include "player.h"
+#include "input.h"
+#include "render.h"
+#include "world.h"
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
-void updateController()
-{
-
-}
+
bool initApp()
{
- return true;
+ return true;
}
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};
-Player player_one = {
- .position = { 0 },
- .direction = { 1, 0, 0 },
- .speed = 1.0f/60.0f
+
+World world = {
+ .players = {
+ {
+ .position = { 0 },
+ .direction = { 1, 0, 0 },
+ .speed = 1.0f/60.0f,
+ .color = BLUE,
+ },
+ {
+ .position = { 1, 1, 1 },
+ .direction = { 1, 0, 0 },
+ .speed = 1.0f/60.0f,
+ .color = RED,
+ }
+ }
};
-struct controller_data controllers;
//------------------------------------------------------------------------------------
// Program main entry point
//------------------------------------------------------------------------------------
int main(void)
{
- // Initialization
- //--------------------------------------------------------------------------------------
- const int screenWidth = ATTR_NINTENDO64_WIDTH;
- const int screenHeight = ATTR_NINTENDO64_HEIGHT;
-
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ const int screenWidth = ATTR_NINTENDO64_WIDTH;
+ const int screenHeight = ATTR_NINTENDO64_HEIGHT;
+
+
+ InitWindow(screenWidth, screenHeight, "raylib [shapes] example - basic shapes");
+
+ // 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;
- InitWindow(screenWidth, screenHeight, "raylib [shapes] example - basic shapes");
-
+ // 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;
- // 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;
- controller_init();
+ Texture2D texture = LoadTexture("rom:/cubicmap_atlas32x32.png"); // Load map texture
+ //Model model = LoadModel("rom:/plane.m3d");
- Texture2D texture = LoadTexture("rom:/cubicmap_atlas32x32.png"); // Load map texture
- //Model model = LoadModel("rom:/plane.m3d");
+ Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
- Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
+ //BoundingBox bounds = GetMeshBoundingBox(model.meshes[0]); // Set model bounds
- //BoundingBox bounds = GetMeshBoundingBox(model.meshes[0]); // Set model bounds
-
- SetTargetFPS(60); // Set our game to run at 60 frames-per-second
- //----------------------------------------------------------
+ SetTargetFPS(60); // Set our game to run at 60 frames-per-second
+ //----------------------------------------------------------
- // Main game loop
- while (flag) // Detect window close with Start button
- {
- // Update
- //-----------------------------------------------------
- updateController();
- controller_read(&controllers);
+ // Main game loop
+ while (flag) // Detect window close with Start button
+ {
+ // Update
+ //-----------------------------------------------------
+ //controller_read(&controllers);
- movePlayer(&player_one);
+ movePlayer(&(world.players[0]));
- // Update
- //----------------------------------------------------------------------------------
- //UpdateCamera(&camera, CAMERA_ORBITAL);
- //----------------------------------------------------------------------------------
+ // Update
+ //----------------------------------------------------------------------------------
+ //UpdateCamera(&camera, CAMERA_ORBITAL);
+ //----------------------------------------------------------------------------------
- // Draw
- //----------------------------------------------------------------------------------
- BeginDrawing();
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
- ClearBackground(DARKGRAY);
+ ClearBackground(DARKGRAY);
- BeginMode3D(camera);
+ BeginScissorMode(320/2, 0, 320/2, 240);
+ rlViewport(320/2, 0, 320/2, 240);
+ renderWorld(&world, &camera);
+ EndScissorMode();
+ BeginScissorMode(0, 0, 320/2, 240);
+ rlViewport(0, 0, 320/2, 240);
+ renderWorld(&world, &camera2);
+ EndScissorMode();
+ rlViewport(0, 0, 320, 240);
- drawPlayer(&player_one);
+ // 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);
+
+ updateController();
- // 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[500];
+ sprintf(text, "Joystick %d,%d", inputs_p1.stick_x, inputs_p1.stick_y);
+ DrawText(text, 10, 30, 12, GREEN);
+ DrawFPS(10, 10);
- DrawGrid(10, 1.0f); // Draw a grid
+ EndDrawing();
- EndMode3D();
- DrawFPS(10, 10);
+ //-----------------------------------------------------
+ }
- EndDrawing();
-
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ UnloadTexture(texture); // Unload map texture
-
- //-----------------------------------------------------
- }
+ CloseWindow(); // Close window and OpenGL context
+ //----------------------------------------------------------
- // De-Initialization
- //--------------------------------------------------------------------------------------
- UnloadTexture(texture); // Unload map texture
-
- CloseWindow(); // Close window and OpenGL context
- //----------------------------------------------------------
-
- finishApp();
- return 0;
+ finishApp();
+ 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);
+ 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);
+ 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 aca5a80..f2b5a8e 100644
--- a/src/player.c
+++ b/src/player.c
@@ -4,12 +4,14 @@ void
drawPlayer(Player *player)
{
//DrawCube(player->position, 1.0f, 1.0f, 1.0f, BLUE);
- DrawSphereEx(player->position, 0.5f, 3, 3, BLUE);
+ DrawSphereEx(player->position, 0.5f, 3, 3, player->color);
}
void
movePlayer(Player *player)
{
+ player->direction.x = inputs_p1.stick_x / 126.0f;
+ player->direction.z = -inputs_p1.stick_y / 126.0f;
player->position.x += player->direction.x * player->speed;
player->position.y += player->direction.y * player->speed;
player->position.z += player->direction.z * player->speed;
diff --git a/src/player.h b/src/player.h
index e6d8f66..68b5910 100644
--- a/src/player.h
+++ b/src/player.h
@@ -1,4 +1,8 @@
+#ifndef GAME_PLAYER_H
+#define GAME_PLAYER_H
+
#include "raylib.h"
+#include "input.h"
typedef
struct
@@ -6,7 +10,7 @@ struct
Vector3 position;
Vector3 direction;
float speed;
-
+ Color color;
}
Player;
@@ -15,3 +19,5 @@ drawPlayer(Player *player);
void
movePlayer(Player *player);
+
+#endif
diff --git a/src/render.c b/src/render.c
new file mode 100644
index 0000000..a0bfa8e
--- /dev/null
+++ b/src/render.c
@@ -0,0 +1,11 @@
+#include "render.h"
+
+void
+renderWorld(World* world, Camera* camera)
+{
+ customBeginMode3D(*camera);
+ DrawGrid(100, 1);
+ drawPlayer(&world->players[0]);
+ drawPlayer(&world->players[1]);
+ EndMode3D();
+}
diff --git a/src/render.h b/src/render.h
new file mode 100644
index 0000000..7a16c83
--- /dev/null
+++ b/src/render.h
@@ -0,0 +1,12 @@
+#ifndef GAME_RENDER_H
+#define GAME_RENDER_H
+
+#include "raylib.h"
+#include "rlgl.h"
+#include "world.h"
+
+void
+renderWorld(World* world, Camera* camera);
+
+#endif
+
diff --git a/src/second.c b/src/second.c
deleted file mode 100644
index d63296e..0000000
--- a/src/second.c
+++ /dev/null
@@ -1,17 +0,0 @@
-
-#include <stdio.h>
-#include "second.h"
-#include <raylib.h>
-
-void test(void)
-{
- //TraceLog(3, "Test Worked\n");
- for(float i = -2; i <= 2; ++i)
- {
- for(float j = -2; j <= 2; ++j)
- {
- //DrawCubeTexture(texture, (Vector3){ i, 0.0f, j }, 1.0f, 1.0f, 1.0f, WHITE);
- DrawCube((Vector3){ i, 0.0f, j }, 0.5f, 0.5f, 0.5f, RED);
- }
- }
-}
diff --git a/src/second.h b/src/second.h
deleted file mode 100644
index c0f76b7..0000000
--- a/src/second.h
+++ /dev/null
@@ -1 +0,0 @@
-void test(void);
diff --git a/src/world.h b/src/world.h
new file mode 100644
index 0000000..9f18137
--- /dev/null
+++ b/src/world.h
@@ -0,0 +1,13 @@
+#ifndef GAME_WORLD_H
+#define GAME_WORLD_H
+
+#include "player.h"
+
+typedef
+struct
+{
+ Player players[2];
+}
+World;
+
+#endif