[ADD] character falls when it hits a tree
This commit is contained in:
@@ -7,17 +7,24 @@
|
|||||||
#include"../renderEngine/loader.h"
|
#include"../renderEngine/loader.h"
|
||||||
namespace entities
|
namespace entities
|
||||||
{
|
{
|
||||||
|
float movement_speed;
|
||||||
|
float down_speed;
|
||||||
|
float side_speed;
|
||||||
|
bool is_playing;
|
||||||
|
|
||||||
MainCharacter::MainCharacter(const models::TexturedModel& model, const glm::vec3& position,
|
MainCharacter::MainCharacter(const models::TexturedModel& model, const glm::vec3& position,
|
||||||
const glm::vec3& rotation, float scale, const collision::Box& bounding_box)
|
const glm::vec3& rotation, float scale, const collision::Box& bounding_box)
|
||||||
: CollisionEntity(model, position, rotation, scale, bounding_box)
|
: CollisionEntity(model, position, rotation, scale, bounding_box)
|
||||||
{
|
{
|
||||||
|
is_playing = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 MainCharacter::Move(GLFWwindow* window)
|
void MainCharacter::Move(GLFWwindow* window)
|
||||||
{
|
{
|
||||||
float movement_speed = -0.5f; //Forward speed adjustment, bee is moving at a standard speedrate
|
if (is_playing) {
|
||||||
float down_speed = -1.0f; //Down speed adjustment, downspeed is difference between down_speed and UP_SPEED
|
movement_speed = -0.5f; //Forward speed adjustment, bee is moving at a standard speedrate
|
||||||
float side_speed = 0; //Side speed adjustment
|
down_speed = -1.0f; //Down speed adjustment, downspeed is difference between down_speed and UP_SPEED
|
||||||
|
side_speed = 0; //Side speed adjustment
|
||||||
|
|
||||||
//For gameplay with use of keyboard keys: W, A, S, D
|
//For gameplay with use of keyboard keys: W, A, S, D
|
||||||
//W: Go forward
|
//W: Go forward
|
||||||
@@ -25,6 +32,7 @@ namespace entities
|
|||||||
//S: Go backwards
|
//S: Go backwards
|
||||||
//D: Go right
|
//D: Go right
|
||||||
//TODO Implement CV actions
|
//TODO Implement CV actions
|
||||||
|
SetRotation(glm::vec3(0, 90, 0));
|
||||||
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
||||||
{
|
{
|
||||||
movement_speed -= SIDE_SPEED;
|
movement_speed -= SIDE_SPEED;
|
||||||
@@ -34,12 +42,24 @@ namespace entities
|
|||||||
{
|
{
|
||||||
movement_speed += SIDE_SPEED;
|
movement_speed += SIDE_SPEED;
|
||||||
}
|
}
|
||||||
|
//top right
|
||||||
|
if (glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS)
|
||||||
|
{
|
||||||
|
side_speed += SIDE_SPEED;
|
||||||
|
down_speed += UP_SPEED;
|
||||||
|
}
|
||||||
|
//right
|
||||||
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
|
||||||
{
|
{
|
||||||
side_speed += SIDE_SPEED;
|
side_speed += SIDE_SPEED;
|
||||||
}
|
}
|
||||||
|
//top left
|
||||||
|
if (glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS)
|
||||||
|
{
|
||||||
|
down_speed += UP_SPEED;
|
||||||
|
side_speed -= SIDE_SPEED;
|
||||||
|
}
|
||||||
|
//left
|
||||||
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)
|
||||||
{
|
{
|
||||||
side_speed -= SIDE_SPEED;
|
side_speed -= SIDE_SPEED;
|
||||||
@@ -48,11 +68,13 @@ namespace entities
|
|||||||
if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS)
|
||||||
{
|
{
|
||||||
down_speed += UP_SPEED;
|
down_speed += UP_SPEED;
|
||||||
|
SetRotation(glm::vec3(10, 90, 0));
|
||||||
}
|
}
|
||||||
if (glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS)
|
||||||
{
|
{
|
||||||
down_speed -= UP_SPEED;
|
down_speed -= UP_SPEED;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
IncreasePosition(glm::vec3(side_speed, down_speed, movement_speed));
|
IncreasePosition(glm::vec3(side_speed, down_speed, movement_speed));
|
||||||
|
|
||||||
//Use only for binding bee to house, such that it doesn't go outside of the room.
|
//Use only for binding bee to house, such that it doesn't go outside of the room.
|
||||||
@@ -61,13 +83,18 @@ namespace entities
|
|||||||
else if (position.x < -190) position.x = -190;
|
else if (position.x < -190) position.x = -190;
|
||||||
if (position.y > 350) position.y = 350;
|
if (position.y > 350) position.y = 350;
|
||||||
else if (position.y < -40) position.y = -40;
|
else if (position.y < -40) position.y = -40;
|
||||||
|
|
||||||
//Move player bounding box according to the position on screen
|
//Move player bounding box according to the position on screen
|
||||||
MoveCollisionBox();
|
MoveCollisionBox();
|
||||||
return glm::vec3(side_speed, down_speed, movement_speed );
|
if (glfwGetKey(window, GLFW_KEY_Z) == GLFW_PRESS)
|
||||||
|
{
|
||||||
|
is_playing = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainCharacter::OnCollide(const collision::Collision& collision) {
|
void MainCharacter::OnCollide(const collision::Collision& collision) {
|
||||||
std::cout << "collide" << std::endl;
|
down_speed = -2.0f;
|
||||||
|
movement_speed = 0.0f;
|
||||||
|
is_playing = false;
|
||||||
|
std::cout << "collision" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -31,7 +31,7 @@ namespace entities
|
|||||||
*
|
*
|
||||||
* @return: Vector with the adjusted side_speed, down_speed, and movement_speed
|
* @return: Vector with the adjusted side_speed, down_speed, and movement_speed
|
||||||
*/
|
*/
|
||||||
glm::vec3 Move(GLFWwindow* window);
|
void Move(GLFWwindow* window);
|
||||||
|
|
||||||
void OnCollide(const collision::Collision& collision) override;
|
void OnCollide(const collision::Collision& collision) override;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ namespace scene
|
|||||||
{
|
{
|
||||||
//camera.Move(window);
|
//camera.Move(window);
|
||||||
|
|
||||||
glm::vec3 movement = main_character->Move(window);
|
main_character->Move(window);
|
||||||
|
|
||||||
//std::cout << "x get: " << movement.x << "\ny get: " << movement.y << "\nz get: " << movement.z << "\n";
|
//std::cout << "x get: " << movement.x << "\ny get: " << movement.y << "\nz get: " << movement.z << "\n";
|
||||||
camera.Follow(main_character->GetPosition());
|
camera.Follow(main_character->GetPosition());
|
||||||
|
|||||||
Reference in New Issue
Block a user