Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have been struggling to make a game like Doodle Jump where the sprite jumps on a platform. So how do you make a sprite jump upon platforms in XNA? Th platforms are represented by a list of positions like Public platformList As List(Of Vector2)

This is the collision detection under update()

        Dim mainSpriteRect As Rectangle = New Rectangle(CInt(mainSprite.Position.X), CInt(mainSprite.Position.Y), mainSprite.texture.Width, mainSprite.texture.Height)
         'a node is simply a class with the texture and position'
        For Each _node As Node In _gameMap.nodeList
            Dim blockRect As Rectangle = New Rectangle(CInt(_node.Position.X), CInt(_node.Position.Y), _BlocksTexture.Width, _BlocksTexture.Height)


            If mainSpriteRect.Intersects(blockRect) Then
                'what should I do here? For example velocity and position?'
            End If

            If (_node.Position.Y > 800) Then
                nodeList.Remove(_node)
            End If

        Next
share|improve this question
3  
The question is too vague, because it depends on how your platforms are represented, in order to know how to process collisions. But usually, after gravity moves your player down in each frame, you detect if there's been a collision between him and your platform, in which case you'll have to move him back up to the top of the platform. You also set his vertical velocity to zero when it happens. –  David Gouveia Apr 8 '12 at 0:11
    
This is correct for a platformer but not for a doodle jump clone (the guy never stands still on top of the platform, he just jumps again) –  krolth Apr 8 '12 at 6:57
    
@krolth That's pretty much just a minor variation of the same concept. –  David Gouveia Apr 8 '12 at 9:30
add comment

1 Answer

up vote 1 down vote accepted

You need a vector representing your velocity. This vector will modify your position every time the update method is called.

Then in every update check if the player is not touching a platform. If he is not then modify the velocity vector by some positive Y amount (this is gravity)

Once you have that all you need to do is detect when the player collide swith a platform and modify the velocity with a negative Y value (this is your jump)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.