Code Correctness
As always, this assignment has a particular set of design features that we expect you to focus on. This time, there is only one new one: encapsulation (hiding data from
clients of structures in the .c
files). Here’s the list of the other design features we’ve already highlighted:
- code duplication
- 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)
Game
This week, you will be implementing mouse clicking detection, allows the user to interact with the game by clicking the screen.
Since the SDL feature this week is keyboard events for the pacman demo, by additionally incorporating mouse click detection, users will be able to interact with your game using the mouse and the keys.
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 your teammates to learn about the game loop, text, images, and rendering in C!
Mouse Clicking
Now, it’s time to implement mouse clicking! You will be using mouse clicking to click through different CS 3 related memes. We have give you TrueType (.ttf) files for fonts and images for the memes in the assets
folder. 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 meme generator to have at least the following
- three meme templates
- captions (as shown in the video) for the memes
- the use of mouse clicking to “cycle” the memes and print the (x,y) coordinates of the click to the black box underneath your demo (
stdout
)
Here are a few hints and starting questions for how to approach your meme generator
- Build your
state_t
as you code, what should it include? Are there variables that would be useful to keep track of or cycle through? - Once again, familiarize yourself with
sdl_wrapper.c
andsdl_wrapper.h
. How does mouse clicking actually work? Refer to how key press detection is implemented in sdl_wrapper and discuss with you teammate working on the demo on their understanding of key press detection - Brush up on your
char *
knowledge, how do we make strings in C?
As always, feel free to play around with different fonts and images. You are welcome to make more memes, but make sure you have the ones shown above.
For some help, take a look at the official SDL documentation, SDL documentation on mouse, 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). Additionally, you are allowed to use google (responsibly!) as resource to understand the documentation.
Note that you should not be re-implementing image rendering code or text displaying code; one of your teammates should have implemented that last week. Thus, you should copy over your team’s image and text methods from sdl_wrapper.c/sdl_wrapper.h and use game.c from last week as a foundation for your game this 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.