Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7406915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:37:46+00:00 2026-05-29T05:37:46+00:00

I am making a lunar lander game that randomizes the terrain for each new

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T05:37:47+00:00Added an answer on May 29, 2026 at 5:37 am

    Create your on path as a spline curve by using the System.Drawing.Drawing2D.GraphicsPath class. You can add the points to the path with the AddClosedCurve method. Then you can test if a point lies within the closed curve with path.IsVisible(point) or path.IsVisible(x, y).

    Finally you can draw the path with terrainDraw.FillPath(brush, path)


    Your code

    Me.xpoint1 = (Rnd() * 10) + (Rnd() * 20) + (Rnd() * 10) - (Rnd() * 20)
    

    could be simplified as

    Me.xpoint1 = 20 * Rnd()
    

    As 10 Rnd + 20 Rnd + 10 Rnd - 20 Rnd == 20 Rnd. You will not get a better random value by adding four random values.


    The Region class is also interesting. It can contain rectangles and graphic paths and has an Intersect method, which returns the intersection of itself and another Region, GraphicsPath or Rectangle. It also has a Complement method that you could use to get the outside of the terrain. If you intersect the outside of the terrain with some graphic object and the result is empty (which you can test with the IsEmpty method), it means that there is no collision.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Making a new shooter game here in the vein of Galaga (my fav shooter
Making game of life I need to a have a grid that is 30x20
Making a ship game because I am incredibly original.. With that aside, I have
im making an application that store multipe information like name description images for each
Making my first steps with NHibernate, I'm trying to have it creating my Tables
Making an adobe flex ui in which data that is calculated must use proprietary
Making UML sequence diagram in VS 2010RC I've observed that there is no activation
After making some changes in my models (eg. new field in a model and
When making software, specially games, those resources like graphics and sounds are something freaky
making a new jsp and got a mock-up from some analyst. Notice the sections

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.