Download the * Startup Code from here* !
In this game, we will start working with real images and adding some basic animation features.
You will be using a simplified version of OpenCV = Open-Source Computer Vision library.
Download the project template and open the BrickBreaker solution
.
(Rclick ->
) Set BrickBreaker_Test
project as a Startup Project
. Run and see all the wonderful unit test failures
that pop out in the console. Pretty, hu?
You have the SnadBox.c
file to learn and practice the most common commands in OpenCV.
Set the OpenCV_Playground
project as the Startup Project
, and now you can run this.
Look at the code in the file, and play with parameters, etc.
Don't forget to restore the Startup Project
to BrickBreaker_Test
.
Open Geometry.h
and take a look on the two custom types there:
- The two dimensional Point:
typedef union
{
float coords[2];
struct
{
float x;
float y;
};
} Point;
It’s a union
for allowing access both as an array and with members (note! The inner struct is name-less!). So, for
a Point p = {.x = 10, .y = 20};
both p.coords[0]
and p.x
refer to the same variable! (yes! Exactly the same place
in memory! It’s a union!)
Now go ahead and :
-
implement in the
Point_????
Functions so that the relevant tests
(underGeometryTest_main
) pass! -
Commit & Push!
Now that you’ve done with Points, let’s move on – to Rectangles.
The two-dimensional Rectangle:
typedef union
{
float arr[4];
struct
{
float x;
float y;
float width;
float height;
};
struct
{
Point TL;
Point WH;
};
} Rect;
This union allows three alternative ways to access the memory of a variable of type Rect:
Sample memory addresses | Access with arr | Access with first struct | Access with second struct |
---|---|---|---|
0x1DDE39F828 | arr[0] | x | TL (top left corner coordinates) |
0x1DDE39F82C | arr[1] | y | |
0x1DDE39F830 | arr[2] | width | WH (width & height) |
0x1DDE39F834 | arr[3] | height |
Now go ahead and :
-
implement in the
Rect_????
functions so that the relevant tests
(underGeometryTest_main
) pass! -
Commit & Push!
-
A Geometric Riddle: What does
Rect Rect_GuessWhat(Rect const* r1, Rect const* r2)
do?
After you figure that out, renameRect_GuessWhat
to some meaningful name all over the solution! You can do that by “replace all” (Ctrl+Shift+H) or by Refactor-Rename (Ctrl + R + R – just hold the Ctrl and press “R” twice).
Here we will write all the functions that will help us with files. Read carefully the documentation at FileUtils.h
, then
go ahead and implement the functions.
-
bool isFileExists(const char* filepath)
-
char* concatPaths(const char* root, const char* toAppend)
-
getFramePath
, andcountAnimationFrames
is already implemented, based on the two functions above that you have to fill in. go over the implementation, see that you understand what’s going on 😊
When all FileUtilsTest_main
unit tests pass, commit & push!
Read carefully the description of the members in the Entity struct
, and find out in Entity.c
which functions it’s up to
you to implement (search for TODO
in this file). Pay attention to the function descriptions in the Entity.h
file.
Why do we describe functions in the .h
file and not in the .c
file? Because the .h
file is visible to our code users,
they shouldn’t dig into implementation to understand what’s going on!
Note: since linked list is represented by it’s anchor,
we typedef
ed LinkedList
to be a synonym to Link *
.
Again, fill in the blanks in Entity.c till EntityTest_main
Pass!
Tip!: Read core.h
file and find out the usefull functions.
Commit & Push.
At this point, you should be able to set BrickBreakerRunner
as a startup project
and enjoy the game 😊
If there is a problem, pay attention to the includes.
In this project, the game class was written for you. Go over its code in Game.h and Game.c and make sure you understand it, you can fill in the TODOs if you’d like – not a must.
How do we check collisions?
Last modified: Thursday, 1 march 2024, 14:14