Skip to content

Instantly share code, notes, and snippets.

@GabrielRRussell
Created June 14, 2017 18:46
Show Gist options
  • Save GabrielRRussell/6a56a4a6c8a9d95dd4c0a7d9e092ccf0 to your computer and use it in GitHub Desktop.
Save GabrielRRussell/6a56a4a6c8a9d95dd4c0a7d9e092ccf0 to your computer and use it in GitHub Desktop.
Write up of printing to screen in Cookie Clicker 3DS
In Cookie Clicker 3DS, writing to the screen is fairly simple, but was a challenge to start off with as I had no knowledge of C.
In particular, screens. I have three screens so far: Shop, Home, and Config. These screens are selected by moving the arrow button and pressing A, or returning home by pressing B.
There is a variable labelled "screen" as an integer. This keeps track of which screen I use.
When the program decides when to draw something, it will first determine which screen to draw based on the value. If the value is zero, it draws home. If the value is one, it draws the shop. If the value is 2, it will draw the config. After it draws this on the top screen, it will draw the bottom screen (which contains important info).
As for selecting the screens, there is another variable labelled "cursor" stored as an integer. The cursor is incremented by pressing down, and decremented by pressing up.
Depending on the value of the cursor and screen, it will print different messages. For example, printing to home screen, this is the code I use:
if (cursor == 1 & screen == 0) {
printf("\x1b[12;2H\x1b[40;33m>\x1b[0m Shop\e[K\n");
printf("\x1b[13;2H Options\e[K\n");
} else if (cursor == 2 & screen == 0) {
printf("\x1b[12;2H Shop\e[K\n");
printf("\x1b[13;2H\x1b[40;33m>\x1b[0m Options\e[K\n");
}
There is a symbol (>) displayed on the message that is currently selected (indicated by cursor value). So when cursor is equal to 1, the screen will display:
> Shop
Options
But if the cursor is equal to 2, you will see
Shop
> Options
Then there is another check to determine which option is currently being selected.
if (kDown & KEY_A & cursor == 1) {
screen = 1;
cursor = 0;
consoleClear();
} else if (kDown & KEY_A & (cursor == 2)) {
screen = 2;
cursor = 0;
consoleClear();
}
If the cursor is equal to 1, and the A button is pressed, the screen is set to 1 (shop), and the cursor is reset to 0 (explanation on that in a bit). Same thing for the value of 2.
To make sure that the player cannot increment past the maximum value or decrement past the minimum value, there is another check that resets the cursor value.
if (cursor < 1) {
cursor = 1;
} else if (cursor > 2) {
cursor = 2;
}
The cursor value should never be under 1. If so, it is reset back to 1, the minimum value (the top of the list). This way, I can reset the cursor easily by setting it to the minimum value each time you enter a different screen.
If the player were to somehow get past the simple barrier, the messages wouldn't print until they returned.
As for the bottom screen, it is all static, with no interaction. It is printed after the top screen is printed. This makes it relatively simple, as I can just put the values I need there.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment