Replace Player Iritaion with getPlayer()
Added a Boss Fix Item Pickup
This commit is contained in:
parent
4cbb91fd43
commit
5baeff583f
Binary file not shown.
After Width: | Height: | Size: 715 B |
Binary file not shown.
After Width: | Height: | Size: 580 B |
|
@ -39,6 +39,8 @@ public abstract class Entity implements Updateable, Paintable {
|
|||
*/
|
||||
private BufferedImage img;
|
||||
|
||||
private boolean removed = false;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
@ -148,11 +150,21 @@ public abstract class Entity implements Updateable, Paintable {
|
|||
g.drawImage(this.img, this.x, this.y, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Boolean If the Entity got Removed.
|
||||
* @return removed
|
||||
*/
|
||||
|
||||
public boolean isRemoved() {
|
||||
return removed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes entity from the game by telling the current Screen
|
||||
* to remove it from its list.
|
||||
*/
|
||||
public void remove() {
|
||||
this.removed = true;
|
||||
Screen.currentScreen.removeEntity(this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -176,4 +176,18 @@ public abstract class ShootingEntity extends LivingEntity {
|
|||
this.primaryShotImage
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom Shoot for Custom Action!!!
|
||||
*/
|
||||
public void createCustomShot(int x, int y, int speed, int dmg, String filename) {
|
||||
new Shot(
|
||||
this.getX() + x,
|
||||
this.getY() + y,
|
||||
Shot.LEFT,
|
||||
speed,
|
||||
dmg,
|
||||
filename
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
package de.teamteamteam.spacescooter.entity.enemy;
|
||||
|
||||
import de.teamteamteam.spacescooter.entity.explosion.MultiExplosion;
|
||||
import de.teamteamteam.spacescooter.gui.BossBar;
|
||||
import de.teamteamteam.spacescooter.utility.GameConfig;
|
||||
import de.teamteamteam.spacescooter.utility.Random;
|
||||
|
||||
public class EnemyBoss extends Enemy{
|
||||
|
||||
private int move = 1;
|
||||
|
||||
public EnemyBoss(int x, int y) {
|
||||
super(x, y);
|
||||
this.setImage("images/boss.png");
|
||||
this.setPrimaryShotImage("images/shots/ballshot.png");
|
||||
this.setShootSpeed(5);
|
||||
this.setShootDelay(50);
|
||||
this.setShootSpawn(-10, 30);
|
||||
this.setShootDamage(8);
|
||||
this.setHealthPoints(300);
|
||||
this.setCollisionDamage(50);
|
||||
this.setScore(5000);
|
||||
this.willShoot = true;
|
||||
this.setPosition(GameConfig.windowWidth, Random.nextInt(GameConfig.windowHeight - this.getHeight() - 50) +50);
|
||||
new BossBar(10, 44, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* This enemy spawns an Item on its death and causes another enemy to appear.
|
||||
*/
|
||||
@Override
|
||||
public void die() {
|
||||
super.die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom MultiExplosion for this enemy.
|
||||
*/
|
||||
@Override
|
||||
public void explode() {
|
||||
new MultiExplosion(this.getX(), this.getY());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
this.setPosition(750, this.getY()+move);
|
||||
if(this.getY() == 51){
|
||||
move = 1;
|
||||
}
|
||||
if(this.getY() == 560){
|
||||
move = -1;
|
||||
}
|
||||
if(Random.nextInt(1000) < 5) new EnemyBossMinion(730, this.getY());
|
||||
if(Random.nextInt(1000) < 50) {
|
||||
createCustomShot(-10, 3, 8, 15, "images/shots/laser_red.png");
|
||||
createCustomShot(-10, 59, 8, 15, "images/shots/laser_red.png");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
package de.teamteamteam.spacescooter.entity.enemy;
|
||||
|
||||
import de.teamteamteam.spacescooter.entity.Player;
|
||||
import de.teamteamteam.spacescooter.entity.explosion.MultiExplosion;
|
||||
import de.teamteamteam.spacescooter.entity.item.Item;
|
||||
import de.teamteamteam.spacescooter.screen.GameScreen;
|
||||
import de.teamteamteam.spacescooter.utility.Random;
|
||||
|
||||
public class EnemyBossMinion extends Enemy{
|
||||
|
||||
private double newY;
|
||||
private double ySpeed = 0.4;
|
||||
|
||||
public EnemyBossMinion(int x, int y) {
|
||||
super(x, y);
|
||||
this.setImage("images/enemybossminion.png");
|
||||
this.setPrimaryShotImage("images/shots/laser_green.png");
|
||||
this.setShootSpeed(4);
|
||||
this.setShootDelay(42);
|
||||
this.setShootSpawn(-10, 10);
|
||||
this.setShootDamage(5);
|
||||
this.setHealthPoints(15);
|
||||
this.setCollisionDamage(10);
|
||||
this.setScore(10);
|
||||
this.newY = this.getY();
|
||||
}
|
||||
|
||||
/**
|
||||
* This enemy spawns an Item on its death and causes another enemy to appear.
|
||||
*/
|
||||
@Override
|
||||
public void die() {
|
||||
if(Random.nextInt(10) < 5) Item.create(getX(), getY());
|
||||
new EnemyBossMinion(0, 0);
|
||||
super.die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom MultiExplosion for this enemy.
|
||||
*/
|
||||
@Override
|
||||
public void explode() {
|
||||
new MultiExplosion(this.getX(), this.getY());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
this.setPosition(this.getX()-1, this.getY());
|
||||
Player player = GameScreen.getPlayer();
|
||||
if(this.getY() < player.getY()){
|
||||
this.newY += ySpeed;
|
||||
this.setPosition(this.getX(), (int) newY);
|
||||
}else if(this.getY() > player.getY()){
|
||||
this.newY -= ySpeed;
|
||||
this.setPosition(this.getX(), (int) newY);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,11 +1,9 @@
|
|||
package de.teamteamteam.spacescooter.entity.enemy;
|
||||
|
||||
import de.teamteamteam.spacescooter.datastructure.ConcurrentIterator;
|
||||
import de.teamteamteam.spacescooter.entity.Entity;
|
||||
import de.teamteamteam.spacescooter.entity.Player;
|
||||
import de.teamteamteam.spacescooter.entity.explosion.MultiExplosion;
|
||||
import de.teamteamteam.spacescooter.entity.item.Item;
|
||||
import de.teamteamteam.spacescooter.screen.Screen;
|
||||
import de.teamteamteam.spacescooter.screen.GameScreen;
|
||||
import de.teamteamteam.spacescooter.utility.GameConfig;
|
||||
import de.teamteamteam.spacescooter.utility.Random;
|
||||
|
||||
|
@ -13,7 +11,6 @@ public class EnemyThree extends Enemy{
|
|||
|
||||
private double newY;
|
||||
private double ySpeed = 0.4;
|
||||
private ConcurrentIterator<Entity> entityIterator;
|
||||
|
||||
public EnemyThree(int x, int y) {
|
||||
super(x, y);
|
||||
|
@ -28,7 +25,6 @@ public class EnemyThree extends Enemy{
|
|||
this.setScore(30);
|
||||
this.setPosition(GameConfig.windowWidth, Random.nextInt(GameConfig.windowHeight - this.getHeight() - 50) +50);
|
||||
this.newY = this.getY();
|
||||
this.entityIterator = Screen.currentScreen.createEntityIterator();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -57,20 +53,13 @@ public class EnemyThree extends Enemy{
|
|||
this.remove();
|
||||
new EnemyThree(0, 0);
|
||||
}
|
||||
entityIterator.reset();
|
||||
while (entityIterator.hasNext()) {
|
||||
Entity entity = entityIterator.next();
|
||||
if(entity instanceof Player){
|
||||
Player player = (Player) entity;
|
||||
if(this.getY() < player.getY()){
|
||||
this.newY += ySpeed;
|
||||
this.setPosition(this.getX(), (int) newY);
|
||||
}else if(this.getY() > player.getY()){
|
||||
this.newY -= ySpeed;
|
||||
this.setPosition(this.getX(), (int) newY);
|
||||
}
|
||||
}
|
||||
Player player = GameScreen.getPlayer();
|
||||
if(this.getY() < player.getY()){
|
||||
this.newY += ySpeed;
|
||||
this.setPosition(this.getX(), (int) newY);
|
||||
}else if(this.getY() > player.getY()){
|
||||
this.newY -= ySpeed;
|
||||
this.setPosition(this.getX(), (int) newY);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,21 +1,15 @@
|
|||
package de.teamteamteam.spacescooter.entity.item;
|
||||
|
||||
import de.teamteamteam.spacescooter.datastructure.ConcurrentIterator;
|
||||
import de.teamteamteam.spacescooter.entity.CollidableEntity;
|
||||
import de.teamteamteam.spacescooter.entity.Entity;
|
||||
import de.teamteamteam.spacescooter.entity.Player;
|
||||
import de.teamteamteam.spacescooter.entity.spi.Collidable;
|
||||
import de.teamteamteam.spacescooter.screen.Screen;
|
||||
import de.teamteamteam.spacescooter.sound.SoundSystem;
|
||||
|
||||
public abstract class Item extends CollidableEntity {
|
||||
|
||||
private ConcurrentIterator<Entity> entityIterator;
|
||||
|
||||
|
||||
public Item(int x, int y) {
|
||||
super(x, y);
|
||||
this.entityIterator = Screen.currentScreen.createEntityIterator();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -24,12 +18,7 @@ public abstract class Item extends CollidableEntity {
|
|||
public void collideWith(Collidable entity) {
|
||||
if(entity instanceof Player) {
|
||||
SoundSystem.playSound("sounds/powerup_pickup.wav");
|
||||
while(entityIterator.hasNext()) {
|
||||
Entity e = entityIterator.next();
|
||||
if(e instanceof Player){
|
||||
itemCollected((Player) e);
|
||||
}
|
||||
}
|
||||
itemCollected((Player) entity);
|
||||
this.remove();
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +28,6 @@ public abstract class Item extends CollidableEntity {
|
|||
if(this.getX() < 0-this.getWidth()){
|
||||
this.remove();
|
||||
};
|
||||
entityIterator.reset();
|
||||
}
|
||||
|
||||
public abstract void itemCollected(Player player);
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
package de.teamteamteam.spacescooter.gui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics2D;
|
||||
|
||||
import de.teamteamteam.spacescooter.entity.Entity;
|
||||
import de.teamteamteam.spacescooter.entity.enemy.Enemy;
|
||||
|
||||
public class BossBar extends Entity {
|
||||
|
||||
private int width = 150;
|
||||
private int height = 14;
|
||||
private int health = 0;
|
||||
private int fullhealth = 0;
|
||||
private int healthwidth = 0;
|
||||
private static Enemy boss;
|
||||
|
||||
public BossBar(int x, int y, Enemy ent) {
|
||||
super(x, y);
|
||||
BossBar.boss = ent;
|
||||
this.fullhealth = boss.getHealthPoints();
|
||||
}
|
||||
|
||||
public void paint(Graphics2D g) {
|
||||
try {
|
||||
this.health = (int) (((double) boss.getHealthPoints() / (double) this.fullhealth) * 100);
|
||||
this.healthwidth = ((this.width) * this.health) / 100;
|
||||
} catch(Exception e) {
|
||||
this.healthwidth = 0;
|
||||
}
|
||||
g.setColor(Color.WHITE);
|
||||
g.setFont(new Font("Monospace", 0, 16));
|
||||
g.drawString("Boss:", this.getX(), this.getY()+12);
|
||||
g.setColor(Color.PINK);
|
||||
g.fillRect(this.getX()+70, this.getY(), this.healthwidth, this.height);
|
||||
g.setColor(Color.WHITE);
|
||||
g.drawRect(this.getX()+70, this.getY(), this.width, this.height);
|
||||
}
|
||||
|
||||
public void update() {
|
||||
if (boss.isAlive() == false || boss.isRemoved() == true) {
|
||||
this.remove();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -8,6 +8,7 @@ import java.util.ArrayList;
|
|||
import de.teamteamteam.spacescooter.background.StarBackground;
|
||||
import de.teamteamteam.spacescooter.control.Keyboard;
|
||||
import de.teamteamteam.spacescooter.entity.Player;
|
||||
import de.teamteamteam.spacescooter.entity.enemy.EnemyBoss;
|
||||
import de.teamteamteam.spacescooter.entity.enemy.EnemyFour;
|
||||
import de.teamteamteam.spacescooter.entity.enemy.EnemyThree;
|
||||
import de.teamteamteam.spacescooter.entity.item.ItemChance;
|
||||
|
@ -41,9 +42,10 @@ public class GameScreen extends Screen {
|
|||
new HealthBar(10, 5);
|
||||
new ShieldBar(10, 27);
|
||||
new ScoreBar(575, 33);
|
||||
new EnemyFour(800, 400, points);
|
||||
new EnemyThree(650, 300);
|
||||
new EnemyThree(450, 100);
|
||||
//new EnemyFour(800, 400, points);
|
||||
//new EnemyThree(650, 300);
|
||||
//new EnemyThree(450, 100);
|
||||
new EnemyBoss(200, 300);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue