diff --git a/src/main/java/org/ergasia/javaspacegame/Ammo.java b/src/main/java/org/ergasia/javaspacegame/Ammo.java index 6655822..d4745ed 100644 --- a/src/main/java/org/ergasia/javaspacegame/Ammo.java +++ b/src/main/java/org/ergasia/javaspacegame/Ammo.java @@ -30,6 +30,7 @@ public class Ammo { private Image image; /*This boolean variable is used for the shot system*/ private boolean check = false; + private boolean updatedSpeed = false; /** * The Constructor. @@ -87,6 +88,19 @@ public void fire(){ dy = 5; } + public void setFirespeed() { + if (this.dy<=5) { + this.dy = this.dy * 3; + updatedSpeed=true; + } + + } + + + + public void resetSpeed() { + this.dy = 5; + } /** * if the player typed the right keyboard button * the dx value increases, so the object moves right. diff --git a/src/main/java/org/ergasia/javaspacegame/Panel.java b/src/main/java/org/ergasia/javaspacegame/Panel.java index 7c4f10d..adc42a4 100644 --- a/src/main/java/org/ergasia/javaspacegame/Panel.java +++ b/src/main/java/org/ergasia/javaspacegame/Panel.java @@ -74,7 +74,10 @@ public class Panel extends JPanel implements ActionListener, KeyListener { private boolean endGame = false; /*Image of the background */ private Image bg; - private int frameCounter = 0; + + private PowerUpFuel fuel; + private int frameCounter = 0; + private int fuelEffectDuration = 300; @@ -107,7 +110,8 @@ public Panel() { } - timer = new Timer(16, this);// ~= 60fps. + + timer = new Timer(16, this);// ~= 60fps. timer.start();//Starting the thread. } @@ -190,6 +194,15 @@ private void doDrawing(Graphics g) { g2d.drawImage(ship.getImage(), ship.getX(), ship.getY() - 25/*the height of the image*/, this); + if (fuel!= null && fuel.getImage() != null) { + if (!fuel.fuelCheck()){ + g2d.drawImage(fuel.getImage(), fuel.getX(), fuel.getY(), this); + } + } + else{ + //System.out.println("Fuel is "+frameCounter); + + } } /** @@ -200,7 +213,40 @@ private void doDrawing(Graphics g) { */ @Override public void actionPerformed(ActionEvent e) { + frameCounter++; + if (fuel != null && !fuel.fuelCheck()) { + fuel.checkForCollision(ammos); + + } + + if (fuel != null && fuel.fuelCheck()){ + + // or 300 if using frames + // Set all ammo to be fast + for (Ammo ammo : ammos) { + ammo.setFirespeed(); + } + + + + fuelEffectDuration--; + System.out.println(fuelEffectDuration); + if (fuelEffectDuration <= 0) { + fuel.changefuelhit();// end the powerup + + fuelEffectDuration = 300; + // Reset ammo speeds if needed + for (Ammo ammo : ammos) { + ammo.resetSpeed(); // You may need to make this method + + } + } + + } + if (frameCounter == 100) { + fuel= new PowerUpFuel(); + } //if stage is beaten this if statement is responsible for the setup for the next stage. if(restart){ for(int i=0; i 642 && y < 137); + + width = image.getWidth(null); + height = image.getHeight(null); + } + public Image getImage() { + return image; + } + public int getX() { + return x; + } + + public int getY() { + return y; + } + + + public void checkForCollision(ArrayList ammos) { + if (fuelhit) return; + + for(int i=0; i y && ammoY + ammoHeight < y + height){ + if(ammoX + ammoWidth > x && ammoX < x + width){ + image = null; + fuelhit = true; + boolean isActive = true; + + } + } + + } + + } + public boolean fuelCheck(){ + return fuelhit; + } + + + + public void changefuelhit() { + this.fuelhit = false; + ; + } +} diff --git a/src/main/resources/gasolina.png b/src/main/resources/gasolina.png new file mode 100644 index 0000000..1a25a6d Binary files /dev/null and b/src/main/resources/gasolina.png differ