Skip to content
Snippets Groups Projects
Commit a7fef7c6 authored by Oscar Wiberg's avatar Oscar Wiberg
Browse files

bomb droppen fungerar

parent b668950d
No related branches found
No related tags found
1 merge request!2Newmode
...@@ -8,7 +8,7 @@ import javafx.scene.image.Image; ...@@ -8,7 +8,7 @@ import javafx.scene.image.Image;
public class Bomb { public class Bomb {
private double startX; private double startX;
private double posY = 100; private double posY = 50;
private Image image; private Image image;
public Bomb(double bombDropX, String bombImg) { public Bomb(double bombDropX, String bombImg) {
......
...@@ -48,6 +48,10 @@ public class FlyingEnemy extends Antagonist{ ...@@ -48,6 +48,10 @@ public class FlyingEnemy extends Antagonist{
return null; return null;
} }
public void resetBombDrop() {
bombDropped = false;
}
@Override @Override
public boolean playerAntagonistCollision(Player player) { public boolean playerAntagonistCollision(Player player) {
......
...@@ -180,35 +180,26 @@ public class PlayState extends GameState { ...@@ -180,35 +180,26 @@ public class PlayState extends GameState {
g.drawImage(flyingEnemy.getImage(), flyingEnemy.getX(), flyingEnemy.getY(), Constants.enemyWidth, Constants.enemyHeight); g.drawImage(flyingEnemy.getImage(), flyingEnemy.getX(), flyingEnemy.getY(), Constants.enemyWidth, Constants.enemyHeight);
// If the flying enemy has passed the screen, drop a bomb (now always drops on the first pass)
if (flyingEnemy.getX() < 0 - Constants.enemyWidth) {
flyingEnemy.setAntagonistX(Constants.screenWidth); // Reset the enemy's position
player.updatePasses(1);
System.out.println("Before dropBomb, bomb is: " + bomb);
// Drop the bomb if it hasn't been dropped already
if (bomb == null) {
bomb = flyingEnemy.dropBomb(); // Call the method in FlyingEnemy to drop the bomb
// System.out.println("Bomb dropped at X: " + bomb.getX() + ", Y: " + bomb.getY());
}
if (player.getPasses() % 5 == 0) { if (flyingEnemy.getX() < 0 - Constants.enemyWidth) {
movingSpeed += 2; flyingEnemy.setAntagonistX(Constants.screenWidth); // Reset the enemy's position
} player.updatePasses(1);
}
// Render the bomb if it exists // Reset bomb drop flag to allow the next bomb drop
if (bomb != null) { flyingEnemy.resetBombDrop();
g.drawImage(bomb.getImage(), bomb.getX(), bomb.getY(), Constants.bombWidth, Constants.bombHeight); if (player.getPasses() % 5 == 0) {
movingSpeed += 2;
}
}
// Render the bomb if it exists
if (bomb != null) {
g.drawImage(bomb.getImage(), bomb.getX(), bomb.getY(), Constants.bombWidth, Constants.bombHeight);
}
} }
}
...@@ -284,6 +275,7 @@ public class PlayState extends GameState { ...@@ -284,6 +275,7 @@ public class PlayState extends GameState {
// enemy.setAntagonistX(enemy.getX()-10); // enemy.setAntagonistX(enemy.getX()-10);
// enemy.setAntagonistX(enemy.getX()-movingSpeed); // enemy.setAntagonistX(enemy.getX()-movingSpeed);
flyingEnemy.setAntagonistX(flyingEnemy.getX() -movingSpeed); flyingEnemy.setAntagonistX(flyingEnemy.getX() -movingSpeed);
Bomb droppedBomb = flyingEnemy.dropBomb(); Bomb droppedBomb = flyingEnemy.dropBomb();
if (droppedBomb != null) { if (droppedBomb != null) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment