From c0cba79892b7d9b41a23d18f0d08b83ac3ed9730 Mon Sep 17 00:00:00 2001 From: marcus13345 Date: Sat, 28 Mar 2015 00:37:05 -0400 Subject: [PATCH] getting rid of bounding box... --- src/MAndApps/apps/spacewars/Entity.java | 22 ++++--------------- src/MAndApps/apps/spacewars/Particle.java | 6 ++--- src/MAndApps/apps/spacewars/SpaceWars.java | 6 ++++- src/MAndApps/apps/spacewars/entity/Enemy.java | 5 ++++- .../apps/spacewars/entity/Player.java | 10 ++++----- .../spacewars/entity/enemy/NormalEnemy.java | 15 +++++++++---- .../apps/spacewars/tools/Explosion.java | 1 - 7 files changed, 30 insertions(+), 35 deletions(-) diff --git a/src/MAndApps/apps/spacewars/Entity.java b/src/MAndApps/apps/spacewars/Entity.java index 8760427..c4f9781 100644 --- a/src/MAndApps/apps/spacewars/Entity.java +++ b/src/MAndApps/apps/spacewars/Entity.java @@ -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(); diff --git a/src/MAndApps/apps/spacewars/Particle.java b/src/MAndApps/apps/spacewars/Particle.java index d36c9ee..9f9c265 100644 --- a/src/MAndApps/apps/spacewars/Particle.java +++ b/src/MAndApps/apps/spacewars/Particle.java @@ -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); } diff --git a/src/MAndApps/apps/spacewars/SpaceWars.java b/src/MAndApps/apps/spacewars/SpaceWars.java index d2b3b2a..f9644cf 100644 --- a/src/MAndApps/apps/spacewars/SpaceWars.java +++ b/src/MAndApps/apps/spacewars/SpaceWars.java @@ -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)); diff --git a/src/MAndApps/apps/spacewars/entity/Enemy.java b/src/MAndApps/apps/spacewars/entity/Enemy.java index 03a0f17..39bfb6a 100644 --- a/src/MAndApps/apps/spacewars/entity/Enemy.java +++ b/src/MAndApps/apps/spacewars/entity/Enemy.java @@ -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){ diff --git a/src/MAndApps/apps/spacewars/entity/Player.java b/src/MAndApps/apps/spacewars/entity/Player.java index d670076..683e9e4 100644 --- a/src/MAndApps/apps/spacewars/entity/Player.java +++ b/src/MAndApps/apps/spacewars/entity/Player.java @@ -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; } diff --git a/src/MAndApps/apps/spacewars/entity/enemy/NormalEnemy.java b/src/MAndApps/apps/spacewars/entity/enemy/NormalEnemy.java index f037f8e..3704a96 100644 --- a/src/MAndApps/apps/spacewars/entity/enemy/NormalEnemy.java +++ b/src/MAndApps/apps/spacewars/entity/enemy/NormalEnemy.java @@ -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); diff --git a/src/MAndApps/apps/spacewars/tools/Explosion.java b/src/MAndApps/apps/spacewars/tools/Explosion.java index 63014c2..6f4e3f0 100644 --- a/src/MAndApps/apps/spacewars/tools/Explosion.java +++ b/src/MAndApps/apps/spacewars/tools/Explosion.java @@ -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;