VG:Mines

From MyProjectFun
Jump to: navigation, search

Student: I am trying to make mines that when an enemy steps/floats near them they blow up. Also how hard would it be to add walls that i can place? The enemies don't have to be able to figure out how to go around but that would also be cool…

Instructor: For the mines, you can make your animation with some extra space on the sides - that will make the auto-generated collision a bit large for your sprite. Then you just check collision, and it will look like they explode when the player gets near them. As for walls, that's a bit of a painful issue. I'll make a new topic if I can find time to explain that properly.

Student:

public static void CollisionWithMineFN()
{
  //Make a timer
  int ExplodeDelay = 60; // 60 frames = 1 second
  const int ExplodeDelayReset = 60;
 
  //Find master mine
  Sprite Mine = This.Sprite.CollisionWithSprite("MineCopy" );
  //if we find mine
  if (Mine != null)
  {
    //play click sound
 
    //if timer = 60 frames (one second)
    if (ExplodeDelay <= 0)
    {
 
 
      //We should do something cool
 
      //add to score?
 
      //delete me
      This.Sprite.Delete();
 
      //Delete mine
      Mine.Delete();
 
      //reset timer
      ExplodeDelay = ExplodeDelayReset;
    }
 
    //otherwise
    else
    {
 
      //decrement the timer
      --ExplodeDelay;
    }
  }
}

Why is this not working? I have tested if they were colliding and they were and yes i assigned the behavior.

Instructor: This is your problem...

//Make a timer
int ExplodeDelay = 60; // 60 frames = 1 second
const int ExplodeDelayReset = 60;

This stuff needs to be declared outside of the function - and therefore made public (like our spawn timers in smash). As is, they will always be 60, since they don't exist until you run that function.

However, making them public could cause issues if you don't want every mine to use the same timer. The answer to that would be to use local data instead.

Personal tools
Namespaces
Variants
Actions
Navigation
Engineering
Game Design
Multimedia Production
VG Programming
Downloads
Toolbox