User Tools

Site Tools


notes:fall2024:projects:msi0

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:fall2024:projects:msi0 [2024/09/03 15:50] – [array via pointer arithmetic] cmazzaranotes:fall2024:projects:msi0 [2024/09/12 01:07] (current) – [space invaders] cburling
Line 6: Line 6:
 <code> <code>
 array = ( Sprite * )malloc(sizeof(Sprite) * size ); array = ( Sprite * )malloc(sizeof(Sprite) * size );
 +</code>
 +more generally malloc arrays will follow the pattern of
 +<code>
 +ARRAYNAME = ( VARIABLETYPE * )malloc(sizeof(VARIABLETYPE) * ARRAYSIZE)
 </code> </code>
 =====pointer arithmetic===== =====pointer arithmetic=====
Line 15: Line 19:
 Where 'Sprite' is the name of the struct, '*' declares a pointer to the struct, 'array' is the name of the pointer variable that is being declared, and 'NULL' indicates that the pointer does not currently point to any memory location (to avoid using an uninitialized pointer).  Where 'Sprite' is the name of the struct, '*' declares a pointer to the struct, 'array' is the name of the pointer variable that is being declared, and 'NULL' indicates that the pointer does not currently point to any memory location (to avoid using an uninitialized pointer). 
 =====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; index++ ) {
 +  //do stuff with array
 +  (*(basicAray+index)).x = someValue;
 +  
 +  //alternatively you can use -> notation which could help your code look a bit cleaner
 +  (basicArray+index)->y = someValue;
 +  
 +  //example
 +  if( ((basicArray+index)->y + spriteHeight ) > someValue ) { 
 +    ...
 +  }
 +}
 +</code>
 +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  *(basicArray+index)  if you wanted to in the future you can shorthand that to basicArray[index] as the [ ] are operators themselves.
 =====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 topThe enemies were arrayed into several rows and columns, and they would shuffle left and right until they reached the screen's borders. When that would happen, the remaining enemies positioned themselves down one row, creeping toward the player. The enemies could also shoot at the player, in random order. The player, in their own defense, had shields to protect them from the enemies' advance. The shield had its own health value, and as the enemies would shoot at the player, the shields would eat up the damage to spare the player but deteriorate as time went on. Eventually, they would disappear entirely. The player could move left and right on rails and shoot back at the enemies. This is Space Invaders in a nutshell.+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-axisYou would fight enemies who would be organized in rows and columns at the top, they would also move along the a-axis and move towards the player by one row when an alien made contact with the left and right "walls" respectively.\\  
 +The enemies could also shoot at the player at random. The player, in their own defense, had shields to protect them from the enemies' advance. The shield had its own health value, and as the enemies would shoot at the player, the shields would eat up the damage to spare the player but deteriorate as time went on. Eventually, they would disappear entirely. The player could move and shoot back at the enemies. This is Space Invaders in a nutshell.
  
 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://freeinvaders.org/]]
 +
 +=====sounds=====
 +
 +Vircon uses .wav files for sounds!
 +
 +If you want to have music being played on a loop it is important to set it up and not come back to it. By that I mean say you have
 +<code>
 +select_sound( MusicBackground );
 +set_sound_loop( MusicBackground );
 +play_sound_in_channel( MusicBackground, 15 );
 +</code>
 +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://youtu.be/vlzOb4OLj94?si=Vl8EyVWcAXazNq0W
notes/fall2024/projects/msi0.1725378604.txt.gz · Last modified: 2024/09/03 15:50 by cmazzara