Throughout this course, we also want you to focus on your code quality in addition to the functionality of your code. For the complete list of code quality items we’ll look at throughout the quarter, please consult the code quality document. If we see code quality issues during code reviews, we will ask your group to resubmit the project with those issues fixed.
We will take off points if your code has memory leaks, so be sure to check for them before you submit your code!
Implementing the engine is a prerequisite for implementing the demo!
Demos
The main demo this week is a simple version of Breakout.
Your game demo must have the following features (but feel free to play around and implement anything you want otherwise):
- The ball must bounce off the paddle, the walls, the bricks (as well as destroy the bricks)
- The game should reset when the player loses
We have give you starter code along with some in-line comments for the demo.
Note that you should only need to replace the parts in demo.c marked with TODO.
Before you start, however, here are a few things we want to go over:
Collisions
We have added new collision functions for you in forces.h and forces.c. Like forces,
collisions are “registered” in the scene using the create_x() and x_collision_handler() pattern.
Take a look at them for more detail, and note the following things:
collision_aux_t
We’ve added a new collision_aux_t struct in forces.c that the new collision functions reference. Note that
its structure is similar to that of body_aux_t with the exception of three additional fields:
-
handler: this is a collision handler that will run if a collision occurs between two bodies. Its type,collision_handler_t, has been defined for you inforces.h. -
aux: thisvoid *field is for any extra information that thecollision_aux_twill need access to. It’s a little bit meta and might be hard to wrap your head around at first, but this field will be especially helpeful when we need to reference variables like our state or scene. It can also be passed in as anaux_tto carry information about the force constant that certain collisions will use.
Take a look at collision_aux_free and note how aux is owned and freed by the collision_aux_t. Like before,
you can pass in NULL as the freer if the aux shouldn’t be freed.
create_physics_collision and create_destructive_collision
We’ve defined a generic create_collision function, which is referenced in create_physics_collision and create_destructive_collision (both will be implemented by the engine student). The key takeaway here is that abstraction can
make our code much simpler and also more flexible! Note how create_physics_collision
passes in a constant (the elasticity) through the aux.
Look over these functions and their documentation carefully! You will be referencing these functions and have
to write the implementations for the breakout collision functions in forces.c as well. Note that the collision handler between the
ball and the brick should also be a physics collision, with the additional requirement of removing the brick.
Thus, the new collision functions in forces.c that you have to write should be very short if written correctly.
The teammates working on the game portion of this week’s project may have modified sdl_wrapper.c.
If they already made these changes, make sure not to override them! Otherwise, copy and paste sdl_wrapper.c
and sdl_wrapper.h from last week to this week.
Task 0.
Modify breakout.c and forces.c and test that the demo works by running make demo or make NO_ASAN=true demo.
Once all your group members have finished, work with them to complete the extension (more information in the main project page).