Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions OpenGL/src/game_objects/Bomb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ void Bomb::explode() {
ShouldDestroy = true;
}

void Bomb::kick(bool hitWall, int dx, int dy) {
Entity::kick(hitWall, dx, dy);
void Bomb::kick(bool hitWall, int dx, int dy, bool superKick) {
Entity::kick(hitWall, dx, dy, superKick);

if (hitWall) {
if (hitWall && superKick) {
explode();
}
}
2 changes: 1 addition & 1 deletion OpenGL/src/game_objects/Bomb.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Bomb : public Entity {
public:
Bomb(const std::string& name, float x, float y);
virtual void tickUpdate() override;
virtual void kick(bool hitWall, int dx, int dy) override;
virtual void kick(bool hitWall, int dx, int dy, bool superKick) override;
int ExplodeTick;
void explode();
};
17 changes: 13 additions & 4 deletions OpenGL/src/game_objects/Character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ bool Character::move(int new_x, int new_y) {
int knockback_dy = (dy != 0) ? dy / std::abs(dy) : 0;

bool can_knockback = true;
const int max_knockback_distance = 3;
const int max_knockback_distance = 5;
int knockback_distance = max_knockback_distance;

// Check if enemy can be knocked back 3 tiles
Expand Down Expand Up @@ -131,10 +131,19 @@ bool Character::move(int new_x, int new_y) {
return false;
}

void Character::kick(bool hitWall, int dx, int dy) {
Entity::kick(hitWall, dx, dy);
void Character::kick(bool hitWall, int dx, int dy, bool superKick) {
Entity::kick(hitWall, dx, dy, superKick);

if (hitWall && superKick) {
stunnedLength = 9;
auto tile = World::at<Tile>(tile_x + dx + sign(dx), tile_y + dy + sign(dy)).front();
if (!tile->unbreakable) {
tile->wall = false;
}
hurt();
}


stunnedLength = 9;
tintColor = {1.0, 0.5, 0.0, 0.5};
}

Expand Down
2 changes: 1 addition & 1 deletion OpenGL/src/game_objects/Character.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Character : public Entity {
void die();
int health = 1;
virtual void hurt();
virtual void kick(bool hitWall, int dx, int dy) override;
virtual void kick(bool hitWall, int dx, int dy, bool superKick) override;
int stunnedLength = 0;
std::optional<KickState> kicking;

Expand Down
11 changes: 8 additions & 3 deletions OpenGL/src/game_objects/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
Entity::Entity(const std::string& name, DrawPriority drawPriority, int tile_x, int tile_y, std::string texturepath)
: SquareObject(name, drawPriority, tile_x, tile_y, texturepath) {}

void Entity::kick(bool hitWall, int dx, int dy) {
void Entity::kick(bool hitWall, int dx, int dy, bool superKick) {
audio().Impact.play();
tile_x += dx;
tile_y += dy;
if (!superKick) {
tile_x += std::clamp(dx, -3, 3);
tile_y += std::clamp(dy, -3, 3);
} else {
tile_x += dx;
tile_y += dy;
}
}
2 changes: 1 addition & 1 deletion OpenGL/src/game_objects/Entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
class Entity : public SquareObject {
public:
Entity(const std::string& name, DrawPriority drawPriority, int tile_x, int tile_y, std::string texturepath);
virtual void kick(bool hitWall, int dx, int dy);
virtual void kick(bool hitWall, int dx, int dy, bool superKick);
};
23 changes: 20 additions & 3 deletions OpenGL/src/game_objects/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,31 @@ void Player::update() {

if (kicking) {
if (auto kickedGuy = kicking->victim.lock()) {
if (glm::length(kickedGuy->position - position) < 1.5) {
kickedGuy->kick(kicking->intoWall, kicking->direction.x, kicking->direction.y);
if (kickTime) {
if (glfwGetTime() - *kickTime > 0.8) {
kickedGuy->kick(kicking->intoWall, kicking->direction.x, kicking->direction.y, false);
kickTime.reset();
kicking.reset();
}
else {
Renderer::DebugLine(position, kickedGuy->position, {1, 0, 0, 1});
if (Input::keys_pressed_down[GLFW_KEY_LEFT_SHIFT]) {
kickedGuy->kick(kicking->intoWall, kicking->direction.x, kicking->direction.y, true);
kicking.reset();
}
}
World::timeSpeed = 0.1f;
audio().Update(World::timeSpeed);
} else if (glm::length(kickedGuy->position - position) < 1.5) {
kickTime = glfwGetTime();
World::timeSpeed = 0.1f;
audio().Update(World::timeSpeed);
kicking.reset();
} else {
std::cout << "kickedGuy->position - position " << glm::length(kickedGuy->position - position) << std::endl;
}
} else {
kicking.reset();
kickTime.reset();
}
}

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 @@ -15,6 +15,7 @@ class Player : public Character {
bool second_step = false;
virtual void render(Renderer& renderer, RenderPass& renderPass) override;
bool pauseTicks() { return kicking.has_value(); }
std::optional<float> kickTime = 0;

std::unique_ptr<Text> healthText;
std::unique_ptr<Text> topText;
Expand Down
2 changes: 1 addition & 1 deletion OpenGL/src/game_objects/enemies/Turret.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Turret::Turret(const std::string& name, float x, float y)
: Character(name, x, y, "enemy.png") {
drawPriority = DrawPriority::Character;
health = 1;
health = 3;
}

void Turret::update() {
Expand Down