XNA Creators Club Online
Page 1 of 1 (7 items)
Sort Posts: Previous Next

platformer kit question

Last post 7/3/2009 4:24 PM by Raiden55. 6 replies.
  • 6/11/2009 11:21 PM

    platformer kit question

    I've been messing around with the platformer kit and I was wondering how hard would it be/ is it possible to change the conditions for making the exit appear on a level by level basis?  For example one level you have to collect all the gems but on the next, you have to kill all of the enemies.
  • 6/12/2009 12:34 AM In reply to

    Re: platformer kit question

    Shouldn't be hard at all. You would have to store the condition somewhere and associate it with the level though. Maybe a separate file that you read in at the start of the game and store in memory.
    Jim Perry - Microsoft XNA MVP
    If people spent a minute searching the forums and reading the FAQs before posting I'd be out of a job.
      Got some XNA Game Studio/XNA Framework development info to share with the community? Put it on the XNA Wiki.
        Please mark posts as Answers or Good Feedback when appropriate.
  • 6/15/2009 5:25 PM In reply to

    Re: platformer kit question

    Thanks a bunch.  I was also gonna start work on making health for the player and the enemy.  I was going to do it by making a class.  Would you advise me doing it another way or am I on the right track?
  • 6/15/2009 5:32 PM In reply to

    Re: platformer kit question

    If I remember correctly, that example already has classes defined for both the player and enemy, you would just need to add a new property (attribute) to the existing class(es) to represent a health value, and update it accordingly in the collision logic.
  • 6/30/2009 8:01 AM In reply to

    Re: platformer kit question

    Werwolf696:
    If I remember correctly, that example already has classes defined for both the player and enemy, you would just need to add a new property (attribute) to the existing class(es) to represent a health value, and update it accordingly in the collision logic.


    Yeah, you're right, they do. On the surface it seems pretty trivial to add. I'm trying to implement this, but I might have overlooked something. In player.cs I've set

    public int health { getset; } 

    In the player class. Then set health to 100 in Reset, as this seemed the best place for it.

            public void Reset(Vector2 position) 
            { 
                powerUpTime = 0.0f; 
                Position = position; 
                Velocity = Vector2.Zero; 
                isAlive = true
                sprite.PlayAnimation(idleAnimation); 
                health = 100; 
            } 

    Then over to level.cs I edited the UpdateEnemies class that handles the collision with the player.

            private void UpdateEnemies(GameTime gameTime) 
            { 
                foreach (Enemy enemy in enemies) 
                { 
                    enemy.Update(gameTime); 
     
                    // Touching an enemy instantly kills the player unless powerup 
                    if (enemy.IsAlive && enemy.BoundingRectangle.Intersects(Player.BoundingRectangle)) 
                    { 
                        if (Player.IsPoweredUp) 
                        { 
                            OnEnemyKilled(enemy, Player); 
                        } 
                        else if (player.health > 50) 
                        { 
                            player.health -= 50; 
                        }  
                        else  
                        { 
                            OnPlayerKilled(enemy); 
                        } 
                    } 
     
                } 
            } 

    However when I collide I just die like normal. Maybe i'm overlooking something, maybe because it's 1am? ;) Thanks for any help in advance!
  • 6/30/2009 8:14 AM In reply to

    Re: platformer kit question

    Turns out this was a late night overlook, which I figured out after making the post. Seems very obvious now. Though for anyone interested I needed to bounce my player away from the enemy after collision. Otherwise my player is in contact with the enemy long enough to kill the player (two update cycles @50 health each).
  • 7/3/2009 4:24 PM In reply to

    Re: platformer kit question

    maybe you can make your player temporarily invincible after getting hit by an enemy. I remember in old games the player would flash to indicate you were hit, and then when it was solid you vulnerable again. Just a suggestion.
Page 1 of 1 (7 items) Previous Next