Compare commits
8 Commits
master
...
screensave
| Author | SHA1 | Date |
|---|---|---|
|
|
14f800bc0c | |
|
|
cdc6a2d51f | |
|
|
083bfa11ce | |
|
|
c0cba79892 | |
|
|
b30711e2cf | |
|
|
24a2056c34 | |
|
|
793b6d6762 | |
|
|
7aeab62b43 |
|
|
@ -43,3 +43,4 @@ Icon
|
||||||
Network Trash Folder
|
Network Trash Folder
|
||||||
Temporary Items
|
Temporary Items
|
||||||
.apdisk
|
.apdisk
|
||||||
|
/bin/
|
||||||
|
|
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 7.0 MiB |
|
|
@ -1,4 +1,5 @@
|
||||||
package MAndApps.apps.spacewars.tools;
|
package MAndApps.apps.spacewars;
|
||||||
|
|
||||||
|
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
|
|
||||||
|
|
@ -1,33 +1,31 @@
|
||||||
package MAndApps.apps.spacewars;
|
package MAndApps.apps.spacewars;
|
||||||
|
|
||||||
import java.awt.Rectangle;
|
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import MAndApps.apps.spacewars.tools.BasicTickAndRender;
|
|
||||||
|
|
||||||
public abstract class Entity extends BasicTickAndRender{
|
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){
|
protected double x, y, dx, dy, width, height;
|
||||||
boundingBox.setBounds(x, y, width, height);
|
|
||||||
}
|
|
||||||
public void keyPressed(KeyEvent e){}
|
public void keyPressed(KeyEvent e){}
|
||||||
public void keyReleased(KeyEvent e){}
|
public void keyReleased(KeyEvent e){}
|
||||||
public final double getX(){
|
public final double getX(){
|
||||||
return boundingBox.getX();
|
return x;
|
||||||
}
|
}
|
||||||
public final double getY(){
|
public final double getY(){
|
||||||
return boundingBox.getY();
|
return y;
|
||||||
}
|
}
|
||||||
public int rand(int i, int j){
|
public final double getWidth() {
|
||||||
return r.nextInt(j-i) + i;
|
return width;
|
||||||
}
|
}
|
||||||
public Rectangle getBoundingBox(){
|
public final double getHeight() {
|
||||||
return boundingBox;
|
return height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract boolean isCollidable();
|
||||||
|
|
||||||
|
public abstract void die();
|
||||||
|
|
||||||
|
public abstract boolean getAlive();
|
||||||
|
|
||||||
|
public abstract void collidedWith(Entity e);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,12 @@
|
||||||
package MAndApps.apps.spacewars.tools;
|
package MAndApps.apps.spacewars;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import static MAndEngine.Utils.rand;
|
||||||
import MAndApps.apps.spacewars.SpaceWars;
|
|
||||||
|
|
||||||
|
|
||||||
public class Particle extends Entity{
|
public class Particle extends Entity{
|
||||||
private double x, y, life, speed;
|
private double life, speed;
|
||||||
private final int angleDeg, moveLife, renderLife, size;
|
private final int angleDeg, moveLife, renderLife, size;
|
||||||
private final double DECAY;
|
private final double DECAY;
|
||||||
private boolean alive = false, bubble;
|
private boolean alive = false, bubble;
|
||||||
|
|
@ -18,7 +16,6 @@ public class Particle extends Entity{
|
||||||
public Particle(int angle, double speed, int movelife, int renderlife,
|
public Particle(int angle, double speed, int movelife, int renderlife,
|
||||||
int x, int y, double speedDecay, int r, int g, int b, int variant,
|
int x, int y, double speedDecay, int r, int g, int b, int variant,
|
||||||
boolean singleVariant, boolean bubble, int sizeOfParticles) {
|
boolean singleVariant, boolean bubble, int sizeOfParticles) {
|
||||||
super(0, 0, 1, 1);
|
|
||||||
renderLife = renderlife;
|
renderLife = renderlife;
|
||||||
this.speed = speed;
|
this.speed = speed;
|
||||||
angleDeg = angle;
|
angleDeg = angle;
|
||||||
|
|
@ -63,7 +60,6 @@ public class Particle extends Entity{
|
||||||
} else {
|
} else {
|
||||||
color = new Color(rand(0, 256), rand(0, 256), rand(0, 256));
|
color = new Color(rand(0, 256), rand(0, 256), rand(0, 256));
|
||||||
}
|
}
|
||||||
updateBoundingBox((int)x, (int)y, size , size);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -98,4 +94,21 @@ public class Particle extends Entity{
|
||||||
public boolean getAlive() {
|
public boolean getAlive() {
|
||||||
return alive;
|
return alive;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCollidable() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void die() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collidedWith(Entity e) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -6,148 +6,138 @@ import java.awt.Font;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Image;
|
import java.awt.Image;
|
||||||
import java.awt.Rectangle;
|
|
||||||
import java.awt.RenderingHints;
|
import java.awt.RenderingHints;
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
import java.awt.image.BufferedImage;
|
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.entity.Player;
|
||||||
import MAndApps.apps.spacewars.shop.Shop;
|
import MAndApps.apps.spacewars.entity.enemy.NormalEnemy;
|
||||||
import MAndApps.apps.spacewars.tools.Explosion;
|
import MAndApps.apps.spacewars.tools.Explosion;
|
||||||
import MAndEngine.BasicApp;
|
import MAndEngine.BasicApp;
|
||||||
import MAndEngine.Engine;
|
import MAndEngine.Engine;
|
||||||
|
import MAndEngine.ImageCreator;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* main basicapp class that takes care of managing the abstract concepts of the game.
|
||||||
|
* like the shop, the player's level and experience, what enemies and explosion particles
|
||||||
|
* are laying around.
|
||||||
|
*
|
||||||
|
* this is somewhat old architecture and some half finished new architecture can be found
|
||||||
|
* in the screen saver branch as i plan to make this both a game and a screen saver with
|
||||||
|
* a player AI. as well, some of these concepts will be ported over to mandengine
|
||||||
|
* once they are abstracted a little better.
|
||||||
|
*
|
||||||
|
* screen saver branch has been remerged and deleted.
|
||||||
|
* screen saver will still be made, but i think the base engine needs more polish first
|
||||||
|
*
|
||||||
|
* @author mgosselin
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
public class SpaceWars implements BasicApp {
|
public class SpaceWars implements BasicApp {
|
||||||
|
|
||||||
//
|
//
|
||||||
private static boolean paused = false, debug = false;
|
public static boolean debug = false;
|
||||||
private static int redPoints = 0, bluePoints = 0, greenPoints = 0, time = 0;
|
private static final int ORIGINAL_WIDTH = 1024, ORIGINAL_HEIGHT = 600;
|
||||||
private static final int WIDTH = 1024, HEIGHT = 600;
|
|
||||||
private static Player player = new Player();
|
|
||||||
private static Image background;
|
private static Image background;
|
||||||
private static Random r = new Random();
|
private static ArrayList<Entity> entities = new ArrayList<Entity>();
|
||||||
private static Stack<Enemy> enemies = new Stack<Enemy>();
|
private static Player player;
|
||||||
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();
|
|
||||||
|
|
||||||
//
|
//
|
||||||
public static final Font defaultFont = new Font("Ubuntu", Font.BOLD, 10);
|
public static final Font defaultFont = new Font("Ubuntu", Font.BOLD, 10);
|
||||||
public static final Font moneyFont = new Font("Ubuntu", Font.BOLD, 20);
|
public static final Font moneyFont = new Font("Ubuntu", Font.BOLD, 20);
|
||||||
public static final Font levelFont = new Font("Ubuntu", Font.BOLD, 40);
|
public static final Font levelFont = new Font("Ubuntu", Font.BOLD, 40);
|
||||||
public static final Font pausedFont = new Font("Ubuntu", Font.BOLD, 60);
|
public static final Font pausedFont = new Font("Ubuntu", Font.BOLD, 60);
|
||||||
|
private boolean paused;
|
||||||
|
private static int WIDTH = ORIGINAL_WIDTH;
|
||||||
|
private static int HEIGHT = ORIGINAL_HEIGHT;
|
||||||
|
public static int scale;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tick() {
|
public void tick() {
|
||||||
addEXP(1);
|
|
||||||
if (!paused && !shopping) {
|
|
||||||
time++;
|
|
||||||
// ticks enemy stack
|
|
||||||
for (int i = 0; i < enemies.size(); i++)
|
|
||||||
enemies.elementAt(i).tick();
|
|
||||||
// tick explosions
|
|
||||||
for (int i = 0; i < explosions.size(); i++)
|
|
||||||
explosions.elementAt(i).tick();
|
|
||||||
// tick player class
|
|
||||||
player.tick();
|
|
||||||
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());
|
|
||||||
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 );
|
|
||||||
*/
|
|
||||||
|
|
||||||
addRedPoints(enemies.elementAt(i).getColor().getRed());
|
//add entities
|
||||||
addGreenPoints(enemies.elementAt(i).getColor().getGreen());
|
for(Entity e : toAdd)
|
||||||
addBluePoints(enemies.elementAt(i).getColor().getBlue());
|
entities.add(e);
|
||||||
log("You gained " + enemies.elementAt(i).getWorth() + " exp.");
|
toAdd.clear();
|
||||||
addEXP(enemies.elementAt(i).getWorth());
|
|
||||||
|
|
||||||
// enemies.remove(i);
|
// ticks entities
|
||||||
|
for (int i = 0; i < entities.size(); i++)
|
||||||
|
entities.get(i).tick();
|
||||||
|
|
||||||
|
// check dem collisions yo
|
||||||
|
for (int i = 0; i < entities.size(); i++) {
|
||||||
|
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()) {
|
||||||
|
|
||||||
|
// because efficiency.
|
||||||
|
if(
|
||||||
|
//x width2 collide
|
||||||
|
(((e1.getX() > e2.getX()) & (e1.getX() < e2.getX() + e2.getWidth())) ||
|
||||||
|
|
||||||
|
//x2 width collide
|
||||||
|
((e2.getX() > e1.getX()) & (e2.getX() < e1.getX() + e1.getWidth()))) &&
|
||||||
|
|
||||||
|
//y height2 collide
|
||||||
|
(((e1.getY() > e2.getY()) & (e1.getY() < e2.getY() + e2.getHeight())) ||
|
||||||
|
|
||||||
|
//y2 height collide
|
||||||
|
((e2.getY() > e1.getY()) & (e2.getY() < e1.getY() + e1.getHeight())))
|
||||||
|
|
||||||
|
) {
|
||||||
|
e1.collidedWith(e2);
|
||||||
|
e2.collidedWith(e1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// cleanup method.
|
||||||
|
for (int i = 0; i < entities.size();) {
|
||||||
|
Entity entity = entities.get(i);
|
||||||
|
if (!entity.getAlive()) {
|
||||||
|
entity.die();
|
||||||
|
entities.remove(i);
|
||||||
} else
|
} else
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (i < explosions.size()) {
|
|
||||||
if (!explosions.elementAt(i).getAlive()) {
|
|
||||||
explosions.remove(i);
|
|
||||||
} else {
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
expBar += ((int) (((double) xp / (double) xpToNextLVL) * 424) - expBar) / 10;
|
private static ArrayList<Entity> toAdd;
|
||||||
}
|
|
||||||
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) {
|
public static void addEntity(Entity e) {
|
||||||
logs.push(s);
|
|
||||||
}
|
toAdd.add(e);
|
||||||
|
|
||||||
public static Stack<Enemy> getEnemies() {
|
|
||||||
return enemies;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(Graphics2D g) {
|
public void render(Graphics2D g) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
g.drawImage(background, 0, 0, null);
|
||||||
|
|
||||||
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||||
|
|
||||||
g.setFont(defaultFont);
|
g.setFont(defaultFont);
|
||||||
g.drawImage(background, 0, 0, WIDTH, HEIGHT, null);
|
|
||||||
|
|
||||||
for (int i = 0; i < explosions.size(); i++)
|
for (int i = 0; i < entities.size(); i++)
|
||||||
explosions.elementAt(i).render(g, i);
|
entities.get(i).render(g);
|
||||||
|
|
||||||
player.render(g);
|
|
||||||
for (int i = 0; i < enemies.size(); i++)
|
|
||||||
enemies.elementAt(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);
|
g.setFont(defaultFont);
|
||||||
|
|
||||||
// render level and xp bar.
|
|
||||||
g.setFont(levelFont);
|
|
||||||
g.setColor(Color.WHITE);
|
g.setColor(Color.WHITE);
|
||||||
g.drawString("" + lvl, 300 - ((("" + lvl).length() - 1) * 20), 40);
|
g.drawString("" + entities.size(), 20, 32);
|
||||||
g.drawRect(330, 18, 424, 15);
|
|
||||||
g.fillRect(330, 18, expBar, 15);
|
|
||||||
g.setFont(defaultFont);
|
|
||||||
|
|
||||||
if (paused) {
|
if (paused) {
|
||||||
g.setFont(pausedFont);
|
g.setFont(pausedFont);
|
||||||
|
|
@ -155,7 +145,7 @@ public class SpaceWars implements BasicApp {
|
||||||
g.drawString("Paused", 410, 280);
|
g.drawString("Paused", 410, 280);
|
||||||
g.setFont(defaultFont);
|
g.setFont(defaultFont);
|
||||||
}
|
}
|
||||||
shop.render(g, WIDTH);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
@ -181,44 +171,42 @@ public class SpaceWars implements BasicApp {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dimension getResolution() {
|
public Dimension getResolution() {
|
||||||
return new Dimension(WIDTH, HEIGHT);
|
return new Dimension(ORIGINAL_WIDTH, ORIGINAL_HEIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
try {
|
try {
|
||||||
background = ImageIO.read(new URL("http://wallpapersus.com/wallpapers/2012/10/Cool-Wave-600x1024.jpg"));
|
toAdd = new ArrayList<Entity>();
|
||||||
|
player = new Player();
|
||||||
|
entities.add(player);
|
||||||
|
for(int i = 0; i < 10; i ++)
|
||||||
|
entities.add(new NormalEnemy());
|
||||||
|
|
||||||
|
Engine.timeScale = 60d / (1000d * 1000d);
|
||||||
|
background = ImageCreator.colorNoise(Color.WHITE, .4, .6, WIDTH, HEIGHT );
|
||||||
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
background = (Image) new BufferedImage(1024, 600, BufferedImage.TRANSLUCENT);
|
|
||||||
Graphics g = background.getGraphics();
|
|
||||||
g.setColor(Color.BLUE);
|
|
||||||
g.fillRect(0, 0, 1024, 600);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void keyPressed(KeyEvent e) {
|
public void keyPressed(KeyEvent e) {
|
||||||
player.keyPressed(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) {
|
if (e.getKeyCode() == KeyEvent.VK_P || e.getKeyCode() == KeyEvent.VK_SPACE) {
|
||||||
paused = !paused;
|
paused = !paused;
|
||||||
} else if (e.getKeyCode() == KeyEvent.VK_E) {
|
|
||||||
xp = xpToNextLVL - 1;
|
|
||||||
} else if (e.getKeyCode() == KeyEvent.VK_Q) {
|
} else if (e.getKeyCode() == KeyEvent.VK_Q) {
|
||||||
|
System.out.println("YOEIRGSODBH");
|
||||||
debug = !debug;
|
debug = !debug;
|
||||||
} else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
|
|
||||||
shopping = !shopping;
|
|
||||||
shop.toggleState();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void keyReleased(KeyEvent e) {
|
public void keyReleased(KeyEvent e) {
|
||||||
player.keyReleased(e);
|
player.keyReleased(e);
|
||||||
for (int i = 0; i < enemies.size(); i++)
|
for (int i = 0; i < entities.size(); i++)
|
||||||
enemies.elementAt(i).keyReleased(e);
|
entities.get(i).keyReleased(e);
|
||||||
shop.keyReleased(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -231,94 +219,21 @@ public class SpaceWars implements BasicApp {
|
||||||
return new Color(88, 128, 255);
|
return new Color(88, 128, 255);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getFramerate() {
|
|
||||||
return 50;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean getResizable() {
|
public boolean getResizable() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
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) {
|
Explosion explosion = new Explosion(speed, decay, r, g, b, variant, singleVariant);
|
||||||
redPoints += d;
|
entities.add((Entity) explosion);
|
||||||
}
|
explosion.goBoom(x, y, size, bubble, sizeOfParticles);
|
||||||
|
|
||||||
public void addGreenPoints(int d) {
|
|
||||||
greenPoints += d;
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
@Override
|
||||||
public boolean visibleInMenu() {
|
public boolean visibleInMenu() {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -332,15 +247,18 @@ public class SpaceWars implements BasicApp {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void resized(int width, int height) {
|
public void resized(int width, int height) {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void click() {
|
public void click() {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
BOOM(75, 1.2, 100, 100, 100, 50, Engine.mouseX, Engine.mouseY, 550, true, true, 10);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateDimensions(int width, int height) {
|
||||||
|
scale = ((int)(Math.sqrt(width*width + height*height)))/((int)(Math.sqrt(WIDTH*WIDTH + HEIGHT*HEIGHT)));
|
||||||
|
WIDTH = width;
|
||||||
|
HEIGHT = height;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,12 @@ package MAndApps.apps.spacewars.entity;
|
||||||
|
|
||||||
import MAndApps.apps.spacewars.Entity;
|
import MAndApps.apps.spacewars.Entity;
|
||||||
import MAndApps.apps.spacewars.entity.bullet.BasicPlayerBullet;
|
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.PlayerImpactBullet;
|
||||||
import MAndApps.apps.spacewars.entity.bullet.PlayerPiercingBullet;
|
import MAndApps.apps.spacewars.entity.bullet.PlayerPiercingBullet;
|
||||||
|
import MAndApps.apps.spacewars.tools.Direction;
|
||||||
|
|
||||||
public abstract class Bullet extends Entity {
|
public abstract class Bullet extends Entity {
|
||||||
|
|
||||||
//these are the bullet identities. i think its fairly self explanatory..
|
//these are the bullet identities. i think its fairly self explanatory..
|
||||||
//public static final int NAME_OF_BULLET_TYPE = some_number_not_being_used_as_another_id;
|
//public static final int NAME_OF_BULLET_TYPE = some_number_not_being_used_as_another_id;
|
||||||
public static final int BASIC = 0;
|
public static final int BASIC = 0;
|
||||||
|
|
@ -20,16 +21,6 @@ public abstract class Bullet extends Entity {
|
||||||
public static final int PLAYER_PIERCE_EIGHT = 8;
|
public static final int PLAYER_PIERCE_EIGHT = 8;
|
||||||
public static final int PLAYER_PIERCE_NINE = 9;
|
public static final int PLAYER_PIERCE_NINE = 9;
|
||||||
public static final int PLAYER_PIERCE_TEN = 10;
|
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_ONE = 21;
|
||||||
public static final int PLAYER_IMPACT_TWO = 22;
|
public static final int PLAYER_IMPACT_TWO = 22;
|
||||||
public static final int PLAYER_IMPACT_THREE = 23;
|
public static final int PLAYER_IMPACT_THREE = 23;
|
||||||
|
|
@ -42,67 +33,12 @@ public abstract class Bullet extends Entity {
|
||||||
public static final int PLAYER_IMPACT_TEN = 30;
|
public static final int PLAYER_IMPACT_TEN = 30;
|
||||||
public static final int PLAYER_GODMODE = 31;
|
public static final int PLAYER_GODMODE = 31;
|
||||||
public Bullet(int x, int y, int width, int height) {
|
public Bullet(int x, int y, int width, int height) {
|
||||||
super(x, y, width, height);
|
super.x = x;
|
||||||
|
super.y = y;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public static Bullet getNewBullet(int bulletType, int x, int y, Direction direction){
|
||||||
* bullet class now references here to get the cool down for the current bullet
|
|
||||||
* updates upon ammo change or initialization of a gun type.
|
|
||||||
* @param bulletType
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static int getCooldown(int bulletType){
|
|
||||||
switch (bulletType){
|
|
||||||
case BASIC:
|
|
||||||
return 25;
|
|
||||||
case PLAYER_PIERCE_ONE:
|
|
||||||
return 20;
|
|
||||||
case PLAYER_PIERCE_TWO:
|
|
||||||
return 18;
|
|
||||||
case PLAYER_PIERCE_THREE:
|
|
||||||
return 16;
|
|
||||||
case PLAYER_PIERCE_FOUR:
|
|
||||||
return 14;
|
|
||||||
case PLAYER_PIERCE_FIVE:
|
|
||||||
return 12;
|
|
||||||
case PLAYER_PIERCE_SIX:
|
|
||||||
return 10;
|
|
||||||
case PLAYER_PIERCE_SEVEN:
|
|
||||||
return 8;
|
|
||||||
case PLAYER_PIERCE_EIGHT:
|
|
||||||
return 6;
|
|
||||||
case PLAYER_PIERCE_NINE:
|
|
||||||
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:
|
|
||||||
return 25;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Bullet getNewBullet(int bulletType, int x, int y, int direction){
|
|
||||||
switch(bulletType){
|
switch(bulletType){
|
||||||
//this is the literal bit that goes through and indexes what to do
|
//this is the literal bit that goes through and indexes what to do
|
||||||
//with certain IDs that you defined above..
|
//with certain IDs that you defined above..
|
||||||
|
|
@ -119,46 +55,6 @@ public abstract class Bullet extends Entity {
|
||||||
//"arguments" or "parameters".
|
//"arguments" or "parameters".
|
||||||
case BASIC:
|
case BASIC:
|
||||||
return new BasicPlayerBullet(direction, x, y);
|
return new BasicPlayerBullet(direction, x, y);
|
||||||
case PLAYER_PIERCE_ONE:
|
|
||||||
return new PlayerPiercingBullet(direction, x, y, 2, false);
|
|
||||||
case PLAYER_PIERCE_TWO:
|
|
||||||
return new PlayerPiercingBullet(direction, x, y, 3, false);
|
|
||||||
case PLAYER_PIERCE_THREE:
|
|
||||||
return new PlayerPiercingBullet(direction, x, y, 4, false);
|
|
||||||
case PLAYER_PIERCE_FOUR:
|
|
||||||
return new PlayerPiercingBullet(direction, x, y, 5, false);
|
|
||||||
case PLAYER_PIERCE_FIVE:
|
|
||||||
return new PlayerPiercingBullet(direction, x, y, 6, false);
|
|
||||||
case PLAYER_PIERCE_SIX:
|
|
||||||
return new PlayerPiercingBullet(direction, x, y, 7, false);
|
|
||||||
case PLAYER_PIERCE_SEVEN:
|
|
||||||
return new PlayerPiercingBullet(direction, x, y, 8, false);
|
|
||||||
case PLAYER_PIERCE_EIGHT:
|
|
||||||
return new PlayerPiercingBullet(direction, x, y, 9, false);
|
|
||||||
case PLAYER_PIERCE_NINE:
|
|
||||||
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:
|
case PLAYER_IMPACT_ONE:
|
||||||
return new PlayerImpactBullet(direction, x, y, 1);
|
return new PlayerImpactBullet(direction, x, y, 1);
|
||||||
case PLAYER_IMPACT_TWO:
|
case PLAYER_IMPACT_TWO:
|
||||||
|
|
@ -180,7 +76,6 @@ public abstract class Bullet extends Entity {
|
||||||
case PLAYER_IMPACT_TEN:
|
case PLAYER_IMPACT_TEN:
|
||||||
return new PlayerImpactBullet(direction, x, y, 10);
|
return new PlayerImpactBullet(direction, x, y, 10);
|
||||||
case PLAYER_GODMODE:
|
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..
|
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.
|
return new BasicPlayerBullet(direction, x, y);//return it a basic bullet.
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,57 +2,23 @@ package MAndApps.apps.spacewars.entity;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
|
||||||
import MAndApps.apps.spacewars.entity.enemy.BlueEnemy;
|
import MAndApps.apps.spacewars.Entity;
|
||||||
import MAndApps.apps.spacewars.entity.enemy.GreenEnemy;
|
import MAndApps.apps.spacewars.SpaceWars;
|
||||||
import MAndApps.apps.spacewars.entity.enemy.NormalEnemy;
|
|
||||||
import MAndApps.apps.spacewars.entity.enemy.RedEnemy;
|
|
||||||
import MAndApps.apps.spacewars.tools.Entity;
|
|
||||||
|
|
||||||
public abstract class Enemy extends Entity {
|
public abstract class Enemy extends Entity {
|
||||||
public static final int NORMAL = 0;
|
|
||||||
public static final int
|
|
||||||
RED_TIER_ONE = 1,
|
|
||||||
RED_TIER_TWO = 2,
|
|
||||||
RED_TIER_THREE = 3,
|
|
||||||
RED_TIER_FOUR = 4,
|
|
||||||
RED_TIER_FIVE = 5;
|
|
||||||
public static final int
|
|
||||||
BLUE_TIER_ONE = 6,
|
|
||||||
BLUE_TIER_TWO = 7,
|
|
||||||
BLUE_TIER_THREE = 8,
|
|
||||||
BLUE_TIER_FOUR = 9,
|
|
||||||
BLUE_TIER_FIVE = 10;
|
|
||||||
public static final int
|
|
||||||
GREEN_TIER_ONE = 11,
|
|
||||||
GREEN_TIER_TWO = 12,
|
|
||||||
GREEN_TIER_THREE = 13,
|
|
||||||
GREEN_TIER_FOUR = 14,
|
|
||||||
GREEN_TIER_FIVE = 15;
|
|
||||||
|
|
||||||
public Enemy(int x, int y, int width, int height) {
|
|
||||||
super(x, y, width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
public final static Enemy getNewEnemy(int type, int x, int y){
|
|
||||||
switch(type){
|
|
||||||
case NORMAL:
|
|
||||||
return new NormalEnemy(x, y);
|
|
||||||
case BLUE_TIER_ONE:
|
|
||||||
return new BlueEnemy(x, y, 2);
|
|
||||||
case RED_TIER_ONE:
|
|
||||||
return new RedEnemy(x, y, 2);
|
|
||||||
case GREEN_TIER_ONE:
|
|
||||||
return new GreenEnemy(x, y, 2);
|
|
||||||
default:
|
|
||||||
return new NormalEnemy(x, y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public abstract boolean getAlive();
|
public abstract boolean getAlive();
|
||||||
public abstract Color getColor();
|
public abstract Color getColor();
|
||||||
|
|
||||||
public int getWorth() {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract void damage(int damage);
|
public abstract void damage(int damage);
|
||||||
|
|
||||||
|
public abstract boolean isCollidable();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final void collidedWith(Entity e) {
|
||||||
|
if(e instanceof Bullet) {
|
||||||
|
Bullet b = (Bullet)e;
|
||||||
|
damage(b.getDamage());
|
||||||
|
SpaceWars.BOOM(1.0, 1.0, 255, 255, 255, 1, (int)x, (int)y, 100, true, false, 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,28 +1,28 @@
|
||||||
package MAndApps.apps.spacewars.tools;
|
package MAndApps.apps.spacewars.entity;
|
||||||
|
|
||||||
|
import static MAndEngine.Utils.rand;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Rectangle;
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import MAndApps.apps.spacewars.Entity;
|
||||||
import MAndApps.apps.spacewars.SpaceWars;
|
import MAndApps.apps.spacewars.SpaceWars;
|
||||||
|
import MAndEngine.Engine;
|
||||||
|
|
||||||
|
|
||||||
public class CollisionParticle extends Entity {
|
public class Particle extends Entity{
|
||||||
private double x, y, life, speed;
|
private double x, y, life, speed;
|
||||||
private final int angleDeg, moveLife, renderLife, size;
|
private final double angleDeg, moveLife, renderLife;
|
||||||
|
private final int size;
|
||||||
private final double DECAY;
|
private final double DECAY;
|
||||||
private boolean alive = false, bubble;
|
private boolean alive = false, bubble;
|
||||||
private Random rand = new Random();
|
private Random rand = new Random();
|
||||||
private Color color;
|
private Color color;
|
||||||
private final int damage;
|
|
||||||
private boolean active = true;
|
|
||||||
|
|
||||||
public CollisionParticle(int angle, double speed, int movelife,
|
public Particle(int angle, double speed, int movelife, int renderlife,
|
||||||
int renderlife, int x, int y, double speedDecay, int r, int g,
|
int x, int y, double speedDecay, int r, int g, int b, int variant,
|
||||||
int b, int variant, boolean singleVariant, boolean bubble,
|
boolean singleVariant, boolean bubble, int sizeOfParticles) {
|
||||||
int sizeOfParticles, int damage) {
|
|
||||||
super(0, 0, 1, 1);
|
|
||||||
renderLife = renderlife;
|
renderLife = renderlife;
|
||||||
this.speed = speed;
|
this.speed = speed;
|
||||||
angleDeg = angle;
|
angleDeg = angle;
|
||||||
|
|
@ -65,52 +65,57 @@ public class CollisionParticle extends Entity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
color = new Color(rand(0, 256), rand(0, 256), rand(0, 256));
|
color = new Color(rand(0, 255), rand(0, 255), rand(0, 255));
|
||||||
}
|
}
|
||||||
this.damage = damage;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final double PHI = 1.618033988749894848204586;
|
||||||
|
|
||||||
public int tick() {
|
public int tick() {
|
||||||
if (life < moveLife) {
|
if (life < moveLife) {
|
||||||
x += Math.cos(((double) angleDeg * Math.PI) / 180d) * speed;
|
x += Math.cos(((double) angleDeg * Math.PI) / 180d) * speed;
|
||||||
y += Math.sin(((double) angleDeg * Math.PI) / 180d) * speed;
|
y += Math.sin(((double) angleDeg * Math.PI) / 180d) * speed;
|
||||||
}
|
}
|
||||||
speed /= DECAY;
|
speed /= PHI;
|
||||||
if (life > renderLife)
|
if (life > renderLife)
|
||||||
alive = false;
|
alive = false;
|
||||||
if(life > moveLife){
|
|
||||||
active = false;
|
|
||||||
}
|
|
||||||
if (x > SpaceWars.getWIDTH() || x < 0 - size
|
if (x > SpaceWars.getWIDTH() || x < 0 - size
|
||||||
|| y > SpaceWars.getHEIGHT() || y < 0 - size) {
|
|| y > SpaceWars.getHEIGHT() || y < 0 - size) {
|
||||||
alive = false;
|
alive = false;
|
||||||
}
|
}
|
||||||
life++;
|
|
||||||
if(active){
|
life+= Engine.deltaTime / 2d;
|
||||||
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);
|
|
||||||
//active = false;
|
|
||||||
i = SpaceWars.getEnemies().size();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
updateBoundingBox((int) x, (int) y, size, size);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render(Graphics g) {
|
public void render(Graphics g) {
|
||||||
if (alive) {
|
if (alive) {
|
||||||
g.setColor(color);
|
g.setColor(color);
|
||||||
if (bubble)
|
if(bubble) g.drawOval((int) x, (int) y, size, size);
|
||||||
g.drawOval((int) x, (int) y, size, size);
|
else g.fillRect((int) x, (int) y, size, size);
|
||||||
else
|
|
||||||
g.fillRect((int) x, (int) y, size, size);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getAlive() {
|
public boolean getAlive() {
|
||||||
return alive;
|
return alive;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCollidable() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void die() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collidedWith(Entity e) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -3,45 +3,72 @@ package MAndApps.apps.spacewars.entity;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import MAndApps.apps.spacewars.SpaceWars;
|
import MAndApps.apps.spacewars.SpaceWars;
|
||||||
import MAndApps.apps.spacewars.gun.Gun;
|
import MAndApps.apps.spacewars.gun.Gun;
|
||||||
import MAndApps.apps.spacewars.tools.Direction;
|
import MAndApps.apps.spacewars.tools.Direction;
|
||||||
import MAndApps.apps.spacewars.tools.Entity;
|
import MAndApps.apps.spacewars.Entity;
|
||||||
|
import static MAndEngine.Utils.rand;
|
||||||
|
import MAndEngine.Engine;
|
||||||
|
|
||||||
public class Player extends Entity {
|
public class Player extends Entity {
|
||||||
private final static int WIDTH = 16, HEIGHT = 16;
|
|
||||||
private double x = 512, y = 550;
|
|
||||||
private static final double ACC = 0.5, MAXSPEED = 5;
|
private static final double ACC = 0.5, MAXSPEED = 5;
|
||||||
private double dx = 0, dy = 0;
|
private boolean alive = false;
|
||||||
private boolean A = false, S = false, D = false, W = false, alive = true;
|
private Gun gun = new Gun(Bullet.BASIC);
|
||||||
private Random r = new Random();
|
|
||||||
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() {
|
||||||
super((int) 512, (int) 550, WIDTH, HEIGHT);
|
reset();
|
||||||
|
width = 16 * SpaceWars.scale;
|
||||||
|
height = 16 * SpaceWars.scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void reset() {
|
||||||
|
x = SpaceWars.getWIDTH() / 2 - width / 2;
|
||||||
|
y = SpaceWars.getHEIGHT() - (50 * SpaceWars.scale);
|
||||||
|
dy = -10;
|
||||||
|
dx = 0;
|
||||||
|
timer = 0;
|
||||||
|
time = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int tick() {
|
public int tick() {
|
||||||
|
double ACC = Player.ACC * Engine.deltaTime / 2d;
|
||||||
|
|
||||||
if (goBoom) {
|
if (goBoom) {
|
||||||
SpaceWars.BOOM(50, 1.2, 50, 50, 50, 30, (int) x, (int) y, 550, true,
|
SpaceWars.BOOM(50, 1.2, 50, 50, 50, 30, (int)(x + width/2), (int)(y + height/2), 550,
|
||||||
false, 3);
|
true, false, 3);
|
||||||
goBoom = false;
|
goBoom = false;
|
||||||
}
|
}
|
||||||
gun.tick();
|
gun.tick();
|
||||||
if (alive) {
|
if (alive) {
|
||||||
|
|
||||||
|
//hold up, before we dive into physics...
|
||||||
|
|
||||||
|
if(Engine.keys[KeyEvent.VK_I]) gun.shoot(Direction.UP);
|
||||||
|
else if(Engine.keys[KeyEvent.VK_J]) gun.shoot(Direction.LEFT);
|
||||||
|
else if(Engine.keys[KeyEvent.VK_K]) gun.shoot(Direction.DOWN);
|
||||||
|
else if(Engine.keys[KeyEvent.VK_L]) gun.shoot(Direction.RIGHT);
|
||||||
|
|
||||||
|
|
||||||
if (time != 1)
|
if (time != 1)
|
||||||
time -= 0.05d;
|
time -= 0.05d * Engine.deltaTime;
|
||||||
if (time < 1)
|
if (time < 1)
|
||||||
time = 1;
|
time = 1;
|
||||||
|
|
||||||
if (D && !A)
|
if (x > SpaceWars.getWIDTH() - width) {
|
||||||
|
dx -= ACC;
|
||||||
|
} else if (x < 0) {
|
||||||
dx += ACC;
|
dx += ACC;
|
||||||
else if (A && !D) {
|
} else if ((Engine.keys[KeyEvent.VK_D] && !Engine.keys[KeyEvent.VK_A]))
|
||||||
|
dx += ACC;
|
||||||
|
else if ((Engine.keys[KeyEvent.VK_A] && !Engine.keys[KeyEvent.VK_D])) {
|
||||||
dx -= ACC;
|
dx -= ACC;
|
||||||
} else {
|
} else {
|
||||||
if ((int) (dx * 100) > 0)
|
if ((int) (dx * 100) > 0)
|
||||||
|
|
@ -52,9 +79,14 @@ public class Player extends Entity {
|
||||||
dx = 0;
|
dx = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (S && !W)
|
if (y > SpaceWars.getHEIGHT() - height) {
|
||||||
|
dy -= ACC;
|
||||||
|
} else if (y < 0) {
|
||||||
dy += ACC;
|
dy += ACC;
|
||||||
else if (W && !S) {
|
} else if (Engine.keys[KeyEvent.VK_S]
|
||||||
|
&& !Engine.keys[KeyEvent.VK_W])
|
||||||
|
dy += ACC;
|
||||||
|
else if (Engine.keys[KeyEvent.VK_W] && !Engine.keys[KeyEvent.VK_S]) {
|
||||||
dy -= ACC;
|
dy -= ACC;
|
||||||
} else {
|
} else {
|
||||||
if ((int) (dy * 100) > 0)
|
if ((int) (dy * 100) > 0)
|
||||||
|
|
@ -66,203 +98,81 @@ public class Player extends Entity {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dx > MAXSPEED)
|
if (dx > MAXSPEED)
|
||||||
while (dx > MAXSPEED)
|
|
||||||
dx -= ACC;
|
dx -= ACC;
|
||||||
if (dx < 0 - MAXSPEED)
|
if (dx < 0 - MAXSPEED)
|
||||||
while (dx < 0 - MAXSPEED)
|
|
||||||
dx += ACC;
|
dx += ACC;
|
||||||
if (dy > MAXSPEED)
|
if (dy > MAXSPEED)
|
||||||
while (dy > MAXSPEED)
|
|
||||||
dy -= ACC;
|
dy -= ACC;
|
||||||
if (dy < 0 - MAXSPEED)
|
if (dy < 0 - MAXSPEED)
|
||||||
while (dy < 0 - MAXSPEED)
|
|
||||||
dy += ACC;
|
dy += ACC;
|
||||||
|
|
||||||
y += dy;
|
y += dy * Engine.deltaTime;
|
||||||
x += dx;
|
x += dx * Engine.deltaTime;
|
||||||
|
|
||||||
if (x > SpaceWars.getWIDTH() - WIDTH)
|
|
||||||
while (x > SpaceWars.getWIDTH() - WIDTH)
|
|
||||||
x--;
|
|
||||||
if (x < 0)
|
|
||||||
while (x < 0)
|
|
||||||
x++;
|
|
||||||
|
|
||||||
if (y > SpaceWars.getHEIGHT() - HEIGHT)
|
|
||||||
while (y > SpaceWars.getHEIGHT() - HEIGHT)
|
|
||||||
y--;
|
|
||||||
if (y < 0)
|
|
||||||
while (y < 0)
|
|
||||||
y++;
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
x = -1;
|
if (timer > 4 * 50)
|
||||||
y = -1;
|
|
||||||
if (timer > 4 * 50) {
|
|
||||||
alive = true;
|
alive = true;
|
||||||
x = 512;
|
else
|
||||||
y = 550;
|
timer += 0.75d * Engine.deltaTime;
|
||||||
}
|
}
|
||||||
timer++;
|
|
||||||
}
|
|
||||||
updateBoundingBox((int) x, (int) y, WIDTH, HEIGHT);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int timer = 0;
|
private double timer = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(Graphics g) {
|
public void render(Graphics g) {
|
||||||
|
|
||||||
g.setColor(Color.BLACK);
|
g.setColor(Color.BLACK);
|
||||||
|
|
||||||
if (alive) {
|
if (alive) {
|
||||||
int temp;
|
int temp = rand(1, (int) time);
|
||||||
try {
|
|
||||||
temp = r.nextInt((int) time);
|
if (temp == 1)
|
||||||
} catch (Exception e) {
|
g.fillRect((int) x, (int) y, (int) width, (int) height);
|
||||||
temp = 1;
|
|
||||||
}
|
}
|
||||||
if (temp == 0)
|
|
||||||
g.fillRect((int) x, (int) y, WIDTH, HEIGHT);
|
|
||||||
}
|
|
||||||
gun.render(g);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private double time = 0;
|
private double time = 0;
|
||||||
|
|
||||||
@Override
|
public boolean getAlive() {
|
||||||
public void keyPressed(KeyEvent e) {
|
return true;
|
||||||
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) {
|
public boolean isRespawning() {
|
||||||
gun.updatePosition((int)x + WIDTH/2, (int)y + HEIGHT/2);
|
return !alive;
|
||||||
gun.shoot(direction);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void keyReleased(KeyEvent e) {
|
public void die() {
|
||||||
switch (e.getKeyCode()) {
|
// TODO Auto-generated method stub
|
||||||
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) {
|
@Override
|
||||||
|
public void collidedWith(Entity e) {
|
||||||
|
|
||||||
|
if (alive && e instanceof Enemy) {
|
||||||
|
alive = false;
|
||||||
goBoom = true;
|
goBoom = true;
|
||||||
timer = 0;
|
timer = 0;
|
||||||
alive = false;
|
|
||||||
time = 5;
|
time = 5;
|
||||||
|
reset();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getAlive() {
|
@Override
|
||||||
return alive;
|
public boolean isCollidable() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLevel(int i) {
|
public int getCenterY() {
|
||||||
switch (i) {
|
return (int)(y + height / 2d);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getCenterX() {
|
||||||
|
return (int)(x + width / 2d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,64 +4,53 @@ 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;
|
||||||
|
|
||||||
|
import MAndEngine.Engine;;
|
||||||
|
|
||||||
public class BasicPlayerBullet extends Bullet {
|
public class BasicPlayerBullet extends Bullet {
|
||||||
private final int direction;
|
private final Direction direction;
|
||||||
private final int WIDTH, HEIGHT;
|
|
||||||
private final static int SPEED = 10;
|
private final static int SPEED = 10;
|
||||||
private double x, y;
|
|
||||||
private boolean alive = true;
|
private boolean alive = true;
|
||||||
|
|
||||||
public BasicPlayerBullet(int direction, int x, int y) {
|
|
||||||
|
public BasicPlayerBullet(Direction direction, int x, int y) {
|
||||||
super(x, y, 1, 1);
|
super(x, y, 1, 1);
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.direction = direction;
|
this.direction = direction;
|
||||||
if (direction == Direction.UP || direction == Direction.DOWN) {
|
if (direction == Direction.UP || direction == Direction.DOWN) {
|
||||||
WIDTH = 3;
|
width = 3;
|
||||||
HEIGHT = 8;
|
height = 8;
|
||||||
} else {
|
} else {
|
||||||
WIDTH = 8;
|
width = 8;
|
||||||
HEIGHT = 3;
|
height = 3;
|
||||||
}
|
}
|
||||||
updateBoundingBox((int) this.x, (int) this.y, WIDTH, HEIGHT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int tick() {
|
public int tick() {
|
||||||
if (alive) {
|
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);
|
y += direction.getY() * SPEED * Engine.deltaTime;
|
||||||
Rectangle r = getBoundingBox();
|
x += direction.getX() * SPEED * Engine.deltaTime;
|
||||||
for (int i = 0; i < SpaceWars.getEnemies().size(); i++) {
|
|
||||||
if (r.intersects(SpaceWars.getEnemies().elementAt(i).getBoundingBox())) {
|
if(y + height < 0) alive = false;
|
||||||
SpaceWars.getEnemies().elementAt(i).damage(getDamage());
|
if(y > SpaceWars.getHEIGHT()) alive = false;
|
||||||
alive = false;
|
if(x + width < 0) alive = false;
|
||||||
i = SpaceWars.getEnemies().size();
|
if(x > SpaceWars.getWIDTH()) alive = false;
|
||||||
}
|
|
||||||
}
|
|
||||||
if(x > SpaceWars.getWIDTH() || x < 0 - WIDTH || y > SpaceWars.getHEIGHT() || y < 0 - HEIGHT){
|
|
||||||
alive = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render(Graphics g) {
|
public void render(Graphics g) {
|
||||||
g.setColor(Color.BLACK);
|
g.setColor(Color.BLACK);
|
||||||
if (alive)
|
if (alive)
|
||||||
g.fillRect((int) x, (int) y, WIDTH, HEIGHT);
|
g.fillRect((int) x, (int) y, (int)width, (int)height);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -74,12 +63,30 @@ public class BasicPlayerBullet extends Bullet {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getWIDTH(){
|
public boolean isCollidable() {
|
||||||
return WIDTH;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getHEIGHT(){
|
@Override
|
||||||
return HEIGHT;
|
public void die() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collidedWith(Entity e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getWIDTH() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getHEIGHT() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,94 +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().elementAt(i).getBoundingBox())) {
|
|
||||||
SpaceWars.getEnemies().elementAt(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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -4,12 +4,13 @@ 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;
|
||||||
|
|
||||||
public class PlayerImpactBullet extends Bullet {
|
public class PlayerImpactBullet extends Bullet {
|
||||||
private final int direction;
|
private final Direction direction;
|
||||||
private final int WIDTH, HEIGHT;
|
private final int WIDTH, HEIGHT;
|
||||||
private final static int SPEED = 10;
|
private final static int SPEED = 10;
|
||||||
private double x, y;
|
private double x, y;
|
||||||
|
|
@ -24,19 +25,18 @@ public class PlayerImpactBullet extends Bullet {
|
||||||
return HEIGHT;
|
return HEIGHT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerImpactBullet(int direction, int x, int y, int level) {
|
public PlayerImpactBullet(Direction direction2, int x, int y, int level) {
|
||||||
super(x, y, 1, 1);
|
super(x, y, 1, 1);
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.direction = direction;
|
this.direction = direction2;
|
||||||
if (direction == Direction.UP || direction == Direction.DOWN) {
|
if (direction2 == Direction.UP || direction2 == Direction.DOWN) {
|
||||||
WIDTH = 3;
|
WIDTH = 3;
|
||||||
HEIGHT = 8;
|
HEIGHT = 8;
|
||||||
} else {
|
} else {
|
||||||
WIDTH = 8;
|
WIDTH = 8;
|
||||||
HEIGHT = 3;
|
HEIGHT = 3;
|
||||||
}
|
}
|
||||||
updateBoundingBox((int) this.x, (int) this.y, WIDTH, HEIGHT);
|
|
||||||
this.level = level;
|
this.level = level;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -52,15 +52,6 @@ public class PlayerImpactBullet extends Bullet {
|
||||||
x += SPEED;
|
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().elementAt(i).getBoundingBox())) {
|
|
||||||
SpaceWars.getEnemies().elementAt(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;
|
||||||
}
|
}
|
||||||
|
|
@ -84,4 +75,19 @@ public class PlayerImpactBullet extends Bullet {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isCollidable() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void die() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collidedWith(Entity e) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,14 +3,18 @@ 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;
|
||||||
|
|
||||||
|
import MAndEngine.Engine;
|
||||||
|
|
||||||
public class PlayerPiercingBullet extends Bullet {
|
public class PlayerPiercingBullet extends Bullet {
|
||||||
private final int direction, MAX_HITS;
|
private final Direction direction;
|
||||||
|
private final int MAX_HITS;
|
||||||
private final int WIDTH, HEIGHT;
|
private final int WIDTH, HEIGHT;
|
||||||
private final static int SPEED = 10;
|
private final static double SPEED = .01;
|
||||||
private double x, y, oldX, oldY;
|
private double x, y, oldX, oldY;
|
||||||
private boolean alive = true;
|
private boolean alive = true;
|
||||||
private int hits = 0;
|
private int hits = 0;
|
||||||
|
|
@ -25,7 +29,7 @@ public class PlayerPiercingBullet extends Bullet {
|
||||||
return HEIGHT;
|
return HEIGHT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerPiercingBullet(int direction, int x, int y, int pierce, boolean b) {
|
public PlayerPiercingBullet(Direction direction, int x, int y, int pierce) {
|
||||||
super(x, y, 1, 1);
|
super(x, y, 1, 1);
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
|
|
@ -38,39 +42,16 @@ public class PlayerPiercingBullet extends Bullet {
|
||||||
WIDTH = 8;
|
WIDTH = 8;
|
||||||
HEIGHT = 3;
|
HEIGHT = 3;
|
||||||
}
|
}
|
||||||
updateBoundingBox((int) this.x, (int) this.y, WIDTH, HEIGHT);
|
INFINISHOT = pierce == -1;
|
||||||
INFINISHOT = b;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int tick() {
|
public int tick() {
|
||||||
oldX = x;
|
oldX = x;
|
||||||
oldY = y;
|
oldY = y;
|
||||||
if (alive) {
|
if (alive) {
|
||||||
switch(direction){
|
y += SPEED * direction.getY() * Engine.deltaTime;
|
||||||
case Direction.UP:
|
x += SPEED * direction.getX() * Engine.deltaTime;
|
||||||
y -= SPEED;
|
|
||||||
break;
|
|
||||||
case Direction.DOWN:
|
|
||||||
y += SPEED;
|
|
||||||
break;
|
|
||||||
case Direction.LEFT:
|
|
||||||
x -= SPEED;
|
|
||||||
break;
|
|
||||||
case Direction.RIGHT:
|
|
||||||
x += SPEED;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
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)) {
|
|
||||||
hits++;
|
|
||||||
SpaceWars.getEnemies().elementAt(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;
|
||||||
}
|
}
|
||||||
|
|
@ -94,4 +75,20 @@ public class PlayerPiercingBullet extends Bullet {
|
||||||
public int getDamage(){
|
public int getDamage(){
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isCollidable() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void die() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collidedWith(Entity e) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,177 +0,0 @@
|
||||||
package MAndApps.apps.spacewars.entity.enemy;
|
|
||||||
|
|
||||||
import java.awt.Color;
|
|
||||||
import java.awt.Graphics;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import MAndApps.apps.spacewars.SpaceWars;
|
|
||||||
import MAndApps.apps.spacewars.entity.Enemy;
|
|
||||||
|
|
||||||
public class BlueEnemy 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 Color color;
|
|
||||||
private boolean debug = false, alive = true;
|
|
||||||
private double healthBar = 1;
|
|
||||||
|
|
||||||
public BlueEnemy(int x, int y, int i) {
|
|
||||||
super(x, y, 16, 16);
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
final int LOW = 200, HIGH = 256, color = rand(LOW, HIGH);
|
|
||||||
this.color = new Color(color, color, color);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int tick() {
|
|
||||||
// epic AI
|
|
||||||
if((int)healthBar <= 0){
|
|
||||||
alive = false;
|
|
||||||
}
|
|
||||||
if (alive) {
|
|
||||||
if (SpaceWars.getPlayer().getAlive()) {
|
|
||||||
if (time > 0.4d) {
|
|
||||||
time = 0;
|
|
||||||
Xmod = rand(-PROXIMITY, PROXIMITY);
|
|
||||||
Ymod = rand(-PROXIMITY, PROXIMITY);
|
|
||||||
}
|
|
||||||
|
|
||||||
desiredX = SpaceWars.getPlayer().getX() + Xmod;
|
|
||||||
desiredY = SpaceWars.getPlayer().getY() + Ymod;
|
|
||||||
|
|
||||||
if ((int) desiredX > (int) x)
|
|
||||||
dx += ACC;
|
|
||||||
else if ((int) desiredX < (int) x) {
|
|
||||||
dx -= ACC;
|
|
||||||
}
|
|
||||||
if ((int) desiredY > (int) y)
|
|
||||||
dy += ACC;
|
|
||||||
else if ((int) desiredY < (int) y) {
|
|
||||||
dy -= ACC;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dx > MAXSPEED)
|
|
||||||
while (dx > MAXSPEED)
|
|
||||||
dx -= ACC;
|
|
||||||
if (dx < 0 - MAXSPEED)
|
|
||||||
while (dx < 0 - MAXSPEED)
|
|
||||||
dx += ACC;
|
|
||||||
if (dy > MAXSPEED)
|
|
||||||
while (dy > MAXSPEED)
|
|
||||||
dy -= ACC;
|
|
||||||
if (dy < 0 - MAXSPEED)
|
|
||||||
while (dy < 0 - MAXSPEED)
|
|
||||||
dy += ACC;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
if (time > 0.4d) {
|
|
||||||
time = 0;
|
|
||||||
Xmod = rand(0, 1024);
|
|
||||||
Ymod = rand(0, 200);
|
|
||||||
}
|
|
||||||
|
|
||||||
desiredX = Xmod;
|
|
||||||
desiredY = Ymod;
|
|
||||||
|
|
||||||
if ((int) desiredX > (int) x)
|
|
||||||
dx += DEAD_ACC;
|
|
||||||
else if ((int) desiredX < (int) x) {
|
|
||||||
dx -= DEAD_ACC;
|
|
||||||
}
|
|
||||||
if ((int) desiredY > (int) y)
|
|
||||||
dy += DEAD_ACC;
|
|
||||||
else if ((int) desiredY < (int) y) {
|
|
||||||
dy -= DEAD_ACC;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dx > DEAD_MAXSPEED)
|
|
||||||
while (dx > DEAD_MAXSPEED)
|
|
||||||
dx -= DEAD_ACC;
|
|
||||||
if (dx < 0 - DEAD_MAXSPEED)
|
|
||||||
while (dx < 0 - DEAD_MAXSPEED)
|
|
||||||
dx += DEAD_ACC;
|
|
||||||
if (dy > DEAD_MAXSPEED)
|
|
||||||
while (dy > DEAD_MAXSPEED)
|
|
||||||
dy -= DEAD_ACC;
|
|
||||||
if (dy < 0 - DEAD_MAXSPEED)
|
|
||||||
while (dy < 0 - DEAD_MAXSPEED)
|
|
||||||
dy += DEAD_ACC;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
x += dx;
|
|
||||||
y += dy;
|
|
||||||
|
|
||||||
if (x > SpaceWars.getWIDTH() - WIDTH)
|
|
||||||
while (x > SpaceWars.getWIDTH() - WIDTH)
|
|
||||||
x--;
|
|
||||||
if (x < 0)
|
|
||||||
while (x < 0)
|
|
||||||
x++;
|
|
||||||
|
|
||||||
if (y > SpaceWars.getHEIGHT() - HEIGHT)
|
|
||||||
while (y > SpaceWars.getHEIGHT() - HEIGHT)
|
|
||||||
y--;
|
|
||||||
if (y < 0)
|
|
||||||
while (y < 0)
|
|
||||||
y++;
|
|
||||||
}
|
|
||||||
time += 0.01;
|
|
||||||
absoluteTime++;
|
|
||||||
updateBoundingBox((int) x, (int) y, 16, 16);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Random r = new Random();
|
|
||||||
private int absoluteTime = 0;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void render(Graphics g) {
|
|
||||||
g.setColor(color);
|
|
||||||
int temp;
|
|
||||||
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);
|
|
||||||
|
|
||||||
healthBar += ((((double)health/(double)MAX_HEALTH)*16) - healthBar)/6;
|
|
||||||
//healthbar
|
|
||||||
g.setColor(Color.RED);
|
|
||||||
g.fillRect((int)x, (int)y, WIDTH - 1, 3);
|
|
||||||
g.setColor(Color.GREEN);
|
|
||||||
g.fillRect((int)x, (int)y, (int)healthBar, 3);
|
|
||||||
g.setColor(Color.BLACK);
|
|
||||||
g.drawRect((int)x, (int)y, WIDTH - 1, 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void damage(int i) {
|
|
||||||
health -= i;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean getAlive() {
|
|
||||||
return alive;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Color getColor() {
|
|
||||||
return color;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getWorth(){
|
|
||||||
return r.nextInt(3)+1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,183 +0,0 @@
|
||||||
package MAndApps.apps.spacewars.entity.enemy;
|
|
||||||
|
|
||||||
import java.awt.Color;
|
|
||||||
import java.awt.Graphics;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import MAndApps.apps.spacewars.SpaceWars;
|
|
||||||
import MAndApps.apps.spacewars.entity.Enemy;
|
|
||||||
|
|
||||||
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 Color color;
|
|
||||||
private boolean debug = false, alive = true;
|
|
||||||
private double healthBar = 1;
|
|
||||||
|
|
||||||
public GreenEnemy(int x, int y, int i) {
|
|
||||||
super(x, y, WIDTH, HEIGHT);
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
this.color = new Color(rand(50, 75), 255, rand(50, 75));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int tick() {
|
|
||||||
// epic AI
|
|
||||||
if((int)healthBar <= 0){
|
|
||||||
alive = false;
|
|
||||||
}
|
|
||||||
if (alive) {
|
|
||||||
//UIFM
|
|
||||||
if (SpaceWars.getPlayer().getAlive()) {
|
|
||||||
if (time > 0.4d) {
|
|
||||||
time = 0;
|
|
||||||
Xmod = rand(-PROXIMITY, PROXIMITY);
|
|
||||||
Ymod = rand(-PROXIMITY, PROXIMITY);
|
|
||||||
}
|
|
||||||
|
|
||||||
desiredX = SpaceWars.getPlayer().getX() + Xmod;
|
|
||||||
desiredY = SpaceWars.getPlayer().getY() + Ymod;
|
|
||||||
|
|
||||||
//UIFM
|
|
||||||
if ((int) desiredX > (int) x)
|
|
||||||
dx += ACC;
|
|
||||||
else if ((int) desiredX < (int) x) {
|
|
||||||
dx -= ACC;
|
|
||||||
}
|
|
||||||
if ((int) desiredY > (int) y)
|
|
||||||
dy += ACC;
|
|
||||||
else if ((int) desiredY < (int) y) {
|
|
||||||
dy -= ACC;
|
|
||||||
}
|
|
||||||
|
|
||||||
//UIFM
|
|
||||||
if (dx > MAXSPEED)
|
|
||||||
while (dx > MAXSPEED)
|
|
||||||
dx -= ACC;
|
|
||||||
if (dx < 0 - MAXSPEED)
|
|
||||||
while (dx < 0 - MAXSPEED)
|
|
||||||
dx += ACC;
|
|
||||||
if (dy > MAXSPEED)
|
|
||||||
while (dy > MAXSPEED)
|
|
||||||
dy -= ACC;
|
|
||||||
if (dy < 0 - MAXSPEED)
|
|
||||||
while (dy < 0 - MAXSPEED)
|
|
||||||
dy += ACC;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
//UIFM
|
|
||||||
if (time > 0.4d) {
|
|
||||||
time = 0;
|
|
||||||
Xmod = rand(0, 1024);
|
|
||||||
Ymod = rand(0, 200);
|
|
||||||
}
|
|
||||||
|
|
||||||
desiredX = Xmod;
|
|
||||||
desiredY = Ymod;
|
|
||||||
|
|
||||||
if ((int) desiredX > (int) x)
|
|
||||||
dx += DEAD_ACC;
|
|
||||||
else if ((int) desiredX < (int) x) {
|
|
||||||
dx -= DEAD_ACC;
|
|
||||||
}
|
|
||||||
if ((int) desiredY > (int) y)
|
|
||||||
dy += DEAD_ACC;
|
|
||||||
else if ((int) desiredY < (int) y) {
|
|
||||||
dy -= DEAD_ACC;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dx > DEAD_MAXSPEED)
|
|
||||||
while (dx > DEAD_MAXSPEED)
|
|
||||||
dx -= DEAD_ACC;
|
|
||||||
if (dx < 0 - DEAD_MAXSPEED)
|
|
||||||
while (dx < 0 - DEAD_MAXSPEED)
|
|
||||||
dx += DEAD_ACC;
|
|
||||||
if (dy > DEAD_MAXSPEED)
|
|
||||||
while (dy > DEAD_MAXSPEED)
|
|
||||||
dy -= DEAD_ACC;
|
|
||||||
if (dy < 0 - DEAD_MAXSPEED)
|
|
||||||
while (dy < 0 - DEAD_MAXSPEED)
|
|
||||||
dy += DEAD_ACC;
|
|
||||||
|
|
||||||
//UIFMMMMMMMMM
|
|
||||||
}
|
|
||||||
|
|
||||||
//UIFMMMMM
|
|
||||||
x += dx;
|
|
||||||
y += dy;
|
|
||||||
|
|
||||||
if (x > SpaceWars.getWIDTH() - WIDTH)
|
|
||||||
while (x > SpaceWars.getWIDTH() - WIDTH)
|
|
||||||
x--;
|
|
||||||
if (x < 0)
|
|
||||||
while (x < 0)
|
|
||||||
x++;
|
|
||||||
|
|
||||||
//UIFM UNIDENTIFIED FLYING MATH
|
|
||||||
if (y > SpaceWars.getHEIGHT() - HEIGHT)
|
|
||||||
while (y > SpaceWars.getHEIGHT() - HEIGHT)
|
|
||||||
y--;
|
|
||||||
if (y < 0)
|
|
||||||
while (y < 0)
|
|
||||||
y++;
|
|
||||||
}
|
|
||||||
time += 0.01;
|
|
||||||
absoluteTime++;
|
|
||||||
updateBoundingBox((int) x, (int) y, 16, 16);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Random r = new Random();
|
|
||||||
private int absoluteTime = 0;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void render(Graphics g) {
|
|
||||||
g.setColor(color);
|
|
||||||
int temp;
|
|
||||||
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);
|
|
||||||
|
|
||||||
healthBar += ((((double)health/(double)MAX_HEALTH)*16) - healthBar)/6;
|
|
||||||
//healthbar
|
|
||||||
g.setColor(Color.RED);
|
|
||||||
g.fillRect((int)x, (int)y, WIDTH - 1, 3);
|
|
||||||
g.setColor(Color.GREEN);
|
|
||||||
g.fillRect((int)x, (int)y, (int)healthBar, 3);
|
|
||||||
g.setColor(Color.BLACK);
|
|
||||||
g.drawRect((int)x, (int)y, WIDTH - 1, 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void damage(int i) {
|
|
||||||
health -= i;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean getAlive() {
|
|
||||||
return alive;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Color getColor() {
|
|
||||||
return color;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getWorth(){
|
|
||||||
return r.nextInt(3)+1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -4,91 +4,97 @@ 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;
|
||||||
|
import MAndEngine.Engine;
|
||||||
|
|
||||||
|
import static MAndEngine.Utils.rand;
|
||||||
|
|
||||||
public class NormalEnemy extends Enemy {
|
public class NormalEnemy extends Enemy {
|
||||||
private int health = 2;
|
private int health = 2;
|
||||||
private final int MAX_HEALTH = health;
|
private final int MAX_HEALTH = health;
|
||||||
private static final int WIDTH = 16, HEIGHT = 16, PROXIMITY = 200;
|
private static final int PROXIMITY = 200;
|
||||||
private double x, y, time = 0, desiredX, desiredY, Xmod, Ymod, dx = 0,
|
private double time = 10000, desiredX, desiredY, Xmod, Ymod;
|
||||||
dy = 0;
|
private static final double ACC = 0.005, MAXSPEED = 1, DEAD_ACC = 0.5d, DEAD_MAXSPEED = 5;
|
||||||
private static final double ACC = 0.005, MAXSPEED = 1, DEAD_ACC = 0.5d,
|
|
||||||
DEAD_MAXSPEED = 5;
|
|
||||||
private Color color;
|
private Color color;
|
||||||
private boolean debug = false, alive = true;
|
private boolean alive = true;
|
||||||
private double healthBar = 1;
|
private double healthBar = 1;
|
||||||
|
private final double reEvaluateTime;
|
||||||
|
|
||||||
public NormalEnemy(int x, int y) {
|
public NormalEnemy() {
|
||||||
super(x, y, 16, 16);
|
this(Math.random());
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
}
|
||||||
final int LOW = 200, HIGH = 256, color = rand(LOW, HIGH);
|
|
||||||
|
public NormalEnemy(double hyperness) {
|
||||||
|
final int LOW = 200, HIGH = 255, color = rand(LOW, HIGH);
|
||||||
this.color = new Color(color, color, color);
|
this.color = new Color(color, color, color);
|
||||||
|
x = SpaceWars.getWIDTH() / 2 - width / 2;
|
||||||
|
y = 100;
|
||||||
|
reEvaluateTime = 1 - hyperness;
|
||||||
|
width = 16 * SpaceWars.scale;
|
||||||
|
height = 16 * SpaceWars.scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int tick() {
|
public int tick() {
|
||||||
// epic AI
|
// epic AI
|
||||||
if((int)healthBar <= 0){
|
if ((int) healthBar <= 0) {
|
||||||
alive = false;
|
alive = false;
|
||||||
}
|
}
|
||||||
if (alive) {
|
if (alive) {
|
||||||
if (SpaceWars.getPlayer().getAlive()) {
|
if (!SpaceWars.getPlayer().isRespawning()) {
|
||||||
if (time > 0.4d) {
|
if (time > reEvaluateTime) {
|
||||||
time = 0;
|
time = 0;
|
||||||
Xmod = rand(-PROXIMITY, PROXIMITY);
|
Xmod = rand(-PROXIMITY * SpaceWars.scale, PROXIMITY * SpaceWars.scale);
|
||||||
Ymod = rand(-PROXIMITY, PROXIMITY);
|
Ymod = rand(-PROXIMITY * SpaceWars.scale, PROXIMITY * SpaceWars.scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
desiredX = SpaceWars.getPlayer().getX() + Xmod;
|
desiredX = SpaceWars.getPlayer().getX() + Xmod;
|
||||||
desiredY = SpaceWars.getPlayer().getY() + Ymod;
|
desiredY = SpaceWars.getPlayer().getY() + Ymod;
|
||||||
|
|
||||||
if ((int) desiredX > (int) x)
|
if ((int) desiredX > (int) x)
|
||||||
dx += ACC;
|
dx += ACC * Engine.deltaTime;
|
||||||
else if ((int) desiredX < (int) x) {
|
else if ((int) desiredX < (int) x) {
|
||||||
dx -= ACC;
|
dx -= ACC * Engine.deltaTime;
|
||||||
}
|
}
|
||||||
if ((int) desiredY > (int) y)
|
if ((int) desiredY > (int) y)
|
||||||
dy += ACC;
|
dy += ACC * Engine.deltaTime;
|
||||||
else if ((int) desiredY < (int) y) {
|
else if ((int) desiredY < (int) y) {
|
||||||
dy -= ACC;
|
dy -= ACC * Engine.deltaTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dx > MAXSPEED)
|
if (dx > MAXSPEED)
|
||||||
while (dx > MAXSPEED)
|
dx = MAXSPEED;
|
||||||
dx -= ACC;
|
|
||||||
if (dx < 0 - MAXSPEED)
|
if (dx < 0 - MAXSPEED)
|
||||||
while (dx < 0 - MAXSPEED)
|
dx = 0 - MAXSPEED;
|
||||||
dx += ACC;
|
|
||||||
if (dy > MAXSPEED)
|
if (dy > MAXSPEED)
|
||||||
while (dy > MAXSPEED)
|
dy = MAXSPEED;
|
||||||
dy -= ACC;
|
|
||||||
if (dy < 0 - MAXSPEED)
|
if (dy < 0 - MAXSPEED)
|
||||||
while (dy < 0 - MAXSPEED)
|
dy = 0 - MAXSPEED;
|
||||||
dy += ACC;
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (time > 0.4d) {
|
if (time > reEvaluateTime) {
|
||||||
time = 0;
|
time = 0;
|
||||||
Xmod = rand(0, 1024);
|
Xmod = rand(0, SpaceWars.getWIDTH());
|
||||||
Ymod = rand(0, 200);
|
Ymod = rand(0, SpaceWars.getHEIGHT() / 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
desiredX = Xmod;
|
desiredX = Xmod;
|
||||||
desiredY = Ymod;
|
desiredY = Ymod;
|
||||||
|
|
||||||
if ((int) desiredX > (int) x)
|
if ((int) desiredX > (int) x)
|
||||||
dx += DEAD_ACC;
|
dx += DEAD_ACC * Engine.deltaTime;
|
||||||
else if ((int) desiredX < (int) x) {
|
else if ((int) desiredX < (int) x) {
|
||||||
dx -= DEAD_ACC;
|
dx -= DEAD_ACC * Engine.deltaTime;
|
||||||
}
|
}
|
||||||
if ((int) desiredY > (int) y)
|
if ((int) desiredY > (int) y)
|
||||||
dy += DEAD_ACC;
|
dy += DEAD_ACC * Engine.deltaTime;
|
||||||
else if ((int) desiredY < (int) y) {
|
else if ((int) desiredY < (int) y) {
|
||||||
dy -= DEAD_ACC;
|
dy -= DEAD_ACC * Engine.deltaTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dx > DEAD_MAXSPEED)
|
if (dx > DEAD_MAXSPEED)
|
||||||
|
|
@ -106,53 +112,54 @@ public class NormalEnemy extends Enemy {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
x += dx;
|
x += dx * Engine.deltaTime;
|
||||||
y += dy;
|
y += dy * Engine.deltaTime;
|
||||||
|
|
||||||
if (x > SpaceWars.getWIDTH() - WIDTH)
|
if (x > SpaceWars.getWIDTH() - width)
|
||||||
while (x > SpaceWars.getWIDTH() - WIDTH)
|
while (x > SpaceWars.getWIDTH() - width)
|
||||||
x--;
|
x--;
|
||||||
if (x < 0)
|
if (x < 0)
|
||||||
while (x < 0)
|
while (x < 0)
|
||||||
x++;
|
x++;
|
||||||
|
|
||||||
if (y > SpaceWars.getHEIGHT() - HEIGHT)
|
if (y > SpaceWars.getHEIGHT() - height)
|
||||||
while (y > SpaceWars.getHEIGHT() - HEIGHT)
|
while (y > SpaceWars.getHEIGHT() - height)
|
||||||
y--;
|
y--;
|
||||||
if (y < 0)
|
if (y < 0)
|
||||||
while (y < 0)
|
while (y < 0)
|
||||||
y++;
|
y++;
|
||||||
}
|
}
|
||||||
time += 0.01;
|
time += 0.01 * Engine.deltaTime;
|
||||||
absoluteTime++;
|
absoluteTime += 0.01 * Engine.deltaTime;
|
||||||
updateBoundingBox((int) x, (int) y, 16, 16);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Random r = new Random();
|
private double absoluteTime = 0;
|
||||||
private int absoluteTime = 0;
|
|
||||||
|
|
||||||
|
private Random r = new Random();
|
||||||
@Override
|
@Override
|
||||||
public void render(Graphics g) {
|
public void render(Graphics g) {
|
||||||
g.setColor(color);
|
g.setColor(color);
|
||||||
int temp;
|
int temp;
|
||||||
|
|
||||||
try{
|
try{
|
||||||
temp = r.nextInt((int)(0-((double)absoluteTime/20d))+5);
|
temp = r.nextDouble() > absoluteTime / 2 ? 1 : 0;
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
temp = 0;
|
temp = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (temp == 0) if (alive) g.fillRect((int) x, (int) y, WIDTH, HEIGHT);
|
if (temp == 0) if (alive) g.fillRect((int) x, (int) y, (int)width, (int)height);
|
||||||
if (debug) g.drawLine((int) x, (int) y, (int) desiredX, (int) desiredY);
|
|
||||||
|
|
||||||
healthBar += ((((double)health/(double)MAX_HEALTH)*16) - healthBar)/6;
|
if (SpaceWars.debug) g.drawLine((int)(x + width / 2), (int)(y + height / 2), (int)(desiredX + width / 2), (int)(desiredY + height / 2));
|
||||||
|
|
||||||
|
healthBar += (((((double)health/(double)MAX_HEALTH)*(width + 1)) - healthBar)/6) * Engine.deltaTime;
|
||||||
//healthbar
|
//healthbar
|
||||||
g.setColor(Color.RED);
|
|
||||||
g.fillRect((int)x, (int)y, WIDTH - 1, 3);
|
|
||||||
g.setColor(Color.GREEN);
|
|
||||||
g.fillRect((int)x, (int)y, (int)healthBar, 3);
|
|
||||||
g.setColor(Color.BLACK);
|
g.setColor(Color.BLACK);
|
||||||
g.drawRect((int)x, (int)y, WIDTH - 1, 3);
|
g.fillRect((int) x, (int) y - 5, (int)width - 1, 3);
|
||||||
|
g.setColor(Color.RED);
|
||||||
|
g.fillRect((int) x, (int) y - 5, (int)width, 3);
|
||||||
|
g.setColor(Color.GREEN);
|
||||||
|
g.fillRect((int) x, (int) y - 5, (int) healthBar, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -170,8 +177,13 @@ public class NormalEnemy extends Enemy {
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isCollidable() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getWorth(){
|
public void die() {
|
||||||
return r.nextInt(3)+1;
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,174 +0,0 @@
|
||||||
package MAndApps.apps.spacewars.entity.enemy;
|
|
||||||
|
|
||||||
import java.awt.Color;
|
|
||||||
import java.awt.Graphics;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import MAndApps.apps.spacewars.SpaceWars;
|
|
||||||
import MAndApps.apps.spacewars.entity.Enemy;
|
|
||||||
|
|
||||||
public class RedEnemy 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 Color color;
|
|
||||||
private boolean debug = false, alive = true;
|
|
||||||
private double healthBar = 1;
|
|
||||||
|
|
||||||
public RedEnemy(int x, int y, int i) {
|
|
||||||
super(x, y, WIDTH, HEIGHT);
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
this.color = new Color(255, rand(50, 75), rand(50, 75));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public int tick() {
|
|
||||||
// epic AI
|
|
||||||
if((int)healthBar <= 0){
|
|
||||||
alive = false;
|
|
||||||
}
|
|
||||||
if (alive) {
|
|
||||||
if (SpaceWars.getPlayer().getAlive()) {
|
|
||||||
if (time > 0.4d) {
|
|
||||||
time = 0;
|
|
||||||
Xmod = rand(-PROXIMITY, PROXIMITY);
|
|
||||||
Ymod = rand(-PROXIMITY, PROXIMITY);
|
|
||||||
}
|
|
||||||
|
|
||||||
desiredX = SpaceWars.getPlayer().getX() + Xmod;
|
|
||||||
desiredY = SpaceWars.getPlayer().getY() + Ymod;
|
|
||||||
|
|
||||||
if ((int) desiredX > (int) x)
|
|
||||||
dx += ACC;
|
|
||||||
else if ((int) desiredX < (int) x) {
|
|
||||||
dx -= ACC;
|
|
||||||
}
|
|
||||||
if ((int) desiredY > (int) y)
|
|
||||||
dy += ACC;
|
|
||||||
else if ((int) desiredY < (int) y) {
|
|
||||||
dy -= ACC;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dx > MAXSPEED)
|
|
||||||
while (dx > MAXSPEED)
|
|
||||||
dx -= ACC;
|
|
||||||
if (dx < 0 - MAXSPEED)
|
|
||||||
while (dx < 0 - MAXSPEED)
|
|
||||||
dx += ACC;
|
|
||||||
if (dy > MAXSPEED)
|
|
||||||
while (dy > MAXSPEED)
|
|
||||||
dy -= ACC;
|
|
||||||
if (dy < 0 - MAXSPEED)
|
|
||||||
while (dy < 0 - MAXSPEED)
|
|
||||||
dy += ACC;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
if (time > 0.4d) {
|
|
||||||
time = 0;
|
|
||||||
Xmod = rand(0, 1024);
|
|
||||||
Ymod = rand(0, 200);
|
|
||||||
}
|
|
||||||
|
|
||||||
desiredX = Xmod;
|
|
||||||
desiredY = Ymod;
|
|
||||||
|
|
||||||
if ((int) desiredX > (int) x)
|
|
||||||
dx += DEAD_ACC;
|
|
||||||
else if ((int) desiredX < (int) x) {
|
|
||||||
dx -= DEAD_ACC;
|
|
||||||
}
|
|
||||||
if ((int) desiredY > (int) y)
|
|
||||||
dy += DEAD_ACC;
|
|
||||||
else if ((int) desiredY < (int) y) {
|
|
||||||
dy -= DEAD_ACC;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dx > DEAD_MAXSPEED)
|
|
||||||
while (dx > DEAD_MAXSPEED)
|
|
||||||
dx -= DEAD_ACC;
|
|
||||||
if (dx < 0 - DEAD_MAXSPEED)
|
|
||||||
while (dx < 0 - DEAD_MAXSPEED)
|
|
||||||
dx += DEAD_ACC;
|
|
||||||
if (dy > DEAD_MAXSPEED)
|
|
||||||
while (dy > DEAD_MAXSPEED)
|
|
||||||
dy -= DEAD_ACC;
|
|
||||||
if (dy < 0 - DEAD_MAXSPEED)
|
|
||||||
while (dy < 0 - DEAD_MAXSPEED)
|
|
||||||
dy += DEAD_ACC;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
x += dx;
|
|
||||||
y += dy;
|
|
||||||
|
|
||||||
if (x > SpaceWars.getWIDTH() - WIDTH)
|
|
||||||
while (x > SpaceWars.getWIDTH() - WIDTH)
|
|
||||||
x--;
|
|
||||||
if (x < 0)
|
|
||||||
while (x < 0)
|
|
||||||
x++;
|
|
||||||
|
|
||||||
if (y > SpaceWars.getHEIGHT() - HEIGHT)
|
|
||||||
while (y > SpaceWars.getHEIGHT() - HEIGHT)
|
|
||||||
y--;
|
|
||||||
if (y < 0)
|
|
||||||
while (y < 0)
|
|
||||||
y++;
|
|
||||||
}
|
|
||||||
time += 0.01;
|
|
||||||
absoluteTime++;
|
|
||||||
updateBoundingBox((int) x, (int) y, 16, 16);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Random r = new Random();
|
|
||||||
private int absoluteTime = 0;
|
|
||||||
|
|
||||||
public void render(Graphics g) {
|
|
||||||
g.setColor(color);
|
|
||||||
int temp;
|
|
||||||
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);
|
|
||||||
|
|
||||||
healthBar += ((((double)health/(double)MAX_HEALTH)*16) - healthBar)/6;
|
|
||||||
//healthbar
|
|
||||||
g.setColor(Color.RED);
|
|
||||||
g.fillRect((int)x, (int)y, WIDTH - 1, 3);
|
|
||||||
g.setColor(Color.GREEN);
|
|
||||||
g.fillRect((int)x, (int)y, (int)healthBar, 3);
|
|
||||||
g.setColor(Color.BLACK);
|
|
||||||
g.drawRect((int)x, (int)y, WIDTH - 1, 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void damage(int i) {
|
|
||||||
health -= i;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean getAlive() {
|
|
||||||
return alive;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Color getColor() {
|
|
||||||
return color;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getWorth(){
|
|
||||||
return (int)(Math.random() * 3)+1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,58 +1,25 @@
|
||||||
package MAndApps.apps.spacewars.gun;
|
package MAndApps.apps.spacewars.gun;
|
||||||
|
|
||||||
import java.awt.Graphics;
|
import MAndApps.apps.spacewars.SpaceWars;
|
||||||
import java.util.Stack;
|
|
||||||
|
|
||||||
import MAndApps.apps.spacewars.entity.Bullet;
|
import MAndApps.apps.spacewars.entity.Bullet;
|
||||||
|
import MAndApps.apps.spacewars.tools.Direction;
|
||||||
|
|
||||||
public class Gun {
|
public class Gun {
|
||||||
private Stack<Bullet> bullets = new Stack<Bullet>();
|
|
||||||
private int bulletType;
|
|
||||||
private int MAX_COOLDOWN;
|
private int MAX_COOLDOWN;
|
||||||
private int cooldown = 0, x, y;
|
private double cooldown = 0;
|
||||||
public Gun(int bulletType, int cooldown, int x, int y){
|
public Gun(int bulletType){
|
||||||
MAX_COOLDOWN = cooldown;
|
MAX_COOLDOWN = 5;
|
||||||
this.bulletType = bulletType;
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updatePosition(int x, int y){
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void render(Graphics g){
|
|
||||||
for(int i = 0; i < bullets.size(); i ++)
|
|
||||||
bullets.elementAt(i).render(g);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void tick(){
|
public void tick(){
|
||||||
cooldown ++;
|
cooldown += MAndEngine.Engine.deltaTime;
|
||||||
//tick bullets
|
|
||||||
for(int i = 0; i < bullets.size(); i++)
|
|
||||||
bullets.elementAt(i).tick();
|
|
||||||
for(int i = 0; i < bullets.size(); i++){
|
|
||||||
if(!bullets.elementAt(i).getAlive())
|
|
||||||
bullets.remove(i);
|
|
||||||
else
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shoot(int direction){
|
public void shoot(Direction direction){
|
||||||
if(cooldown >= MAX_COOLDOWN){
|
if(cooldown >= MAX_COOLDOWN){
|
||||||
cooldown = 0;
|
cooldown = 0;
|
||||||
bullets.push(Bullet.getNewBullet(bulletType, x-(Bullet.getNewBullet(bulletType, x, y, direction).getWIDTH()/2), y-(Bullet.getNewBullet(bulletType, x, y, direction).getHEIGHT()/2), direction));
|
SpaceWars.addEntity(Bullet.getNewBullet(Bullet.BASIC, SpaceWars.getPlayer().getCenterX(), SpaceWars.getPlayer().getCenterY(), direction));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void switchAmmo(int bulletType){
|
|
||||||
this.bulletType = bulletType;
|
|
||||||
MAX_COOLDOWN = Bullet.getCooldown(bulletType);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCooldown(int i) {
|
|
||||||
MAX_COOLDOWN = i;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -9,6 +9,7 @@ public class Shop {
|
||||||
private final int ON = 17, OFF = 64, BOX_WIDTH = 500, BOX_HEIGHT = 200, BOX_Y_OFFSET = 50, BOX_Y_MULTIPLIER = 250, MAX_ANIMATION_TIME = BOX_WIDTH;
|
private final int ON = 17, OFF = 64, BOX_WIDTH = 500, BOX_HEIGHT = 200, BOX_Y_OFFSET = 50, BOX_Y_MULTIPLIER = 250, MAX_ANIMATION_TIME = BOX_WIDTH;
|
||||||
private int state = OFF, selection = 0;
|
private int state = OFF, selection = 0;
|
||||||
private double animationTime = 0;
|
private double animationTime = 0;
|
||||||
|
|
||||||
public void render(Graphics g, final int WIDTH){
|
public void render(Graphics g, final int WIDTH){
|
||||||
g.setColor(selection == 0 ? Color.CYAN : Color.BLUE);
|
g.setColor(selection == 0 ? Color.CYAN : Color.BLUE);
|
||||||
g.fillRect((int)animationTime-BOX_WIDTH, BOX_Y_OFFSET, BOX_WIDTH, BOX_HEIGHT);
|
g.fillRect((int)animationTime-BOX_WIDTH, BOX_Y_OFFSET, BOX_WIDTH, BOX_HEIGHT);
|
||||||
|
|
|
||||||
|
|
@ -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,12 +1,85 @@
|
||||||
package MAndApps.apps.spacewars.tools;
|
package MAndApps.apps.spacewars.tools;
|
||||||
|
|
||||||
public class Direction {
|
public abstract class Direction {
|
||||||
private final int direction;
|
public static Direction UP = new Direction() {
|
||||||
public static final int UP = 0, DOWN = 1, LEFT = 2, RIGHT = 3;
|
|
||||||
public Direction(int i){
|
@Override
|
||||||
direction = i;
|
public int getX() {
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
public int getDirection() {
|
|
||||||
return direction;
|
@Override
|
||||||
|
public Direction getOpposite() {
|
||||||
|
return DOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getY() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static Direction DOWN = new Direction() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getX() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Direction getOpposite() {
|
||||||
|
return UP;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getY() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static Direction LEFT = new Direction() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getX() {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Direction getOpposite() {
|
||||||
|
return RIGHT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getY() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static Direction RIGHT = new Direction() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getX() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Direction getOpposite() {
|
||||||
|
return LEFT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getY() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public abstract int getX();
|
||||||
|
|
||||||
|
public abstract Direction getOpposite();
|
||||||
|
|
||||||
|
public abstract int getY();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -6,7 +6,12 @@ import java.util.Random;
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
|
||||||
|
|
||||||
public class Explosion {
|
import MAndApps.apps.spacewars.Entity;
|
||||||
|
import MAndApps.apps.spacewars.Particle;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
@ -21,7 +26,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;
|
||||||
|
|
@ -32,6 +38,7 @@ public class Explosion {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render(Graphics g, int line) {
|
public void render(Graphics g, int line) {
|
||||||
|
|
@ -75,5 +82,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
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,15 @@
|
||||||
import MAndEngine.Engine;
|
import MAndEngine.Engine;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* initializes an engine object that will open up spacewars.
|
||||||
|
* @author mgosselin
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
Engine engine = new Engine(new String[] {"MAndApps.apps.spacewars.SpaceWars"}, false);
|
Engine engine = new Engine(new String[] {"MAndApps.apps.spacewars.SpaceWars"}, false, false);
|
||||||
|
engine.debug = 2;
|
||||||
engine.run();
|
engine.run();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue