wut
parent
a69dfac55c
commit
813909cd25
|
|
@ -43,3 +43,4 @@ Icon
|
|||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
/bin/
|
||||
|
|
|
|||
|
|
@ -23,13 +23,27 @@ import MAndApps.apps.spacewars.shop.Shop;
|
|||
import MAndApps.apps.spacewars.tools.Explosion;
|
||||
import MAndEngine.BasicApp;
|
||||
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 screensaver 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 mand engine
|
||||
* once they are abstracted a little better.
|
||||
*
|
||||
* @author mgosselin
|
||||
*
|
||||
*/
|
||||
public class SpaceWars implements BasicApp {
|
||||
|
||||
//
|
||||
private static boolean paused = false, debug = false;
|
||||
private static int time = 0;
|
||||
private static int WIDTH = 1024, HEIGHT = 600;
|
||||
private static final int WIDTH = 1024, HEIGHT = 600;
|
||||
private static int CORRECTED_WIDTH = WIDTH, CORRECTED_HEIGHT = HEIGHT;
|
||||
private static Player player = new Player();
|
||||
private static Image background;
|
||||
private static Stack<Enemy> enemies = new Stack<Enemy>();
|
||||
|
|
@ -67,10 +81,19 @@ public class SpaceWars implements BasicApp {
|
|||
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 );
|
||||
|
||||
|
||||
|
||||
log("You gained " + enemies.elementAt(i).getWorth() + " exp.");
|
||||
addEXP(enemies.elementAt(i).getWorth());
|
||||
|
||||
// enemies.remove(i);
|
||||
enemies.remove(i);
|
||||
|
||||
} else
|
||||
i++;
|
||||
|
|
@ -100,7 +123,7 @@ public class SpaceWars implements BasicApp {
|
|||
|
||||
@Override
|
||||
public void render(Graphics2D g) {
|
||||
|
||||
g.drawString("SDFGSDFGBORNJSTBRJOSNB", 100, 100);
|
||||
try {
|
||||
|
||||
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
|
|
@ -156,15 +179,18 @@ public class SpaceWars implements BasicApp {
|
|||
|
||||
@Override
|
||||
public Dimension getResolution() {
|
||||
System.out.println("WIDTHasdf: " + WIDTH);
|
||||
System.out.println("HEIGHTsdf: " + HEIGHT);
|
||||
return new Dimension(WIDTH = 1024, HEIGHT = 600);
|
||||
return new Dimension(WIDTH, HEIGHT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
try {
|
||||
background = ImageIO.read(new FileInputStream(new File("res/background.png")));
|
||||
//background = ImageIO.read(new FileInputStream(new File("res/background.png")));
|
||||
Engine.timeScale = 1d / (1000d/(1000d/60));
|
||||
|
||||
background = ImageCreator.colorNoise(Color.WHITE, .4, .6, CORRECTED_WIDTH, CORRECTED_HEIGHT);
|
||||
for(int i = 0; i < 10; i ++)
|
||||
enemies.add(Enemy.getNewEnemy(Enemy.NORMAL, 0, 0));
|
||||
|
||||
} catch (Exception e) {
|
||||
background = (Image) new BufferedImage(1024, 600, BufferedImage.TRANSLUCENT);
|
||||
|
|
@ -209,17 +235,13 @@ public class SpaceWars implements BasicApp {
|
|||
return new Color(88, 128, 255);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFramerate() {
|
||||
return 50;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getResizable() {
|
||||
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);
|
||||
}
|
||||
|
|
@ -234,7 +256,7 @@ public class SpaceWars implements BasicApp {
|
|||
xp -= xpToNextLVL;
|
||||
lvl++;
|
||||
xpToNextLVL = getMaxXPForLvl(lvl);
|
||||
for (int j = 0; j < 424; j += 100) {
|
||||
for (int j = 12; j < 424; j += 100) {
|
||||
BOOM(75, 1.618, 255, 255, 255, 0, 300 + (j), 20, 200, true, false, 2);
|
||||
}
|
||||
}
|
||||
|
|
@ -291,9 +313,7 @@ public class SpaceWars implements BasicApp {
|
|||
|
||||
@Override
|
||||
public void updateDimensions(int width, int height) {
|
||||
System.out.println("" + WIDTH);
|
||||
System.out.println("" + HEIGHT);
|
||||
WIDTH = width;
|
||||
HEIGHT = height;
|
||||
CORRECTED_WIDTH = width;
|
||||
CORRECTED_HEIGHT = height;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,9 +6,11 @@ import java.awt.event.KeyEvent;
|
|||
import java.util.Random;
|
||||
|
||||
import MAndApps.apps.spacewars.SpaceWars;
|
||||
import MAndApps.apps.spacewars.entity.enemy.NormalEnemy;
|
||||
import MAndApps.apps.spacewars.gun.Gun;
|
||||
import MAndApps.apps.spacewars.tools.Direction;
|
||||
import MAndApps.apps.spacewars.tools.Entity;
|
||||
import MAndEngine.Engine;
|
||||
|
||||
public class Player extends Entity {
|
||||
private final static int WIDTH = 16, HEIGHT = 16;
|
||||
|
|
@ -26,6 +28,10 @@ public class Player extends Entity {
|
|||
|
||||
@Override
|
||||
public int tick() {
|
||||
double ACC = Player.ACC * Engine.deltaTime / 10;
|
||||
double dx = this.dx * Engine.deltaTime / 10;
|
||||
double dy = this.dy * Engine.deltaTime / 10;
|
||||
|
||||
if (goBoom) {
|
||||
SpaceWars.BOOM(50, 1.2, 50, 50, 50, 30, (int) x, (int) y, 550, true,
|
||||
false, 3);
|
||||
|
|
@ -184,85 +190,8 @@ public class Player extends Entity {
|
|||
|
||||
}
|
||||
|
||||
public void collideWithEnemy(double x, double y) {
|
||||
goBoom = true;
|
||||
timer = 0;
|
||||
alive = false;
|
||||
time = 5;
|
||||
}
|
||||
|
||||
public boolean getAlive() {
|
||||
return alive;
|
||||
}
|
||||
|
||||
public void setLevel(int i) {
|
||||
switch (i) {
|
||||
case 2:
|
||||
gun.switchAmmo(Bullet.PLAYER_PIERCE_ONE);
|
||||
break;
|
||||
case 3:
|
||||
gun.switchAmmo(Bullet.PLAYER_PIERCE_TWO);
|
||||
break;
|
||||
case 4:
|
||||
gun.switchAmmo(Bullet.PLAYER_PIERCE_THREE);
|
||||
break;
|
||||
case 5:
|
||||
gun.switchAmmo(Bullet.PLAYER_PIERCE_FOUR);
|
||||
break;
|
||||
case 6:
|
||||
gun.switchAmmo(Bullet.PLAYER_PIERCE_FIVE);
|
||||
break;
|
||||
case 7:
|
||||
gun.switchAmmo(Bullet.PLAYER_PIERCE_SIX);
|
||||
break;
|
||||
case 8:
|
||||
gun.switchAmmo(Bullet.PLAYER_PIERCE_SEVEN);
|
||||
break;
|
||||
case 9:
|
||||
gun.switchAmmo(Bullet.PLAYER_PIERCE_EIGHT);
|
||||
break;
|
||||
case 10:
|
||||
gun.switchAmmo(Bullet.PLAYER_PIERCE_NINE);
|
||||
break;
|
||||
case 11:
|
||||
gun.switchAmmo(Bullet.PLAYER_PIERCE_TEN);
|
||||
break;
|
||||
case 12:
|
||||
gun.switchAmmo(Bullet.PLAYER_EXPLOSIVE_ONE);
|
||||
break;
|
||||
case 13:
|
||||
gun.switchAmmo(Bullet.PLAYER_EXPLOSIVE_TWO);
|
||||
break;
|
||||
case 14:
|
||||
gun.switchAmmo(Bullet.PLAYER_EXPLOSIVE_THREE);
|
||||
break;
|
||||
case 15:
|
||||
gun.switchAmmo(Bullet.PLAYER_EXPLOSIVE_FOUR);
|
||||
break;
|
||||
case 16:
|
||||
gun.switchAmmo(Bullet.PLAYER_EXPLOSIVE_FIVE);
|
||||
break;
|
||||
case 17:
|
||||
gun.switchAmmo(Bullet.PLAYER_EXPLOSIVE_SIX);
|
||||
break;
|
||||
case 18:
|
||||
gun.switchAmmo(Bullet.PLAYER_EXPLOSIVE_SEVEN);
|
||||
break;
|
||||
case 19:
|
||||
gun.switchAmmo(Bullet.PLAYER_EXPLOSIVE_EIGHT);
|
||||
break;
|
||||
case 20:
|
||||
gun.switchAmmo(Bullet.PLAYER_EXPLOSIVE_NINE);
|
||||
break;
|
||||
case 21:
|
||||
gun.switchAmmo(Bullet.PLAYER_EXPLOSIVE_TEN);
|
||||
break;
|
||||
case 22:
|
||||
gun.switchAmmo(Bullet.PLAYER_GODMODE);
|
||||
break;
|
||||
}
|
||||
if(i >= 22){
|
||||
gun.switchAmmo(Bullet.PLAYER_GODMODE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,17 +6,18 @@ import java.util.Random;
|
|||
|
||||
import MAndApps.apps.spacewars.SpaceWars;
|
||||
import MAndApps.apps.spacewars.entity.Enemy;
|
||||
import MAndEngine.Engine;
|
||||
|
||||
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,
|
||||
private double x, y, time = 0, absoluteTime = 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 boolean debug = true, alive = true;
|
||||
private double healthBar = 1;
|
||||
|
||||
public NormalEnemy(int x, int y) {
|
||||
|
|
@ -30,6 +31,9 @@ public class NormalEnemy extends Enemy {
|
|||
|
||||
@Override
|
||||
public int tick() {
|
||||
double ACC = NormalEnemy.ACC * Engine.deltaTime;
|
||||
double dx = this.dx * Engine.deltaTime;
|
||||
double dy = this.dy * Engine.deltaTime;
|
||||
// epic AI
|
||||
if((int)healthBar <= 0){
|
||||
alive = false;
|
||||
|
|
@ -123,27 +127,27 @@ public class NormalEnemy extends Enemy {
|
|||
while (y < 0)
|
||||
y++;
|
||||
}
|
||||
time += 0.01;
|
||||
absoluteTime++;
|
||||
time += 0.01 * Engine.deltaTime;
|
||||
absoluteTime += 0.01 * Engine.deltaTime;
|
||||
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);
|
||||
temp = r.nextDouble() > absoluteTime / 2000 ? 1 : 0;
|
||||
}catch(Exception e){
|
||||
temp = 0;
|
||||
}
|
||||
|
||||
if (temp == 0) if (alive) g.fillRect((int) x, (int) y, WIDTH, HEIGHT);
|
||||
if (debug) g.drawLine((int) x, (int) y, (int) desiredX, (int) desiredY);
|
||||
|
||||
if (debug) g.drawLine((int) x + 8, (int) y + 8, (int) desiredX + 8, (int) desiredY + 8);
|
||||
|
||||
healthBar += ((((double)health/(double)MAX_HEALTH)*16) - healthBar)/6;
|
||||
//healthbar
|
||||
|
|
|
|||
|
|
@ -1,10 +1,14 @@
|
|||
import MAndEngine.Engine;
|
||||
|
||||
|
||||
/**
|
||||
* initializes an engine object that will open up spacewars.
|
||||
* @author mgosselin
|
||||
*
|
||||
*/
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
|
||||
Engine engine = new Engine(new String[] {"MAndApps.apps.spacewars.SpaceWars"}, false, true);
|
||||
Engine engine = new Engine(new String[] {"MAndApps.apps.spacewars.SpaceWars"}, false, false);
|
||||
engine.run();
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue