Skip to content

Instantly share code, notes, and snippets.

@ybakos
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ybakos/9230779 to your computer and use it in GitHub Desktop.
Save ybakos/9230779 to your computer and use it in GitHub Desktop.
A starting point for class, Feb. 26.
// 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