Enemies können jetzt schießen. Wir auch.
This commit is contained in:
parent
65a4d2a682
commit
27f1f486d5
@ -1,9 +1,15 @@
|
||||
package de.teamteamteam.spacescooter.entity;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public abstract class Enemy extends ShootingEntity {
|
||||
|
||||
public Enemy(int x, int y) {
|
||||
super(x, y);
|
||||
Random r = new Random();
|
||||
this.name = "EnemyOne";
|
||||
this.willShoot = r.nextBoolean();
|
||||
this.setShootDirection(Shot.LEFT);
|
||||
}
|
||||
|
||||
protected String name;
|
||||
@ -11,7 +17,7 @@ public abstract class Enemy extends ShootingEntity {
|
||||
|
||||
public void update() {
|
||||
super.update();
|
||||
if(willShoot)
|
||||
if(willShoot == true)
|
||||
this.shoot();
|
||||
}
|
||||
|
||||
|
@ -1,16 +1,28 @@
|
||||
package de.teamteamteam.spacescooter.entity;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
public class EnemyOne extends Enemy {
|
||||
|
||||
private static BufferedImage img;
|
||||
|
||||
static {
|
||||
try {
|
||||
img = ImageIO.read(Player.class.getClassLoader().getResourceAsStream("images/nyancat.png"));
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public EnemyOne(int x, int y) {
|
||||
super(x, y);
|
||||
}
|
||||
|
||||
public void paint(Graphics g) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
this.setImage(EnemyOne.img);
|
||||
this.setShootSpeed(2);
|
||||
this.setShootDelay(42);
|
||||
this.setShootSpawn(0, 32);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -27,8 +27,10 @@ public class Player extends ShootingEntity {
|
||||
this.setImage(Player.img);
|
||||
this.setShootDelay(40);
|
||||
this.setShootSpawn(32, 16);
|
||||
this.setShootDirection(Shot.RIGHT);
|
||||
this.setShootSpeed(2);
|
||||
}
|
||||
|
||||
|
||||
public void update() {
|
||||
super.update();
|
||||
int off = 3;
|
||||
|
@ -8,10 +8,11 @@ public abstract class ShootingEntity extends LivingEntity {
|
||||
private int currentShootDelay;
|
||||
private int shootSpawnX;
|
||||
private int shootSpawnY;
|
||||
private int shootDirection;
|
||||
private int shootSpeed;
|
||||
|
||||
public ShootingEntity(int x, int y) {
|
||||
super(x, y);
|
||||
this.shootDelay = 10;
|
||||
this.currentShootDelay = 0;
|
||||
}
|
||||
|
||||
@ -21,11 +22,19 @@ public abstract class ShootingEntity extends LivingEntity {
|
||||
|
||||
protected void shoot() {
|
||||
if(this.currentShootDelay == 0) {
|
||||
Screen.currentScreen.addEntity(new SingleShot(this.x + this.shootSpawnX, this.y + this.shootSpawnY));
|
||||
Screen.currentScreen.addEntity(new SingleShot(this.x + this.shootSpawnX, this.y + this.shootSpawnY, this.shootDirection, this.shootSpeed));
|
||||
this.currentShootDelay = this.shootDelay;
|
||||
}
|
||||
}
|
||||
|
||||
public void setShootDirection(int direction) {
|
||||
this.shootDirection = direction;
|
||||
}
|
||||
|
||||
public void setShootSpeed(int speed) {
|
||||
this.shootSpeed = speed;
|
||||
}
|
||||
|
||||
public void setShootDelay(int shootDelay) {
|
||||
this.shootDelay = shootDelay;
|
||||
}
|
||||
|
@ -4,12 +4,19 @@ import java.awt.image.BufferedImage;
|
||||
|
||||
public abstract class Shot extends CollidableEntity {
|
||||
|
||||
public static final int RIGHT = 1;
|
||||
public static final int LEFT= -1;
|
||||
|
||||
protected int damageValue;
|
||||
protected int collisionCount;
|
||||
|
||||
private int speed;
|
||||
private int direction;
|
||||
|
||||
public Shot(int x, int y) {
|
||||
public Shot(int x, int y, int shootDirection, int shootSpeed) {
|
||||
super(x, y);
|
||||
this.direction = shootDirection;
|
||||
this.speed = shootSpeed;
|
||||
this.collisionCount = 1;
|
||||
}
|
||||
|
||||
@ -21,11 +28,16 @@ public abstract class Shot extends CollidableEntity {
|
||||
public void collideWith(Collidable entity) {
|
||||
this.collisionCount--;
|
||||
if(this.collisionCount == 0) {
|
||||
//scoot is over
|
||||
//TODO: scoot is over
|
||||
}
|
||||
}
|
||||
|
||||
public int getDamageValue() {
|
||||
return this.damageValue;
|
||||
}
|
||||
|
||||
public void update() {
|
||||
this.x += this.direction * this.speed;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,13 +19,9 @@ public class SingleShot extends Shot {
|
||||
}
|
||||
|
||||
|
||||
public SingleShot(int x, int y) {
|
||||
super(x, y);
|
||||
public SingleShot(int x, int y, int shootDirection, int shootSpeed) {
|
||||
super(x, y, shootDirection, shootSpeed);
|
||||
this.setImage(img);
|
||||
}
|
||||
|
||||
public void update() {
|
||||
this.x += 2;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ 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.Entity;
|
||||
import de.teamteamteam.spacescooter.entity.Player;
|
||||
|
||||
@ -17,6 +18,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));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user