tags:

views:

178

answers:

3

I remember a QuickBasic program (named Gorillas) where there was a monkey who would toss a banana, I believe at another monkey. I want to write this in .NET to learn some. How would I get started doing that?

+2  A: 

It's simple projectile motion. There's tons of resources on the internet for this.

  • generate a path given the angle and velocity of the projectile (banana)
  • animate the projectile following the path
  • once the projectile collides with the target animate an "explosion"
  • start over

You could use the .NET Console as it's very easy to use and would make it "just like" the old one or you could use GDI+ graphics. Either is sufficient.

Here's a generic C# "main" to get you started. (Play with the time resolution/angle and velocity.)


static void Main(string[] args)
{            
  double t = 0; // time
  double v = 25; // muzzle velocity (m/s)
  double a = (Math.PI * 35 / 180.0); // launch angle in radians            
  double h0 = 0; // initial height (m)

  while (true)
  {
    PointF pt = new PointF((float)(v * Math.Cos(a) * t), 
                           (float)(h0 + (v * Math.Sin(a) * t) - (9.8 * t * t) / 2));
    t += .01;
    if (pt.Y > Console.WindowHeight - 1)
      continue;
    if (pt.Y < 0 || pt.X < 0 || pt.X > Console.WindowWidth - 1)
      break;
    Console.SetCursorPosition((int)pt.X, Console.WindowHeight - (int)pt.Y - 1);
    Console.Write("x");                
  };

  Console.ReadLine();
}
A: 

Here's a good place to start:

http://en.wikipedia.org/wiki/Gorillas_(computer_game)

Even better:

http://www.rickyroad.com/games/gorillas

MusiGenesis
+1  A: 

@MusiGenesis - Thanks for the links. 1000 points! Do you really have the power to do that? :)

@roygbiv - Appreciate the sample code.

No, but the $1000 is within reach. If I can bring myself to actually stop playing Gorillas and reliving Fall of '92, I may send you the money. Thank you for putting my life on hold for the next 2-3 days. :)
MusiGenesis