Flappy Square(Direct X)

    • VB.NET
    • .NET (FX) 3.0–3.5

      Flappy Square(Direct X)

      Flappy Square(Direct X)

      Ein einfach Testprojekt nach Mr.Flap (play.google.com/store/apps/details?id=com.mrflap).

      Screenshot:



      Quelltext:
      Spoiler anzeigen

      VB.NET-Quellcode

      1. Imports Microsoft.DirectX
      2. Imports Microsoft.DirectX.Direct3D
      3. Public Class Main
      4. Dim device As Device
      5. Dim pp As New PresentParameters
      6. Dim v(5) As CustomVertex.PositionNormalColored
      7. Dim x, y As Decimal
      8. Dim w As Decimal
      9. Public Sub New(ByVal Form As Form)
      10. 'DX Initialisiren
      11. Try
      12. Form.FormBorderStyle = Windows.Forms.FormBorderStyle.None
      13. Form.WindowState = FormWindowState.Maximized
      14. pp.Windowed = True
      15. pp.SwapEffect = SwapEffect.Discard
      16. device = New Device(0, DeviceType.Hardware, Form, CreateFlags.SoftwareVertexProcessing, pp)
      17. Catch ex As Exception
      18. MsgBox(ex.Message)
      19. End
      20. End Try
      21. Try
      22. 'Laden der Komponenten:
      23. 'Erstellen eines Queadrates
      24. v(0) = New CustomVertex.PositionNormalColored With {.X = -1, .Y = -1, .Z = 0, .Color = Color.White.ToArgb}
      25. v(1) = New CustomVertex.PositionNormalColored With {.X = 1, .Y = -1, .Z = 0, .Color = Color.White.ToArgb}
      26. v(2) = New CustomVertex.PositionNormalColored With {.X = -1, .Y = 1, .Z = 0, .Color = Color.White.ToArgb}
      27. v(3) = New CustomVertex.PositionNormalColored With {.X = 1, .Y = -1, .Z = 0, .Color = Color.White.ToArgb}
      28. v(4) = New CustomVertex.PositionNormalColored With {.X = 1, .Y = 1, .Z = 0, .Color = Color.White.ToArgb}
      29. v(5) = New CustomVertex.PositionNormalColored With {.X = -1, .Y = 1, .Z = 0, .Color = Color.White.ToArgb}
      30. x = 2
      31. device.RenderState.Lighting = False
      32. device.RenderState.CullMode = Cull.None
      33. Catch ex As Exception
      34. MsgBox(ex.Message)
      35. End Try
      36. End Sub
      37. Public Sub frame()
      38. device.Clear(ClearFlags.Target, Color.SkyBlue, 1, 0)
      39. device.BeginScene()
      40. 'Rendern
      41. device.Transform.Projection = Matrix.PerspectiveFovLH(Geometry.DegreeToRadian(45), pp.BackBufferWidth / pp.BackBufferHeight, 0.001, 5000)
      42. device.Transform.View = Matrix.LookAtLH(New Vector3(0, 0, -100), New Vector3(0, 0, 0), New Vector3(0, 1, 0))
      43. device.VertexFormat = CustomVertex.PositionNormalColored.Format
      44. 'Drehungs fortschritt
      45. w += 0.1
      46. If w = 10 Then
      47. w = 0
      48. End If
      49. 'Zeichnen und positioniren
      50. Dim px, py As Decimal
      51. Dim rot As Decimal = w / 100 * 360
      52. device.Transform.World = Matrix.Identity
      53. device.Transform.World *= Matrix.RotationZ(Geometry.DegreeToRadian(rot * -1))
      54. px = Math.Sin(Geometry.DegreeToRadian(rot)) * fx(w)
      55. py = Math.Cos(Geometry.DegreeToRadian(rot)) * fx(w)
      56. device.Transform.World *= Matrix.Translation(px, py, 0)
      57. device.DrawUserPrimitives(PrimitiveType.TriangleList, 2, v)
      58. 'Innenkreis
      59. For i = 0 To 360
      60. device.Transform.World = Matrix.Identity
      61. device.Transform.World *= Matrix.RotationZ(Geometry.DegreeToRadian(i))
      62. device.DrawUserPrimitives(PrimitiveType.TriangleList, 2, v)
      63. Next
      64. device.EndScene()
      65. device.Present()
      66. End Sub
      67. Public Sub click()
      68. y = fx(w) + 1
      69. x = w + 2
      70. End Sub
      71. Function fx(gx As Decimal)
      72. 'Quadratische Funktion für steig und fall mechanismus
      73. Dim erg As Decimal
      74. erg = -0.5 * ((gx - x) ^ 2) + y
      75. 'ausname fegen einsinken in den boden
      76. If erg < 2 Then
      77. erg = 2
      78. End If
      79. Return (erg)
      80. End Function
      81. End Class

      Bilder
      • flappy square.png

        9,16 kB, 1.920×1.080, 133 mal angesehen
      Dateien
      • flapy square.zip

        (81,06 kB, 109 mal heruntergeladen, zuletzt: )