Skip to content

Commit

Permalink
Health increase
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexpop11 committed Oct 6, 2024
1 parent 8cd4733 commit 7fba85c
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 8 deletions.
6 changes: 4 additions & 2 deletions OpenGL/src/Input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ float Input::deltaTime = 0.01;
bool Input::keys_pressed[GLFW_KEY_LAST] = {false};
bool Input::keys_pressed_last_frame[GLFW_KEY_LAST] = {false};
bool Input::keys_pressed_down[GLFW_KEY_LAST] = {false};
bool Input::mouse_pressed = false;
bool Input::mouse_pressed_down = false;
bool Input::left_mouse_pressed = false;
bool Input::left_mouse_pressed_down = false;
bool Input::right_mouse_pressed = false;
bool Input::right_mouse_pressed_down = false;

float zeno(float current, float target, float timeConstant) {
float alpha = 1.0f - std::exp(-Input::deltaTime / timeConstant);
Expand Down
12 changes: 8 additions & 4 deletions OpenGL/src/Input.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ class Input {
public:
static bool keys_pressed[GLFW_KEY_LAST];
static bool keys_pressed_down[GLFW_KEY_LAST];
static bool mouse_pressed;
static bool mouse_pressed_down;
static bool left_mouse_pressed;
static bool left_mouse_pressed_down;
static bool right_mouse_pressed;
static bool right_mouse_pressed_down;
static float startTime;
static float deltaTime;

Expand All @@ -26,8 +28,10 @@ class Input {
keys_pressed_down[key] = !keys_pressed_last_frame[key] && keys_pressed[key];
}

mouse_pressed_down = !mouse_pressed && glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_1) == GLFW_PRESS;
mouse_pressed = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_1) == GLFW_PRESS;
left_mouse_pressed_down = !left_mouse_pressed && glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_1) == GLFW_PRESS;
left_mouse_pressed = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_1) == GLFW_PRESS;
right_mouse_pressed_down = !right_mouse_pressed && glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_2) == GLFW_PRESS;
right_mouse_pressed = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_2) == GLFW_PRESS;
}
};

Expand Down
1 change: 1 addition & 0 deletions OpenGL/src/game_objects/Bomb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Bomb::Bomb(const std::string& name, float x, float y)
}

void Bomb::tickUpdate() {
tintColor.a = zeno(tintColor.a, 0.0, 0.5);
// Explode the bomb
if (ExplodeTick > 6) {
explode();
Expand Down
17 changes: 15 additions & 2 deletions OpenGL/src/game_objects/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Player::Player(const std::string& name, int tile_x, int tile_y)
: Character(name, tile_x, tile_y, "Textures/alternate-player.png") {
drawPriority = DrawPriority::Character;
health = 3;
health = 5;
Camera::position = {tile_x, tile_y};

healthText = std::make_unique<Text>("Health", Renderer::jacquard12_big, glm::vec2{20, 20});
Expand Down Expand Up @@ -71,7 +71,7 @@ void Player::update() {

void Player::render(Renderer& renderer) {
Character::render(renderer);
if (Input::mouse_pressed_down) {
if (Input::left_mouse_pressed_down) {
if (gunCooldown == 0) {
Renderer::DebugLine(position, renderer.MousePos(), {1, 0, 0, 1});
audio().Zap.play();
Expand All @@ -86,6 +86,19 @@ void Player::render(Renderer& renderer) {
gunCooldown = playerGunCooldown;
}
}
if (Input::right_mouse_pressed) {
if (hasSlomo) {
Renderer::DebugLine(position, renderer.MousePos(), {1, 0, 0, 1});
// get what is at mouse position
for (auto& character : World::at<Character>(renderer.MousePos().x + 0.5, renderer.MousePos().y + 0.5)) {
character->tintColor = {1.0, 0.5, 0.0, 0.5};
}
for (auto& bomb : World::at<Bomb>(renderer.MousePos().x + 0.5, renderer.MousePos().y + 0.5)) {
bomb->tintColor = {1.0, 0.5, 0.0, 0.5};
}
// need to figure out some way to slow tick rate and also make all things zeno at a fraction of normal speed
}
}
}

void Player::hurt() {
Expand Down
1 change: 1 addition & 0 deletions OpenGL/src/game_objects/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ class Player : public Character {
// Powerups
int playerBunnyHopCoolDown = 6;
int playerGunCooldown = 3;
bool hasSlomo = true;
};
1 change: 1 addition & 0 deletions OpenGL/src/game_objects/SquareObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ void SquareObject::render(Renderer& renderer) {

void SquareObject::update() {
position = zeno(position, glm::vec2(tile_x, tile_y), 0.05);
tintColor.a = zeno(tintColor.a, 0.0, 0.3);
}

0 comments on commit 7fba85c

Please sign in to comment.