Corning Community College
CSCS2320 Data Structures
With a basic pong game bootstrapped, transition it to a breakout-style game, making use of a malloc’ed array of structs to represent the field of bricks.
You will want to go here to edit and fill in the various sections of the document:
After creating your sprites, you will need to move them onto lab46 and possibly onto your PI. One way of doing this is using the scp command. To use the scp command use to following format:
scp FILENAME DESTINATION:PATH
Here is an example:
scp sprites.png username@lab46.g7n.org:~/src/fall2023/discrete/ttb0
If necessary, this is how you would get the desired file onto your PI:
scp sprites.png username@raspberrypi:~/src/fall2023/discrete/ttb0
Once you have your sprites .png file on lab46 and on your PI it is now time to load them into the cartridge.
Make sure your texture.png is in your ttb0 directory or you supply the correct path to the file.
To add them to the cartridge open your make.sh file.
Once in the make.sh file, add the following lines:
echo echo Convert the PNG textures echo -------------------------- png2vircon BreakoutTextures.png -o BreakoutTextures.vtex || abort_build
“BreakoutTextures.png” is an example that represents the name of your texture file. Yours could be TexturesBreakout.png for example
After including the texture file in make.sh you also need to add it to your .xml file. To do so, open your .xml file and add the following:
<textures> <texture path="BreakoutTextures.vtex" /> </textures>
“BreakoutTextures” represents the name of your breakout texture file.
Once you have added your texture file to BOTH the make.sh and the .xml file your textures are loaded into the cartridge.
When making your structure for the brick, it is important to remember that every time the ball hits the brick it needs to disappear. This means that inside the brick structure, you need to have a flag, in the below example the flag would be a boolean named Active. The value for a particular index's Active member would change upon collision.
Here is a simple brick structure that you can add or build onto if necessary:
struct BrickOBJ { bool Active; int X, Y; // Brick X and Y location int Width, Height; // Brick size };
A pointer points to and references a location in memory. We can obtain the value that is stored at that location by de-referencing the pointer. The main use of pointers in this project will be to reference/de-reference each brick you have allocated memory for (malloc).
Memory Allocation. This is a way to perform memory management manually for dynamic memory. The syntax for malloc is below.
ptr = (cast-type*)malloc(byte-size);
The array exists as a linear allocation of memory, and any particular value in the array can be accessed by adding the value of that location to the pointer when calling it
Example:
(*(b_arr + 0)).x = 20;
would make the first x value of the array 20 and
(*(b_arr + 1)).x = 30;
would make the second x value of the array 30, and so on
Pointers to structs can be accessed the same way a class can, like so
[POINTER NAME].[VARIABLE NAME] = [VARIABLE VALUE]
a more practical example would be
(*b_arr).x = 64
or some such, it functions as classes would in C++, we just need to make them ourselves since this is just C
For this project we will be using a pointer to point to an array of structs that we have allocated memory for. So we can use a line that looks similar to this.
ptr = (Brick *)malloc(sizeof(Brick)*number_of_bricks); Brick*ptr = NULL;
With Brick being a struct. You need to make sure you set the ptr to = NULL before you use it as that is creating it and it needs a value.
free( ptr );
Be sure to free any allocated memory by the end of the program.
To be successful in this project, the following criteria (or their equivalent) must be met:
Let's say you have completed work on the project, and are ready to submit, you would do the following:
lab46:~/src/SEMESTER/DESIG/PROJECT$ submit DESIG PROJECT file1 file2 file3 ... fileN
You should get some sort of confirmation indicating successful submission if all went according to plan. If not, check for typos and or locational mismatches.
I'll be evaluating the project based on the following criteria:
26:ttb0:final tally of results (26/26) *:ttb0:functional breakout game [13/13] *:ttb0:malloced array of structs used for bricks [13/13]