acorn is now collectable
This commit is contained in:
37
main.c
37
main.c
@@ -97,6 +97,7 @@ typedef struct
|
|||||||
enum game_state state;
|
enum game_state state;
|
||||||
int shouldExit;
|
int shouldExit;
|
||||||
Player player;
|
Player player;
|
||||||
|
int nearAcorn;
|
||||||
} Master;
|
} Master;
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
@@ -122,6 +123,8 @@ static float ModelLengthZUnits(Model m);
|
|||||||
static void DrawPerimeter(Model wall, float border, float scale);
|
static void DrawPerimeter(Model wall, float border, float scale);
|
||||||
static void CollidePerimeter(Master* g, Model wall, float border, float scale); // optional
|
static void CollidePerimeter(Master* g, Model wall, float border, float scale); // optional
|
||||||
|
|
||||||
|
float square(float num);
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Program main entry point
|
// Program main entry point
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
@@ -151,6 +154,7 @@ int main(void)
|
|||||||
g.index = 0;
|
g.index = 0;
|
||||||
g.state = STATE_MENU;
|
g.state = STATE_MENU;
|
||||||
g.shouldExit = 0;
|
g.shouldExit = 0;
|
||||||
|
g.nearAcorn = 0;
|
||||||
|
|
||||||
//Define player values
|
//Define player values
|
||||||
g.player.sensitivity = (Vector2){ 0.001f, 0.001f };
|
g.player.sensitivity = (Vector2){ 0.001f, 0.001f };
|
||||||
@@ -184,7 +188,7 @@ int main(void)
|
|||||||
float wall_roll = 0.0f; // rotate around Z
|
float wall_roll = 0.0f; // rotate around Z
|
||||||
|
|
||||||
Model acorn = LoadModel("resources/3d_models/my_models/my_acorn.glb");
|
Model acorn = LoadModel("resources/3d_models/my_models/my_acorn.glb");
|
||||||
Vector3 acorn_position = { 0.0f, 0.0f, 0.0f };
|
Vector3 acorn_position = { 0.0f, 0.0f, -9.0f };
|
||||||
float acorn_yaw = 0.0f; // rotate around Y
|
float acorn_yaw = 0.0f; // rotate around Y
|
||||||
float acorn_pitch = 0.0f; // rotate around X
|
float acorn_pitch = 0.0f; // rotate around X
|
||||||
float acorn_roll = 0.0f; // rotate around Z
|
float acorn_roll = 0.0f; // rotate around Z
|
||||||
@@ -382,6 +386,22 @@ int main(void)
|
|||||||
// Collide player vs wall (XZ slide)
|
// Collide player vs wall (XZ slide)
|
||||||
ResolveAgainstBoxXZ(&g, acornBox);
|
ResolveAgainstBoxXZ(&g, acornBox);
|
||||||
|
|
||||||
|
int player_acorn_diff = square(g.player.position.x - acorn_position.x) + square(g.player.position.z - acorn_position.z);
|
||||||
|
|
||||||
|
if (player_acorn_diff <= 3)
|
||||||
|
{
|
||||||
|
g.nearAcorn = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g.nearAcorn = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g.nearAcorn == 1 && IsKeyPressed(KEY_E))
|
||||||
|
{
|
||||||
|
acorn_position.x = 15;
|
||||||
|
acorn_position.z = 15;
|
||||||
|
}
|
||||||
|
|
||||||
// put near your update logic
|
// put near your update logic
|
||||||
float B = 122;
|
float B = 122;
|
||||||
@@ -537,10 +557,17 @@ int main(void)
|
|||||||
DrawText("- Look around: arrow keys or mouse", 15, 45, 20, BLACK);
|
DrawText("- Look around: arrow keys or mouse", 15, 45, 20, BLACK);
|
||||||
DrawText(TextFormat("- Velocity Len: (%06.3f)", Vector2Length((Vector2){ g.player.velocity.x, g.player.velocity.z })), 15, 60, 20, BLACK);
|
DrawText(TextFormat("- Velocity Len: (%06.3f)", Vector2Length((Vector2){ g.player.velocity.x, g.player.velocity.z })), 15, 60, 20, BLACK);
|
||||||
DrawText(
|
DrawText(
|
||||||
TextFormat("x: (%06.3f), y: (%06.3f), z: (%06.3f)", wall_position.x, wall_position.y, wall_position.z),
|
TextFormat("x: (%06.3f), y: (%06.3f), z: (%06.3f)", acorn_position.x, acorn_position.y, acorn_position.z),
|
||||||
15, 75, 20, BLACK
|
15, 75, 20, BLACK
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
if (g.nearAcorn == 1)
|
||||||
|
{
|
||||||
|
int acorn_text_width = MeasureText("Press E to Collect the Acorn", 50);
|
||||||
|
DrawText("Press E to Collect the Acorn", (screenWidth - acorn_text_width)/2, screenHeight * 0.8, 50, PURPLE);
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1060,3 +1087,9 @@ static void CollidePerimeter(Master* g, Model wall, float border, float scale) {
|
|||||||
ResolveAgainstBoxXZ(g, MakeModelWorldAABB(wall, (Vector3){ -border, 0.0f, z }, scl, 90.0f));
|
ResolveAgainstBoxXZ(g, MakeModelWorldAABB(wall, (Vector3){ -border, 0.0f, z }, scl, 90.0f));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float square(float num)
|
||||||
|
{
|
||||||
|
float out = num * num;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user