diff --git a/src/de/teamteamteam/spacescooter/control/Keyboard.java b/src/de/teamteamteam/spacescooter/control/Keyboard.java index d9ff803..2a27d95 100644 --- a/src/de/teamteamteam/spacescooter/control/Keyboard.java +++ b/src/de/teamteamteam/spacescooter/control/Keyboard.java @@ -12,7 +12,11 @@ public class Keyboard implements KeyListener { public static boolean isKeyDown(int keyCode) { return Keyboard.activeKeys.contains((Integer) keyCode); } - + + public static boolean isKeyUp(int keyCode) { + return !Keyboard.activeKeys.contains((Integer) keyCode); + } + public void keyPressed(KeyEvent e) { if(Keyboard.activeKeys.contains((Integer) e.getKeyCode())) return; Keyboard.activeKeys.add((Integer) e.getKeyCode()); diff --git a/src/de/teamteamteam/spacescooter/entity/HealthBar.java b/src/de/teamteamteam/spacescooter/entity/HealthBar.java new file mode 100644 index 0000000..5f70e3f --- /dev/null +++ b/src/de/teamteamteam/spacescooter/entity/HealthBar.java @@ -0,0 +1,34 @@ +package de.teamteamteam.spacescooter.entity; + +import java.awt.Color; +import java.awt.Graphics2D; + +public class HealthBar extends Entity { + + private int width = 100; + private int height = 20; + private Graphics2D g; + + public HealthBar(int x, int y) { + super(x, y); + + } + + public void paint(Graphics2D g) { + this.g = g; + this.g.setColor(new Color(0,255,0)); + this.g.fillRect(this.x, this.y, this.width, this.height); + } + + public void update() { + //this.g.setColor(new Color(0,0,255)); + } + + public int getWidth() { + return 0; + } + + public int getHeight() { + return 0; + } +} diff --git a/src/de/teamteamteam/spacescooter/entity/Player.java b/src/de/teamteamteam/spacescooter/entity/Player.java index 796221a..c4304d3 100644 --- a/src/de/teamteamteam/spacescooter/entity/Player.java +++ b/src/de/teamteamteam/spacescooter/entity/Player.java @@ -6,7 +6,7 @@ import de.teamteamteam.spacescooter.utility.GameConfig; public class Player extends ShootingEntity { - protected boolean shoot = false; + private boolean shoot = false; private boolean canMove = true; public Player(int x, int y) { @@ -16,7 +16,8 @@ public class Player extends ShootingEntity { this.setShootSpawn(50, 16); this.setShootDirection(Shot.RIGHT); this.setShootSpeed(4); - this.setHealthPoints(100); + this.setHealthPoints(10000); + inputThread.start(); } public void update() { @@ -35,20 +36,42 @@ 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) && shoot==false) { - shoot = true; + if(shoot == true) { this.shoot(); } - if(!Keyboard.isKeyDown(KeyEvent.VK_SPACE) && shoot==true) { - shoot = false; - } } - - + } public void setCanMove(boolean canMove){ this.canMove = canMove; } + public void setShoot(boolean shoot){ + this.shoot = shoot; + } + + Thread inputThread = new Thread(new Runnable() { + public void run() { + int down = 0; + while (true) { + setShootDelay(5); + + + if(Keyboard.isKeyDown(KeyEvent.VK_SPACE)) { + do { + if (Keyboard.isKeyUp(KeyEvent.VK_SPACE)) + System.out.print("lol"); + setShoot(true); + + setShootDelay(20); + } while(Keyboard.isKeyDown(KeyEvent.VK_SPACE)); + } else { + setShootDelay(5); + setShoot(false); + } + } + } + }); + } diff --git a/src/de/teamteamteam/spacescooter/screen/GameScreen.java b/src/de/teamteamteam/spacescooter/screen/GameScreen.java index 7aef9ad..f140b2d 100644 --- a/src/de/teamteamteam/spacescooter/screen/GameScreen.java +++ b/src/de/teamteamteam/spacescooter/screen/GameScreen.java @@ -13,6 +13,7 @@ import de.teamteamteam.spacescooter.entity.EnemyFour; import de.teamteamteam.spacescooter.entity.EnemyThree; import de.teamteamteam.spacescooter.entity.EnemyTwo; import de.teamteamteam.spacescooter.entity.Entity; +import de.teamteamteam.spacescooter.entity.HealthBar; import de.teamteamteam.spacescooter.entity.Player; public class GameScreen extends Screen { @@ -26,6 +27,7 @@ public class GameScreen extends Screen { points.add(new Point(0,500)); this.entities.add(new StarBackground(0, 0)); this.entities.add(new Player(200, 300)); + this.entities.add(new HealthBar(10, 10)); this.entities.add(new EnemyFour(800, 400, points)); this.entities.add(new EnemyThree(650, 300)); this.entities.add(new EnemyThree(450, 100));