Compare commits

...

6 Commits

Author SHA1 Message Date
Marcus Gosselin 1b70098f1f uhkay 2016-02-13 15:24:57 -05:00
Marcus Gosselin 34411e6eb6 Merge remote-tracking branch 'origin/master'
Conflicts:
	src/MAndApps/apps/spacewars/SpaceWars.java
2015-04-02 14:45:33 -04:00
Marcus Gosselin 813909cd25 wut 2015-04-02 14:44:06 -04:00
Marcus Gosselin a69dfac55c stuff 2015-04-01 10:38:46 -04:00
marcus13345 7ceec47bb8 kay 2015-03-27 22:38:53 -04:00
mgosselinUTC 0cb95490b2 made it like...work 2015-03-16 15:05:13 -04:00
9 changed files with 80 additions and 167 deletions

1
.gitignore vendored
View File

@ -43,3 +43,4 @@ Icon
Network Trash Folder
Temporary Items
.apdisk
/bin/

BIN
res/background.png 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 MiB

View File

@ -10,8 +10,9 @@ import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.net.URL;
import java.util.Random;
import java.util.Stack;
import javax.imageio.ImageIO;
@ -22,16 +23,32 @@ import MAndApps.apps.spacewars.shop.Shop;
import MAndApps.apps.spacewars.tools.Explosion;
import MAndEngine.BasicApp;
import MAndEngine.Engine;
<<<<<<< HEAD
import MAndEngine.ImageCreator;
=======
>>>>>>> origin/master
/**
* 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 redPoints = 0, bluePoints = 0, greenPoints = 0, time = 0;
private static int time = 0;
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 Random r = new Random();
private static Stack<Enemy> enemies = new Stack<Enemy>();
private static Stack<Explosion> explosions = new Stack<Explosion>();
private static Stack<String> logs = new Stack<String>();
@ -47,7 +64,7 @@ public class SpaceWars implements BasicApp {
@Override
public void tick() {
addEXP(1);
//addEXP(1);
if (!paused && !shopping) {
time++;
// ticks enemy stack
@ -66,22 +83,15 @@ public class SpaceWars implements BasicApp {
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());
addGreenPoints(enemies.elementAt(i).getColor().getGreen());
addBluePoints(enemies.elementAt(i).getColor().getBlue());
log("You gained " + enemies.elementAt(i).getWorth() + " exp.");
addEXP(enemies.elementAt(i).getWorth());
// enemies.remove(i);
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 );
enemies.remove(i);
} else
i++;
@ -99,10 +109,6 @@ public class SpaceWars implements BasicApp {
expBar += ((int) (((double) xp / (double) xpToNextLVL) * 424) - expBar) / 10;
}
shop.tick();
// check if there are any new items to log
int cap = logs.size();
for (int i = 0; i < cap; i++)
Engine.log(logs.pop());
}
public static void log(String s) {
@ -115,14 +121,14 @@ 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);
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g.setFont(defaultFont);
g.drawImage(background, 0, 0, WIDTH, HEIGHT, null);
g.drawImage(background, 0, 0, null);
for (int i = 0; i < explosions.size(); i++)
explosions.elementAt(i).render(g, i);
@ -131,16 +137,6 @@ public class SpaceWars implements BasicApp {
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);
// render level and xp bar.
g.setFont(levelFont);
g.setColor(Color.WHITE);
@ -148,7 +144,7 @@ public class SpaceWars implements BasicApp {
g.drawRect(330, 18, 424, 15);
g.fillRect(330, 18, expBar, 15);
g.setFont(defaultFont);
if (paused) {
g.setFont(pausedFont);
g.setColor(Color.WHITE);
@ -187,12 +183,17 @@ public class SpaceWars implements BasicApp {
@Override
public void initialize() {
try {
background = ImageIO.read(new URL("http://wallpapersus.com/wallpapers/2012/10/Cool-Wave-600x1024.jpg"));
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);
Graphics g = background.getGraphics();
g.setColor(Color.BLUE);
g.fillRect(0, 0, 1024, 600);
g.fillRect(0, 0, 3000, 2000);
}
}
@ -206,6 +207,7 @@ public class SpaceWars implements BasicApp {
} else if (e.getKeyCode() == KeyEvent.VK_E) {
xp = xpToNextLVL - 1;
} else if (e.getKeyCode() == KeyEvent.VK_Q) {
System.out.println("YOEIRGSODBH");
debug = !debug;
} else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
shopping = !shopping;
@ -231,54 +233,17 @@ 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);
}
public void addRedPoints(int d) {
redPoints += d;
}
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));
}
@ -289,7 +254,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);
}
}
@ -343,4 +308,10 @@ public class SpaceWars implements BasicApp {
BOOM(75, 1.2, 100, 100, 100, 50, Engine.mouseX, Engine.mouseY, 550, true, true, 10);
}
@Override
public void updateDimensions(int width, int height) {
CORRECTED_WIDTH = width;
CORRECTED_HEIGHT = height;
}
}

View File

@ -1,10 +1,11 @@
package MAndApps.apps.spacewars.tools;
package MAndApps.apps.spacewars.entity;
import java.awt.Color;
import java.awt.Graphics;
import java.util.Random;
import MAndApps.apps.spacewars.SpaceWars;
import MAndApps.apps.spacewars.tools.Entity;
public class Particle extends Entity{

View File

@ -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);
}
}
}

View File

@ -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

View File

@ -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 int state = OFF, selection = 0;
private double animationTime = 0;
public void render(Graphics g, final int WIDTH){
g.setColor(selection == 0 ? Color.CYAN : Color.BLUE);
g.fillRect((int)animationTime-BOX_WIDTH, BOX_Y_OFFSET, BOX_WIDTH, BOX_HEIGHT);

View File

@ -5,6 +5,8 @@ import java.awt.Graphics;
import java.util.Random;
import java.util.Stack;
import MAndApps.apps.spacewars.entity.Particle;
public class Explosion {
private Stack<Particle> bits = new Stack<Particle>();

View File

@ -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);
Engine engine = new Engine(new String[] {"MAndApps.apps.spacewars.SpaceWars"}, false, false);
engine.run();
}