# Midterm: progress in retrogress

##### Inspiration

On a Saturday night, NYUAD students tend to have more meal swipes than they need. Students face the dilemma of either stacking more food with their extra swipes or losing all the swipes the next day.

The idea then is to create a game where the player (student) would try to stack as much food as can be balanced on an unstable food tray.

To win and make the most of your meal swipes, just be patient and stack away. Oh, don’t forget we are working with time😄

##### Process

To build this game, I need

1. Start / Instructions page

2. Game window

3. Win / Lose / Restart Page

4. Sound Integration

##### Progress Work

Let’s get to work

I explored how I would be changing the game screens based on the stage of the game. I created functions to take care of each of the 3 main stages of the game: start, gameplay, and game over. I represented the different screens with 3 different colors.

I moved on to integrate a timer for the gameplay screen which when runs out and automatically changes the screen to indicate game over. That’s when I started facing difficulties.

I added some buttons and signal text to make the user’s life easier.

##### Challenges

Timer!

For some reason, I couldn’t figure it out for a long time, my timer was not working as expected, the gameplay screen didn’t change even if the timer was out. Oh, I get it now! I fell into the trap of not scoping my variables properly. I experimented with the location of my timer function and I finally got it to work when I globalized the variables accessed by the timer function.

Please stay we me, we are not done with the timer yet! I decided to print the timer values on the game screen and I was getting negative seconds. How? Yeah, I was confused as you are. Still haven’t figured why but it seems to work fine now.

```// THE THREE SCREENS
// 0: Start Page (Instructions)
// 1: Game Window
// 2: Win / Lose Page ( GameOver)

int gameScreen = 0;
int score = 0;
int totalTime = 10; // 10 seconds
int savedTime = second();
int passedTime;

void setup() {
size(640, 640);
}

void draw() {
// Display the contents of the current screen
if (gameScreen == 0) {
startScreen();
} else if (gameScreen == 1) {
gameWindow();
timer();
} else if (gameScreen == 2) {
gameOverScreen();
}
}

// THE THREE SCREENS
void startScreen() {
background(#6f00ff);
textAlign(CENTER);
textSize(70);
text("It's Saturday Night", width/2, height/2-50);
textSize(20);
text("Stack Up as much food as you can while you have the time.", width/2, height/2);
text("Click on the Start button, The clock is ticking!", width/2, height/2 + 50);
textSize(20);

// start button
noFill();
rectMode(CENTER);
rect(width/2, height-100, 120, 30, 10);
text("Click to start", width/2, height-95);
}

void gameWindow() {
background(#a75502);
textSize(50);
text("Timer!", width/2, 95);
}

void gameOverScreen() {
background(#6f00ff);
textAlign(CENTER);
fill(236, 240, 241);
textSize(15);
text("Your Score", width/2, height/2 - 120);
textSize(130);
text(score, width/2, height/2);

// restart button
noFill();
rectMode(CENTER);
rect(width/2, height-100, 150, 30, 10);
textSize(20);
text("Click to Restart", width/2, height-95);
}

// SCREEN CHANGERS
void  startGame() {
gameScreen=1;
}

void gameOver() {
gameScreen=2;
}

// RESTART

void restart() {
score = 0;
savedTime = second();
startGame();
}

// TIMER

void timer() {
passedTime = second() - savedTime;
textSize(100);
text(passedTime, width/2, height/2 + 30);
if (passedTime > totalTime) {
gameOver();
}
}

// BUTTON CONTROLS
void mousePressed() {
// toggle between instructions and restart when mouse is clicked
if (gameScreen==0) {
startGame();
}
if (gameScreen==2) {
restart();
}
}

```
##### Next Steps

It’s going to be more fun and challenging. I will be working mainly on the gameplay screen and polishing the start and end screen

1.  Create the assets ( the food to be stacked) and the unstable tray block

2. Work on the game mechanics ( counting length of the food stack )

3. Add sound to make it lively

PS. Would appreciate any resources to achieve the above steps. I know it’s going to be existing!

## 2 thoughts on “Midterm: progress in retrogress”

1. Aaron says:

Hi Eric, I think the reason you’re getting negative numbers or weird values with your tie is becasue you set the saved time at the very beginning of the sketch, even before calling setup. Put it into your start game function and then it will work consistently from 0.

On your home screen, you can click anywhere to start the game, not just in the button. If you provide a button functionality (and describe that in the instructions!) make sure the button is a button (and don’t allow clicking anywhere in the screen to work as the button).

1. Eric Asare says:

Yes, I moved the saved time, and it’s working! I decided to use the button shape as a highlighter just for signal purposes. I also changed the instruction from the button to press the ENTER key. Thank you!