This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
notes:data:fall2023:projects:ttb0 [2023/09/14 00:44] – cburling | notes:data:fall2023:projects:ttb0 [2023/09/14 02:58] (current) – [MALLOC’ED ARRAY] cfoster8 | ||
---|---|---|---|
Line 23: | Line 23: | ||
===Adding Sprites To Game=== | ===Adding Sprites To Game=== | ||
- | Once you have your sprites .png file on lab46 and on your PI it is now time to load them into the cartridge. To do this open your make.sh file. | + | 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 | ||
Once in the make.sh file, add the following lines: | Once in the make.sh file, add the following lines: | ||
Line 49: | Line 52: | ||
=====STRUCT===== | =====STRUCT===== | ||
===Making Brick Struct=== | ===Making Brick Struct=== | ||
- | 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. | + | 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' |
Here is a simple brick structure that you can add or build onto if necessary: | Here is a simple brick structure that you can add or build onto if necessary: | ||
Line 73: | Line 76: | ||
| | ||
=====MALLOC’ED ARRAY===== | =====MALLOC’ED ARRAY===== | ||
+ | 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 | ||
- | To access the specific parts of your array you need to use (*(ptr)). | + | Example: |
- | The ptr is the pointer | + | |
+ | would make the first x value of the array 20 and | ||
+ | | ||
+ | would make the second x value of the array 30, and so on | ||
====ACCESSING WITH POINTER ARITHMETIC==== | ====ACCESSING WITH POINTER ARITHMETIC==== | ||
- | When you have a ptr with a variable | + | 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 | ||
+ | | ||
+ | or some such, it functions | ||
=====MALLOC’ED ARRAY OF STRUCTS===== | =====MALLOC’ED ARRAY OF STRUCTS===== | ||