User Tools

Site Tools


Sidebar

projects

wcp1 (due 20240828)
btt0 (due 20240904)
wcp2 (due 20240904)
pct0 (bonus; due 20240905)
pct1 (bonus; due 20240905)
pct2 (due 20240905)
abc0 (due 20240906)
msi0 (due 20240911)
pct3 (bonus; due 20240911)
wcp3 (due 20240911)
msi1 (due 20240918)
pct4 (due 20240918)
wcp4 (due 20240918)
dsr0 (due 20240926)
pct5 (bonus; due 20240926)
wcp5 (due 20240926)
gfo0 (due 20241002)
pct6 (due 20241002)
pnc0 (due 20241002)
wcp6 (due 20241002)
dsr1 (due 20241009)
pct7 (bonus; due 20241009)
wcp7 (due 20241009)
bwp1 (bonus; due 20241016)
pct8 (due 20241016)
pnc1 (due 20241016)
wcp8 (due 20241016)
pct9 (bonus; due 20241023)
pnc2 (due 20241023)
wcp9 (due 20241023)
gfo1 (due 20241030)
mag0 (due 20241030)
pctA (due 20241030)
wcpA (due 20241030)
mag1 (due 20241106)
pctB (bonus; due 20241106)
wcpB (due 20241106)
mag2 (due 20241113)
pctC (due 20241113)
wcpC (due 20241113)
pctD (bonus; due 20241120)
wcpD (bonus; due 20241120)
bwp2 (bonus; due 20241204)
gfo2 (due 20241204)
pctE (bonus; due 20241204)
wcpE (bonus; due 20241204)
EoCE (due 20241216)
haas:fall2024:discrete:projects:msi0

Corning Community College

CSCS2320 Discrete Structures

PROJECT: Make Space Invaders (MSI0)

OBJECTIVE

Implement, using Vircon32, a space invaders game where the enemies are backed by a runtime-allocated array of sprite structs. Use pointer arithmetic for all array accesses.

EDIT

You will want to go here to edit and fill in the various sections of the document:

msi0

malloc

After doing the pointer arithmetic one might want to make their sprite a reality. The first step is to

array = ( Sprite * )malloc(sizeof(Sprite) * size );

more generally malloc arrays will follow the pattern of

ARRAYNAME = ( VARIABLETYPE * )malloc(sizeof(VARIABLETYPE) * ARRAYSIZE)

pointer arithmetic

A pointer identifies and refers to a specific memory location. By de-referencing the pointer, we can access the value stored at that location. In this project, pointers will primarily be used to refer to and access each enemy struct (or any other struct) for which you’ve allocated memory for using “malloc”.

Forming arrays using pointers:

Sprite *array = NULL;

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

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.

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 ) { 
    ...
  }
}

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

Your sprite needs to be a struct and a struct is a way to group several different variables into one place. Here is a basic example of how a struct should look:

struct Sprite
{
 bool Active;
 int X, Y;
};

You can then use this struct to make your player and enemies. For a player it could look something like:

 Sprite Player;
 Player.Active = true;
 Player.X = 320;
 Player.Y = 300;

But for an enemy that there are multiple of you will have to use a loop:

 for( index=0; index<Size; index++ ) {
  (Enemy+index) -> Active = true;
  (Enemy+index) -> X = 200;
  (Enemy+index) -> Y = 100;
 }

This loop when combined with whatever Sprite attribute that has been defined is how you initialize your enemies.

space invaders

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 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.

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 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

select_sound( MusicBackground );
set_sound_loop( MusicBackground );
play_sound_in_channel( MusicBackground, 15 );

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

 

SUBMISSION

To be successful in this project, the following criteria (or their equivalent) must be met:

  • Project must be submit on time, by the deadline.
    • Late submissions will lose 33% credit per day, with the submission window closing on the 3rd day following the deadline.
  • Executed programs must display in a manner similar to provided output
    • output formatted, where applicable, must match that of project requirements
  • Processing must be correct based on input given and output requested
  • Output, if applicable, must be correct based on values input
  • Code must be nicely and consistently indented
  • Code must be consistently written, to strive for readability from having a consistent style throughout
  • Code must be commented
    • Any “to be implemented” comments MUST be removed
      • these “to be implemented” comments, if still present at evaluation time, will result in points being deducted.
      • Sufficient comments explaining the point of provided logic MUST be present
  • No global variables (without instructor approval), no goto statements, no calling of main()!
  • Track/version the source code in your lab46 semester repository
  • Submit a copy of your source code to me using the submit tool by the deadline.

Submit Tool Usage

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.

RUBRIC

I'll be evaluating the project based on the following criteria:

39:msi0:final tally of results (39/39)
*:msi0:pointer arithmetic used for all array transactions [13/13]
*:msi0:space invaders with working mechanics [13/13]
*:msi0:malloced array of sprites used for enemies [13/13]

Pertaining to the collaborative authoring of project documentation

  • each class member is to participate in the contribution of relevant information and formatting of the documentation
    • minimal member contributions consist of:
      • near the class average edits (a value of at least four productive edits)
      • near the average class content change average (a value of at least 1024 bytes (absolute value of data content change))
      • no zero-sum commits (adding in one commit then later removing in its entirety for the sake of satisfying edit requirements)
    • adding and formatting data in an organized fashion, aiming to create an informative and readable document that anyone in the class can reference
    • content contributions will be factored into a documentation coefficient, a value multiplied against your actual project submission to influence the end result:
      • no contributions, co-efficient is 0.50
      • less than minimum contributions is 0.75
      • met minimum contribution threshold is 1.00

Additionally

  • Solutions not abiding by spirit of project will be subject to a 50% overall deduction
  • Solutions not utilizing descriptive why and how comments will be subject to a 25% overall deduction
  • Solutions not utilizing indentation to promote scope and clarity or otherwise maintaining consistency in code style and presentation will be subject to a 25% overall deduction
  • Solutions not organized and easy to read (assume a terminal at least 90 characters wide, 40 characters tall) are subject to a 25% overall deduction
haas/fall2024/discrete/projects/msi0.txt · Last modified: 2024/08/28 18:19 by 127.0.0.1