more refactoring and reorganizing.
parent
793b6d6762
commit
24a2056c34
|
|
@ -30,4 +30,10 @@ public abstract class Entity extends BasicTickAndRender{
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract boolean isCollidable();
|
public abstract boolean isCollidable();
|
||||||
|
|
||||||
|
public abstract void die();
|
||||||
|
|
||||||
|
public abstract boolean getAlive();
|
||||||
|
|
||||||
|
public abstract void collidedWith(Entity e);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -101,4 +101,16 @@ public class Particle extends Entity{
|
||||||
public boolean isCollidable() {
|
public boolean isCollidable() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void die() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collidedWith(Entity e) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,8 @@ import javax.imageio.ImageIO;
|
||||||
|
|
||||||
import MAndApps.apps.spacewars.entity.Enemy;
|
import MAndApps.apps.spacewars.entity.Enemy;
|
||||||
import MAndApps.apps.spacewars.entity.Player;
|
import MAndApps.apps.spacewars.entity.Player;
|
||||||
|
import MAndApps.apps.spacewars.entity.enemy.NormalEnemy;
|
||||||
|
import MAndApps.apps.spacewars.entity.enemy.RedEnemy;
|
||||||
import MAndApps.apps.spacewars.tools.Explosion;
|
import MAndApps.apps.spacewars.tools.Explosion;
|
||||||
import MAndEngine.BasicApp;
|
import MAndEngine.BasicApp;
|
||||||
|
|
||||||
|
|
@ -27,10 +29,8 @@ public class SpaceWars implements BasicApp {
|
||||||
private static boolean debug = false;
|
private static boolean debug = false;
|
||||||
private static final int WIDTH = 1024, HEIGHT = 600;
|
private static final int WIDTH = 1024, HEIGHT = 600;
|
||||||
private static Image background;
|
private static Image background;
|
||||||
private static Random r = new Random();
|
private static ArrayList<Entity> entities = new ArrayList<Entity>();
|
||||||
private static ArrayList<Enemy> entities = new ArrayList<Enemy>();
|
|
||||||
private static Player player = new Player();
|
private static Player player = new Player();
|
||||||
private static ArrayList<Explosion> explosions = new ArrayList<Explosion>();
|
|
||||||
|
|
||||||
//
|
//
|
||||||
public static final Font defaultFont = new Font("Ubuntu", Font.BOLD, 10);
|
public static final Font defaultFont = new Font("Ubuntu", Font.BOLD, 10);
|
||||||
|
|
@ -45,44 +45,36 @@ public class SpaceWars implements BasicApp {
|
||||||
for (int i = 0; i < entities.size(); i++)
|
for (int i = 0; i < entities.size(); i++)
|
||||||
entities.get(i).tick();
|
entities.get(i).tick();
|
||||||
|
|
||||||
// tick explosions
|
// check dem collisions yo
|
||||||
for (int i = 0; i < explosions.size(); i++)
|
for (int i = 0; i < entities.size(); i++) {
|
||||||
explosions.get(i).tick();
|
Entity e1 = entities.get(i);
|
||||||
|
if (e1.isCollidable()) {
|
||||||
|
for (int j = i + 1; j < entities.size(); j++) {
|
||||||
|
Entity e2 = entities.get(j);
|
||||||
|
if(e2.isCollidable()) {
|
||||||
|
|
||||||
// tick player object
|
//because efficiency.
|
||||||
Rectangle playerRect = player.getBoundingBox();
|
e1.collidedWith(e2);
|
||||||
if (player.getAlive())
|
e2.collidedWith(e1);
|
||||||
for (int i = 0; i < entities.size(); i++)
|
|
||||||
if (entities.get(i).isCollidable() && entities.get(i).getBoundingBox().intersects(playerRect))
|
|
||||||
player.collideWithEnemy(entities.get(i).getX(), entities.get(i).getY());
|
|
||||||
|
|
||||||
int i = 0;
|
}
|
||||||
while (i < entities.size()) {
|
}
|
||||||
if (!entities.get(i).getAlive()) {
|
}
|
||||||
|
|
||||||
BOOM( 75, 1.2, entities.get(i).getColor().getRed()-50,
|
}
|
||||||
entities.get(i).getColor().getGreen()-50,
|
|
||||||
entities.get(i).getColor().getBlue()-50, 50,
|
|
||||||
(int)entities.get(i).getX(),
|
|
||||||
(int)entities.get(i).getY(), 550, true, true, 10 );
|
|
||||||
|
|
||||||
|
// cleanup method.
|
||||||
|
for (int i = 0; i < entities.size();) {
|
||||||
|
Entity entity = entities.get(i);
|
||||||
|
if (!entity.getAlive()) {
|
||||||
|
entity.die();
|
||||||
entities.remove(i);
|
entities.remove(i);
|
||||||
|
|
||||||
} else
|
} else
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (i < explosions.size()) {
|
|
||||||
if (!explosions.get(i).getAlive()) {
|
|
||||||
explosions.remove(i);
|
|
||||||
} else {
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<Enemy> getEnemies() {
|
public static ArrayList<Entity> getEnemies() {
|
||||||
return entities;
|
return entities;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -97,10 +89,6 @@ public class SpaceWars implements BasicApp {
|
||||||
g.setFont(defaultFont);
|
g.setFont(defaultFont);
|
||||||
g.drawImage(background, 0, 0, WIDTH, HEIGHT, null);
|
g.drawImage(background, 0, 0, WIDTH, HEIGHT, null);
|
||||||
|
|
||||||
for (int i = 0; i < explosions.size(); i++)
|
|
||||||
explosions.get(i).render(g, i);
|
|
||||||
|
|
||||||
player.render(g);
|
|
||||||
for (int i = 0; i < entities.size(); i++)
|
for (int i = 0; i < entities.size(); i++)
|
||||||
entities.get(i).render(g);
|
entities.get(i).render(g);
|
||||||
|
|
||||||
|
|
@ -136,6 +124,10 @@ public class SpaceWars implements BasicApp {
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
try {
|
try {
|
||||||
background = ImageIO.read(new URL("http://wallpaperswiki.org/wallpapers/2012/11/Wallpaper-Abstract-Wallpaper-Background-Texture-Texture-Yellow-Pictures-600x1024.jpg"));
|
background = ImageIO.read(new URL("http://wallpaperswiki.org/wallpapers/2012/11/Wallpaper-Abstract-Wallpaper-Background-Texture-Texture-Yellow-Pictures-600x1024.jpg"));
|
||||||
|
entities.add(player);
|
||||||
|
entities.add(new NormalEnemy(0, 0));
|
||||||
|
entities.add(new NormalEnemy(0, 0));
|
||||||
|
entities.add(new NormalEnemy(0, 0));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
background = (Image) new BufferedImage(1024, 600, BufferedImage.TRANSLUCENT);
|
background = (Image) new BufferedImage(1024, 600, BufferedImage.TRANSLUCENT);
|
||||||
Graphics g = background.getGraphics();
|
Graphics g = background.getGraphics();
|
||||||
|
|
@ -180,7 +172,7 @@ public class SpaceWars implements BasicApp {
|
||||||
|
|
||||||
Explosion explosion = new Explosion(speed, decay, r, g, b, variant, singleVariant);
|
Explosion explosion = new Explosion(speed, decay, r, g, b, variant, singleVariant);
|
||||||
|
|
||||||
explosions.add(explosion);
|
entities.add((Entity) explosion);
|
||||||
explosion.goBoom(x, y, size, bubble, sizeOfParticles);
|
explosion.goBoom(x, y, size, bubble, sizeOfParticles);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import MAndApps.apps.spacewars.entity.enemy.GreenEnemy;
|
||||||
import MAndApps.apps.spacewars.entity.enemy.NormalEnemy;
|
import MAndApps.apps.spacewars.entity.enemy.NormalEnemy;
|
||||||
import MAndApps.apps.spacewars.entity.enemy.RedEnemy;
|
import MAndApps.apps.spacewars.entity.enemy.RedEnemy;
|
||||||
import MAndApps.apps.spacewars.Entity;
|
import MAndApps.apps.spacewars.Entity;
|
||||||
|
import MAndApps.apps.spacewars.SpaceWars;
|
||||||
|
|
||||||
public abstract class Enemy extends Entity {
|
public abstract class Enemy extends Entity {
|
||||||
public static final int NORMAL = 0;
|
public static final int NORMAL = 0;
|
||||||
|
|
@ -57,4 +58,12 @@ public abstract class Enemy extends Entity {
|
||||||
public abstract void damage(int damage);
|
public abstract void damage(int damage);
|
||||||
|
|
||||||
public abstract boolean isCollidable();
|
public abstract boolean isCollidable();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collidedWith(Entity e) {
|
||||||
|
if(e instanceof Bullet) {
|
||||||
|
Bullet b = (Bullet)e;
|
||||||
|
damage(b.getDamage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,11 @@ public class Player extends Entity {
|
||||||
private boolean A = false, S = false, D = false, W = false, alive = true;
|
private boolean A = false, S = false, D = false, W = false, alive = true;
|
||||||
private Random r = new Random();
|
private Random r = new Random();
|
||||||
private Gun gun = new Gun(Bullet.BASIC, 25, (int)x, (int)y);
|
private Gun gun = new Gun(Bullet.BASIC, 25, (int)x, (int)y);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* go boom is a callback when it dies because it dies on tick i assume?
|
||||||
|
* TODO fix that so no die on tick.
|
||||||
|
*/
|
||||||
private boolean goBoom = false;
|
private boolean goBoom = false;
|
||||||
|
|
||||||
public Player() {
|
public Player() {
|
||||||
|
|
@ -130,67 +135,6 @@ public class Player extends Entity {
|
||||||
|
|
||||||
private double time = 0;
|
private double time = 0;
|
||||||
|
|
||||||
@Override
|
|
||||||
public void keyPressed(KeyEvent e) {
|
|
||||||
switch (e.getKeyCode()) {
|
|
||||||
case KeyEvent.VK_W:
|
|
||||||
W = true;
|
|
||||||
break;
|
|
||||||
case KeyEvent.VK_D:
|
|
||||||
D = true;
|
|
||||||
break;
|
|
||||||
case KeyEvent.VK_S:
|
|
||||||
S = true;
|
|
||||||
break;
|
|
||||||
case KeyEvent.VK_A:
|
|
||||||
A = true;
|
|
||||||
break;
|
|
||||||
case KeyEvent.VK_I:
|
|
||||||
shoot(Direction.UP);
|
|
||||||
break;
|
|
||||||
case KeyEvent.VK_J:
|
|
||||||
shoot(Direction.LEFT);
|
|
||||||
break;
|
|
||||||
case KeyEvent.VK_K:
|
|
||||||
shoot(Direction.DOWN);
|
|
||||||
break;
|
|
||||||
case KeyEvent.VK_L:
|
|
||||||
shoot(Direction.RIGHT);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void shoot(int direction) {
|
|
||||||
gun.updatePosition((int)x + WIDTH/2, (int)y + HEIGHT/2);
|
|
||||||
gun.shoot(direction);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void keyReleased(KeyEvent e) {
|
|
||||||
switch (e.getKeyCode()) {
|
|
||||||
case KeyEvent.VK_W:
|
|
||||||
W = false;
|
|
||||||
break;
|
|
||||||
case KeyEvent.VK_D:
|
|
||||||
D = false;
|
|
||||||
break;
|
|
||||||
case KeyEvent.VK_S:
|
|
||||||
S = false;
|
|
||||||
break;
|
|
||||||
case KeyEvent.VK_A:
|
|
||||||
A = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void collideWithEnemy(double x, double y) {
|
|
||||||
goBoom = true;
|
|
||||||
timer = 0;
|
|
||||||
alive = false;
|
|
||||||
time = 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getAlive() {
|
public boolean getAlive() {
|
||||||
return alive;
|
return alive;
|
||||||
}
|
}
|
||||||
|
|
@ -199,4 +143,20 @@ public class Player extends Entity {
|
||||||
public boolean isCollidable() {
|
public boolean isCollidable() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void die() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collidedWith(Entity e) {
|
||||||
|
if(e instanceof Enemy) {
|
||||||
|
goBoom = true;
|
||||||
|
timer = 0;
|
||||||
|
alive = false;
|
||||||
|
time = 5;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import java.awt.Color;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
|
|
||||||
|
import MAndApps.apps.spacewars.Entity;
|
||||||
import MAndApps.apps.spacewars.SpaceWars;
|
import MAndApps.apps.spacewars.SpaceWars;
|
||||||
import MAndApps.apps.spacewars.entity.Bullet;
|
import MAndApps.apps.spacewars.entity.Bullet;
|
||||||
import MAndApps.apps.spacewars.tools.Direction;
|
import MAndApps.apps.spacewars.tools.Direction;
|
||||||
|
|
@ -15,6 +16,7 @@ public class BasicPlayerBullet extends Bullet {
|
||||||
private double x, y;
|
private double x, y;
|
||||||
private boolean alive = true;
|
private boolean alive = true;
|
||||||
|
|
||||||
|
|
||||||
public BasicPlayerBullet(int direction, int x, int y) {
|
public BasicPlayerBullet(int direction, int x, int y) {
|
||||||
super(x, y, 1, 1);
|
super(x, y, 1, 1);
|
||||||
this.x = x;
|
this.x = x;
|
||||||
|
|
@ -42,15 +44,11 @@ public class BasicPlayerBullet extends Bullet {
|
||||||
x += SPEED;
|
x += SPEED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
updateBoundingBox((int) x, (int) y, WIDTH, HEIGHT);
|
updateBoundingBox((int) x, (int) y, WIDTH, HEIGHT);
|
||||||
Rectangle r = getBoundingBox();
|
Rectangle r = getBoundingBox();
|
||||||
for (int i = 0; i < SpaceWars.getEnemies().size(); i++) {
|
|
||||||
if (r.intersects(SpaceWars.getEnemies().get(i).getBoundingBox())) {
|
//if out of bound
|
||||||
SpaceWars.getEnemies().get(i).damage(getDamage());
|
|
||||||
alive = false;
|
|
||||||
i = SpaceWars.getEnemies().size();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(x > SpaceWars.getWIDTH() || x < 0 - WIDTH || y > SpaceWars.getHEIGHT() || y < 0 - HEIGHT){
|
if(x > SpaceWars.getWIDTH() || x < 0 - WIDTH || y > SpaceWars.getHEIGHT() || y < 0 - HEIGHT){
|
||||||
alive = false;
|
alive = false;
|
||||||
}
|
}
|
||||||
|
|
@ -86,4 +84,16 @@ public class BasicPlayerBullet extends Bullet {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void die() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collidedWith(Entity e) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import java.awt.Color;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
|
|
||||||
|
import MAndApps.apps.spacewars.Entity;
|
||||||
import MAndApps.apps.spacewars.SpaceWars;
|
import MAndApps.apps.spacewars.SpaceWars;
|
||||||
import MAndApps.apps.spacewars.entity.Bullet;
|
import MAndApps.apps.spacewars.entity.Bullet;
|
||||||
import MAndApps.apps.spacewars.tools.Direction;
|
import MAndApps.apps.spacewars.tools.Direction;
|
||||||
|
|
@ -54,13 +55,7 @@ public class PlayerImpactBullet extends Bullet {
|
||||||
|
|
||||||
updateBoundingBox((int) x, (int) y, WIDTH, HEIGHT);
|
updateBoundingBox((int) x, (int) y, WIDTH, HEIGHT);
|
||||||
Rectangle r = getBoundingBox();
|
Rectangle r = getBoundingBox();
|
||||||
for (int i = 0; i < SpaceWars.getEnemies().size(); i++) {
|
|
||||||
if (r.intersects(SpaceWars.getEnemies().get(i).getBoundingBox())) {
|
|
||||||
SpaceWars.getEnemies().get(i).damage(getDamage());
|
|
||||||
alive = false;
|
|
||||||
i = SpaceWars.getEnemies().size();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(x > SpaceWars.getWIDTH() || x < 0 - WIDTH || y > SpaceWars.getHEIGHT() || y < 0 - HEIGHT){
|
if(x > SpaceWars.getWIDTH() || x < 0 - WIDTH || y > SpaceWars.getHEIGHT() || y < 0 - HEIGHT){
|
||||||
alive = false;
|
alive = false;
|
||||||
}
|
}
|
||||||
|
|
@ -87,4 +82,16 @@ public class PlayerImpactBullet extends Bullet {
|
||||||
public boolean isCollidable() {
|
public boolean isCollidable() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void die() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collidedWith(Entity e) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package MAndApps.apps.spacewars.entity.bullet;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
|
|
||||||
|
import MAndApps.apps.spacewars.Entity;
|
||||||
import MAndApps.apps.spacewars.SpaceWars;
|
import MAndApps.apps.spacewars.SpaceWars;
|
||||||
import MAndApps.apps.spacewars.entity.Bullet;
|
import MAndApps.apps.spacewars.entity.Bullet;
|
||||||
import MAndApps.apps.spacewars.tools.Direction;
|
import MAndApps.apps.spacewars.tools.Direction;
|
||||||
|
|
@ -61,16 +62,7 @@ public class PlayerPiercingBullet extends Bullet {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
updateBoundingBox((int) x, (int) y, WIDTH, HEIGHT);
|
updateBoundingBox((int) x, (int) y, WIDTH, HEIGHT);
|
||||||
for (int i = 0; i < SpaceWars.getEnemies().size() && hits < MAX_HITS; i++) {
|
|
||||||
if (SpaceWars.getEnemies().get(i).getBoundingBox().intersectsLine((int)x, (int)y, (int)oldX, (int)oldY)) {
|
|
||||||
hits++;
|
|
||||||
SpaceWars.getEnemies().get(i).damage(getDamage());
|
|
||||||
if(hits >= MAX_HITS){
|
|
||||||
alive = false;
|
|
||||||
i = SpaceWars.getEnemies().size();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(x > SpaceWars.getWIDTH() || x < 0 - WIDTH || y > SpaceWars.getHEIGHT() || y < 0 - HEIGHT){
|
if(x > SpaceWars.getWIDTH() || x < 0 - WIDTH || y > SpaceWars.getHEIGHT() || y < 0 - HEIGHT){
|
||||||
alive = false;
|
alive = false;
|
||||||
}
|
}
|
||||||
|
|
@ -98,4 +90,16 @@ public class PlayerPiercingBullet extends Bullet {
|
||||||
public boolean isCollidable() {
|
public boolean isCollidable() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void die() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collidedWith(Entity e) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import java.awt.Color;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import MAndApps.apps.spacewars.Entity;
|
||||||
import MAndApps.apps.spacewars.SpaceWars;
|
import MAndApps.apps.spacewars.SpaceWars;
|
||||||
import MAndApps.apps.spacewars.entity.Enemy;
|
import MAndApps.apps.spacewars.entity.Enemy;
|
||||||
|
|
||||||
|
|
@ -178,4 +179,16 @@ public class BlueEnemy extends Enemy {
|
||||||
public boolean isCollidable() {
|
public boolean isCollidable() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void die() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collidedWith(Entity e) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import java.awt.Color;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import MAndApps.apps.spacewars.Entity;
|
||||||
import MAndApps.apps.spacewars.SpaceWars;
|
import MAndApps.apps.spacewars.SpaceWars;
|
||||||
import MAndApps.apps.spacewars.entity.Enemy;
|
import MAndApps.apps.spacewars.entity.Enemy;
|
||||||
|
|
||||||
|
|
@ -185,4 +186,16 @@ public class GreenEnemy extends Enemy {
|
||||||
public boolean isCollidable() {
|
public boolean isCollidable() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void die() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collidedWith(Entity e) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import java.awt.Color;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import MAndApps.apps.spacewars.Entity;
|
||||||
import MAndApps.apps.spacewars.SpaceWars;
|
import MAndApps.apps.spacewars.SpaceWars;
|
||||||
import MAndApps.apps.spacewars.entity.Enemy;
|
import MAndApps.apps.spacewars.entity.Enemy;
|
||||||
|
|
||||||
|
|
@ -179,4 +180,16 @@ public class NormalEnemy extends Enemy {
|
||||||
public boolean isCollidable() {
|
public boolean isCollidable() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void die() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collidedWith(Entity e) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import java.awt.Color;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import MAndApps.apps.spacewars.Entity;
|
||||||
import MAndApps.apps.spacewars.SpaceWars;
|
import MAndApps.apps.spacewars.SpaceWars;
|
||||||
import MAndApps.apps.spacewars.entity.Enemy;
|
import MAndApps.apps.spacewars.entity.Enemy;
|
||||||
|
|
||||||
|
|
@ -176,4 +177,16 @@ public class RedEnemy extends Enemy {
|
||||||
public boolean isCollidable() {
|
public boolean isCollidable() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void die() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collidedWith(Entity e) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,16 +5,18 @@ import java.awt.Graphics;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
|
||||||
|
import MAndApps.apps.spacewars.Entity;
|
||||||
import MAndApps.apps.spacewars.Particle;
|
import MAndApps.apps.spacewars.Particle;
|
||||||
|
|
||||||
|
|
||||||
public class Explosion {
|
public class Explosion extends Entity{
|
||||||
private Stack<Particle> bits = new Stack<Particle>();
|
private Stack<Particle> bits = new Stack<Particle>();
|
||||||
private Random rand = new Random();
|
private Random rand = new Random();
|
||||||
private final double SPEED, DECAY;
|
private final double SPEED, DECAY;
|
||||||
private final int r, g, b, variant;
|
private final int r, g, b, variant;
|
||||||
private final boolean singleVariant;
|
private final boolean singleVariant;
|
||||||
public Explosion(double speed, double decay, int r, int g, int b, int variant, boolean singleVariant){
|
public Explosion(double speed, double decay, int r, int g, int b, int variant, boolean singleVariant){
|
||||||
|
super(0, 0, 1, 1);
|
||||||
SPEED = speed;
|
SPEED = speed;
|
||||||
DECAY = decay;
|
DECAY = decay;
|
||||||
this.r = r;
|
this.r = r;
|
||||||
|
|
@ -23,7 +25,8 @@ public class Explosion {
|
||||||
this.variant = variant;
|
this.variant = variant;
|
||||||
this.singleVariant = singleVariant;
|
this.singleVariant = singleVariant;
|
||||||
}
|
}
|
||||||
public void tick() {
|
|
||||||
|
public int tick() {
|
||||||
for(int i = 0; i < bits.size(); i++)
|
for(int i = 0; i < bits.size(); i++)
|
||||||
bits.elementAt(i).tick();
|
bits.elementAt(i).tick();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
@ -34,6 +37,7 @@ public class Explosion {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render(Graphics g, int line) {
|
public void render(Graphics g, int line) {
|
||||||
|
|
@ -77,5 +81,27 @@ public class Explosion {
|
||||||
alive = true;
|
alive = true;
|
||||||
return alive;
|
return alive;
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public boolean isCollidable() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void render(Graphics g) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void die() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collidedWith(Entity e) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue