我正在创建一个类似于Lunar Lander的游戏,我试图在每次游戏加载时制作一个简单的随机生成的地形。我目前正在生成随机点并通过这些点和画布的两个底角绘制曲线。 但是由于某种原因,曲线的峰值被镜像到画布的顶部以及底部。
以下是代码:
Public Class Form1
Dim xpoint1 As Single
Dim ypoint1 As Single
Dim xpoint2 As Single
Dim ypoint2 As Single
Dim xpoint3 As Single
Dim ypoint3 As Single
Dim xpoint4 As Single
Dim ypoint4 As Single
Dim isTerrainDrawn As Integer = 0
Private Sub generateRandomTerrain()
Dim terrainBrush As New SolidBrush(Color.Gray)
Dim terrainDraw As Graphics = Me.CreateGraphics
Dim rand As New Random
'Generate Different Points for Terrain
xpoint1 = 40 * rand.Next(0, 10)
ypoint1 = 40 * rand.Next(0, 10)
xpoint2 = 40 * rand.Next(10, 20)
ypoint2 = 40 * rand.Next(10, 20)
xpoint3 = 40 * rand.Next(20, 30)
ypoint3 = 40 * rand.Next(20, 30)
xpoint4 = 40 * rand.Next(0, 10)
ypoint4 = 40 * rand.Next(0, 10)
'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
Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
generateRandomTerrain()
End Sub
End Class
非常感谢任何帮助。