core stuff almost done, now refactoring.
parent
172ffbc4aa
commit
7aeab62b43
|
|
@ -43,3 +43,4 @@ Icon
|
|||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
/bin/
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import java.util.Random;
|
|||
|
||||
import MAndApps.apps.spacewars.tools.BasicTickAndRender;
|
||||
|
||||
public abstract class Entity extends BasicTickAndRender{
|
||||
public abstract class Entity extends BasicTicAndRender{
|
||||
private Rectangle boundingBox;
|
||||
private Random r = new Random();
|
||||
public Entity(int x, int y, int width, int height){
|
||||
|
|
@ -30,4 +30,6 @@ public abstract class Entity extends BasicTickAndRender{
|
|||
public Rectangle getBoundingBox(){
|
||||
return boundingBox;
|
||||
}
|
||||
|
||||
public abstract boolean isCollidable();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,33 +11,26 @@ import java.awt.RenderingHints;
|
|||
import java.awt.event.KeyEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
import java.util.Stack;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import MAndApps.apps.spacewars.entity.Enemy;
|
||||
import MAndApps.apps.spacewars.entity.Player;
|
||||
import MAndApps.apps.spacewars.shop.Shop;
|
||||
import MAndApps.apps.spacewars.tools.Explosion;
|
||||
import MAndEngine.BasicApp;
|
||||
import MAndEngine.Engine;
|
||||
|
||||
public class SpaceWars implements BasicApp {
|
||||
|
||||
//
|
||||
private static boolean paused = false, debug = false;
|
||||
private static int redPoints = 0, bluePoints = 0, greenPoints = 0, time = 0;
|
||||
private static boolean debug = false;
|
||||
private static final int WIDTH = 1024, HEIGHT = 600;
|
||||
private static Player player = new Player();
|
||||
private static Image background;
|
||||
private static Random r = new Random();
|
||||
private static Stack<Enemy> enemies = new Stack<Enemy>();
|
||||
private static Stack<Explosion> explosions = new Stack<Explosion>();
|
||||
private static Stack<String> logs = new Stack<String>();
|
||||
private static int lvl = 1, xpToNextLVL = getMaxXPForLvl(lvl), xp = 0, expBar = 424;
|
||||
private static boolean shopping = false;
|
||||
private Shop shop = new Shop();
|
||||
private static ArrayList<Enemy> entities = new ArrayList<Enemy>();
|
||||
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);
|
||||
|
|
@ -47,41 +40,33 @@ public class SpaceWars implements BasicApp {
|
|||
|
||||
@Override
|
||||
public void tick() {
|
||||
addEXP(1);
|
||||
if (!paused && !shopping) {
|
||||
time++;
|
||||
// ticks enemy stack
|
||||
for (int i = 0; i < enemies.size(); i++)
|
||||
enemies.elementAt(i).tick();
|
||||
|
||||
// ticks enemies
|
||||
for (int i = 0; i < entities.size(); i++)
|
||||
entities.get(i).tick();
|
||||
|
||||
// tick explosions
|
||||
for (int i = 0; i < explosions.size(); i++)
|
||||
explosions.elementAt(i).tick();
|
||||
// tick player class
|
||||
player.tick();
|
||||
explosions.get(i).tick();
|
||||
|
||||
// tick player object
|
||||
Rectangle playerRect = player.getBoundingBox();
|
||||
if (player.getAlive())
|
||||
for (int i = 0; i < enemies.size(); i++)
|
||||
if (enemies.elementAt(i).getBoundingBox().intersects(playerRect))
|
||||
player.collideWithEnemy(enemies.elementAt(i).getX(), enemies.elementAt(i).getY());
|
||||
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 < enemies.size()) {
|
||||
if (!enemies.elementAt(i).getAlive()) {
|
||||
/*
|
||||
* BOOM( 75, 1.2,
|
||||
* enemies.elementAt(i).getColor().getRed()-50,
|
||||
* enemies.elementAt(i).getColor().getGreen()-50,
|
||||
* enemies.elementAt(i).getColor().getBlue()-50, 50,
|
||||
* (int)enemies.elementAt(i).getX(),
|
||||
* (int)enemies.elementAt(i).getY(), 550, true, true, 10 );
|
||||
*/
|
||||
while (i < entities.size()) {
|
||||
if (!entities.get(i).getAlive()) {
|
||||
|
||||
addRedPoints(enemies.elementAt(i).getColor().getRed());
|
||||
addGreenPoints(enemies.elementAt(i).getColor().getGreen());
|
||||
addBluePoints(enemies.elementAt(i).getColor().getBlue());
|
||||
log("You gained " + enemies.elementAt(i).getWorth() + " exp.");
|
||||
addEXP(enemies.elementAt(i).getWorth());
|
||||
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 );
|
||||
|
||||
// enemies.remove(i);
|
||||
entities.remove(i);
|
||||
|
||||
} else
|
||||
i++;
|
||||
|
|
@ -89,28 +74,16 @@ public class SpaceWars implements BasicApp {
|
|||
|
||||
i = 0;
|
||||
while (i < explosions.size()) {
|
||||
if (!explosions.elementAt(i).getAlive()) {
|
||||
if (!explosions.get(i).getAlive()) {
|
||||
explosions.remove(i);
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
expBar += ((int) (((double) xp / (double) xpToNextLVL) * 424) - expBar) / 10;
|
||||
}
|
||||
shop.tick();
|
||||
// check if there are any new items to log
|
||||
int cap = logs.size();
|
||||
for (int i = 0; i < cap; i++)
|
||||
Engine.log(logs.pop());
|
||||
}
|
||||
|
||||
public static void log(String s) {
|
||||
logs.push(s);
|
||||
}
|
||||
|
||||
public static Stack<Enemy> getEnemies() {
|
||||
return enemies;
|
||||
public static ArrayList<Enemy> getEnemies() {
|
||||
return entities;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -118,44 +91,19 @@ public class SpaceWars implements BasicApp {
|
|||
|
||||
try {
|
||||
|
||||
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
|
||||
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
|
||||
|
||||
g.setFont(defaultFont);
|
||||
g.drawImage(background, 0, 0, WIDTH, HEIGHT, null);
|
||||
|
||||
for (int i = 0; i < explosions.size(); i++)
|
||||
explosions.elementAt(i).render(g, i);
|
||||
explosions.get(i).render(g, i);
|
||||
|
||||
player.render(g);
|
||||
for (int i = 0; i < enemies.size(); i++)
|
||||
enemies.elementAt(i).render(g);
|
||||
for (int i = 0; i < entities.size(); i++)
|
||||
entities.get(i).render(g);
|
||||
|
||||
// render points
|
||||
g.setFont(moneyFont);
|
||||
g.setColor(Color.RED);
|
||||
g.drawString(redPointsToString(), 10, HEIGHT - 10 - (20 * 3));
|
||||
g.setColor(Color.GREEN);
|
||||
g.drawString(greenPointsToString(), 10, HEIGHT - 10 - (20 * 2));
|
||||
g.setColor(Color.BLUE);
|
||||
g.drawString(bluePointsToString(), 10, HEIGHT - 10 - (20 * 1));
|
||||
g.setFont(defaultFont);
|
||||
|
||||
// render level and xp bar.
|
||||
g.setFont(levelFont);
|
||||
g.setColor(Color.WHITE);
|
||||
g.drawString("" + lvl, 300 - ((("" + lvl).length() - 1) * 20), 40);
|
||||
g.drawRect(330, 18, 424, 15);
|
||||
g.fillRect(330, 18, expBar, 15);
|
||||
g.setFont(defaultFont);
|
||||
|
||||
if (paused) {
|
||||
g.setFont(pausedFont);
|
||||
g.setColor(Color.WHITE);
|
||||
g.drawString("Paused", 410, 280);
|
||||
g.setFont(defaultFont);
|
||||
}
|
||||
shop.render(g, WIDTH);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
@ -187,7 +135,7 @@ public class SpaceWars implements BasicApp {
|
|||
@Override
|
||||
public void initialize() {
|
||||
try {
|
||||
background = ImageIO.read(new URL("http://wallpapersus.com/wallpapers/2012/10/Cool-Wave-600x1024.jpg"));
|
||||
background = ImageIO.read(new URL("http://wallpaperswiki.org/wallpapers/2012/11/Wallpaper-Abstract-Wallpaper-Background-Texture-Texture-Yellow-Pictures-600x1024.jpg"));
|
||||
} catch (Exception e) {
|
||||
background = (Image) new BufferedImage(1024, 600, BufferedImage.TRANSLUCENT);
|
||||
Graphics g = background.getGraphics();
|
||||
|
|
@ -198,27 +146,14 @@ public class SpaceWars implements BasicApp {
|
|||
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
player.keyPressed(e);
|
||||
for (int i = 0; i < enemies.size(); i++)
|
||||
enemies.elementAt(i).keyPressed(e);
|
||||
if (e.getKeyCode() == KeyEvent.VK_P || e.getKeyCode() == KeyEvent.VK_SPACE) {
|
||||
paused = !paused;
|
||||
} else if (e.getKeyCode() == KeyEvent.VK_E) {
|
||||
xp = xpToNextLVL - 1;
|
||||
} else if (e.getKeyCode() == KeyEvent.VK_Q) {
|
||||
debug = !debug;
|
||||
} else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
|
||||
shopping = !shopping;
|
||||
shop.toggleState();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
player.keyReleased(e);
|
||||
for (int i = 0; i < enemies.size(); i++)
|
||||
enemies.elementAt(i).keyReleased(e);
|
||||
shop.keyReleased(e);
|
||||
for (int i = 0; i < entities.size(); i++)
|
||||
entities.get(i).keyReleased(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -242,83 +177,16 @@ public class SpaceWars implements BasicApp {
|
|||
}
|
||||
|
||||
public static void BOOM(double speed, double decay, int r, int g, int b, int variant, int x, int y, int size, boolean singleVariant, boolean bubble, int sizeOfParticles) {
|
||||
explosions.push(new Explosion(speed, decay, r, g, b, variant, singleVariant));
|
||||
explosions.peek().goBoom(x, y, size, bubble, sizeOfParticles);
|
||||
}
|
||||
|
||||
public void addRedPoints(int d) {
|
||||
redPoints += d;
|
||||
}
|
||||
Explosion explosion = new Explosion(speed, decay, r, g, b, variant, singleVariant);
|
||||
|
||||
public void addGreenPoints(int d) {
|
||||
greenPoints += d;
|
||||
}
|
||||
explosions.add(explosion);
|
||||
explosion.goBoom(x, y, size, bubble, sizeOfParticles);
|
||||
|
||||
public void addBluePoints(int d) {
|
||||
bluePoints += d;
|
||||
}
|
||||
|
||||
private String redPointsToString() {
|
||||
String _return = "$" + redPoints / 100d;
|
||||
if (_return.length() == ("" + redPoints).length() + 1 || _return.length() == ("" + redPoints).length() + 3)
|
||||
_return += "0";
|
||||
return _return;
|
||||
}
|
||||
|
||||
private String greenPointsToString() {
|
||||
String _return = "$" + greenPoints / 100d;
|
||||
if (_return.length() == ("" + greenPoints).length() + 1 || _return.length() == ("" + greenPoints).length() + 3)
|
||||
_return += "0";
|
||||
return _return;
|
||||
}
|
||||
|
||||
private String bluePointsToString() {
|
||||
String _return = "$" + bluePoints / 100d;
|
||||
if (_return.length() == ("" + bluePoints).length() + 1 || _return.length() == ("" + bluePoints).length() + 3)
|
||||
_return += "0";
|
||||
return _return;
|
||||
}
|
||||
|
||||
private static int getMaxXPForLvl(int lvl) {
|
||||
return (int) (Math.pow(lvl, 1.618));
|
||||
}
|
||||
|
||||
public void addEXP(int i) {
|
||||
xp += i;
|
||||
while (xp >= xpToNextLVL) {
|
||||
xp -= xpToNextLVL;
|
||||
lvl++;
|
||||
xpToNextLVL = getMaxXPForLvl(lvl);
|
||||
for (int j = 0; j < 424; j += 100) {
|
||||
BOOM(75, 1.618, 255, 255, 255, 0, 300 + (j), 20, 200, true, false, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// i got bored and made logic methods... so?
|
||||
|
||||
public boolean or(boolean a, boolean b) {
|
||||
return a || b;
|
||||
}
|
||||
|
||||
public boolean not(boolean a) {
|
||||
return !a;
|
||||
}
|
||||
|
||||
public boolean and(boolean a, boolean b) {
|
||||
return not(or(not(a), not(b)));
|
||||
}
|
||||
|
||||
public boolean xor(boolean a, boolean b) {
|
||||
return not(or(not(or(not(a), not(b))), not(or(a, b))));
|
||||
// return !((!((!a)||(!b)))||(!(a||b)));
|
||||
// return or(not(or(not(a),b)),not(or(not(b),a)));
|
||||
// return ((!(a||!(b)))||(!(b||!(a))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visibleInMenu() {
|
||||
// TODO Auto-generated method stub
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -332,15 +200,11 @@ public class SpaceWars implements BasicApp {
|
|||
|
||||
@Override
|
||||
public void resized(int width, int height) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void click() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
BOOM(75, 1.2, 100, 100, 100, 50, Engine.mouseX, Engine.mouseY, 550, true, true, 10);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,4 +55,6 @@ public abstract class Enemy extends Entity {
|
|||
}
|
||||
|
||||
public abstract void damage(int damage);
|
||||
|
||||
public abstract boolean isCollidable();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,8 +45,8 @@ public class BasicPlayerBullet extends Bullet {
|
|||
updateBoundingBox((int) x, (int) y, WIDTH, HEIGHT);
|
||||
Rectangle r = getBoundingBox();
|
||||
for (int i = 0; i < SpaceWars.getEnemies().size(); i++) {
|
||||
if (r.intersects(SpaceWars.getEnemies().elementAt(i).getBoundingBox())) {
|
||||
SpaceWars.getEnemies().elementAt(i).damage(getDamage());
|
||||
if (r.intersects(SpaceWars.getEnemies().get(i).getBoundingBox())) {
|
||||
SpaceWars.getEnemies().get(i).damage(getDamage());
|
||||
alive = false;
|
||||
i = SpaceWars.getEnemies().size();
|
||||
}
|
||||
|
|
@ -82,4 +82,8 @@ public class BasicPlayerBullet extends Bullet {
|
|||
return HEIGHT;
|
||||
}
|
||||
|
||||
public boolean isCollidable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,8 +60,8 @@ public class PlayerExplodeBullet extends Bullet {
|
|||
updateBoundingBox((int) x, (int) y, WIDTH, HEIGHT);
|
||||
Rectangle r = getBoundingBox();
|
||||
for (int i = 0; i < SpaceWars.getEnemies().size(); i++) {
|
||||
if (r.intersects(SpaceWars.getEnemies().elementAt(i).getBoundingBox())) {
|
||||
SpaceWars.getEnemies().elementAt(i).damage(getDamage());
|
||||
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();
|
||||
|
|
@ -91,4 +91,8 @@ public class PlayerExplodeBullet extends Bullet {
|
|||
public int getDamage() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public boolean isCollidable() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,8 +55,8 @@ public class PlayerImpactBullet extends Bullet {
|
|||
updateBoundingBox((int) x, (int) y, WIDTH, HEIGHT);
|
||||
Rectangle r = getBoundingBox();
|
||||
for (int i = 0; i < SpaceWars.getEnemies().size(); i++) {
|
||||
if (r.intersects(SpaceWars.getEnemies().elementAt(i).getBoundingBox())) {
|
||||
SpaceWars.getEnemies().elementAt(i).damage(getDamage());
|
||||
if (r.intersects(SpaceWars.getEnemies().get(i).getBoundingBox())) {
|
||||
SpaceWars.getEnemies().get(i).damage(getDamage());
|
||||
alive = false;
|
||||
i = SpaceWars.getEnemies().size();
|
||||
}
|
||||
|
|
@ -84,4 +84,7 @@ public class PlayerImpactBullet extends Bullet {
|
|||
return 1;
|
||||
}
|
||||
|
||||
public boolean isCollidable() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,9 +62,9 @@ public class PlayerPiercingBullet extends Bullet {
|
|||
}
|
||||
updateBoundingBox((int) x, (int) y, WIDTH, HEIGHT);
|
||||
for (int i = 0; i < SpaceWars.getEnemies().size() && hits < MAX_HITS; i++) {
|
||||
if (SpaceWars.getEnemies().elementAt(i).getBoundingBox().intersectsLine((int)x, (int)y, (int)oldX, (int)oldY)) {
|
||||
if (SpaceWars.getEnemies().get(i).getBoundingBox().intersectsLine((int)x, (int)y, (int)oldX, (int)oldY)) {
|
||||
hits++;
|
||||
SpaceWars.getEnemies().elementAt(i).damage(getDamage());
|
||||
SpaceWars.getEnemies().get(i).damage(getDamage());
|
||||
if(hits >= MAX_HITS){
|
||||
alive = false;
|
||||
i = SpaceWars.getEnemies().size();
|
||||
|
|
@ -94,4 +94,8 @@ public class PlayerPiercingBullet extends Bullet {
|
|||
public int getDamage(){
|
||||
return 2;
|
||||
}
|
||||
|
||||
public boolean isCollidable() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -174,4 +174,8 @@ public class BlueEnemy extends Enemy {
|
|||
public int getWorth(){
|
||||
return r.nextInt(3)+1;
|
||||
}
|
||||
|
||||
public boolean isCollidable() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,10 +11,8 @@ public class GreenEnemy extends Enemy {
|
|||
private int health = 2;
|
||||
private final int MAX_HEALTH = health;
|
||||
private static final int WIDTH = 16, HEIGHT = 16, PROXIMITY = 200;
|
||||
private double x, y, time = 0, desiredX, desiredY, Xmod, Ymod, dx = 0,
|
||||
dy = 0;
|
||||
private static final double ACC = 0.005, MAXSPEED = 1, DEAD_ACC = 0.5d,
|
||||
DEAD_MAXSPEED = 5;
|
||||
private double x, y, time = 0, desiredX, desiredY, Xmod, Ymod, dx = 0, dy = 0;
|
||||
private static final double ACC = 0.005, MAXSPEED = 1, DEAD_ACC = 0.5d, DEAD_MAXSPEED = 5;
|
||||
private Color color;
|
||||
private boolean debug = false, alive = true;
|
||||
private double healthBar = 1;
|
||||
|
|
@ -30,11 +28,11 @@ public class GreenEnemy extends Enemy {
|
|||
@Override
|
||||
public int tick() {
|
||||
// epic AI
|
||||
if((int)healthBar <= 0){
|
||||
if ((int) healthBar <= 0) {
|
||||
alive = false;
|
||||
}
|
||||
if (alive) {
|
||||
//UIFM
|
||||
// UIFM
|
||||
if (SpaceWars.getPlayer().getAlive()) {
|
||||
if (time > 0.4d) {
|
||||
time = 0;
|
||||
|
|
@ -45,7 +43,7 @@ public class GreenEnemy extends Enemy {
|
|||
desiredX = SpaceWars.getPlayer().getX() + Xmod;
|
||||
desiredY = SpaceWars.getPlayer().getY() + Ymod;
|
||||
|
||||
//UIFM
|
||||
// UIFM
|
||||
if ((int) desiredX > (int) x)
|
||||
dx += ACC;
|
||||
else if ((int) desiredX < (int) x) {
|
||||
|
|
@ -57,7 +55,7 @@ public class GreenEnemy extends Enemy {
|
|||
dy -= ACC;
|
||||
}
|
||||
|
||||
//UIFM
|
||||
// UIFM
|
||||
if (dx > MAXSPEED)
|
||||
while (dx > MAXSPEED)
|
||||
dx -= ACC;
|
||||
|
|
@ -72,7 +70,7 @@ public class GreenEnemy extends Enemy {
|
|||
dy += ACC;
|
||||
|
||||
} else {
|
||||
//UIFM
|
||||
// UIFM
|
||||
if (time > 0.4d) {
|
||||
time = 0;
|
||||
Xmod = rand(0, 1024);
|
||||
|
|
@ -106,10 +104,10 @@ public class GreenEnemy extends Enemy {
|
|||
while (dy < 0 - DEAD_MAXSPEED)
|
||||
dy += DEAD_ACC;
|
||||
|
||||
//UIFMMMMMMMMM
|
||||
// UIFMMMMMMMMM
|
||||
}
|
||||
|
||||
//UIFMMMMM
|
||||
// UIFMMMMM
|
||||
x += dx;
|
||||
y += dy;
|
||||
|
||||
|
|
@ -120,7 +118,7 @@ public class GreenEnemy extends Enemy {
|
|||
while (x < 0)
|
||||
x++;
|
||||
|
||||
//UIFM UNIDENTIFIED FLYING MATH
|
||||
// UIFM UNIDENTIFIED FLYING MATH
|
||||
if (y > SpaceWars.getHEIGHT() - HEIGHT)
|
||||
while (y > SpaceWars.getHEIGHT() - HEIGHT)
|
||||
y--;
|
||||
|
|
@ -141,24 +139,27 @@ public class GreenEnemy extends Enemy {
|
|||
public void render(Graphics g) {
|
||||
g.setColor(color);
|
||||
int temp;
|
||||
try{
|
||||
temp = r.nextInt((int)(0-((double)absoluteTime/20d))+5);
|
||||
}catch(Exception e){
|
||||
try {
|
||||
temp = r.nextInt((int) (0 - ((double) absoluteTime / 20d)) + 5);
|
||||
} catch (Exception e) {
|
||||
temp = 0;
|
||||
}
|
||||
|
||||
//uifm
|
||||
if (temp == 0) if (alive) g.fillRect((int) x, (int) y, WIDTH, HEIGHT);
|
||||
if (debug) g.drawLine((int) x, (int) y, (int) desiredX, (int) desiredY);
|
||||
// uifm
|
||||
if (temp == 0)
|
||||
if (alive)
|
||||
g.fillRect((int) x, (int) y, WIDTH, HEIGHT);
|
||||
if (debug)
|
||||
g.drawLine((int) x, (int) y, (int) desiredX, (int) desiredY);
|
||||
|
||||
healthBar += ((((double)health/(double)MAX_HEALTH)*16) - healthBar)/6;
|
||||
//healthbar
|
||||
healthBar += ((((double) health / (double) MAX_HEALTH) * 16) - healthBar) / 6;
|
||||
// healthbar
|
||||
g.setColor(Color.RED);
|
||||
g.fillRect((int)x, (int)y, WIDTH - 1, 3);
|
||||
g.fillRect((int) x, (int) y, WIDTH - 1, 3);
|
||||
g.setColor(Color.GREEN);
|
||||
g.fillRect((int)x, (int)y, (int)healthBar, 3);
|
||||
g.fillRect((int) x, (int) y, (int) healthBar, 3);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect((int)x, (int)y, WIDTH - 1, 3);
|
||||
g.drawRect((int) x, (int) y, WIDTH - 1, 3);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -177,7 +178,11 @@ public class GreenEnemy extends Enemy {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getWorth(){
|
||||
return r.nextInt(3)+1;
|
||||
public int getWorth() {
|
||||
return r.nextInt(3) + 1;
|
||||
}
|
||||
|
||||
public boolean isCollidable() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,10 +11,8 @@ public class NormalEnemy extends Enemy {
|
|||
private int health = 2;
|
||||
private final int MAX_HEALTH = health;
|
||||
private static final int WIDTH = 16, HEIGHT = 16, PROXIMITY = 200;
|
||||
private double x, y, time = 0, desiredX, desiredY, Xmod, Ymod, dx = 0,
|
||||
dy = 0;
|
||||
private static final double ACC = 0.005, MAXSPEED = 1, DEAD_ACC = 0.5d,
|
||||
DEAD_MAXSPEED = 5;
|
||||
private double x, y, time = 0, desiredX, desiredY, Xmod, Ymod, dx = 0, dy = 0;
|
||||
private static final double ACC = 0.005, MAXSPEED = 1, DEAD_ACC = 0.5d, DEAD_MAXSPEED = 5;
|
||||
private Color color;
|
||||
private boolean debug = false, alive = true;
|
||||
private double healthBar = 1;
|
||||
|
|
@ -31,7 +29,7 @@ public class NormalEnemy extends Enemy {
|
|||
@Override
|
||||
public int tick() {
|
||||
// epic AI
|
||||
if((int)healthBar <= 0){
|
||||
if ((int) healthBar <= 0) {
|
||||
alive = false;
|
||||
}
|
||||
if (alive) {
|
||||
|
|
@ -136,23 +134,26 @@ public class NormalEnemy extends Enemy {
|
|||
public void render(Graphics g) {
|
||||
g.setColor(color);
|
||||
int temp;
|
||||
try{
|
||||
temp = r.nextInt((int)(0-((double)absoluteTime/20d))+5);
|
||||
}catch(Exception e){
|
||||
try {
|
||||
temp = r.nextInt((int) (0 - ((double) absoluteTime / 20d)) + 5);
|
||||
} catch (Exception e) {
|
||||
temp = 0;
|
||||
}
|
||||
|
||||
if (temp == 0) if (alive) g.fillRect((int) x, (int) y, WIDTH, HEIGHT);
|
||||
if (debug) g.drawLine((int) x, (int) y, (int) desiredX, (int) desiredY);
|
||||
if (temp == 0)
|
||||
if (alive)
|
||||
g.fillRect((int) x, (int) y, WIDTH, HEIGHT);
|
||||
if (debug)
|
||||
g.drawLine((int) x, (int) y, (int) desiredX, (int) desiredY);
|
||||
|
||||
healthBar += ((((double)health/(double)MAX_HEALTH)*16) - healthBar)/6;
|
||||
//healthbar
|
||||
healthBar += ((((double) health / (double) MAX_HEALTH) * 16) - healthBar) / 6;
|
||||
// healthbar
|
||||
g.setColor(Color.RED);
|
||||
g.fillRect((int)x, (int)y, WIDTH - 1, 3);
|
||||
g.fillRect((int) x, (int) y, WIDTH - 1, 3);
|
||||
g.setColor(Color.GREEN);
|
||||
g.fillRect((int)x, (int)y, (int)healthBar, 3);
|
||||
g.fillRect((int) x, (int) y, (int) healthBar, 3);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect((int)x, (int)y, WIDTH - 1, 3);
|
||||
g.drawRect((int) x, (int) y, WIDTH - 1, 3);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -171,7 +172,11 @@ public class NormalEnemy extends Enemy {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getWorth(){
|
||||
return r.nextInt(3)+1;
|
||||
public int getWorth() {
|
||||
return r.nextInt(3) + 1;
|
||||
}
|
||||
|
||||
public boolean isCollidable() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -171,4 +171,9 @@ public class RedEnemy extends Enemy {
|
|||
public int getWorth(){
|
||||
return (int)(Math.random() * 3)+1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCollidable() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,8 +89,8 @@ public class CollisionParticle extends Entity {
|
|||
if(active){
|
||||
Rectangle r = getBoundingBox();
|
||||
for (int i = 0; i < SpaceWars.getEnemies().size(); i++) {
|
||||
if (r.intersects(SpaceWars.getEnemies().elementAt(i).getBoundingBox())) {
|
||||
SpaceWars.getEnemies().elementAt(i).damage(damage);
|
||||
if (r.intersects(SpaceWars.getEnemies().get(i).getBoundingBox())) {
|
||||
SpaceWars.getEnemies().get(i).damage(damage);
|
||||
//active = false;
|
||||
i = SpaceWars.getEnemies().size();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,32 +0,0 @@
|
|||
package MAndApps.apps.spacewars.tools;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
public abstract class Entity extends BasicTickAndRender{
|
||||
private Rectangle boundingBox;
|
||||
private Random r = new Random();
|
||||
public Entity(int x, int y, int width, int height){
|
||||
boundingBox = new Rectangle(x, y, width, height);
|
||||
}
|
||||
|
||||
public void updateBoundingBox(int x, int y, int width, int height){
|
||||
boundingBox.setBounds(x, y, width, height);
|
||||
}
|
||||
public void keyPressed(KeyEvent e){}
|
||||
public void keyReleased(KeyEvent e){}
|
||||
public final double getX(){
|
||||
return boundingBox.getX();
|
||||
}
|
||||
public final double getY(){
|
||||
return boundingBox.getY();
|
||||
}
|
||||
public int rand(int i, int j){
|
||||
return r.nextInt(j-i) + i;
|
||||
}
|
||||
public Rectangle getBoundingBox(){
|
||||
return boundingBox;
|
||||
}
|
||||
}
|
||||
|
|
@ -98,4 +98,9 @@ public class Particle extends Entity{
|
|||
public boolean getAlive() {
|
||||
return alive;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCollidable() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue