From 315bcf8dd6447eb588aa445e4818b42473a914cc Mon Sep 17 00:00:00 2001 From: "Erica.Gogova" Date: Fri, 27 Jun 2025 10:13:19 +0100 Subject: [PATCH 1/2] #2 create a powerup that when shot it will increase the shooting speed --- .../java/org/ergasia/javaspacegame/Ammo.java | 3 + .../java/org/ergasia/javaspacegame/Panel.java | 34 ++++++- .../ergasia/javaspacegame/PowerUpFuel.java | 89 ++++++++++++++++++ src/main/resources/gasolina.png | Bin 0 -> 1645 bytes 4 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 src/main/java/org/ergasia/javaspacegame/PowerUpFuel.java create mode 100644 src/main/resources/gasolina.png diff --git a/src/main/java/org/ergasia/javaspacegame/Ammo.java b/src/main/java/org/ergasia/javaspacegame/Ammo.java index 6655822..de6dd8c 100644 --- a/src/main/java/org/ergasia/javaspacegame/Ammo.java +++ b/src/main/java/org/ergasia/javaspacegame/Ammo.java @@ -87,6 +87,9 @@ public void fire(){ dy = 5; } + public void setFirespeed() { + this.dy= this.dy*100; + } /** * 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 7a7ff93..61fd801 100644 --- a/src/main/java/org/ergasia/javaspacegame/Panel.java +++ b/src/main/java/org/ergasia/javaspacegame/Panel.java @@ -74,6 +74,8 @@ public class Panel extends JPanel implements ActionListener, KeyListener { private boolean endGame = false; /*Image of the background */ private Image bg; + private PowerUpFuel fuel; + private int frameCounter = 0; /** @@ -104,7 +106,8 @@ public Panel() { ufos.add(new Ufo()); //Creating the Ufo Objects } - timer = new Timer(16, this);// ~= 60fps. + + timer = new Timer(16, this);// ~= 60fps. timer.start();//Starting the thread. } @@ -187,6 +190,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); + + } } /** @@ -197,7 +209,25 @@ private void doDrawing(Graphics g) { */ @Override public void actionPerformed(ActionEvent e) { + frameCounter++; + if (fuel != null && !fuel.fuelCheck()) { + fuel.checkForCollision(ammos); + } + int duration = 300; + if (fuel != null && fuel.isActive()){ + 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 boolean isActive(){ + return isActive; + } + + public void setActive(boolean active) { + this.isActive = active; + } +} diff --git a/src/main/resources/gasolina.png b/src/main/resources/gasolina.png new file mode 100644 index 0000000000000000000000000000000000000000..1a25a6d706174cded9b2a32d3db1b7caffc63e1b GIT binary patch literal 1645 zcmV-z29o)SP)Px*CrLy>R9Hv7ms@NbRUXE_bH-y&;`kEBj+4}JlZJ$(Ny}v^>8fI4{XTvZ=r0{Hs*j%mScycFDD2F?T!NfM{0 zip8_UeHV?z-#u{G*sJM%2UDr;E(Ap2i%&l0x@Jtz<)%Iq{Y{gXfB5>JTfw~8e|PnT z{)1tGcv~(H<~YbJGUn-5JRtbbl>?-|IpD` zXGe@gBF&JiI`X-h`se@q@VB$GKYY6pNIVjGYq1xXiqUA|`QE{!f9fAPk_d((Bo+xFo10;u{Od2j zDi(8-01RN+?Bvyv(aKZl!RYDS)%xFNC-yVO6j_%4&n@oe-O1#h=Q;+yzq_rA%7(Ei z#L{8Kp^+mW4c+zFlRiO2I=u&1r>{5{C(dYv%!NNzDuv&>6D3i6>CcBA`A2J0ko@lZ zPv4&|7vA2=Z3kk>k4_%^%`=2jYzG3-Xh+ZB9S=-*r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16 +0100 Subject: [PATCH 2/2] #2 create a powerup that when shot it will increase the shooting speed --- .../java/org/ergasia/javaspacegame/Ammo.java | 13 ++++++- .../java/org/ergasia/javaspacegame/Panel.java | 34 ++++++++++++++----- .../ergasia/javaspacegame/PowerUpFuel.java | 10 +++--- 3 files changed, 42 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/ergasia/javaspacegame/Ammo.java b/src/main/java/org/ergasia/javaspacegame/Ammo.java index de6dd8c..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. @@ -88,7 +89,17 @@ public void fire(){ } public void setFirespeed() { - this.dy= this.dy*100; + 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 diff --git a/src/main/java/org/ergasia/javaspacegame/Panel.java b/src/main/java/org/ergasia/javaspacegame/Panel.java index 61fd801..5b90fdf 100644 --- a/src/main/java/org/ergasia/javaspacegame/Panel.java +++ b/src/main/java/org/ergasia/javaspacegame/Panel.java @@ -76,6 +76,7 @@ public class Panel extends JPanel implements ActionListener, KeyListener { private Image bg; private PowerUpFuel fuel; private int frameCounter = 0; + private int fuelEffectDuration = 300; /** @@ -196,7 +197,7 @@ private void doDrawing(Graphics g) { } } else{ - System.out.println("Fuel is "+frameCounter); + //System.out.println("Fuel is "+frameCounter); } } @@ -212,20 +213,35 @@ public void actionPerformed(ActionEvent e) { frameCounter++; if (fuel != null && !fuel.fuelCheck()) { fuel.checkForCollision(ammos); + } - int duration = 300; - if (fuel != null && fuel.isActive()){ - for(int i=0; i ammos) { image = null; fuelhit = true; boolean isActive = true; + } } @@ -79,11 +80,10 @@ public boolean fuelCheck(){ return fuelhit; } - public boolean isActive(){ - return isActive; - } - public void setActive(boolean active) { - this.isActive = active; + + public void changefuelhit() { + this.fuelhit = false; + ; } }