diff --git a/src/de/teamteamteam/spacescooter/entity/EnemyOne.java b/src/de/teamteamteam/spacescooter/entity/EnemyOne.java index 5274953..ee93fa9 100644 --- a/src/de/teamteamteam/spacescooter/entity/EnemyOne.java +++ b/src/de/teamteamteam/spacescooter/entity/EnemyOne.java @@ -9,6 +9,7 @@ public class EnemyOne extends Enemy { this.setShootDelay(42); this.setShootSpawn(-8, 10); this.setHealthPoints(5); + this.setCollisionDamage(100); } @Override diff --git a/src/de/teamteamteam/spacescooter/entity/EnemyThree.java b/src/de/teamteamteam/spacescooter/entity/EnemyThree.java new file mode 100644 index 0000000..95fd918 --- /dev/null +++ b/src/de/teamteamteam/spacescooter/entity/EnemyThree.java @@ -0,0 +1,55 @@ +package de.teamteamteam.spacescooter.entity; + +import java.util.Iterator; +import java.util.LinkedList; +import java.util.Random; + +import de.teamteamteam.spacescooter.screen.Screen; +import de.teamteamteam.spacescooter.utility.GameConfig; + +public class EnemyThree extends Enemy{ + + private double newY; + private double ySpeed = 0.4; + + public EnemyThree(int x, int y) { + super(x, y); + Random random = new Random(); + this.setImage("images/nyancat.png"); + this.setShootSpeed(4); + this.setShootDelay(42); + this.setShootSpawn(-10, 10); + this.setHealthPoints(5); + this.setPosition(GameConfig.windowWidth, random.nextInt(GameConfig.windowHeight - this.getHeight())); + this.newY = this.getY(); + } + + @Override + public void update() { + super.update(); + this.setPosition(this.getX()-1, this.getY()); + if(this.getX() < 0-getWidth()){ + this.remove(); + Screen.currentScreen.addEntity(new EnemyThree(0, 0)); + } + if(!this.isAlive()){ + Screen.currentScreen.addEntity(new EnemyThree(0, 0)); + } + LinkedList list = Screen.currentScreen.getEntities(); + Iterator i = list.iterator(); + while (i.hasNext()) { + Entity entity = i.next(); + if(entity instanceof Player){ + Player player = (Player) entity; + if(this.y < player.getY()){ + this.newY += ySpeed; + this.setPosition(this.getX(), (int) newY); + }else if(this.y > player.getY()){ + this.newY -= ySpeed; + this.setPosition(this.getX(), (int) newY); + } + } + } + } + +} diff --git a/src/de/teamteamteam/spacescooter/entity/EnemyTwo.java b/src/de/teamteamteam/spacescooter/entity/EnemyTwo.java new file mode 100644 index 0000000..5ae4204 --- /dev/null +++ b/src/de/teamteamteam/spacescooter/entity/EnemyTwo.java @@ -0,0 +1,34 @@ +package de.teamteamteam.spacescooter.entity; + +import java.util.Random; + +import de.teamteamteam.spacescooter.screen.Screen; +import de.teamteamteam.spacescooter.utility.GameConfig; + +public class EnemyTwo extends Enemy{ + + public EnemyTwo(int x, int y) { + super(x, y); + Random random = new Random(); + this.setImage("images/nyancat.png"); + this.setShootSpeed(4); + this.setShootDelay(42); + this.setShootSpawn(-10, 10); + this.setHealthPoints(5); + this.setPosition(GameConfig.windowWidth, random.nextInt(GameConfig.windowHeight - this.getHeight())); + } + + @Override + public void update() { + super.update(); + this.setPosition(this.getX()-1, this.getY()); + if(this.getX() < 0-getWidth()){ + this.remove(); + Screen.currentScreen.addEntity(new EnemyTwo(0, 0)); + } + if(!this.isAlive()){ + Screen.currentScreen.addEntity(new EnemyTwo(0, 0)); + } + } + +} diff --git a/src/de/teamteamteam/spacescooter/entity/Player.java b/src/de/teamteamteam/spacescooter/entity/Player.java index bd82294..796221a 100644 --- a/src/de/teamteamteam/spacescooter/entity/Player.java +++ b/src/de/teamteamteam/spacescooter/entity/Player.java @@ -5,13 +5,14 @@ import de.teamteamteam.spacescooter.control.Keyboard; import de.teamteamteam.spacescooter.utility.GameConfig; public class Player extends ShootingEntity { - + + protected boolean shoot = false; private boolean canMove = true; public Player(int x, int y) { super(x, y); this.setImage("images/ship.png"); - this.setShootDelay(40); + this.setShootDelay(5); this.setShootSpawn(50, 16); this.setShootDirection(Shot.RIGHT); this.setShootSpeed(4); @@ -19,7 +20,7 @@ public class Player extends ShootingEntity { } public void update() { - if(this.canMove){ + if(this.canMove) { super.update(); int off = 3; if(Keyboard.isKeyDown(KeyEvent.VK_UP) && this.y > 0) { @@ -34,10 +35,16 @@ public class Player extends ShootingEntity { if(Keyboard.isKeyDown(KeyEvent.VK_RIGHT) && this.x < (GameConfig.windowWidth - this.getImage().getWidth())) { this.x += off; } - if(Keyboard.isKeyDown(KeyEvent.VK_SPACE)) { + if(Keyboard.isKeyDown(KeyEvent.VK_SPACE) && shoot==false) { + shoot = true; this.shoot(); } + if(!Keyboard.isKeyDown(KeyEvent.VK_SPACE) && shoot==true) { + shoot = false; + } } + + } public void setCanMove(boolean canMove){ diff --git a/src/de/teamteamteam/spacescooter/screen/GameOverScreen.java b/src/de/teamteamteam/spacescooter/screen/GameOverScreen.java new file mode 100644 index 0000000..62812e1 --- /dev/null +++ b/src/de/teamteamteam/spacescooter/screen/GameOverScreen.java @@ -0,0 +1,100 @@ +package de.teamteamteam.spacescooter.screen; + +import java.awt.Color; +import java.awt.Font; +import java.awt.Graphics2D; +import java.awt.event.KeyEvent; +import java.awt.image.BufferedImage; +import java.util.Iterator; +import java.util.LinkedList; + +import de.teamteamteam.spacescooter.control.Keyboard; +import de.teamteamteam.spacescooter.entity.Entity; +import de.teamteamteam.spacescooter.entity.Player; +import de.teamteamteam.spacescooter.gui.Button; +import de.teamteamteam.spacescooter.utility.GameConfig; +import de.teamteamteam.spacescooter.utility.Loader; + +public class GameOverScreen extends Screen { + + private BufferedImage img; + private Player player; + private float playerMoveSpeed = 0; + private int colorValue = 0; + private boolean colorValueIncrease = true; + private int menuPoint = 0; + private int animationStatus = 0; //0 = Noch nicht gestartet, 1 = Animation läuft, 2 = Animation beendet + + public GameOverScreen(Screen parent) { + super(parent); + this.img = Loader.getBufferedImageByFilename("images/pausebackground.png"); + this.entities.add(new Button(GameConfig.windowWidth/2-125, 300)); + this.entities.add(new Button(GameConfig.windowWidth/2-125, 400)); + player = new Player(GameConfig.windowWidth/2-170, 309); + player.setCanMove(false); + this.entities.add(player); + } + + @Override + protected void paint(Graphics2D g) { + g.drawImage(this.img, 0, 0, null); + LinkedList list = this.getEntities(); + Iterator i = list.iterator(); + while (i.hasNext()) { + i.next().paint(g); + } + g.setFont(new Font("Monospace", 0, 100)); + g.setColor(new Color(75 + colorValue, 175 + colorValue, 175 + colorValue)); + g.drawString("Game Over", GameConfig.windowWidth/2-290, 200); + g.setFont(new Font("Monospace", 0, 20)); + g.setColor(new Color(0, 0, 0)); + g.drawString("Wiederholen", GameConfig.windowWidth/2-60, 332); + g.drawString("Hauptmenü", GameConfig.windowWidth/2-60, 432); + } + + @Override + protected void update() { + LinkedList list = this.getEntities(); + Iterator i = list.iterator(); + while (i.hasNext()) { + i.next().update(); + } + + if(this.colorValueIncrease){ + this.colorValue += 2; + if(this.colorValue > 70) this.colorValueIncrease = false; + }else{ + this.colorValue -= 2; + if(this.colorValue < -70) this.colorValueIncrease = true; + } + + if(Keyboard.isKeyDown(KeyEvent.VK_DOWN)){ + this.menuPoint = 1; + player.setPosition(player.getX(), 409); + } + if(Keyboard.isKeyDown(KeyEvent.VK_UP)){ + this.menuPoint = 0; + player.setPosition(player.getX(), 309); + } + + if(Keyboard.isKeyDown(KeyEvent.VK_SPACE)) { + this.animationStatus = 1; + } + if(this.animationStatus == 1){ + if(player.getX() <= GameConfig.windowWidth){ + player.setPosition(player.getX() + (int)playerMoveSpeed, player.getY()); + playerMoveSpeed += 0.1; + }else this.animationStatus = 2; + }else if(this.animationStatus == 2){ + switch (this.menuPoint) { + case 0: + this.parent.setOverlay(new GameScreen(this.parent)); + break; + case 1: + this.parent.setOverlay(new MainMenuScreen(this.parent)); + break; + } + } + } + +} diff --git a/src/de/teamteamteam/spacescooter/screen/GameScreen.java b/src/de/teamteamteam/spacescooter/screen/GameScreen.java index eb00e8a..c4a5214 100644 --- a/src/de/teamteamteam/spacescooter/screen/GameScreen.java +++ b/src/de/teamteamteam/spacescooter/screen/GameScreen.java @@ -7,7 +7,8 @@ import java.util.LinkedList; import de.teamteamteam.spacescooter.background.StarBackground; import de.teamteamteam.spacescooter.control.Keyboard; -import de.teamteamteam.spacescooter.entity.EnemyOne; +import de.teamteamteam.spacescooter.entity.EnemyThree; +import de.teamteamteam.spacescooter.entity.EnemyTwo; import de.teamteamteam.spacescooter.entity.Entity; import de.teamteamteam.spacescooter.entity.Explosion; import de.teamteamteam.spacescooter.entity.Player; @@ -18,10 +19,10 @@ public class GameScreen extends Screen { super(parent); this.entities.add(new StarBackground(0, 0)); this.entities.add(new Player(200, 300)); - this.entities.add(new EnemyOne(650, 300)); - this.entities.add(new EnemyOne(450, 100)); - this.entities.add(new EnemyOne(750, 550)); - this.entities.add(new EnemyOne(150, 250)); + this.entities.add(new EnemyThree(650, 300)); + this.entities.add(new EnemyThree(450, 100)); + this.entities.add(new EnemyTwo(750, 550)); + this.entities.add(new EnemyTwo(150, 250)); this.entities.add(new Explosion(200, 200)); } @@ -44,6 +45,12 @@ public class GameScreen extends Screen { if (Keyboard.isKeyDown(KeyEvent.VK_ESCAPE)) { this.setOverlay(new GamePausedScreen(this)); } + if (list.get(1) instanceof Player) { + Player player = (Player) list.get(1); + if (!player.isAlive()) { + this.parent.setOverlay(new GameOverScreen(this.parent)); + } + } } }