Welcome back.  After a long break, I've decided to continue the .NET Platform Game Tour.  Here, I'm going to add some hazards.  This is just 
going to be stuff that kills the main character and that you should avoid.  I'm only going to make two types of hazards: a lava trap, which 
will just be a stationary rectangle of doom, and a floater, which will be a moving object of pain.

First, we'll start off with the lava, since it will be easy.  To get the most of where I place hazards, here's the map that I have created 
(don't forget to rename it to data.lvl) and it's quite odd-looking.  Since the lava will just be a rectangle, we can use 
the Graphics class Rectangle drawing methods.  Since we've done this so many times, let's spice it up a little.
Instead of using the regular old brushes provided by the Brushes class (yes, it is a class, despite its behavior), let's make our own brush.
It will just be a translucent color of orange and it isn't that easy.  We'll do the brush alongside the lava rectangle setup which is covered 
next.

The declarations come first.
		Rectangle lava;
		// This is the box representing where the lava is.
		Brush lavabrsh;
		// The brush that we'll use to draw lava to the display.
lava - defines a rectangle of lava. lavabrsh - defines a brush that has been dipped into the bucket of paint that has the color that I will draw this lava with. And then, the initialization. Right now, the lava is going to be hard-coded, but eventually, we'll move it into the level file.
			lava = Rectangle.FromLTRB(380, 520, 420, thelandheight);
			// Positions the lava on the display at these coordinates.
			lavabrsh = new SolidBrush(Color.FromArgb(180, 255, 155, 40));
			// Make the lavabrush a hot and translucent color of orange.
Next, we draw the spiced-up lava in the artwork() subroutine after we draw the coins. It is a good idea to draw these from back to front at all times regardless if they may never overlap. I want the lava to appear last since it is translucent and shouldn't appear behind many other objects.
			gfx.FillRectangle(lavabrsh, lava);
			gfx.DrawRectangle(Pens.DarkOrange, lava);
			// Draw the lava to the form.
If you run the project, you can walk in the lava, but not for long.
Let's declare another variable to indicate if the player has been defeated by something.
		bool isgoner;
		// If the player is dead, we set this to true.
isgoner - will be set to true when the character steps into lava or whatnot and is killed. This will be used for some defeat animation. Now, to detect if the character has stepped into lava, we need to do a simple collision detection in the charactermovement sub again using Rectangle.IntersectsWith().
			if (playerloc.IntersectsWith(lava)) 
			{
				// Touched the lava, now you must die.
				isgoner = true;

				playerveloc = PFMain.thesbarinitialvelocity;
				// This is for a falling animation when the player is beaten.
			}
This goes after the check for coins, although it probably doesn't matter if you put it before the coins or before the IsJumping if block. It should generally come after the PlayerLoc has been changed. Now, when the player has been defeated, we do not want the user to be able to move freely while we do our defeated animation. So, in the CharacterMovement, add:
			if (!isgoner) {
To the beginning, and then add a closing } as the last line of the subroutine. If you run the project now, you'll see the player come to a complete stop when it touches the lava, as if it is frozen in time (it looks really neat if you jump).
Now, for our defeated animation, let's try to make the player fall off to the bottom of the form, kind of like what Mario does in the classic Super Mario Bros. except we don't have a frame for the character to look at us and instead, we'll just have the character spin while he is falling... we can do this with a Graphics transform. Well, let's try it. First, we need to make the character fall to the bottom of the form. We can use the regular falling formulas that we have for the player during regular gameplay. So, in charactermovement, after we set isgoner to true, notice that we added
				playerveloc = PFMain.thesbarinitialvelocity;
Now, we need to spin the player. We'll need to declare a variable that indicates what angle to go to to cause the player to appear to be spinning. So, we need to declare another variable:
		float rotateangle;
		// This is the angle that the player spins at when he is falling off the bottom of the form.
And this variable will be incremented everytime we enter the artwork Subroutine while the player is defeated. The amount that we increment can be determined by another constant, so let's declare it.
		const float thespinoutspeed = 50.0F;
		// Amount the player spins every frame during spinning animation.
And now, I change the entire section of code that draws the main character in the artwork subroutine to:
			if (isgoner) 
			{
				gfx.TranslateTransform(playerloc.X + (thecharwidth >> 1), playerloc.Y + (thecharheight >> 1));
				// Move the zero point to the center of the character.
				gfx.RotateTransform(rotateangle);
				rotateangle += thespinoutspeed;
				// Apply the rotation.

				if (isjumping) 
				{
					gfx.DrawImage(playerbmp, -thecharwidth >> 1, -thecharheight >> 1, new Rectangle((thecharwidth * thewalkingframecount << 1) + chardirec * thecharwidth, 0, thecharwidth, thecharheight), GraphicsUnit.Pixel);
					// Jumping draw only.
				} 
				else 
				{
					gfx.DrawImage(playerbmp, -thecharwidth >> 1, -thecharheight >> 1, new Rectangle(thecharwidth * chardirec * thewalkingframecount + animcycler * thecharwidth, 0, thecharwidth, thecharheight), GraphicsUnit.Pixel);
					// This draws the character to the display based on the current location.
				}

				playerloc.Offset(0, playerveloc + thegravity >> 1);
				playerveloc += thegravity;
				// Similar to the gravity calculations we made in charactermovement jumping routine.

				gfx.ResetTransform();
			} 
			else 
			{


				if (isjumping) 
				{
					gfx.DrawImage(playerbmp, playerloc.X, playerloc.Y, new Rectangle((thecharwidth * thewalkingframecount << 1) + chardirec * thecharwidth, 0, thecharwidth, thecharheight), GraphicsUnit.Pixel);
					// Jumping draw only.
				} 
				else 
				{
					gfx.DrawImage(playerbmp, playerloc.X, playerloc.Y , new Rectangle(thecharwidth * chardirec * thewalkingframecount + animcycler * thecharwidth, 0, thecharwidth, thecharheight), GraphicsUnit.Pixel);
					// This draws the character to the display based on the current location.
				}
			}
If you run the project, the spinning character looks a bit scary (somewhat), which should convey the fact that the user doesn't want this to happen. If you pick a good value for thespinoutspeed, you'll get different results.
The delay was kind of nice. To make the character delay for a while before tumbling off to the bottom of the screen, let's add another variable in order to cause a delay.
		int doompause;
		// This is for a short delay that happens when the player runs into something deadly.
Of course, we need a constant to determine how long to wait before starting the tumble.
		const int thedoomtimeout = 15;
		// Number of frames to wait before spinning our player off the form.
I have changed the timer interval to 50 at some point during my development, so if your timer interval is still 100, you should change it to 50 so that the game runs faster, or you can halve the number that I have there. Now, my isgoner if section in my artwork sub looks like this:
			if (isgoner) 
			{
				if (doompause >= thedoomtimeout) 
				{
					gfx.TranslateTransform(playerloc.X + (thecharwidth >> 1), playerloc.Y + (thecharheight >> 1));
					// Move the zero point to the center of the character.
					gfx.RotateTransform(rotateangle);
					rotateangle += thespinoutspeed;
					// Apply the rotation.

					if (isjumping) 
					{
						gfx.DrawImage(playerbmp, -thecharwidth >> 1, -thecharheight >> 1, new Rectangle((thecharwidth * thewalkingframecount << 1) + chardirec * thecharwidth, 0, thecharwidth, thecharheight), GraphicsUnit.Pixel);
						// Jumping draw only.
					} 
					else 
					{
						gfx.DrawImage(playerbmp, -thecharwidth >> 1, -thecharheight >> 1, new Rectangle(thecharwidth * chardirec * thewalkingframecount + animcycler * thecharwidth, 0, thecharwidth, thecharheight), GraphicsUnit.Pixel);
						// This draws the character to the display based on the current location.
					}

					playerloc.Offset(0, playerveloc + thegravity >> 1);
					playerveloc += thegravity;
					// Similar to the gravity calculations we made in charactermovement jumping routine.

					gfx.ResetTransform();
				} 
				else 
				{
					rotateangle = 0F;  //Reset the tumbling player.

					doompause += 1;   // Doompause increments until it reaches thedoomtimeout.

					if (isjumping) 
					{
						gfx.DrawImage(playerbmp, playerloc.X, playerloc.Y, new Rectangle((thecharwidth * thewalkingframecount << 1) + chardirec * thecharwidth, 0, thecharwidth, thecharheight), GraphicsUnit.Pixel);
						// Jumping draw only.
					} 
					else 
					{
						gfx.DrawImage(playerbmp, playerloc.X, playerloc.Y , new Rectangle(thecharwidth * chardirec * thewalkingframecount + animcycler * thecharwidth, 0, thecharwidth, thecharheight), GraphicsUnit.Pixel);
						// This draws the character to the display based on the current location.
					}
				}
			} 
And now the character stops for a little while, and then falls down off the bottom of the form.
Now, for the floaters. The floater is going to be a really small critter that moves back and forth via periodic functions. Here is the floater picture. Don't forget to put it in the same folder as the .vb files for this project. Here are the declarations.
		Rectangle floater;
		// This holds the location of the floater.
		Bitmap floatbmp;
		// The floater's picture.
		int floattick;
		// A number that determines what part of the circle the floater is at.
The constants: we just need the size of the floater.
		const int thefloatersize = 16;
		// Width and height of the floater.
A lot of the information about the floater is going to be held back, because, for now, we are just going to have the floater move in a circle. Later on, we'll develop some structures that will greatly expand the features of the floater. Next, the initialization:
			floatbmp = new Bitmap(Application.StartupPath + @"\..\..\iorb.gif");
			// Transparency already included in the GIF.
			floater = new Rectangle(480, 280, thefloatersize, thefloatersize);
			// Set up floater location.
			floattick = 0;
			// Initialize counter.
Then, we draw the floater.
			gfx.DrawImage(floatbmp, floater);
			// Draw the floater.
If you run the project now, you can see the floater on the screen, but it doesn't move and it doesn't kill. It does look quite harmless, though. First, let's do the collision detection to determine if the floater hits the character. You may not be surprised that it looks exactly like the lava collision detection code.
				if (playerloc.IntersectsWith(floater)) 
				{
					// Touched the floater.
					isgoner = true;

					playerveloc = PFMain.thesbarinitialvelocity;
				}
And that is done. Now, all we need to do is move the floater in a circle. We can have the floater move regardless of whether the player has been killed or not, so that means it can go outside of the big isgoner If block that we just added. So, our circular movement section will look like this:
			floater.Offset(Convert.ToInt32(5 * Math.Cos(Convert.ToDouble(floattick) / 8)), Convert.ToInt32(5 * Math.Sin(Convert.ToDouble(floattick) / 8)));
			// Above, dr = [ 5 * Cos(T / 8), 5 * Sin(T / 8) ], which is a circle.
			floattick += 1;
And that comes right before the End Sub of the charactermovement subroutine. Now, the floater is a formidable opponent (or pest). Next, we work over the code so that things should be easier.