Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am making a lunar lander game that randomizes the terrain for each new game, so each game is different. For my game, I am creating a graphics object that draws a closed curve for the terrain of the game. I am trying to then detect if a picture object collides with the graphics object. I create the graphics object like so:

Private Sub generateRandomTerrain()
    Dim terrainBrush As New SolidBrush(Color.Gray)
    Dim terrainDraw As Graphics = Me.CreateGraphics

    'Generate Different Points for Terrain
    Me.xpoint1 = (Rnd() * 10) + (Rnd() * 20) + (Rnd() * 10) - (Rnd() * 20)
    Me.ypoint1 = (Rnd() * 30) + (Rnd() * 10) - (Rnd() * 20) + (Rnd() + 5)

    Me.xpoint2 = (Rnd() * 10) + (Rnd() * 20) + (Rnd() * 10) - (Rnd() * 20)
    Me.ypoint2 = (Rnd() * 30) + (Rnd() * 10) + (Rnd() * 20) + (Rnd() + 5) + (Rnd() * 30) - (Rnd() * 30)

    Me.xpoint3 = (Rnd() * 10) + (Rnd() * 20) + (Rnd() * 10) - (Rnd() * 20)
    Me.ypoint3 = (Rnd() * 30) + (Rnd() * 10) - (Rnd() * 20) + (Rnd() + 5) - (Rnd() * 30) + (Rnd() * 30)

    Me.xpoint4 = (Rnd() * 10) + (Rnd() * 20) + (Rnd() * 10) - (Rnd() * 20)
    Me.ypoint4 = (Rnd() * 30) + (Rnd() * 10) + (Rnd() * 20) + (Rnd() + 5) - (Rnd() * 30) + (Rnd() * 30)

    'Add System to make sure that hills are not too sharp???

    'Generate Points to Draw
    Dim terrain() As Point = {New Point(0, Me.Size.Height), New Point(0, Me.Size.Height - 100), New Point((Me.Size.Width * 0.2) + Me.xpoint1, Me.Size.Height - Me.ypoint1 - 100), New Point((Me.Size.Width * 0.45) + Me.xpoint2, Me.Size.Height - Me.ypoint2 - 100), New Point((Me.Size.Width * 0.75) - Me.xpoint3, Me.Size.Height - 100 - Me.ypoint3), New Point((Me.Size.Width * 0.8) + (Me.Size.Width * 0.05) - Me.xpoint4, Me.Size.Height - Me.ypoint4 - 100), New Point(Me.Size.Width, Me.Size.Height - 100), New Point(Me.Size.Width, Me.Size.Height)}

    'Is Terrain Drawn-Clear
    If Me.isTerrainDrawn = 1 Then
        terrainDraw.Clear(Color.Transparent)
        Me.isTerrainDrawn = 0
    End If

    'Draw Terrain Aspects
    terrainDraw.CompositingQuality = Drawing2D.CompositingQuality.HighQuality
    terrainDraw.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
    terrainDraw.CompositingMode = Drawing2D.CompositingMode.SourceOver

    'Draw Terrain
    terrainDraw.FillClosedCurve(terrainBrush, terrain)

    'Set Terrain to Drawn
    Me.isTerrainDrawn = 1
End Sub

I have tried many ways of doing this, but none of them seem to work.

Thank you.

share|improve this question
You should post the code you've tried to write for the collision detection. – thedaian Oct 20 '11 at 21:50
I have tried to write this, but I cannot figure out how to do collision detection with the graphics object and a picture object. – cessnao3 Oct 22 '11 at 2:40

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.