summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2024-05-11 22:40:22 -0400
committerrealtradam <[email protected]>2024-05-11 22:40:22 -0400
commit963ca487e39dc6f5fa28ea230610d140bf1583fb (patch)
tree8f208c6b152b68ae75c9df7b59ccaee9e6105445
parent8855c3de33c487e09b6a8fd474b0dd351ab3581c (diff)
downloadtojam2024-963ca487e39dc6f5fa28ea230610d140bf1583fb.tar.gz
tojam2024-963ca487e39dc6f5fa28ea230610d140bf1583fb.zip
attempt at first person camera
-rw-r--r--src/input.c56
-rw-r--r--src/input.h4
-rw-r--r--src/main.c4
-rw-r--r--src/player.c56
-rw-r--r--src/player.h5
-rw-r--r--src/world.h2
6 files changed, 115 insertions, 12 deletions
diff --git a/src/input.c b/src/input.c
index 6ac092f..5a43ae5 100644
--- a/src/input.c
+++ b/src/input.c
@@ -4,12 +4,19 @@ joypad_buttons_t pressed_p1;
joypad_buttons_t held_p1;
joypad_inputs_t inputs_p1;
+joypad_buttons_t pressed_p2;
+joypad_buttons_t held_p2;
+joypad_inputs_t inputs_p2;
+
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);
+ 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);
float x = inputs_p1.stick_x;
@@ -82,4 +89,53 @@ void updateController()
inputs_p1.stick_x = x / 55.0f * 127.0f;
inputs_p1.stick_y = y / 55.0f * 127.0f;
+ x = inputs_p2.stick_x;
+ y = inputs_p2.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;
+ }
+
+ 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 5fa4d1a..a65c4a3 100644
--- a/src/input.h
+++ b/src/input.h
@@ -7,6 +7,10 @@ extern joypad_buttons_t pressed_p1;
extern joypad_buttons_t held_p1;
extern joypad_inputs_t inputs_p1;
+extern joypad_buttons_t pressed_p2;
+extern joypad_buttons_t held_p2;
+extern joypad_inputs_t inputs_p2;
+
void updateController(void);
#endif
diff --git a/src/main.c b/src/main.c
index 3a93df2..3f26d88 100644
--- a/src/main.c
+++ b/src/main.c
@@ -101,7 +101,6 @@ int main(void)
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
//BoundingBox bounds = GetMeshBoundingBox(model.meshes[0]); // Set model bounds
@@ -117,7 +116,8 @@ int main(void)
//-----------------------------------------------------
//controller_read(&controllers);
- movePlayer(&(world.players[0]));
+ movePlayers();
+ //camera = lookThroughPlayer(camera, world.players[0], world.players[1]);
// Update
//----------------------------------------------------------------------------------
diff --git a/src/player.c b/src/player.c
index f2b5a8e..4616fbd 100644
--- a/src/player.c
+++ b/src/player.c
@@ -1,18 +1,56 @@
#include "player.h"
+#include "world.h"
+#include <fmath.h>
-void
+ void
drawPlayer(Player *player)
{
//DrawCube(player->position, 1.0f, 1.0f, 1.0f, BLUE);
- DrawSphereEx(player->position, 0.5f, 3, 3, player->color);
+ //DrawSphereEx(player->position, 0.5f, 3, 3, player->color);
+ DrawCube(player->position, 0.5f, 0.5f, 0.5f, player->color);
}
-void
-movePlayer(Player *player)
+Camera
+lookThroughPlayer(Camera camera, Player player, Player player2)
{
- 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;
+ camera.position = player.position;
+ //camera.target.x = player.position.x + player.direction.x;
+ //camera.target.y = player.position.y + player.direction.y;
+ //camera.target.z = player.position.z + player.direction.z;
+ //camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
+ //camera.target = player2.position;
+ //camera.target = (Vector3){
+ // 0, 0, 0
+ //};
+ camera.fovy = 45.0f;
+ camera.projection = CAMERA_PERSPECTIVE;
+ return camera;
+}
+
+ void
+movePlayers(void)
+{
+ float x = inputs_p1.stick_x / 126.0f;
+ float y = -inputs_p1.stick_y / 126.0f;
+
+ //float x = world.players[0].direction.x;
+ //float y = world.players[0].direction.z;
+
+ float distance = sqrtf(x * x + y * y);
+
+ if(distance != 0)
+ {
+ world.players[0].direction.x = x / distance;
+ world.players[0].direction.y = -y / distance;
+ }
+
+ world.players[1].direction.x = inputs_p2.stick_x / 126.0f;
+ world.players[1].direction.z = -inputs_p2.stick_y / 126.0f;
+
+ world.players[0].position.x += world.players[0].direction.x * world.players[0].speed;
+ world.players[0].position.y += world.players[0].direction.y * world.players[0].speed;
+ world.players[0].position.z += world.players[0].direction.z * world.players[0].speed;
+ world.players[1].position.x += world.players[1].direction.x * world.players[1].speed;
+ world.players[1].position.y += world.players[1].direction.y * world.players[1].speed;
+ world.players[1].position.z += world.players[1].direction.z * world.players[1].speed;
}
diff --git a/src/player.h b/src/player.h
index 68b5910..eca7579 100644
--- a/src/player.h
+++ b/src/player.h
@@ -14,10 +14,13 @@ struct
}
Player;
+Camera
+lookThroughPlayer(Camera camera, Player player, Player player2);
+
void
drawPlayer(Player *player);
void
-movePlayer(Player *player);
+movePlayers(void);
#endif
diff --git a/src/world.h b/src/world.h
index 9f18137..3a54c59 100644
--- a/src/world.h
+++ b/src/world.h
@@ -10,4 +10,6 @@ struct
}
World;
+extern World world;
+
#endif