parent
7aeab62b43
commit
793b6d6762
|
|
@ -1,4 +1,5 @@
|
|||
package MAndApps.apps.spacewars.tools;
|
||||
package MAndApps.apps.spacewars;
|
||||
|
||||
|
||||
import java.awt.Graphics;
|
||||
|
||||
|
|
@ -4,9 +4,7 @@ import java.awt.Rectangle;
|
|||
import java.awt.event.KeyEvent;
|
||||
import java.util.Random;
|
||||
|
||||
import MAndApps.apps.spacewars.tools.BasicTickAndRender;
|
||||
|
||||
public abstract class Entity extends BasicTicAndRender{
|
||||
public abstract class Entity extends BasicTickAndRender{
|
||||
private Rectangle boundingBox;
|
||||
private Random r = new Random();
|
||||
public Entity(int x, int y, int width, int height){
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
package MAndApps.apps.spacewars.tools;
|
||||
package MAndApps.apps.spacewars;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.util.Random;
|
||||
|
||||
import MAndApps.apps.spacewars.SpaceWars;
|
||||
|
||||
|
||||
public class Particle extends Entity{
|
||||
private double x, y, life, speed;
|
||||
|
|
@ -2,7 +2,6 @@ package MAndApps.apps.spacewars.entity;
|
|||
|
||||
import MAndApps.apps.spacewars.Entity;
|
||||
import MAndApps.apps.spacewars.entity.bullet.BasicPlayerBullet;
|
||||
import MAndApps.apps.spacewars.entity.bullet.PlayerExplodeBullet;
|
||||
import MAndApps.apps.spacewars.entity.bullet.PlayerImpactBullet;
|
||||
import MAndApps.apps.spacewars.entity.bullet.PlayerPiercingBullet;
|
||||
|
||||
|
|
@ -20,16 +19,6 @@ public abstract class Bullet extends Entity {
|
|||
public static final int PLAYER_PIERCE_EIGHT = 8;
|
||||
public static final int PLAYER_PIERCE_NINE = 9;
|
||||
public static final int PLAYER_PIERCE_TEN = 10;
|
||||
public static final int PLAYER_EXPLOSIVE_ONE = 11;
|
||||
public static final int PLAYER_EXPLOSIVE_TWO = 12;
|
||||
public static final int PLAYER_EXPLOSIVE_THREE = 13;
|
||||
public static final int PLAYER_EXPLOSIVE_FOUR = 14;
|
||||
public static final int PLAYER_EXPLOSIVE_FIVE = 15;
|
||||
public static final int PLAYER_EXPLOSIVE_SIX = 16;
|
||||
public static final int PLAYER_EXPLOSIVE_SEVEN = 17;
|
||||
public static final int PLAYER_EXPLOSIVE_EIGHT = 18;
|
||||
public static final int PLAYER_EXPLOSIVE_NINE = 19;
|
||||
public static final int PLAYER_EXPLOSIVE_TEN = 20;
|
||||
public static final int PLAYER_IMPACT_ONE = 21;
|
||||
public static final int PLAYER_IMPACT_TWO = 22;
|
||||
public static final int PLAYER_IMPACT_THREE = 23;
|
||||
|
|
@ -75,26 +64,6 @@ public abstract class Bullet extends Entity {
|
|||
return 4;
|
||||
case PLAYER_PIERCE_TEN:
|
||||
return 2;
|
||||
case PLAYER_EXPLOSIVE_ONE:
|
||||
return 50;
|
||||
case PLAYER_EXPLOSIVE_TWO:
|
||||
return 48;
|
||||
case PLAYER_EXPLOSIVE_THREE:
|
||||
return 46;
|
||||
case PLAYER_EXPLOSIVE_FOUR:
|
||||
return 44;
|
||||
case PLAYER_EXPLOSIVE_FIVE:
|
||||
return 42;
|
||||
case PLAYER_EXPLOSIVE_SIX:
|
||||
return 40;
|
||||
case PLAYER_EXPLOSIVE_SEVEN:
|
||||
return 38;
|
||||
case PLAYER_EXPLOSIVE_EIGHT:
|
||||
return 36;
|
||||
case PLAYER_EXPLOSIVE_NINE:
|
||||
return 34;
|
||||
case PLAYER_EXPLOSIVE_TEN:
|
||||
return 32;
|
||||
case PLAYER_GODMODE:
|
||||
return 0;
|
||||
default:
|
||||
|
|
@ -139,26 +108,6 @@ public abstract class Bullet extends Entity {
|
|||
return new PlayerPiercingBullet(direction, x, y, 10, false);
|
||||
case PLAYER_PIERCE_TEN:
|
||||
return new PlayerPiercingBullet(direction, x, y, 15, true);
|
||||
case PLAYER_EXPLOSIVE_ONE:
|
||||
return new PlayerExplodeBullet(direction, x, y, 2);
|
||||
case PLAYER_EXPLOSIVE_TWO:
|
||||
return new PlayerExplodeBullet(direction, x, y, 3);
|
||||
case PLAYER_EXPLOSIVE_THREE:
|
||||
return new PlayerExplodeBullet(direction, x , y, 4);
|
||||
case PLAYER_EXPLOSIVE_FOUR:
|
||||
return new PlayerExplodeBullet(direction, x, y, 5);
|
||||
case PLAYER_EXPLOSIVE_FIVE:
|
||||
return new PlayerExplodeBullet(direction, x, y, 6);
|
||||
case PLAYER_EXPLOSIVE_SIX:
|
||||
return new PlayerExplodeBullet(direction, x, y, 7);
|
||||
case PLAYER_EXPLOSIVE_SEVEN:
|
||||
return new PlayerExplodeBullet(direction, x, y, 8);
|
||||
case PLAYER_EXPLOSIVE_EIGHT:
|
||||
return new PlayerExplodeBullet(direction, x, y, 9);
|
||||
case PLAYER_EXPLOSIVE_NINE:
|
||||
return new PlayerExplodeBullet(direction, x, y, 10);
|
||||
case PLAYER_EXPLOSIVE_TEN:
|
||||
return new PlayerExplodeBullet(direction, x, y, 15);
|
||||
case PLAYER_IMPACT_ONE:
|
||||
return new PlayerImpactBullet(direction, x, y, 1);
|
||||
case PLAYER_IMPACT_TWO:
|
||||
|
|
@ -180,7 +129,6 @@ public abstract class Bullet extends Entity {
|
|||
case PLAYER_IMPACT_TEN:
|
||||
return new PlayerImpactBullet(direction, x, y, 10);
|
||||
case PLAYER_GODMODE:
|
||||
return new PlayerExplodeBullet(direction, x, y, 200);
|
||||
default://if the bullet type passed in for this function is not one of the above cases..
|
||||
return new BasicPlayerBullet(direction, x, y);//return it a basic bullet.
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import MAndApps.apps.spacewars.entity.enemy.BlueEnemy;
|
|||
import MAndApps.apps.spacewars.entity.enemy.GreenEnemy;
|
||||
import MAndApps.apps.spacewars.entity.enemy.NormalEnemy;
|
||||
import MAndApps.apps.spacewars.entity.enemy.RedEnemy;
|
||||
import MAndApps.apps.spacewars.tools.Entity;
|
||||
import MAndApps.apps.spacewars.Entity;
|
||||
|
||||
public abstract class Enemy extends Entity {
|
||||
public static final int NORMAL = 0;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import java.util.Random;
|
|||
import MAndApps.apps.spacewars.SpaceWars;
|
||||
import MAndApps.apps.spacewars.gun.Gun;
|
||||
import MAndApps.apps.spacewars.tools.Direction;
|
||||
import MAndApps.apps.spacewars.tools.Entity;
|
||||
import MAndApps.apps.spacewars.Entity;
|
||||
|
||||
public class Player extends Entity {
|
||||
private final static int WIDTH = 16, HEIGHT = 16;
|
||||
|
|
@ -195,74 +195,8 @@ public class Player extends Entity {
|
|||
return alive;
|
||||
}
|
||||
|
||||
public void setLevel(int i) {
|
||||
switch (i) {
|
||||
case 2:
|
||||
gun.switchAmmo(Bullet.PLAYER_PIERCE_ONE);
|
||||
break;
|
||||
case 3:
|
||||
gun.switchAmmo(Bullet.PLAYER_PIERCE_TWO);
|
||||
break;
|
||||
case 4:
|
||||
gun.switchAmmo(Bullet.PLAYER_PIERCE_THREE);
|
||||
break;
|
||||
case 5:
|
||||
gun.switchAmmo(Bullet.PLAYER_PIERCE_FOUR);
|
||||
break;
|
||||
case 6:
|
||||
gun.switchAmmo(Bullet.PLAYER_PIERCE_FIVE);
|
||||
break;
|
||||
case 7:
|
||||
gun.switchAmmo(Bullet.PLAYER_PIERCE_SIX);
|
||||
break;
|
||||
case 8:
|
||||
gun.switchAmmo(Bullet.PLAYER_PIERCE_SEVEN);
|
||||
break;
|
||||
case 9:
|
||||
gun.switchAmmo(Bullet.PLAYER_PIERCE_EIGHT);
|
||||
break;
|
||||
case 10:
|
||||
gun.switchAmmo(Bullet.PLAYER_PIERCE_NINE);
|
||||
break;
|
||||
case 11:
|
||||
gun.switchAmmo(Bullet.PLAYER_PIERCE_TEN);
|
||||
break;
|
||||
case 12:
|
||||
gun.switchAmmo(Bullet.PLAYER_EXPLOSIVE_ONE);
|
||||
break;
|
||||
case 13:
|
||||
gun.switchAmmo(Bullet.PLAYER_EXPLOSIVE_TWO);
|
||||
break;
|
||||
case 14:
|
||||
gun.switchAmmo(Bullet.PLAYER_EXPLOSIVE_THREE);
|
||||
break;
|
||||
case 15:
|
||||
gun.switchAmmo(Bullet.PLAYER_EXPLOSIVE_FOUR);
|
||||
break;
|
||||
case 16:
|
||||
gun.switchAmmo(Bullet.PLAYER_EXPLOSIVE_FIVE);
|
||||
break;
|
||||
case 17:
|
||||
gun.switchAmmo(Bullet.PLAYER_EXPLOSIVE_SIX);
|
||||
break;
|
||||
case 18:
|
||||
gun.switchAmmo(Bullet.PLAYER_EXPLOSIVE_SEVEN);
|
||||
break;
|
||||
case 19:
|
||||
gun.switchAmmo(Bullet.PLAYER_EXPLOSIVE_EIGHT);
|
||||
break;
|
||||
case 20:
|
||||
gun.switchAmmo(Bullet.PLAYER_EXPLOSIVE_NINE);
|
||||
break;
|
||||
case 21:
|
||||
gun.switchAmmo(Bullet.PLAYER_EXPLOSIVE_TEN);
|
||||
break;
|
||||
case 22:
|
||||
gun.switchAmmo(Bullet.PLAYER_GODMODE);
|
||||
break;
|
||||
}
|
||||
if(i >= 22){
|
||||
gun.switchAmmo(Bullet.PLAYER_GODMODE);
|
||||
}
|
||||
@Override
|
||||
public boolean isCollidable() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,98 +0,0 @@
|
|||
package MAndApps.apps.spacewars.entity.bullet;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Rectangle;
|
||||
|
||||
import MAndApps.apps.spacewars.SpaceWars;
|
||||
import MAndApps.apps.spacewars.entity.Bullet;
|
||||
import MAndApps.apps.spacewars.tools.BulletExplosion;
|
||||
import MAndApps.apps.spacewars.tools.Direction;
|
||||
|
||||
public class PlayerExplodeBullet extends Bullet {
|
||||
private BulletExplosion bulletExplosion;
|
||||
private final int direction;
|
||||
private final int WIDTH, HEIGHT;
|
||||
private final static int SPEED = 10;
|
||||
private double x, y;
|
||||
private boolean alive = true;
|
||||
private final int size;
|
||||
private static final double PHI = 1.618033988749894848204586;
|
||||
|
||||
public int getWIDTH(){
|
||||
return WIDTH;
|
||||
}
|
||||
|
||||
public int getHEIGHT(){
|
||||
return HEIGHT;
|
||||
}
|
||||
|
||||
public PlayerExplodeBullet(int direction, int x, int y, int i) {
|
||||
super(x, y, 1, 1);
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.direction = direction;
|
||||
if (direction == Direction.UP || direction == Direction.DOWN) {
|
||||
WIDTH = 3;
|
||||
HEIGHT = 8;
|
||||
} else {
|
||||
WIDTH = 8;
|
||||
HEIGHT = 3;
|
||||
}
|
||||
updateBoundingBox((int) this.x, (int) this.y, WIDTH, HEIGHT);
|
||||
bulletExplosion = new BulletExplosion(i, 1.02, 100, 100, 100, 0, false, i);
|
||||
size = i;
|
||||
|
||||
}
|
||||
|
||||
public int tick() {
|
||||
if (alive) {
|
||||
if (direction == Direction.UP) {
|
||||
y -= SPEED;
|
||||
} else if (direction == Direction.DOWN) {
|
||||
y += SPEED;
|
||||
} else if (direction == Direction.LEFT) {
|
||||
x -= SPEED;
|
||||
} else if (direction == Direction.RIGHT) {
|
||||
x += SPEED;
|
||||
}
|
||||
|
||||
updateBoundingBox((int) x, (int) y, WIDTH, HEIGHT);
|
||||
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());
|
||||
bulletExplosion.goBoom((int)x, (int)y, size * 10, false, size+2);
|
||||
alive = false;
|
||||
i = SpaceWars.getEnemies().size();
|
||||
}
|
||||
}
|
||||
if(x > SpaceWars.getWIDTH() || x < 0 - WIDTH || y > SpaceWars.getHEIGHT() || y < 0 - HEIGHT){
|
||||
alive = false;
|
||||
}
|
||||
}
|
||||
bulletExplosion.tick();
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void render(Graphics g) {
|
||||
g.setColor(Color.BLACK);
|
||||
if (alive)
|
||||
g.fillRect((int) x, (int) y, WIDTH, HEIGHT);
|
||||
bulletExplosion.render(g);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getAlive() {
|
||||
return alive || bulletExplosion.getAlive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDamage() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public boolean isCollidable() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,81 +0,0 @@
|
|||
package MAndApps.apps.spacewars.tools;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.util.Random;
|
||||
import java.util.Stack;
|
||||
|
||||
|
||||
public class BulletExplosion {
|
||||
private Stack<CollisionParticle> bits = new Stack<CollisionParticle>();
|
||||
private Random rand = new Random();
|
||||
private final double SPEED, DECAY;
|
||||
private final int r, g, b, variant;
|
||||
private final boolean singleVariant;
|
||||
private final int damage;
|
||||
public BulletExplosion(double speed, double decay, int r, int g, int b, int variant, boolean singleVariant, int damage){
|
||||
SPEED = speed;
|
||||
DECAY = decay;
|
||||
this.r = r;
|
||||
this.g = g;
|
||||
this.b = b;
|
||||
this.variant = variant;
|
||||
this.singleVariant = singleVariant;
|
||||
this.damage = damage;
|
||||
}
|
||||
public void tick() {
|
||||
for(int i = 0; i < bits.size(); i++)
|
||||
bits.elementAt(i).tick();
|
||||
int i = 0;
|
||||
while(i < bits.size()){
|
||||
if(!bits.elementAt(i).getAlive()){
|
||||
bits.remove(i);
|
||||
}else{
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void render(Graphics g) {
|
||||
for(int i = 0; i < bits.size(); i++)
|
||||
bits.elementAt(i).render(g);
|
||||
//g.setColor(Color.WHITE);
|
||||
//g.drawString("particles: " + bits.size(), 920 - (int)(Math.floor((double)line/20) * 100), 15 + ((line%20)*12));
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
bits.clear();
|
||||
}
|
||||
|
||||
public void goBoom(double x, double y, int size, boolean bubble, int sizeOfParticles) {
|
||||
for(int i = 0; i < size; i++){
|
||||
bits.push(
|
||||
new CollisionParticle(
|
||||
rand.nextInt(360),
|
||||
(rand.nextDouble()*1000)%SPEED,
|
||||
rand.nextInt(100),
|
||||
rand.nextInt(50) + 100,
|
||||
(int)x,
|
||||
(int)y,
|
||||
DECAY,
|
||||
r,
|
||||
g,
|
||||
b,
|
||||
variant,
|
||||
singleVariant,
|
||||
bubble,
|
||||
sizeOfParticles,
|
||||
damage
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean getAlive(){
|
||||
boolean alive = false;
|
||||
for(int i = 0; i < bits.size(); i++)
|
||||
if(bits.elementAt(i).getAlive())
|
||||
alive = true;
|
||||
return alive;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,116 +0,0 @@
|
|||
package MAndApps.apps.spacewars.tools;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Rectangle;
|
||||
import java.util.Random;
|
||||
|
||||
import MAndApps.apps.spacewars.SpaceWars;
|
||||
|
||||
|
||||
public class CollisionParticle extends Entity {
|
||||
private double x, y, life, speed;
|
||||
private final int angleDeg, moveLife, renderLife, size;
|
||||
private final double DECAY;
|
||||
private boolean alive = false, bubble;
|
||||
private Random rand = new Random();
|
||||
private Color color;
|
||||
private final int damage;
|
||||
private boolean active = true;
|
||||
|
||||
public CollisionParticle(int angle, double speed, int movelife,
|
||||
int renderlife, int x, int y, double speedDecay, int r, int g,
|
||||
int b, int variant, boolean singleVariant, boolean bubble,
|
||||
int sizeOfParticles, int damage) {
|
||||
super(0, 0, 1, 1);
|
||||
renderLife = renderlife;
|
||||
this.speed = speed;
|
||||
angleDeg = angle;
|
||||
this.x = x;
|
||||
moveLife = movelife;
|
||||
this.y = y;
|
||||
alive = true;
|
||||
size = rand.nextInt(sizeOfParticles);
|
||||
DECAY = speedDecay;
|
||||
int i = 0;
|
||||
this.bubble = bubble;
|
||||
if (!bubble) {
|
||||
if (!singleVariant) {
|
||||
while (i < 10) {
|
||||
try {
|
||||
color = new Color(r + rand.nextInt(variant * 2)
|
||||
- variant, g + rand.nextInt(variant * 2)
|
||||
- variant, b + rand.nextInt(variant * 2)
|
||||
- variant);
|
||||
i = 10;
|
||||
} catch (IllegalArgumentException e) {
|
||||
i++;
|
||||
if (i >= 10) {
|
||||
color = new Color(r, g, b);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
while (i < 10) {
|
||||
try {
|
||||
int tempVar = rand.nextInt(variant * 2) - variant;
|
||||
color = new Color(r + tempVar, g + tempVar, b + tempVar);
|
||||
i = 10;
|
||||
} catch (IllegalArgumentException e) {
|
||||
i++;
|
||||
if (i >= 10) {
|
||||
color = new Color(r, g, b);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
color = new Color(rand(0, 256), rand(0, 256), rand(0, 256));
|
||||
}
|
||||
this.damage = damage;
|
||||
}
|
||||
|
||||
public int tick() {
|
||||
if (life < moveLife) {
|
||||
x += Math.cos(((double) angleDeg * Math.PI) / 180d) * speed;
|
||||
y += Math.sin(((double) angleDeg * Math.PI) / 180d) * speed;
|
||||
}
|
||||
speed /= DECAY;
|
||||
if (life > renderLife)
|
||||
alive = false;
|
||||
if(life > moveLife){
|
||||
active = false;
|
||||
}
|
||||
if (x > SpaceWars.getWIDTH() || x < 0 - size
|
||||
|| y > SpaceWars.getHEIGHT() || y < 0 - size) {
|
||||
alive = false;
|
||||
}
|
||||
life++;
|
||||
if(active){
|
||||
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(damage);
|
||||
//active = false;
|
||||
i = SpaceWars.getEnemies().size();
|
||||
}
|
||||
}
|
||||
}
|
||||
updateBoundingBox((int) x, (int) y, size, size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void render(Graphics g) {
|
||||
if (alive) {
|
||||
g.setColor(color);
|
||||
if (bubble)
|
||||
g.drawOval((int) x, (int) y, size, size);
|
||||
else
|
||||
g.fillRect((int) x, (int) y, size, size);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean getAlive() {
|
||||
return alive;
|
||||
}
|
||||
}
|
||||
|
|
@ -5,6 +5,8 @@ import java.awt.Graphics;
|
|||
import java.util.Random;
|
||||
import java.util.Stack;
|
||||
|
||||
import MAndApps.apps.spacewars.Particle;
|
||||
|
||||
|
||||
public class Explosion {
|
||||
private Stack<Particle> bits = new Stack<Particle>();
|
||||
|
|
|
|||
Loading…
Reference in New Issue