5 przeciwnikow, jakos to dziala
This commit is contained in:
@@ -13,6 +13,15 @@ Wiazkowiec::Wiazkowiec(int x, int y, const sf::Texture& texture) : Actor(x, y, t
|
||||
// BombaTexture.loadFromFile("../assets/img/bullets/bomba.png");
|
||||
}
|
||||
|
||||
void Wiazkowiec::setPlanszaHeight(float height) {
|
||||
planszaHeight = height;
|
||||
}
|
||||
|
||||
void Wiazkowiec::setMapBounds(float width, float height) {
|
||||
mapWidth = width;
|
||||
mapHeight = height;
|
||||
}
|
||||
|
||||
void Wiazkowiec::spawnBeam() {
|
||||
float beamX = position.x;
|
||||
float beamY = position.y;
|
||||
@@ -23,16 +32,24 @@ void Wiazkowiec::spawnBeam() {
|
||||
case DirectionW::Up:
|
||||
beamHeight = position.y;
|
||||
beamY -= beamHeight;
|
||||
beam = Beam(beamX, beamY, beamWidth, beamHeight, sf::Color::Red);
|
||||
break;
|
||||
case DirectionW::Down:
|
||||
beamHeight = 600 - position.y;
|
||||
beamHeight = planszaHeight - position.y; // Dynamiczna wysokość okna
|
||||
beam = Beam(beamX, beamY, beamWidth, beamHeight, sf::Color::Red);
|
||||
break;
|
||||
case DirectionW::Left:
|
||||
beamWidth = position.x;
|
||||
beamX -= beamWidth;
|
||||
beamHeight = 50.f; // Stała wysokość
|
||||
beamWidth = position.x;
|
||||
beamX -= beamWidth; // Wiązka w lewo od pozycji statku
|
||||
beamY = position.y + (actorSprite.getGlobalBounds().height / 2) - 25.f;
|
||||
beam = Beam(beamX, beamY, beamWidth, beamHeight, sf::Color::Red);
|
||||
break;
|
||||
case DirectionW::Right:
|
||||
beamWidth = 800 - position.x;
|
||||
beamHeight = 50.f; // Stała wysokość
|
||||
beamWidth = 800 - position.x;
|
||||
beamY = position.y + (actorSprite.getGlobalBounds().height / 2) - 25.f;
|
||||
beam = Beam(beamX, beamY, beamWidth, beamHeight, sf::Color::Red);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -72,17 +89,19 @@ void Wiazkowiec::setRandomDirection() {
|
||||
}
|
||||
|
||||
void Wiazkowiec::updateDirection() {
|
||||
// Zmieniamy kierunek przeciwnika, gdy dotrze do krawędzi
|
||||
auto spriteBounds = actorSprite.getGlobalBounds();
|
||||
|
||||
// Kontrola dolnej i górnej krawędzi
|
||||
if (position.y <= 0) {
|
||||
direction = DirectionW::Down;
|
||||
} else if (position.y >= 800) {
|
||||
} else if (position.y + spriteBounds.height >= mapHeight) {
|
||||
direction = DirectionW::Up;
|
||||
}
|
||||
|
||||
// logika dla kierunku lewo/prawo
|
||||
// Kontrola lewej i prawej krawędzi
|
||||
if (position.x <= 0) {
|
||||
direction = DirectionW::Right;
|
||||
} else if (position.x >= 1200) {
|
||||
} else if (position.x + spriteBounds.width >= mapWidth) {
|
||||
direction = DirectionW::Left;
|
||||
}
|
||||
}
|
||||
@@ -111,16 +130,16 @@ void Wiazkowiec::update() {
|
||||
|
||||
switch (direction) {
|
||||
case DirectionW::Up:
|
||||
moveUp();
|
||||
if (position.y > 0) moveUp();
|
||||
break;
|
||||
case DirectionW::Down:
|
||||
moveDown();
|
||||
if (position.y + actorSprite.getGlobalBounds().height < mapHeight) moveDown();
|
||||
break;
|
||||
case DirectionW::Left:
|
||||
moveLeft();
|
||||
if (position.x > 0) moveLeft();
|
||||
break;
|
||||
case DirectionW::Right:
|
||||
moveRight();
|
||||
if (position.x + actorSprite.getGlobalBounds().width < mapWidth) moveRight();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user