getting rid of bounding box...

screensaver
marcus13345 2015-03-28 00:37:05 -04:00
parent b30711e2cf
commit c0cba79892
7 changed files with 30 additions and 35 deletions

View File

@ -1,32 +1,18 @@
package MAndApps.apps.spacewars;
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);
}
protected double x, y, dx, dy;
public void keyPressed(KeyEvent e){}
public void keyReleased(KeyEvent e){}
public final double getX(){
return boundingBox.getX();
return x;
}
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;
return y;
}
public abstract boolean isCollidable();

View File

@ -3,10 +3,10 @@ package MAndApps.apps.spacewars;
import java.awt.Color;
import java.awt.Graphics;
import java.util.Random;
import static MAndEngine.Utils.rand;
public class Particle extends Entity{
private double x, y, life, speed;
private double life, speed;
private final int angleDeg, moveLife, renderLife, size;
private final double DECAY;
private boolean alive = false, bubble;
@ -16,7 +16,6 @@ public class Particle extends Entity{
public Particle(int angle, double speed, int movelife, int renderlife,
int x, int y, double speedDecay, int r, int g, int b, int variant,
boolean singleVariant, boolean bubble, int sizeOfParticles) {
super(0, 0, 1, 1);
renderLife = renderlife;
this.speed = speed;
angleDeg = angle;
@ -61,7 +60,6 @@ public class Particle extends Entity{
} else {
color = new Color(rand(0, 256), rand(0, 256), rand(0, 256));
}
updateBoundingBox((int)x, (int)y, size , size);
}

View File

@ -22,6 +22,7 @@ import MAndApps.apps.spacewars.entity.enemy.NormalEnemy;
import MAndApps.apps.spacewars.entity.enemy.RedEnemy;
import MAndApps.apps.spacewars.tools.Explosion;
import MAndEngine.BasicApp;
import MAndEngine.ImageCreator;
public class SpaceWars implements BasicApp {
@ -123,7 +124,10 @@ public class SpaceWars implements BasicApp {
@Override
public void initialize() {
try {
background = ImageIO.read(new URL("http://wallpaperswiki.org/2012/11/Wallpaper-Abstract-Wallpaper-Background-Texture-Texture-Yellow-Pictures-600x1024.jpg"));
//background = ImageIO.read(new URL("http://wallpaperswiki.org/2012/11/Wallpaper-Abstract-Wallpaper-Background-Texture-Texture-Yellow-Pictures-600x1024.jpg"));
background = ImageCreator.colorNoise(Color.WHITE, .4, .6, WIDTH, HEIGHT);
entities.add(player);
for (int i = 0; i < 100; i++)
entities.add(new NormalEnemy(0, 0));

View File

@ -31,7 +31,10 @@ public abstract class Enemy extends Entity {
GREEN_TIER_FIVE = 15;
public Enemy(int x, int y, int width, int height) {
super(x, y, width, height);
super.x = x;
super.y = y;
super.dx = dx;
super.dy = dy;
}
public final static Enemy getNewEnemy(int type, int x, int y){

View File

@ -9,14 +9,12 @@ import MAndApps.apps.spacewars.SpaceWars;
import MAndApps.apps.spacewars.gun.Gun;
import MAndApps.apps.spacewars.tools.Direction;
import MAndApps.apps.spacewars.Entity;
import static MAndEngine.Utils.rand;
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 double dx = 0, dy = 0;
private boolean A = false, S = false, D = false, W = false, alive = true;
private Random r = new Random();
private Gun gun = new Gun(Bullet.BASIC, 25, (int)x, (int)y);
/**
@ -26,7 +24,8 @@ public class Player extends Entity {
private boolean goBoom = false;
public Player() {
super((int) 512, (int) 550, WIDTH, HEIGHT);
x = 512;
y = 550;
}
@Override
@ -110,7 +109,6 @@ public class Player extends Entity {
}
timer++;
}
updateBoundingBox((int) x, (int) y, WIDTH, HEIGHT);
return 0;
}
@ -123,7 +121,7 @@ public class Player extends Entity {
if (alive) {
int temp;
try {
temp = r.nextInt((int) time);
temp = rand(0, (int)time);
} catch (Exception e) {
temp = 1;
}

View File

@ -12,19 +12,26 @@ public class NormalEnemy extends Enemy {
private int health = 2;
private final int MAX_HEALTH = health;
private static final int WIDTH = 16, HEIGHT = 16, PROXIMITY = 200;
private double x, y, time = 0, desiredX, desiredY, Xmod, Ymod, dx = 0, dy = 0;
private double time = 0, desiredX, desiredY, Xmod, Ymod;
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 boolean debug = true, alive = true;
private double healthBar = 1;
private final double reEvaluateTime;
public NormalEnemy(int x, int y) {
this(x, y, Math.random());
}
public NormalEnemy(int x, int y, double hyperness) {
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);
reEvaluateTime = 1 - hyperness;
}
@Override
@ -35,7 +42,7 @@ public class NormalEnemy extends Enemy {
}
if (alive) {
if (SpaceWars.getPlayer().getAlive()) {
if (time > 0.4d) {
if (time > reEvaluateTime) {
time = 0;
Xmod = rand(-PROXIMITY, PROXIMITY);
Ymod = rand(-PROXIMITY, PROXIMITY);
@ -70,7 +77,7 @@ public class NormalEnemy extends Enemy {
} else {
if (time > 0.4d) {
if (time > reEvaluateTime) {
time = 0;
Xmod = rand(0, 1024);
Ymod = rand(0, 200);

View File

@ -16,7 +16,6 @@ public class Explosion extends Entity{
private final int r, g, b, variant;
private final boolean singleVariant;
public Explosion(double speed, double decay, int r, int g, int b, int variant, boolean singleVariant){
super(0, 0, 1, 1);
SPEED = speed;
DECAY = decay;
this.r = r;