10/26/10

Back again (also, I have Twitter now!)

Hello!

So, we got back from Paris late in the Saturday evening. What a refreshing holiday, I have to say. Although my French was rusty, I managed to communicate with the locals (although from time to time we had to use English). Eiffel Tower, Arc de Triomphe, Louvre, Mona Lisa, Versailles... we visited a lot of places, but many were left out, like the Catacombs. I feel a whole lot more cheerful and powered up in all ways, which is a good thing, because I'm going to have hellalot coding ahead of me.



So, yeah. I have about a week to finish the platformer (actually the deadline was on Monday, but it's already late in every way). TODO:

  • Clean up and comment the code
  • Make the ghosts move around (and be deadly!)
  • Collision detection while jumping
  • Some sort of randomization

A friend of mine asked the code for jumping, so I might as well paste it here. It's a bit messy, could use splitting up in methods and commenting, but whatever. The jump itself ain't pretty, but whatever. Oh, btw, did I mention I fell in love with the XML-commentary? Makes life so much easier.

EDIT: Oh yeah, I forgot to mention, I have Twitter now! Feels weird when compared to Facebook, but I guess I'll get the hang of this eventually. In the meanwhile, I'll probably just go ahead and make myself look like a fool trying to make meaningful tweets.
EDIT2: Well, of course I forgot to include link to my profile.
http://twitter.com/#!/_Kaira_





/// <summary>
/// Update method. Moves the blob according to its speed and player input.
/// Also prevents running off screen
/// 
</summary>
/// <param name="game">Game instance</param"
Game instance public override void Update(BGKGame game)
{
   DisplayInfo display = game.GetDisplay();
   KeyboardState keys = game.GetKeys();
   spriteRect.X = (int)(X + 0.5f);
   spriteRect.Y = (int)(Y + 0.5f);
   doorsCopy = doors.GetRange(0, doors.Count);

   if (currentState != state.Jumping)
      startingPosition = spriteRect.Bottom;

   positionY = spriteRect.Top;

   if (keys.IsKeyDown(Keys.Left))
   {
      if (X > display.minDisplayX)
      {
         bool ok = true;
         foreach (DoorSprite door in doors)
         {
            if (CheckCollisionWithDoor(door))
            {
               if (CheckKeyToDoor(door))
                  doorsCopy.Remove(door);
               else
                  ok = false;
            }
         }

         if (ok)
         {
            XSpeed = Math.Abs(XSpeed) * -1;
            X = X + XSpeed;
            spriteRect.X = (int)(X + 0.5f);
            spriteRect.Y = (int)(Y + 0.5f);
         }
      }
   }

   if (keys.IsKeyDown(Keys.Right))
   {
      if (X + spriteRect.Width < display.maxDisplayX)

      
         bool ok = true; 
         foreach (DoorSprite door in doors){
           if (CheckCollisionWithDoor(door)) 
           {
              if (CheckKeyToDoor(door))
                 doorsCopy.Remove(door); 
              else ok = false; 
           
         
         if (ok)
         
            XSpeed = Math.Abs(XSpeed); 
            X = X + XSpeed; 
            spriteRect.X = (int)(X + 0.5f);
            spriteRect.Y = (int)(Y + 0.5f); 
         
      
  } 
  if (keys.IsKeyDown(Keys.Space) && currentState == state.Walking)
  { 
     Jump(); 
  } 
  if (currentState == state.Falling) 
  { 
     YSpeed = Math.Abs(XSpeed); 
     Y = Y + YSpeed; 
     spriteRect.X = (int)(X + 0.5f); 
     spriteRect.Y = (int)(Y + 0.5f);
  } 
  UpdateJump(); 
  doors.Clear(); 
  doors = doorsCopy.GetRange(0, doorsCopy.Count); 

/// <summary>




/// Makes the blob go "JUMP!"
/// 
</summary>
private void Jump()
{
   if (currentState != state.Jumping)
   {
   
   currentState = state.Jumping;
      startingPosition = spriteRect.Bottom;
      YSpeed = Math.Abs(XSpeed) * -1;
   }
}

/// <summary>





/// Updates blobs movement while jumping, increasing current position on Y-axis if
/// maximum jumping height has not been reached.
/// If maximum jumping height is reached, blob
/// will begin falling
/// </summary>

private void UpdateJump()
{
   if (currentState == state.Jumping)
   {
   
   if (spriteRect.Bottom <= startingPosition - jumpingHeight)
      
         currentState = state.Falling; 
         YSpeed = Math.Abs(XSpeed); 
         Y = Y + YSpeed; 
      
      else
      
         YSpeed = Math.Abs(XSpeed) * -1; 
         Y = Y + YSpeed; 
         spriteRect.X = (int)(X + 0.5f); 
         spriteRect.Y = (int)(Y + 0.5f); 
      
   

No comments:

Post a Comment