Flappy Square(Direct X)
Ein einfach Testprojekt nach Mr.Flap (play.google.com/store/apps/details?id=com.mrflap).
Screenshot:
Quelltext:
Spoiler anzeigen
Ein einfach Testprojekt nach Mr.Flap (play.google.com/store/apps/details?id=com.mrflap).
Screenshot:
Quelltext:
VB.NET-Quellcode
-
- Imports Microsoft.DirectX
- Imports Microsoft.DirectX.Direct3D
- Public Class Main
- Dim device As Device
- Dim pp As New PresentParameters
- Dim v(5) As CustomVertex.PositionNormalColored
- Dim x, y As Decimal
- Dim w As Decimal
- Public Sub New(ByVal Form As Form)
- 'DX Initialisiren
- Try
- Form.FormBorderStyle = Windows.Forms.FormBorderStyle.None
- Form.WindowState = FormWindowState.Maximized
- pp.Windowed = True
- pp.SwapEffect = SwapEffect.Discard
- device = New Device(0, DeviceType.Hardware, Form, CreateFlags.SoftwareVertexProcessing, pp)
- Catch ex As Exception
- MsgBox(ex.Message)
- End
- End Try
- Try
- 'Laden der Komponenten:
- 'Erstellen eines Queadrates
- v(0) = New CustomVertex.PositionNormalColored With {.X = -1, .Y = -1, .Z = 0, .Color = Color.White.ToArgb}
- v(1) = New CustomVertex.PositionNormalColored With {.X = 1, .Y = -1, .Z = 0, .Color = Color.White.ToArgb}
- v(2) = New CustomVertex.PositionNormalColored With {.X = -1, .Y = 1, .Z = 0, .Color = Color.White.ToArgb}
- v(3) = New CustomVertex.PositionNormalColored With {.X = 1, .Y = -1, .Z = 0, .Color = Color.White.ToArgb}
- v(4) = New CustomVertex.PositionNormalColored With {.X = 1, .Y = 1, .Z = 0, .Color = Color.White.ToArgb}
- v(5) = New CustomVertex.PositionNormalColored With {.X = -1, .Y = 1, .Z = 0, .Color = Color.White.ToArgb}
- x = 2
- device.RenderState.Lighting = False
- device.RenderState.CullMode = Cull.None
- Catch ex As Exception
- MsgBox(ex.Message)
- End Try
- End Sub
- Public Sub frame()
- device.Clear(ClearFlags.Target, Color.SkyBlue, 1, 0)
- device.BeginScene()
- 'Rendern
- device.Transform.Projection = Matrix.PerspectiveFovLH(Geometry.DegreeToRadian(45), pp.BackBufferWidth / pp.BackBufferHeight, 0.001, 5000)
- device.Transform.View = Matrix.LookAtLH(New Vector3(0, 0, -100), New Vector3(0, 0, 0), New Vector3(0, 1, 0))
- device.VertexFormat = CustomVertex.PositionNormalColored.Format
- 'Drehungs fortschritt
- w += 0.1
- If w = 10 Then
- w = 0
- End If
- 'Zeichnen und positioniren
- Dim px, py As Decimal
- Dim rot As Decimal = w / 100 * 360
- device.Transform.World = Matrix.Identity
- device.Transform.World *= Matrix.RotationZ(Geometry.DegreeToRadian(rot * -1))
- px = Math.Sin(Geometry.DegreeToRadian(rot)) * fx(w)
- py = Math.Cos(Geometry.DegreeToRadian(rot)) * fx(w)
- device.Transform.World *= Matrix.Translation(px, py, 0)
- device.DrawUserPrimitives(PrimitiveType.TriangleList, 2, v)
- 'Innenkreis
- For i = 0 To 360
- device.Transform.World = Matrix.Identity
- device.Transform.World *= Matrix.RotationZ(Geometry.DegreeToRadian(i))
- device.DrawUserPrimitives(PrimitiveType.TriangleList, 2, v)
- Next
- device.EndScene()
- device.Present()
- End Sub
- Public Sub click()
- y = fx(w) + 1
- x = w + 2
- End Sub
- Function fx(gx As Decimal)
- 'Quadratische Funktion für steig und fall mechanismus
- Dim erg As Decimal
- erg = -0.5 * ((gx - x) ^ 2) + y
- 'ausname fegen einsinken in den boden
- If erg < 2 Then
- erg = 2
- End If
- Return (erg)
- End Function
- End Class