Last active
August 29, 2015 13:56
-
-
Save ybakos/9230779 to your computer and use it in GitHub Desktop.
A starting point for class, Feb. 26.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// TODO: your name | |
// Decomposing space invaders, for function re-use | |
// Focusing on remaining ships and the forts. | |
final int TEXT_SIZE = 32; | |
color green = color(0, 200, 0); | |
color white = color(255); | |
int shipsLeft = 4; | |
int credit = 0; | |
void setup() { | |
size(640, 480); | |
background(0); | |
} | |
void draw() { | |
drawBottomStatusBar(); | |
// to be continued ... | |
} | |
void drawBottomStatusBar() { | |
drawBottomStatusBarLine(); | |
drawCreditLeft(); | |
drawNumberOfShipsLeft(); | |
drawShipsLeft(); | |
} | |
void drawBottomStatusBarLine() { | |
stroke(green); | |
line(0, height - 50, width, height - 50); | |
} | |
void drawNumberOfShipsLeft() { | |
setBottomBarTextStyle(); | |
text(shipsLeft, 10, height - 20); | |
} | |
void drawShipsLeft() { | |
drawRemainingShip(0); | |
drawRemainingShip(1); | |
drawRemainingShip(2); | |
drawRemainingShip(3); | |
} | |
void drawRemainingShip(int shipNumber) { | |
// TODO | |
// draw each Nth ship in a position relative to coordinate (50, 440). | |
} | |
// Draws 0X when X, the credit left, is less than 10. | |
// Otherwise draws the amount of credit left. | |
void drawCreditLeft() { | |
setBottomBarTextStyle(); | |
text("CREDIT", width - (TEXT_SIZE * 6), height - 20); | |
// TODO: Implement this | |
} | |
// Notice how this function just encapsulates repetitive | |
// code that is used by both drawShipsLeft and drawCreditLeft. | |
void setBottomBarTextStyle() { | |
fill(white); | |
textSize(TEXT_SIZE); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment