Skip to content

Commit

Permalink
Changed card drawing/reshuffling
Browse files Browse the repository at this point in the history
  • Loading branch information
nrichman committed May 3, 2017
1 parent 4d3383b commit 298d788
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 4 deletions.
62 changes: 58 additions & 4 deletions GOTY 2K17/src/game/Game.java
Expand Up @@ -23,7 +23,9 @@
import game.maps.TownMap;
import game.menu.Button;
import game.menu.DeckMaker;
import game.menu.DrawButton;
import game.menu.LevelSelect;
import game.menu.ReshuffleButton;
import game.menu.TitleScreen;
import game.sound.PlayerControl;
import game.units.GameOverSprite;
Expand Down Expand Up @@ -69,9 +71,15 @@ public class Game extends TileFramework {
private TitleScreen title;
private LevelSelect level;
private DeckMaker deckEditor;
private DrawButton drawButton;
private ReshuffleButton reshuffleButton;
Button quitButton;
Button doneButton;


private int drawCost=25; //Cost to draw a card
private int reshuffleCost=0; //Cost to reshuffle deck
private int startHand = 0; //Draw 5 cards at start of game

@Override
protected void initialize() {
super.initialize();
Expand All @@ -98,7 +106,11 @@ protected void initialize() {

deck = deckEditor.getDeck();
deck.resetDeck();

deck.getHand().clear();

drawButton = new DrawButton(getWorld());
reshuffleButton = new ReshuffleButton(getWorld());
}

protected void restart(){
Expand All @@ -117,6 +129,7 @@ protected void restart(){
this.getWorld().getUnits().clear();
getWorld().setGameover(false);
getWorld().getMap().addBoss(getWorld(), new Boss(getWorld()));
startHand = 0;
}

@Override
Expand All @@ -128,7 +141,7 @@ protected void processInput(float delta) {
if (mouseVec.x < .55 && mouseVec.x > -.55 && mouseVec.y < -1.2 && mouseVec.y > -1.57) {
if (mouse.buttonDownOnce(MouseEvent.BUTTON1)) {
titleScreen = false;
levelSelection = true;
deckCreation = true;
return;
}
title.selectButton();
Expand Down Expand Up @@ -199,9 +212,17 @@ else if (mouseVec.x < .4 && mouseVec.x > -.4 && mouseVec.y < -1.22 && mouseVec.y

if (gameplay) {
if (!pause) {

if(deck.getCardsRemaining() == 0) reshuffleCost = 0;
else reshuffleCost = 100;

if(deck.getHand().size() < 5 && startHand == 0){
if(deck.getCardsRemaining() == 0) startHand = 1;
deck.drawCard();
} else startHand = 1;
// Player drops card
if (!mouse.buttonDown(MouseEvent.BUTTON1) && grabbedCard != null) {
if (onBoard(mouseVec) && (getWorld().getBoneNum() > grabbedCard.getCost())) {
if (onBoard(mouseVec) && (getWorld().getBoneNum() >= grabbedCard.getCost())) {
if (grabbedCard instanceof MonsterSpawnCard || grabbedCard instanceof UnitSelectCard
|| grabbedCard instanceof TrapSpawnCard) {
selectingTarget = true;
Expand Down Expand Up @@ -265,7 +286,6 @@ else if (mouseVec.x < .4 && mouseVec.x > -.4 && mouseVec.y < -1.22 && mouseVec.y
// Draw card by clicking on deck
if (deck.getCardBack().isPointWithin(mouseVec)) {
if (mouse.buttonDownOnce(MouseEvent.BUTTON1)) {
deck.drawCard();
}
}

Expand All @@ -291,6 +311,20 @@ else if (mouseVec.x < .4 && mouseVec.x > -.4 && mouseVec.y < -1.22 && mouseVec.y
// getWorld().addUnitToTile(new TileLocation(0, 5), new Freelancer(getWorld()));
// getWorld().addUnitToTile(new TileLocation(0, 8), new Freelancer(getWorld()));
}
System.out.println(mouseVec.x + " " + mouseVec.y);
if (mouseVec.x < 2.91 && mouseVec.x > 2.045 && mouseVec.y < -.84 && mouseVec.y > -1.03) {
if (mouse.buttonDownOnce(MouseEvent.BUTTON1) && getWorld().getBoneNum() >= drawCost && deck.getCardsRemaining() > 0){
deck.drawCard();
getWorld().setBoneNum(getWorld().getBoneNum() - drawCost);
}
}
if (mouseVec.x < 2.91 && mouseVec.x > 2.045 && mouseVec.y < -1.78 && mouseVec.y > -1.98) {
if (mouse.buttonDownOnce(MouseEvent.BUTTON1) && getWorld().getBoneNum() >= reshuffleCost){
getWorld().setBoneNum(getWorld().getBoneNum() - reshuffleCost);
deck.resetDeck();
deck.getHand().clear();
}
}
}
if (keyboard.keyDownOnce(KeyEvent.VK_ESCAPE)) {
pause = !pause;
Expand Down Expand Up @@ -398,6 +432,8 @@ protected void render(Graphics g) {
message = "select target location";
if (activatedCard instanceof MonsterSpawnCard)
message = "select summon location";
if (activatedCard instanceof TrapSpawnCard)
message = "select build location";
g.drawString(message, 581, 666);
message = "";
}
Expand Down Expand Up @@ -426,7 +462,25 @@ else if ((selectingTarget || grabbedCard == null && !pause) && onBoard(mouseVec)
deck.getCardBack().setView(view);
if (deck.getCardsRemaining() > 0)
deck.getCardBack().draw(g2d);

g.setFont(new Font("Titillium Web", Font.PLAIN, 18));
g.setColor(Color.WHITE);

drawButton.setView(view);
drawButton.draw(g2d);
reshuffleButton.setView(view);
reshuffleButton.draw(g2d);


g.drawString(String.format("%03d", drawCost), 1376, 703);
g.drawString(String.format("%03d", reshuffleCost), 1376, 927);

//Render wave num and bones
g.setFont(new Font("Titillium Web", Font.PLAIN, 25));
g.drawString(String.format("%03d", getWorld().getWaveNum()), 99, 664);
g.drawString(String.format("%04d", getWorld().getBoneNum()), 1292, 664);


// Render grabbed card last so it's on top of everything
if (grabbedCard != null)
grabbedCard.draw(g2d);
Expand Down
36 changes: 36 additions & 0 deletions GOTY 2K17/src/game/menu/DrawButton.java
@@ -0,0 +1,36 @@
package game.menu;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;

import javax.imageio.ImageIO;

import game.TileWorld;
import game.sprites.BoundingSprite;
import game.units.monsters.Zombie;
import game.vectors.AxisAlignedBoundingBox;
import game.vectors.Vector2f;

public class DrawButton extends BoundingSprite{

private static BufferedImage spriteSheet;

private static ArrayList<BufferedImage> buttonList;

static{
URL url = Zombie.class.getResource("/resources/menus/buttons/drawButton.png");
try {
spriteSheet = (ImageIO.read(url));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

public DrawButton(TileWorld world) {
super(spriteSheet, 1, 1);
this.setLocation(new Vector2f(2.485f, -.95f));
}
}
35 changes: 35 additions & 0 deletions GOTY 2K17/src/game/menu/ReshuffleButton.java
@@ -0,0 +1,35 @@
package game.menu;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;

import javax.imageio.ImageIO;

import game.TileWorld;
import game.sprites.BoundingSprite;
import game.units.monsters.Zombie;
import game.vectors.Vector2f;

public class ReshuffleButton extends BoundingSprite{

private static BufferedImage spriteSheet;

private static ArrayList<BufferedImage> buttonList;

static{
URL url = Zombie.class.getResource("/resources/menus/buttons/reshuffleButton.png");
try {
spriteSheet = (ImageIO.read(url));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

public ReshuffleButton(TileWorld world) {
super(spriteSheet, 1, 1);
this.setLocation(new Vector2f(2.485f, -1.885f));
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 298d788

Please sign in to comment.