comments, clang-format and screensize
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
BasedOnStyle: LLVM
|
||||
IndentWidth: 4
|
||||
ColumnLimit: 120
|
||||
BreakBeforeBraces: Allman
|
||||
@@ -1,6 +1,11 @@
|
||||
all: build/game
|
||||
|
||||
build/game: src/*
|
||||
mkdir -p build
|
||||
gcc -o build/game src/* \
|
||||
-I./raylib-6.0_linux_amd64/include \
|
||||
-L./raylib-6.0_linux_amd64/lib \
|
||||
-l:libraylib.a -lm -lX11
|
||||
|
||||
format:
|
||||
find src/ -type f | xargs clang-format -i
|
||||
|
||||
+5
-2
@@ -2,6 +2,7 @@
|
||||
|
||||
void MyDrawCube(Cube *cube)
|
||||
{
|
||||
// Gravity
|
||||
if (!cube->grabbed && cube->position.y > cube->edge / 2.0f)
|
||||
{
|
||||
float delta = GetFrameTime();
|
||||
@@ -14,6 +15,8 @@ void MyDrawCube(Cube *cube)
|
||||
}
|
||||
}
|
||||
|
||||
DrawModelEx(cube->model, cube->position, (Vector3){ 0.0f, 1.0f, 0.0f }, cube->hRotation, (Vector3){ 1.0f, 1.0f, 1.0f }, cube->color);
|
||||
DrawModelWiresEx(cube->model, cube->position, (Vector3){ 0.0f, 1.0f, 0.0f }, cube->hRotation, (Vector3){ 1.0f, 1.0f, 1.0f }, cube->wiresColor);
|
||||
DrawModelEx(cube->model, cube->position, (Vector3){0.0f, 1.0f, 0.0f}, cube->hRotation, (Vector3){1.0f, 1.0f, 1.0f},
|
||||
cube->color);
|
||||
DrawModelWiresEx(cube->model, cube->position, (Vector3){0.0f, 1.0f, 0.0f}, cube->hRotation,
|
||||
(Vector3){1.0f, 1.0f, 1.0f}, cube->wiresColor);
|
||||
}
|
||||
|
||||
+2
-1
@@ -3,7 +3,8 @@
|
||||
|
||||
#include "raylib.h"
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
bool initialized;
|
||||
Model model;
|
||||
Vector3 position;
|
||||
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include "raylib.h"
|
||||
#include "cube.h"
|
||||
#include "player.h"
|
||||
#include "raylib.h"
|
||||
#include "screen.h"
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
|
||||
Cube cube = {
|
||||
.initialized = false,
|
||||
|
||||
+9
-6
@@ -1,8 +1,8 @@
|
||||
#include <stddef.h>
|
||||
#include "player.h"
|
||||
#include "raylib.h"
|
||||
#include "raymath.h"
|
||||
#include "screen.h"
|
||||
#include "player.h"
|
||||
#include <stddef.h>
|
||||
|
||||
extern Vector2 lookRotation;
|
||||
extern Vector2 lean;
|
||||
@@ -15,7 +15,7 @@ static Color colors[MAX_COLUMNS] = {0};
|
||||
|
||||
int main()
|
||||
{
|
||||
InitWindow(800, 600, "Super cool game");
|
||||
InitWindow(1600, 900, "Super cool game");
|
||||
|
||||
Player player = {0};
|
||||
Camera *camera = &player.camera;
|
||||
@@ -39,7 +39,8 @@ int main()
|
||||
DisableCursor();
|
||||
SetTargetFPS(GAME_FPS);
|
||||
|
||||
while (!WindowShouldClose()) {
|
||||
while (!WindowShouldClose())
|
||||
{
|
||||
Vector2 mouseDelta = GetMouseDelta();
|
||||
lookRotation.x -= mouseDelta.x * sensitivity.x;
|
||||
lookRotation.y += mouseDelta.y * sensitivity.y;
|
||||
@@ -58,12 +59,14 @@ int main()
|
||||
body->position.z,
|
||||
};
|
||||
|
||||
if (body->grounded && ((forward != 0) || (sideway != 0))) {
|
||||
if (body->grounded && ((forward != 0) || (sideway != 0)))
|
||||
{
|
||||
headTimer += delta * 3.0f;
|
||||
walkLerp = Lerp(walkLerp, 1.0f, 10.0f * delta);
|
||||
camera->fovy = Lerp(camera->fovy, 55.0f, 5.0f * delta);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
walkLerp = Lerp(walkLerp, 0.0f, 10.0f * delta);
|
||||
camera->fovy = Lerp(camera->fovy, 60.0f, 5.0f * delta);
|
||||
}
|
||||
|
||||
+23
-12
@@ -1,14 +1,13 @@
|
||||
#include <stddef.h>
|
||||
#include "player.h"
|
||||
#include "raylib.h"
|
||||
#include "raymath.h"
|
||||
#include "player.h"
|
||||
#include <stddef.h>
|
||||
|
||||
Vector2 lookRotation = {0};
|
||||
Vector2 lean = {0};
|
||||
float headTimer = 0.0f;
|
||||
float walkLerp = 0.0f;
|
||||
|
||||
|
||||
void UpdateFpsCamera(Player *player)
|
||||
{
|
||||
Camera *camera = &player->camera;
|
||||
@@ -20,7 +19,10 @@ void UpdateFpsCamera(Player *player)
|
||||
|
||||
float maxAngleUp = Vector3Angle(up, yaw);
|
||||
maxAngleUp -= 0.001f;
|
||||
if ( -(lookRotation.y) > maxAngleUp) { lookRotation.y = -maxAngleUp; }
|
||||
if (-(lookRotation.y) > maxAngleUp)
|
||||
{
|
||||
lookRotation.y = -maxAngleUp;
|
||||
}
|
||||
|
||||
Vector3 right = Vector3Normalize(Vector3CrossProduct(yaw, up));
|
||||
|
||||
@@ -43,17 +45,19 @@ void UpdateFpsCamera(Player *player)
|
||||
|
||||
if (player->grab)
|
||||
{
|
||||
// Move cube where your camera looks
|
||||
Vector3 forward = Vector3Subtract(camera->target, camera->position);
|
||||
forward = Vector3Normalize(forward);
|
||||
Vector3 cubePosition = Vector3Add(camera->target, forward);
|
||||
player->grab->position = cubePosition;
|
||||
|
||||
// Don't let putting grab under the floor
|
||||
if (player->grab->position.y <= player->grab->edge / 2.0f)
|
||||
{
|
||||
player->grab->position.y = player->grab->edge / 2.0f;
|
||||
}
|
||||
player->grab->hRotation = lookRotation.x * RAD2DEG;
|
||||
player->grab->hRotation = lookRotation.x * RAD2DEG; // Rottate cube to be perpendicular to camera
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void UpdateBody(Player *player, float rot, char side, char forward, bool jumpPressed, bool crouchHold)
|
||||
@@ -64,12 +68,14 @@ void UpdateBody(Player *player, float rot, char side, char forward, bool jumpPre
|
||||
|
||||
// Slow down diagonal movement
|
||||
#if defined(NORMALIZE_INPUT)
|
||||
if ((side != 0) && (forward != 0)) input = Vector2Normalize(input);
|
||||
if ((side != 0) && (forward != 0))
|
||||
input = Vector2Normalize(input);
|
||||
#endif
|
||||
|
||||
float delta = GetFrameTime();
|
||||
|
||||
if (!body->grounded) body->velocity.y -= GRAVITY*delta;
|
||||
if (!body->grounded)
|
||||
body->velocity.y -= GRAVITY * delta;
|
||||
|
||||
if (body->grounded && jumpPressed)
|
||||
{
|
||||
@@ -84,14 +90,19 @@ void UpdateBody(Player *player, float rot, char side, char forward, bool jumpPre
|
||||
Vector3 front = (Vector3){sinf(rot), 0.f, cosf(rot)};
|
||||
Vector3 right = (Vector3){cosf(-rot), 0.f, sinf(-rot)};
|
||||
|
||||
Vector3 desiredDir = (Vector3){ input.x*right.x + input.y*front.x, 0.0f, input.x*right.z + input.y*front.z, };
|
||||
Vector3 desiredDir = (Vector3){
|
||||
input.x * right.x + input.y * front.x,
|
||||
0.0f,
|
||||
input.x * right.z + input.y * front.z,
|
||||
};
|
||||
body->dir = Vector3Lerp(body->dir, desiredDir, CONTROL * delta);
|
||||
|
||||
float decel = (body->grounded ? FRICTION : AIR_DRAG);
|
||||
Vector3 hvel = (Vector3){body->velocity.x * decel, 0.0f, body->velocity.z * decel};
|
||||
|
||||
float hvelLength = Vector3Length(hvel); // Magnitude
|
||||
if (hvelLength < (MAX_SPEED*0.01f)) hvel = (Vector3){ 0 };
|
||||
if (hvelLength < (MAX_SPEED * 0.01f))
|
||||
hvel = (Vector3){0};
|
||||
|
||||
// This is what creates strafing
|
||||
float speed = Vector3DotProduct(hvel, body->dir);
|
||||
@@ -112,6 +123,7 @@ void UpdateBody(Player *player, float rot, char side, char forward, bool jumpPre
|
||||
body->position.y += diffy;
|
||||
body->position.z += diffz;
|
||||
|
||||
// Move grab with the player
|
||||
if (player->grab)
|
||||
{
|
||||
Cube *cube = player->grab;
|
||||
@@ -150,8 +162,7 @@ void UpdateGrab(Player *player, Cube *cube)
|
||||
float halfEdge = cube->edge / 2;
|
||||
BoundingBox cubeBox = {
|
||||
(Vector3){cube->position.x - halfEdge, cube->position.y - halfEdge, cube->position.z - halfEdge},
|
||||
(Vector3){ cube->position.x + halfEdge, cube->position.y + halfEdge, cube->position.z + halfEdge }
|
||||
};
|
||||
(Vector3){cube->position.x + halfEdge, cube->position.y + halfEdge, cube->position.z + halfEdge}};
|
||||
|
||||
Vector2 screenCenter = {(float)GetScreenWidth() / 2.0f, (float)GetScreenHeight() / 2.0f};
|
||||
Ray lookRay = GetScreenToWorldRay(screenCenter, player->camera);
|
||||
|
||||
+6
-4
@@ -1,9 +1,9 @@
|
||||
#ifndef PLAYER_H
|
||||
#define PLAYER_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "raylib.h"
|
||||
#include "cube.h"
|
||||
#include "raylib.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
#define GRAVITY 32.0f
|
||||
#define MAX_SPEED 20.0f
|
||||
@@ -17,14 +17,16 @@
|
||||
#define CROUCH_HEIGHT 0.4f
|
||||
#define STAND_HEIGHT 1.0f
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
Vector3 position;
|
||||
Vector3 velocity;
|
||||
Vector3 dir;
|
||||
bool grounded;
|
||||
} Body;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
Body body;
|
||||
Camera camera;
|
||||
Cube *grab;
|
||||
|
||||
Reference in New Issue
Block a user