Code Correctness
As always, this assignment has a particular set of design features that we expect you to focus on:
- good variable and function names
- procedural decomposition
- “overcommenting” (e.g., the comments do not explain things that are already clear from the code itself)
- usage of whitespace
- overmodularization (e.g., modularizing into functions that actually make the code less clear)
Deliverable
This week, you will be adding on to your game by implementing text using the SDL TTF libraries.
If your team has rotated roles correctly, you should have done the physics engine last week. However, the engine component is much more different from the game and demo components since they involve graphics. Thus, before you get started, we highly encourage you to talk with at least your teammate who implemented the game component last week to learn about the game loop and rendering in C!
Text
Now, it’s time to implement text! We have give you a TrueType (.ttf) file in the assets
folder, along with two images. You will be writing code so that when you compile your C program, the following sequence occurs:
For the current project and all future projects, make sure that all your assets (images, text, sound files, etc.) are stored in and referenced from ONLY the assets folder. Not only is this for stylistic purposes, but your files won’t be compiled if they aren’t in the right folder.
We expect your game to contain (at least) the following:
- A counter with a label should be at the top of the screen that increments every second.
- Every 5 seconds, the image on the screen should switch to the other image.
Here are a few hints for how to approach the game:
- In last week’s
game.c
, the state object should have kept track of oneSDL_Texture *
variable to render the CS 3 logo. What should we keep track of in this week’s implementation? - To keep track of time, we strongly recommend you to familiarize yourself with
sdl_wrapper.c
, which contains a function that should be useful. - You must convert the time to a
char *
to render it as text. If you’re not sure how, feel free to search it up!
Feel free to play around with different fonts and images! As long as you meet the above guidelines, you are free to use different assets.
For some help, take a look at the official SDL documentation or some resources here! Also keep in mind that SDL_GetError()
may come in handy when debugging your code (more information in the previous link).
Note that you should not be re-implementing image rendering code; one of your teammates should have implemented that last week. Thus, you should copy over your team’s image methods from sdl_wrapper.c
/sdl_wrapper.h
and use game.c
from last week as a foundation for your game this week.
Important: Since we have rewritten sdl_draw_polygon
to use polygon_t
instead of vec_list_t
, be careful not to overwrite it with the old sdl_draw_polygon
method from last week.
As a reminder, to run the game, all you need to type is make game
.
Helpful Tip for Debugging: Run your game in Chrome! Other browsers may have issues with emscripten, and you can also debug and see what you print in Chrome by right-clicking and clicking “Inspect” and “Console”.
Task 0. When you are done, your group should meet and complete the questions here.