parent
ec140905ee
commit
134483d375
|
@ -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());
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Reference in New Issue