Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/market'
Browse files Browse the repository at this point in the history
  • Loading branch information
Magneseus committed Apr 14, 2015
2 parents c1f9917 + 0753574 commit c53fb24
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 14 deletions.
2 changes: 2 additions & 0 deletions Solarus/AI.pde
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ class AIAttack implements AIState
ptmp.vel = PVector.fromAngle(self.getAngle()-PI/2);
ptmp.vel.setMag(ptmp.maxVel);

ptmp.setDamage(self.getDamage());

if (PVector.angleBetween(ptmp.vel, self.vel) < PI/2)
ptmp.vel.add(self.vel);

Expand Down
82 changes: 73 additions & 9 deletions Solarus/Market.pde
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
public class Market extends State {

//set up UIGroups
private UIGroup GMMenu;
private UIGroup BSButtons;
private UIGroup UpButtons;

//Set up The Availiabel Resources and thier colours
private Resource[] TradeGoods = new Resource[8];
private color[] colours = {
color(255, 0, 0),
Expand All @@ -16,9 +18,11 @@ public class Market extends State {
color(255, 0, 255)
};

//set up the Goods inventory and money
private int[] GoodsStore = new int[8];
private int Money = 500;
private int Money;

//Constructor calls super and initalizes the availiable resources
public Market(StateManager sm) {
super(sm);

Expand All @@ -31,13 +35,18 @@ public class Market extends State {
TradeGoods[6] = new Resource("Water", 500, 100, TAU-HALF_PI, colours[6]);
TradeGoods[7] = new Resource("Food", 500, 90, PI, colours[7]);

Money = 500;

GMMenu = new UIGroup(new PVector(width/2, height/2), new PVector(0, 0));
}

public int getMoney(){return Money;}

//initializes state upon entering
public void init() {

//buttons for both buying/selling resources and upgrades
BSButtons = new UIGroup(new PVector(width/2, height/2));

BSButtons.add(new UIButton(new PVector(395, -405), new PVector(35, 20), "", new BuyGoods0(), color(0, 255, 0), color(75, 200, 255)));
BSButtons.add(new UIButton(new PVector(435, -405), new PVector(35, 20), "", new SellGoods0(), color(255, 0, 0), color(75, 200, 255)));
BSButtons.add(new UIButton(new PVector(395, -310), new PVector(35, 20), "", new BuyGoods1(), color(0, 255, 0), color(75, 200, 255)));
Expand All @@ -62,11 +71,14 @@ public class Market extends State {
UpButtons.add(new UIButton(new PVector(965, 870), new PVector(112, 112), "", new BuyRepair(), color(0, 0, 0, 0), color(75, 200, 255)));
UpButtons.add(new UIButton(new PVector(1130, 870), new PVector(112, 112), "", new BuyShip(), color(0, 0, 0, 0), color(75, 200, 255)));


//updates the values of the availible resources
for (int i=0; i<TradeGoods.length; i++)
{
TradeGoods[i].update();
}

//pause menu
PGraphics tmpBack = createGraphics(500, 650);
tmpBack.beginDraw();
tmpBack.fill(50, 50, 50, 150);
Expand Down Expand Up @@ -124,6 +136,7 @@ public class Market extends State {
new ReturnToLevel() ));
}

//updates buttons in pause menu or market screen
public boolean update() {
if (!pause)
{
Expand Down Expand Up @@ -153,9 +166,10 @@ public class Market extends State {

return true;
}

//renders the market screen or pause menu
public void render() {
background(0);
//renders gaph
for (int i=0; i<TradeGoods.length; i++) {
TradeGoods[i].render((i+1)*95);
fill(TradeGoods[i].col);
Expand All @@ -167,12 +181,17 @@ public class Market extends State {
noFill();
rectMode(CORNERS);
rect(170, 83, 1170, 772);
for (int i=1; i<5; i++) {
line(170+(i*200), 83, 170+(i*200), 772);
}
//stroke(255, 0, 0);
//line(185, 77, 185, 724);

//renders buttons
BSButtons.render(new PVector(0, 0));
UpButtons.render(new PVector(0, 0));

//redners upgrade button graphics
textSize(20);
noStroke();
fill(0, 255, 0);
Expand Down Expand Up @@ -205,6 +224,7 @@ public class Market extends State {
fill(75, 200, 255);
text(("Money: "+Money), 1418, 190);

//renders pause menu
if (pause)
{
if (options)
Expand All @@ -216,7 +236,7 @@ public class Market extends State {
}
}
}

//buy/sell button functions
class BuyGoods0 implements Command {
public void execute()
{
Expand Down Expand Up @@ -361,34 +381,78 @@ public class Market extends State {
}
}
}
//buy upgrade button functions
class BuyHealth implements Command {
public void execute()
{
println("Health Upgrade Bought");
if (Money>=100) {
println("Health Upgrade Bought");
for (int i=0; i<gameRef.players.size (); i++) {
gameRef.players.get(i).getHealthMax().add(5);
}
Money -= 100;
}
}
}
class BuyDamage implements Command {
public void execute()
{
println("Damage Upgrade Bought");
if (Money>=100) {
println("Damage Upgrade Bought");
for (int i=0; i<gameRef.players.size (); i++) {
gameRef.players.get(i).setDamage(gameRef.players.get(i).getDamage()+1);
}
Money -= 100;
}
}
}
class BuyShield implements Command {
public void execute()
{
println("Shield Upgrade Bought");
if (Money>=100) {
println("Shield Upgrade Bought");
for (int i=0; i<gameRef.players.size (); i++) {
gameRef.players.get(i).getShieldMax().add(200);
}
Money -= 100;
}
}
}
class BuyRepair implements Command {
public void execute()
{
println("Repairs Bought");
if (Money>=100) {
println("Repairs Bought");
for (int i=0; i<gameRef.players.size (); i++) {
gameRef.players.get(i).getHealth().add(5);
}
Money -= 100;
}
}
}
class BuyShip implements Command {
public void execute()
{
println("Ship Bought");
if (Money>=100) {
println("Ship Bought");
PC p;
p = parsePC("enemy_basic.player");
//PGraphics im = createGraphics(40,40);
//im.beginDraw();
//im.stroke(0,255,0);
//im.fill(0,255,0);
//im.triangle(0, 40, 20, 0, 40, 40);
//im.endDraw();
//p.setImage(im);
p.setImageInd(gameRef.control.getImageInd());
p.setImage(playerImages[p.getImageInd()]);
p.moveTo(new PVector(gameRef.control.pos.x + random(-200, 200),
gameRef.control.pos.y + random(-200, 200)));
p.projList = gameRef.playerProj;
p.enemyList = gameRef.enemies;
gameRef.players.add(p);
Money -= 100;
}
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions Solarus/PC.pde
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class PC extends Entity
private int shieldTimer = 0, shieldCool;
private float shieldAccel, shieldVel, shieldMaxVel;
private int projCount, projMax;
public int pDamage;
private boolean inControl;
private float percentF, percentB, percentS, slow, rotThresh;

Expand Down Expand Up @@ -62,6 +63,7 @@ class PC extends Entity

projCount = 0;
inControl = false;
pDamage = 1;

percentF = 1;
percentS = 1;
Expand Down Expand Up @@ -281,6 +283,9 @@ class PC extends Entity
public int getImageInd(){ return imageInd; }
public void setImageInd(int imageInd){ this.imageInd = imageInd; }

public void setDamage(int d) {pDamage = d;}
public int getDamage() {return pDamage;}

void setProjMax(int h)
{
projMax = h;
Expand Down
10 changes: 8 additions & 2 deletions Solarus/StateManager.pde
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

GIState gameRef;
int mon = 0;
int monMax = 50000;

class StateManager
{
Expand All @@ -17,6 +19,8 @@ class StateManager
stateList[1] = new GIState(this);
stateList[2] = new Market(this);

gameRef = (GIState)stateList[1];

optionsMenu = new UIGroup(new PVector(width/2, height/2), new PVector(0,0));

class unoptions implements Command { public void execute(){options=false;} }
Expand All @@ -36,7 +40,9 @@ class StateManager

public boolean run()
{
boolean finalRun = true;
boolean finalRun = true;

mon = ((Market)stateList[2]).getMoney();

// Main Menu
for (int i = 0; i < stateList.length; i++)
Expand Down
24 changes: 21 additions & 3 deletions Solarus/States.pde
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ public class GIState extends State
HUD.add(new UIStatusBar(
new PVector(width/2, height-40),
new PVector(250,15),
money,
moneyMax,
color(0,255,0) ));
new IntBox(mon),
new IntBox(monMax),
color(#D1C326) ));

// Game Menu
PGraphics tmpBack = createGraphics(500,650);
Expand Down Expand Up @@ -306,6 +306,7 @@ public class GIState extends State
toast.pushToast("Press Q & E to switch ships.", 4000);
toast.pushToast("Press the '~' key for the menu.", 4000);
toast.pushToast("Press F when over a planet for the market.", 4000);
toast.pushToast("Good luck!.", 4000);
fRun = false;
}
}
Expand All @@ -314,6 +315,23 @@ public class GIState extends State
{
float delta = 30 / frameRate;

UIStatusBar x = (UIStatusBar)HUD.getElements().get(3);
x.setVal(new IntBox(mon));

if (players.size() == 0)
{
sm.changeState("MAIN_MENU");
toast.pushToast("GAME OVER.", 2000);
toast.pushToast("Score: " + mon, 2000);
}

if (mon >= monMax)
{
sm.changeState("MAIN_MENU");
toast.pushToast("YOU WIN.", 2000);
toast.pushToast("Score: " + mon, 2000);
}

//If game is running
if (!pause)
{
Expand Down

0 comments on commit c53fb24

Please sign in to comment.