Skip to content

Commit

Permalink
refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
asalga committed Nov 17, 2013
1 parent 0768adc commit f266f11
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 79 deletions.
4 changes: 0 additions & 4 deletions AssetStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,13 @@ public class AssetStore{
private String BASE_IMG_PATH = "data/images/gems/diablo/";
private PImage[] images;
private String[] imageNames = { "A.png","B.png", "C.png", "D.png", "E.png", "F.png", "G.png"};
//"red_gem.gif", "green_gem.gif", "blue_gem.gif", "yellow_gem.gif", "white_gem.gif", "skull_gem.gif", "purple_gem.gif"};
//"red_normal.gif", "green_normal.gif", "blue_normal.gif", "yellow_normal.gif", "white_normal.gif", "skull_normal.gif", "purple_normal.gif"};

/*
*/
public PImage get(int asset){
return images[asset];
}

//public PImage get(String asset){}

/* As soon as this is contructed, load all the assets
*/
private AssetStore(){
Expand Down
21 changes: 0 additions & 21 deletions FPSTimer.pde

This file was deleted.

13 changes: 8 additions & 5 deletions Horadrix.pde
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import ddf.minim.*;

final boolean DEBUG_CONSOLE_ON = false;
final boolean DEBUG_ON = true;
final boolean SHOW_ALL_TOKENS = true;
final boolean DEBUG_ON = false;
final boolean SHOW_ALL_TOKENS = false;

// This includes the entire board, including the 'queued' tokens not visible
// to the user, that sit above the token the user interacts with.
Expand All @@ -25,7 +25,7 @@ final int START_ROW_INDEX = 8;
final int TOKEN_SIZE = 32;

final int CANVAS_WIDTH = 620;
final int CANVAS_HEIGHT = 650;//650;
final int CANVAS_HEIGHT = 400;

// We define the board size in pixels and allow it to be any size
// and have the tokens center themselves inside those dimensions.
Expand All @@ -38,18 +38,18 @@ final int BOARD_H_IN_PX = TOKEN_SIZE * 8; //273;

// Where on the canvas the tokens start to be rendered.
final int START_X = (int)(CANVAS_WIDTH/2.0f - BOARD_W_IN_PX/2.0f);
final int START_Y = (int)(CANVAS_HEIGHT/2.0f - BOARD_H_IN_PX/2.0f) + 150;
final int START_Y = (int)(CANVAS_HEIGHT/2.0f - BOARD_H_IN_PX/2.0f);// + 150;

// Used by the AssetStore
PApplet globalApplet;

Token[][] board = new Token[BOARD_ROWS][BOARD_COLS];

ScreenSet screens = new ScreenSet();
ScreenStory screenStory;

SoundManager soundManager;


/*
Wrap println so we can easily disable all console output on release
*/
Expand All @@ -72,9 +72,12 @@ void setup(){
soundManager.init();
soundManager.setMute(true);

screenStory = new ScreenStory();

screens.add(new ScreenSplash());
screens.add(new ScreenGameplay());
screens.add(new ScreenGameOver());
screens.add(screenStory);

screens.transitionTo("splash");
}
Expand Down
4 changes: 4 additions & 0 deletions RetroFont.pde
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ public class RetroFont{
//PImage fontSheet = loadImage(imageFilename);
public PImage getGlyph(char ch){
int asciiCode = Utils.charCodeAt(ch);

if(asciiCode-32 >= 96 || asciiCode-32 <= 0){
return chars[0];
}

return chars[asciiCode-32];
}
Expand Down
19 changes: 14 additions & 5 deletions RetroLabel.pde
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,24 @@ public class RetroLabel extends RetroPanel{
dirty = true;

int newWidth = 0;
for(int letter = 0; letter < text.length(); letter++){
int newHeight = font.getGlyphHeight();

int longestLine = 0;

PImage glyph = getGlyph(text.charAt(letter));
for(int letter = 0; letter < text.length(); letter++){

if(glyph != null){
newWidth += glyph.width + horizontalSpacing;
if((text.charAt(letter)) == 10){
newHeight += font.getGlyphHeight();
}
else{
PImage glyph = getGlyph(text.charAt(letter));

if(glyph != null){
newWidth += glyph.width + horizontalSpacing;
}
}
}

h = newHeight;
w = newWidth;
}

Expand Down
64 changes: 27 additions & 37 deletions ScreenGameplay.pde
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ public class ScreenGameplay implements IScreen, Subject{
LayerObserver hudLayer = new HUDLayer(this);

gemsRequiredForLevel = currLevel * 5;

//floatingTokens = new ArrayList<Token>();

dyingTokens = new ArrayList<Token>();

bk = loadImage("data/images/boards/board.png");
Expand Down Expand Up @@ -124,7 +123,6 @@ public class ScreenGameplay implements IScreen, Subject{
background(0);

pushMatrix();

translate(START_X, START_Y);

//rect(0,0, BOARD_W_IN_PX, BOARD_H_IN_PX);
Expand Down Expand Up @@ -152,10 +150,6 @@ public class ScreenGameplay implements IScreen, Subject{
dyingTokens.get(i).draw();
}

//for(int i = 0; i < floatingTokens.size(); i++){
// floatingTokens.get(i).draw();
// }

if(swapToken1 != null){
swapToken1.draw();
}
Expand All @@ -165,7 +159,6 @@ public class ScreenGameplay implements IScreen, Subject{

drawBoard();


// In some cases it is necessary to see the non-visible tokens
// above the visible board. Other cases, I want that part covered.
// for example, when tokens are falling.
Expand Down Expand Up @@ -225,7 +218,13 @@ public class ScreenGameplay implements IScreen, Subject{
// DROP TOKENS
if(Keyboard.isKeyDown(KEY_D)){
dropTokens();
}
}

// NEXT LEVEL
if(Keyboard.isKeyDown(KEY_L)){
goToNextLevel();
}


timer.tick();
float td = timer.getDeltaSec();
Expand Down Expand Up @@ -302,6 +301,7 @@ public class ScreenGameplay implements IScreen, Subject{
}
}

// TODO: refactor?
// Iterate over all the tokens that are dying and increase the score.
for(int i = 0; i < dyingTokens.size(); i++){

Expand All @@ -320,26 +320,26 @@ public class ScreenGameplay implements IScreen, Subject{

dyingTokens.remove(i);
tokensDestroyed++;

}
}

if(DEBUG_ON){
debug.addString("dyingTokens: " + dyingTokens.size());
}

// Update all tokens on board. This includes the falling tokens
for(int r = BOARD_ROWS-1; r >= 0 ; r--){
for(int r = BOARD_ROWS - 1; r >= 0 ; r--){
for(int c = 0; c < BOARD_COLS; c++){
Token t = board[r][c];
t.update(td);

if(t.isFalling() && t.arrivedAtDest()){ //fallingDown
if(t.isFalling() && t.arrivedAtDest()){
t.dropIntoCell();
numTokensArrivedAtDest++;

// If the top token arrived at its destination, it means we can safely
// fill up tokens above it.
// If the top token arrived at its destination, it means we can safely fill up tokens above it.
if(t.getFillCellMarker()){
//markTokensForRemoval(false);
//removeMarkedTokens(true);
//dropTokens();
//board[r][c].setFillCellMarker(false);
fillInvisibleSectionOfColumn(t.getColumn());
setFillMarker(t.getColumn());
}
Expand Down Expand Up @@ -528,7 +528,6 @@ public class ScreenGameplay implements IScreen, Subject{
*
*/
void animateSwapTokens(Token t1, Token t2){
println("animate swap tokens");
int t1Row = t1.getRow();
int t1Col = t1.getColumn();

Expand Down Expand Up @@ -635,29 +634,16 @@ public class ScreenGameplay implements IScreen, Subject{
}

/**
TODO: refactor 'ok'
From bottom to top, search to find first gap
After finding the first gap, set the marker
Find first token, set dst to marker
Increment marker by 1
Find next token
For all the tokens above that gap, until very top
a) detach tokens from board
b) give them appropriate positions
c) give them a velocity
d) give them destination positions
e) place tokens in special floating tokens array to keep track of them.
f) update tokens and allow them to add themselves back in
Find next token
*/
void dropTokens(){

for(int c = 0; c < BOARD_COLS; c++){

// TODO: fix
//if(board[0][c].fallingDown){
// continue;
//}

boolean ok = false;
int dst = BOARD_ROWS;
int src;
Expand All @@ -679,14 +665,11 @@ public class ScreenGameplay implements IScreen, Subject{
}
}

//println("drop");
while(src >= 0){

// move the first token
if(ok){
Token tokenToMove = board[src][c];
tokenToMove.fallTo(dst, c);
//tokenToMove.fallingDown = true;
}
do{
src--;
Expand Down Expand Up @@ -1138,6 +1121,11 @@ public class ScreenGameplay implements IScreen, Subject{
*/
void goToNextLevel(){

screenStory.nextLevel();
screens.transitionTo("story");



// Should the score be reset?
// score = 0;
gemCounter = 0;
Expand All @@ -1156,6 +1144,8 @@ public class ScreenGameplay implements IScreen, Subject{

numGemsOnBoard = currLevel + 1;

fillBoardWithRandomTokens();
//animateLevel();
generateNewBoard();
//fillBoardWithRandomTokens();
}
}
3 changes: 2 additions & 1 deletion ScreenSplash.pde
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public class ScreenSplash implements IScreen{
public void update(){
ticker.tick();
if(ticker.getTotalTime() > 0.5f){
screens.transitionTo("gameplay");
//screens.transitionTo("gameplay");
screens.transitionTo("story");
}
}

Expand Down
62 changes: 62 additions & 0 deletions ScreenStory.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
*/
public class ScreenStory implements IScreen{

private int storyPointer = 0;

RetroFont solarWindsFont;

RetroLabel storyLabel;
RetroLabel continueInstruction;

private String[] story = new String[]{
//There once were some dino
"MATCH 5 GEMS IN 5 MINUTES",
"Match 10 gems in 8 minutes",
"Match 15 gems in 13 minutes",
"Match 20 gems in 15 minutes"
};

public ScreenStory(){
solarWindsFont = new RetroFont("data/fonts/solarwinds.png", 14, 16, 2);

storyLabel = new RetroLabel(solarWindsFont);
storyLabel.setText(story[storyPointer]);
storyLabel.pixelsFromCenter(0, 0);
storyLabel.setDebug(false);

continueInstruction = new RetroLabel(solarWindsFont);
continueInstruction.setText("Click to continue");
continueInstruction.pixelsFromCenter(0, 50);
}

public void draw(){
background(0);
storyLabel.draw();
continueInstruction.draw();
}

public void update(){

}

// Mouse methods
public void mousePressed(){}
public void mouseReleased(){
println("*******");
screens.transitionTo("gameplay");
}
public void mouseDragged(){}
public void mouseMoved(){}

public void keyPressed(){}
public void keyReleased(){}

public String getName(){
return "story";
}

public void nextLevel(){
screens.transitionTo("gameplay");
}
}
Loading

0 comments on commit f266f11

Please sign in to comment.