User Tools

Site Tools


notes:data:fall2023:projects:ttb0

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
notes:data:fall2023:projects:ttb0 [2023/09/14 00:48] – [Setting Up TTB0] cburlingnotes:data:fall2023:projects:ttb0 [2023/09/14 02:58] (current) – [MALLOC’ED ARRAY] cfoster8
Line 52: 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's Active member would change upon collision
  
 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 76: 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 and it can be added to (*(ptr+n)).. If you want to use a part of the structure you will need to put the name of it at the end of (*(ptr)).(varible). You can use an int to add to ptr. The ptr starts with zero so use one more number than you want. +    (*(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
 ====ACCESSING WITH POINTER ARITHMETIC==== ====ACCESSING WITH POINTER ARITHMETIC====
-When you have ptr with variable (*(ptr)).variable they function as that variable so int's can be +,-,/,* booleans can be set false and true, etc.+Pointers to structs can be accessed the same way class can, like so 
 +    [POINTER NAME].[VARIABLE NAME] = [VARIABLE VALUE] 
 +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
 =====MALLOC’ED ARRAY OF STRUCTS===== =====MALLOC’ED ARRAY OF STRUCTS=====
  
notes/data/fall2023/projects/ttb0.1694652492.txt.gz · Last modified: 2023/09/14 00:48 by cburling