This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
notes:fall2024:projects:msi0 [2024/09/03 16:01] – [space invaders] cmazzara | notes:fall2024:projects:msi0 [2024/09/12 01:07] (current) – [space invaders] cburling | ||
---|---|---|---|
Line 6: | Line 6: | ||
< | < | ||
array = ( Sprite * )malloc(sizeof(Sprite) * size ); | array = ( Sprite * )malloc(sizeof(Sprite) * size ); | ||
+ | </ | ||
+ | more generally malloc arrays will follow the pattern of | ||
+ | < | ||
+ | ARRAYNAME = ( VARIABLETYPE * )malloc(sizeof(VARIABLETYPE) * ARRAYSIZE) | ||
</ | </ | ||
=====pointer arithmetic===== | =====pointer arithmetic===== | ||
Line 15: | Line 19: | ||
Where ' | Where ' | ||
=====array via pointer arithmetic===== | =====array via pointer arithmetic===== | ||
+ | The best method for navigating an array with pointer arithmetic is to utilize a for loop as an array has a fixed size in which you decided.\\ | ||
+ | <code c> | ||
+ | for( int index = 0; index < sizeOfArray; | ||
+ | //do stuff with array | ||
+ | (*(basicAray+index)).x = someValue; | ||
+ | | ||
+ | // | ||
+ | (basicArray+index)-> | ||
+ | | ||
+ | //example | ||
+ | if( ((basicArray+index)-> | ||
+ | ... | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | Keep in mind that all an array is, is contiguous memory where same type elements are stored. Hence the malloc(sizeof(thing))\\ | ||
+ | |||
+ | So to navigate you have your array name which is the address in which the array starts and you simply add the size of the type of the array to access the next element | ||
+ | One should also know that while we are using the notation | ||
=====making your sprite===== | =====making your sprite===== | ||
Line 46: | Line 69: | ||
=====space invaders===== | =====space invaders===== | ||
- | The original Space Invaders was a game where the player character was positioned at the bottom of the screen and fought enemies at the top. The enemies | + | The original Space Invaders was a game where the player character was positioned at the bottom of the screen and moved solely along the x-axis. You would fight enemies |
+ | The enemies could also shoot at the player | ||
The objective is to create your own personal twist on Space Invaders. This could be introducing a new theme, or mechanics, while remaining true to the original. Enemy array formation / random attacks, player shooting, hit detection, and custom structs are a MUST. | The objective is to create your own personal twist on Space Invaders. This could be introducing a new theme, or mechanics, while remaining true to the original. Enemy array formation / random attacks, player shooting, hit detection, and custom structs are a MUST. | ||
It also would not hurt to consider having custom sprites, sounds, music, and / or a score for the player. | It also would not hurt to consider having custom sprites, sounds, music, and / or a score for the player. | ||
+ | |||
+ | You can get a feel for how they game is meant to be played [[here|https:// | ||
=====sounds===== | =====sounds===== | ||
Line 63: | Line 89: | ||
</ | </ | ||
You only want to play that once as not doing so will cause the audio to play over it's self and cause issue. The best way to do this would to put a check for an audioflag value == 1 and have an audioflag variable = 1 after the audio has been activated. | You only want to play that once as not doing so will cause the audio to play over it's self and cause issue. The best way to do this would to put a check for an audioflag value == 1 and have an audioflag variable = 1 after the audio has been activated. | ||
+ | |||
+ | You can use Audacity to make your own .wav files and its quite fun | ||
+ | |||
+ | Here's a link for a tutorial https:// |