From b69bc9534f5cad3e5246cc0b634bfacab3ec8fd1 Mon Sep 17 00:00:00 2001 From: Sosch Date: Fri, 31 Oct 2014 09:07:42 +0100 Subject: [PATCH] =?UTF-8?q?men=C3=BC=20eingef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- res/images/button.png | Bin 0 -> 463 bytes res/images/pausebackground.png | Bin 0 -> 2878 bytes .../background/StarBackground.java | 2 +- .../spacescooter/entity/EnemyOne.java | 2 +- .../spacescooter/entity/Player.java | 41 ++++--- .../teamteamteam/spacescooter/gui/Button.java | 34 ++++++ .../spacescooter/gui/GameFrame.java | 2 +- .../spacescooter/screen/GamePausedScreen.java | 89 +++++++++++++-- .../spacescooter/screen/MainMenuScreen.java | 104 +++++++++++++++--- 9 files changed, 234 insertions(+), 40 deletions(-) create mode 100644 res/images/button.png create mode 100644 res/images/pausebackground.png create mode 100644 src/de/teamteamteam/spacescooter/gui/Button.java diff --git a/res/images/button.png b/res/images/button.png new file mode 100644 index 0000000000000000000000000000000000000000..ca9a54b9e0e28888aa70921d2ddd87166f8357e4 GIT binary patch literal 463 zcmeAS@N?(olHy`uVBq!ia0vp^zkt|?gAGWQh97$Zq}Y|gW!U_%O?XxI14-? ziy0WWg+Z8+Vb&Z8pdfpRr>`sfJuX>6IhCKSL7_k)+02lL66gHf+|;}hAeVu`xhOTU zBsE2$JhLQ2!QIn0AVn{goq>VT*we)^q~g}wyQeu1If%4foEhD2%aU_=*`+|MjqC^Q zN}gVF_hETIx0uUA;ls!CYc4H+d1;%~ndi~Wb&ss%e_u=gqPvh=rikT#=nJOyn1k!N zVjoN}{vlxbWXrOX0+v_$ZC&`jCi72p{(HmuNr3$~gwTA}SKQfrU&HS%I_%M%cXr{s zRna99sTbE;UWqI1=2O0Vk#Qk&=hw@dcFb>fWpCl*kQJ~}C~Ra;%zJ0EDu+ZTCP7e1Q>WaVC5Yjq{27-*i}uF&?X?0+Q} zkMfl&)mN5?TVLt;^Hw(Y%>?^T+ZT4rescd8_#&zO&cu3|T{jf-pRC<_ZTZVhzgX)w s^H?(77uoed(fz^h7QKoe?+?hoTj5vrX2nr!F;KXAy85}Sb4q9e05AN+g#Z8m literal 0 HcmV?d00001 diff --git a/res/images/pausebackground.png b/res/images/pausebackground.png new file mode 100644 index 0000000000000000000000000000000000000000..5258f4b4d3b977f852e216a52a46ec561fe913a3 GIT binary patch literal 2878 zcmeAS@N?(olHy`uVBq!ia0y~yU{+vYV2a>i1B%QlYbpRzY)RhkE)4%caKYZ?lYt_f z1s;*b3=G`DAk4@xYmNj^kiEpy*OmPqmz)^4c$!p>4NyonGbEzKIX^cyHLnE7WngeF zN=+EaktaqI1MLqP@xjw2h`|Igdd#?7WT@xt1v zDNGCu1q)Pxx_LMl7!n+?GMIsiz)~m-2?3yDkO&InKm$+|B!bFdV}XjGFboucia{dS z84Zk#5Ghm!$faNr6b2RC4)+bJ+u^=JaXVNI)!eQE42aPfK%}S97+}Gc^g;OqGwH)c zM)Lr)IHE%GftO3Dh0kaV086UTdVm3(!cZy%s?=dBqxAr_n-e7F-_aPLdV`Ko4D5?o Y+sc~%)aq StarBackground.img.getWidth()) { this.offset += StarBackground.img.getWidth(); diff --git a/src/de/teamteamteam/spacescooter/entity/EnemyOne.java b/src/de/teamteamteam/spacescooter/entity/EnemyOne.java index 7768516..b138eec 100644 --- a/src/de/teamteamteam/spacescooter/entity/EnemyOne.java +++ b/src/de/teamteamteam/spacescooter/entity/EnemyOne.java @@ -6,7 +6,7 @@ import java.io.IOException; import javax.imageio.ImageIO; public class EnemyOne extends Enemy { - + private static BufferedImage img; static { diff --git a/src/de/teamteamteam/spacescooter/entity/Player.java b/src/de/teamteamteam/spacescooter/entity/Player.java index da1d66b..a9ba8cb 100644 --- a/src/de/teamteamteam/spacescooter/entity/Player.java +++ b/src/de/teamteamteam/spacescooter/entity/Player.java @@ -11,6 +11,7 @@ import de.teamteamteam.spacescooter.utility.GameConfig; public class Player extends ShootingEntity { private static BufferedImage img; + private boolean canMove = true; static { try { @@ -27,28 +28,34 @@ public class Player extends ShootingEntity { this.setShootDelay(40); this.setShootSpawn(50, 16); this.setShootDirection(Shot.RIGHT); - this.setShootSpeed(2); + this.setShootSpeed(4); this.setHealthPoints(100); } public void update() { - super.update(); - int off = 3; - if(Keyboard.isKeyDown(KeyEvent.VK_UP) && this.y > 0) { - this.y -= off; - } - if(Keyboard.isKeyDown(KeyEvent.VK_DOWN) && this.y < (GameConfig.windowHeight - Player.img.getHeight())) { - this.y += off; - } - if(Keyboard.isKeyDown(KeyEvent.VK_LEFT) && this.x > 0) { - this.x -= off; - } - if(Keyboard.isKeyDown(KeyEvent.VK_RIGHT) && this.x < (GameConfig.windowWidth - Player.img.getWidth())) { - this.x += off; - } - if(Keyboard.isKeyDown(KeyEvent.VK_SPACE)) { - this.shoot(); + if(canMove){ + super.update(); + int off = 3; + if(Keyboard.isKeyDown(KeyEvent.VK_UP) && this.y > 0) { + this.y -= off; + } + if(Keyboard.isKeyDown(KeyEvent.VK_DOWN) && this.y < (GameConfig.windowHeight - Player.img.getHeight())) { + this.y += off; + } + if(Keyboard.isKeyDown(KeyEvent.VK_LEFT) && this.x > 0) { + this.x -= off; + } + if(Keyboard.isKeyDown(KeyEvent.VK_RIGHT) && this.x < (GameConfig.windowWidth - Player.img.getWidth())) { + this.x += off; + } + if(Keyboard.isKeyDown(KeyEvent.VK_SPACE)) { + this.shoot(); + } } } + public void setCanMove(boolean canMove){ + this.canMove = canMove; + } + } diff --git a/src/de/teamteamteam/spacescooter/gui/Button.java b/src/de/teamteamteam/spacescooter/gui/Button.java new file mode 100644 index 0000000..80adbd4 --- /dev/null +++ b/src/de/teamteamteam/spacescooter/gui/Button.java @@ -0,0 +1,34 @@ +package de.teamteamteam.spacescooter.gui; + +import java.awt.image.BufferedImage; +import java.io.IOException; + +import javax.imageio.ImageIO; + +import de.teamteamteam.spacescooter.entity.Entity; +import de.teamteamteam.spacescooter.entity.Player; + +public class Button extends Entity{ + + private static BufferedImage img; + + static{ + try { + img = ImageIO.read(Player.class.getClassLoader().getResourceAsStream("images/button.png")); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public Button(int x, int y) { + super(x, y); + this.setImage(img); + } + + @Override + public void update() { + } + + +} diff --git a/src/de/teamteamteam/spacescooter/gui/GameFrame.java b/src/de/teamteamteam/spacescooter/gui/GameFrame.java index 3b61a9f..1e9d81c 100644 --- a/src/de/teamteamteam/spacescooter/gui/GameFrame.java +++ b/src/de/teamteamteam/spacescooter/gui/GameFrame.java @@ -33,7 +33,7 @@ public class GameFrame extends JFrame { public void init() { this.setTitle("Unser schöner Titel"); this.setSize(GameConfig.windowWidth, GameConfig.windowHeight); - this.setResizable(false); +// this.setResizable(false); this.setUndecorated(false); this.setDefaultCloseOperation(EXIT_ON_CLOSE); diff --git a/src/de/teamteamteam/spacescooter/screen/GamePausedScreen.java b/src/de/teamteamteam/spacescooter/screen/GamePausedScreen.java index bab51b7..9d66518 100644 --- a/src/de/teamteamteam/spacescooter/screen/GamePausedScreen.java +++ b/src/de/teamteamteam/spacescooter/screen/GamePausedScreen.java @@ -4,30 +4,105 @@ import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; import java.awt.event.KeyEvent; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.util.Iterator; +import java.util.LinkedList; + +import javax.imageio.ImageIO; 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; public class GamePausedScreen extends Screen { + private static 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 + + static{ + try { + img = ImageIO.read(Player.class.getClassLoader().getResourceAsStream("images/pausebackground.png")); + } catch (IOException e) { + e.printStackTrace(); + } + } + public GamePausedScreen(Screen parent) { super(parent); + 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.setColor(new Color(0,0,120)); - g.fillRect(0, 0, GameConfig.windowWidth, GameConfig.windowHeight); - g.setColor(new Color(255,255,255)); - g.setFont(new Font("Monospace", 0, 50)); - g.drawString("Pause Menu. LOL", 100, 100); - g.drawString("Press space to continue!", 100, 400); + g.drawImage(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("Pause", GameConfig.windowWidth/2-145, 200); + g.setFont(new Font("Monospace", 0, 20)); + g.setColor(new Color(0, 0, 0)); + g.drawString("Weiter", GameConfig.windowWidth/2-30, 332); + g.drawString("Hauptmenü", GameConfig.windowWidth/2-50, 432); } @Override protected void update() { + LinkedList list = this.getEntities(); + Iterator i = list.iterator(); + while (i.hasNext()) { + i.next().update(); + } + + if(colorValueIncrease){ + colorValue += 2; + if(colorValue > 70) colorValueIncrease = false; + }else{ + colorValue -= 2; + if(colorValue < -70) colorValueIncrease = true; + } + + if(Keyboard.isKeyDown(KeyEvent.VK_DOWN)){ + menuPoint = 1; + player.setPosition(player.getX(), 409); + } + if(Keyboard.isKeyDown(KeyEvent.VK_UP)){ + menuPoint = 0; + player.setPosition(player.getX(), 309); + } + if(Keyboard.isKeyDown(KeyEvent.VK_SPACE)) { - this.parent.setOverlay(null); + animationStatus = 1; + } + if(animationStatus == 1){ + if(player.getX() <= GameConfig.windowWidth){ + player.setPosition(player.getX() + (int)playerMoveSpeed, player.getY()); + playerMoveSpeed += 0.1; + }else animationStatus = 2; + }else if(animationStatus == 2){ + switch (menuPoint) { + case 0: + this.parent.setOverlay(null); + break; + case 1: + this.parent.setOverlay(new MainMenuScreen(this.parent)); + break; + } } } diff --git a/src/de/teamteamteam/spacescooter/screen/MainMenuScreen.java b/src/de/teamteamteam/spacescooter/screen/MainMenuScreen.java index 217eea7..9e39ecd 100644 --- a/src/de/teamteamteam/spacescooter/screen/MainMenuScreen.java +++ b/src/de/teamteamteam/spacescooter/screen/MainMenuScreen.java @@ -5,36 +5,114 @@ import java.awt.Font; import java.awt.Graphics2D; import java.awt.event.KeyEvent; +import java.util.Iterator; +import java.util.LinkedList; +import de.teamteamteam.spacescooter.background.StarBackground; 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; public class MainMenuScreen extends Screen { + private Player player; + private float playerMoveSpeed = 0; + private int colorValue = 0; + private boolean colorValueIncrease = true; + private int menuPoint = 0; + private boolean keyPressed = false; + private int animationStatus = 0; //0 = Animation noch nicht gestartet, 1 = Animation läuft, 2 = Animation beendet + public MainMenuScreen(Screen parent) { super(parent); + this.entities.add(new StarBackground(0, 0)); + this.entities.add(new Button(GameConfig.windowWidth/2-125, 200)); + this.entities.add(new Button(GameConfig.windowWidth/2-125, 275)); + this.entities.add(new Button(GameConfig.windowWidth/2-125, 350)); + this.entities.add(new Button(GameConfig.windowWidth/2-125, 425)); + this.entities.add(new Button(GameConfig.windowWidth/2-125, 500)); + player = new Player(GameConfig.windowWidth/2-170, 209); + player.setCanMove(false); + this.entities.add(player); } @Override public void paint(Graphics2D g) { - g.setColor(new Color(0,0,120)); - g.fillRect(0, 0, GameConfig.windowWidth, GameConfig.windowHeight); - g.setColor(new Color(255,255,255)); - g.setFont(new Font("Monospace", 0, 50)); - g.drawString("Main Menu. LOL", 100, 100); - g.drawString("Press space to play!", 100, 400); + LinkedList list = this.getEntities(); + Iterator i = list.iterator(); + while (i.hasNext()) { + i.next().paint(g); + } + g.setFont(new Font("Monospace", 0, 70)); + g.setColor(new Color(75 + colorValue, 175 + colorValue, 175 + colorValue)); + g.drawString("SpaceScooter", GameConfig.windowWidth/2-225, 125); + g.setFont(new Font("Monospace", 0, 20)); + g.setColor(new Color(0, 0, 0)); + g.drawString("Neues Spiel", GameConfig.windowWidth/2-50, 232); + g.drawString("Hilfe", GameConfig.windowWidth/2-20, 308); + g.drawString("Highscore", GameConfig.windowWidth/2-45, 382); + g.drawString("Credits", GameConfig.windowWidth/2-33, 458); + g.drawString("Beenden", GameConfig.windowWidth/2-38, 532); } @Override public void update() { - /*for(Entity entity : this.entities) { - entity.update(); - }*/ - if(Keyboard.isKeyDown(KeyEvent.VK_SPACE)) { - this.parent.setOverlay(new GameScreen(this.parent)); + LinkedList list = this.getEntities(); + Iterator i = list.iterator(); + while (i.hasNext()) { + i.next().update(); } - if(Keyboard.isKeyDown(KeyEvent.VK_ESCAPE)) { - System.exit(0); + + if(colorValueIncrease){ + colorValue += 2; + if(colorValue > 70) colorValueIncrease = false; + }else{ + colorValue -= 2; + if(colorValue < -70) colorValueIncrease = true; + } + + if(Keyboard.isKeyDown(KeyEvent.VK_DOWN) && !keyPressed && animationStatus == 0){ + keyPressed = true; + if(menuPoint<4){ + menuPoint++; + player.setPosition(player.getX(), 209+(menuPoint*75)); + } + }else if(Keyboard.isKeyDown(KeyEvent.VK_UP) && !keyPressed && animationStatus == 0){ + keyPressed = true; + if(menuPoint>0){ + menuPoint--; + player.setPosition(player.getX(), 209+(menuPoint*75)); + } + }else if(!Keyboard.isKeyDown(KeyEvent.VK_DOWN) && !Keyboard.isKeyDown(KeyEvent.VK_UP)){ + keyPressed = false; + } + + if(Keyboard.isKeyDown(KeyEvent.VK_SPACE)) { + animationStatus = 1; + } + + if(animationStatus == 1){ + if(player.getX() <= GameConfig.windowWidth){ + player.setPosition(player.getX() + (int)playerMoveSpeed, player.getY()); + playerMoveSpeed += 0.1; + }else animationStatus = 2; + }else if(animationStatus == 2){ + switch (menuPoint) { + case 0: + this.parent.setOverlay(new GameScreen(this.parent)); + break; + case 1: + break; + case 2: + break; + case 3: + break; + case 4: + System.exit(0); + break; + } } }