mirror of
https://github.com/BreizhHardware/bloubloulespoissons.git
synced 2026-01-18 16:47:31 +01:00
add collisions
This commit is contained in:
3
player.h
3
player.h
@@ -41,6 +41,7 @@ class Player {
|
||||
bool onlineMovement();
|
||||
int unifiedX = 0;
|
||||
int unifiedY = 0;
|
||||
int HITBOX = 50;
|
||||
public:
|
||||
Player(int x, int y, int playerSpeed, SDL_Renderer* renderer, int playerId) : x(x), y(y), playerBaseX(x), playerBaseY(y), playerSpeed(playerSpeed), playerId(playerId) {
|
||||
playerPosForRender.x = x;
|
||||
@@ -75,6 +76,8 @@ class Player {
|
||||
return playerTexture;
|
||||
}
|
||||
|
||||
int getHITBOX() const {return HITBOX;}
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -55,6 +55,12 @@ void Shark::checkNeighborhood(Player& player, float &xpos_avg, float &ypos_avg,
|
||||
}
|
||||
}
|
||||
|
||||
void Shark::checkCollision(Player& player) {
|
||||
if (player.getUnifiedX() + player.getHITBOX() >= x - HITBOX && player.getUnifiedX() - player.getHITBOX() <= x + HITBOX && player.getUnifiedY() + player.getHITBOX() >= y - HITBOX && player.getUnifiedY() - player.getHITBOX() <= y + HITBOX) {
|
||||
game_running = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Shark::cycle() {
|
||||
int neighboring_player = 0;
|
||||
@@ -62,6 +68,7 @@ void Shark::cycle() {
|
||||
for (auto& player : players_list) {
|
||||
if (isInView(player)) {
|
||||
checkNeighborhood(player, xpos_avg, ypos_avg, xvel_avg, yvel_avg, neighboring_player);
|
||||
checkCollision(player);
|
||||
}
|
||||
}
|
||||
if (neighboring_player > 0) {
|
||||
|
||||
3
shark.h
3
shark.h
@@ -21,6 +21,7 @@ private:
|
||||
const float MAX_SPEED = 3;
|
||||
const float MIN_SPEED = 0.6;
|
||||
const float BIASVALUE = 0.001;
|
||||
const int HITBOX = 50;
|
||||
|
||||
float x, y;
|
||||
float vx, vy;
|
||||
@@ -42,6 +43,7 @@ public:
|
||||
float getY() const { return y; };
|
||||
float getVx() const { return vx; };
|
||||
float getVy() const { return vy; };
|
||||
int getHITBOX() const { return HITBOX; };
|
||||
|
||||
|
||||
|
||||
@@ -52,6 +54,7 @@ public:
|
||||
bool isInView(Player& player);
|
||||
void checkNeighborhood(Player& player, float &xpos_avg, float &ypos_avg, float &xvel_avg, float &yvel_avg, int &neighboring_player);
|
||||
void updatePosition(int newX, int newY);
|
||||
void checkCollision(Player& player);
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user