Hilfe bei der Programmierung mit Visual Basic...

  • Sonstige

Es gibt 14 Antworten in diesem Thema. Der letzte Beitrag () ist von Eistee.

    Hilfe bei der Programmierung mit Visual Basic...

    Servus,

    Ich bin seit grade in diesem Forum angemeldet da ich bemerkt habe das einem hier sehr gut geholfen werden kann.

    Um es schon einmal vorweg zusagen ich programmiere mit Visual Basic seit ca. 2 Jahren ist zwar nicht viel heißt aber das ich nicht ganz ungeübt bin :P

    Zum Themer:
    Ich programmiere im Moment eine GTA1 Visual Basic Version.
    Man kann "schon" Auto fahren,einsteigen im Auto,Aussteigen und rum laufen.
    Jedoch habe ich noch ein paar Sachen dich ich persönlich auch nicht kann.
    Ich liste es einfach mal auf:

    -Wie schaffe ich es das wenn z.B. ein anderes Auto irgendwo steht das meins davor stehen bleibt und nicht drüber/drunter her fährt?
    -Wie kann ich mehrere Autos auf die Pfeiltasten programmieren? Bisher hab ich nur eins. Wenn man nämlich mehrere drauf programmieren würde, würden sich alle mit bewegen was nicht so gut wäre :P

    Das wären auch meine ersten Fragen. Will ja nicht direkt übertreiben :D

    Liebe grüße Crilind...

    Und danke für jede hilfreiche Antwort :)
    Gehe ich recht in der Annahme, dass du dein GTA1 mit Visual Studio (also VB.net oder ggf. auch VB6) programmierst und nicht in Word oder Excel (VBA)?
    In dem Fall hast du dich im Forum verirrt und solltest du die Frage besser im Hauptforum stellen.
    --
    If Not Program.isWorking Then Code.Debug Else Code.DoNotTouch
    --
    Ich befürchte ja das der Code eventuell nicht ganz Objektorientiert ist, da das mit dem: "mehrere Autos auf die Pfeiltasten programmieren" sonst eig. kein Problem wäre.
    Dafür müssten man aber den Code sehen.. wenn das ganze zu "prozedural" ist, wäre es wohl besser von neu zu beginnen.
    Also falls ich hier falsch bin tut es mir leid :P Bin leider neu ich programmiere mit Visual Basic 2013 Express...

    Das ist der bisherige Code:


    Visual Basic-Quellcode

    1. Public Class Form1
    2. Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
    3. Select Case e.KeyChar
    4. Case "w"
    5. player.Top = player.Top - 10
    6. Case "s"
    7. player.Top = player.Top + 10
    8. Case "a"
    9. player.Left = player.Left - 10
    10. Case "d"
    11. player.Left = player.Left + 10
    12. End Select
    13. Select Case e.KeyChar
    14. Case "q"
    15. If player.Visible = False Then
    16. player.Visible = True
    17. Else
    18. player.Visible = False
    19. End If
    20. End Select
    21. End Sub
    22. Private Sub FormKeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
    23. If e.KeyCode = Keys.Up Then
    24. PictureBox1.Visible = True
    25. PictureBox2.Visible = False
    26. PictureBox3.Visible = False
    27. PictureBox4.Visible = False
    28. PictureBox1.Location = New Point(PictureBox1.Location.X - 0, PictureBox1.Location.Y - 20)
    29. PictureBox2.Location = New Point(PictureBox2.Location.X - 0, PictureBox1.Location.Y - 20)
    30. PictureBox3.Location = New Point(PictureBox3.Location.X - 0, PictureBox3.Location.Y - 20)
    31. PictureBox4.Location = New Point(PictureBox4.Location.X - 0, PictureBox4.Location.Y - 20)
    32. player.Location = New Point(player.Location.X - 0, player.Location.Y - 20)
    33. ElseIf e.KeyCode = Keys.Down Then
    34. PictureBox2.Location = New Point(PictureBox2.Location.X + 0, PictureBox2.Location.Y + 20)
    35. PictureBox1.Location = New Point(PictureBox1.Location.X + 0, PictureBox1.Location.Y + 20)
    36. PictureBox3.Location = New Point(PictureBox3.Location.X + 0, PictureBox3.Location.Y + 20)
    37. PictureBox4.Location = New Point(PictureBox4.Location.X + 0, PictureBox4.Location.Y + 20)
    38. player.Location = New Point(player.Location.X + 0, player.Location.Y + 20)
    39. PictureBox2.Visible = True
    40. PictureBox1.Visible = False
    41. PictureBox3.Visible = False
    42. PictureBox4.Visible = False
    43. ElseIf e.KeyCode = Keys.Right Then
    44. PictureBox4.Visible = True
    45. PictureBox1.Visible = False
    46. PictureBox3.Visible = False
    47. PictureBox2.Visible = False
    48. player.Location = New Point(player.Location.X + 20, player.Location.Y + 0)
    49. PictureBox1.Location = New Point(PictureBox1.Location.X + 20, PictureBox1.Location.Y + 0)
    50. PictureBox3.Location = New Point(PictureBox3.Location.X + 20, PictureBox3.Location.Y + 0)
    51. PictureBox2.Location = New Point(PictureBox2.Location.X + 20, PictureBox2.Location.Y + 0)
    52. PictureBox4.Location = New Point(PictureBox4.Location.X + 20, PictureBox4.Location.Y + 0)
    53. ElseIf e.KeyCode = Keys.Left Then
    54. PictureBox3.Location = New Point(PictureBox3.Location.X - 20, PictureBox3.Location.Y - 0)
    55. PictureBox1.Location = New Point(PictureBox1.Location.X - 20, PictureBox1.Location.Y - 0)
    56. PictureBox2.Location = New Point(PictureBox2.Location.X - 20, PictureBox2.Location.Y - 0)
    57. PictureBox4.Location = New Point(PictureBox4.Location.X - 20, PictureBox4.Location.Y - 0)
    58. player.Location = New Point(player.Location.X - 20, player.Location.Y - 0)
    59. PictureBox3.Visible = True
    60. PictureBox1.Visible = False
    61. PictureBox2.Visible = False
    62. PictureBox4.Visible = False
    63. End If
    64. End Sub
    65. Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
    66. If player.Visible = False Then
    67. player.Visible = True
    68. Else
    69. player.Visible = False
    70. End If
    71. End Sub
    72. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    73. MsgBox(" Mit W/A/S/D steuerst du deinen Avatar und mit den Pfeiltasten dein Auto. Um in dein Auto zusteigen klicke einfach drauf!")
    74. End Sub
    75. Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click
    76. If player.Visible = False Then
    77. player.Visible = True
    78. Else
    79. player.Visible = False
    80. End If
    81. End Sub
    82. Private Sub PictureBox4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox4.Click
    83. If player.Visible = False Then
    84. player.Visible = True
    85. Else
    86. player.Visible = False
    87. End If
    88. End Sub
    89. Private Sub PictureBox3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox3.Click
    90. If player.Visible = False Then
    91. player.Visible = True
    92. Else
    93. player.Visible = False
    94. End If
    95. End Sub
    96. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
    97. End Sub
    98. Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
    99. End Sub
    100. Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
    101. End Sub
    102. Private Sub PictureBox9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    103. End Sub
    104. Private Sub PictureBox8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    105. End Sub
    106. Private Sub Timer4_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
    107. End Sub
    108. Private Sub Timer5_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
    109. End Sub
    110. Private Sub PictureBox10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    111. End Sub
    112. Private Sub Timer1_Tick_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    113. player1_bot.Left = player1_bot.Left - 5
    114. End Sub
    115. Private Sub Timer2_Tick_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
    116. Timer1.Stop()
    117. Timer3.Start()
    118. End Sub
    119. Private Sub Timer3_Tick_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
    120. player1_bot.Left = player1_bot.Left + 10
    121. End Sub
    122. Private Sub Timer4_Tick_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer4.Tick
    123. Timer3.Stop()
    124. End Sub
    125. End Class

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „crilind“ ()

    Ich will ehrlich mit dir sein, dein momentaner Wissenstand reicht offensichtlich nicht aus, sowas großes wie ein Spiel zu stemmen. Du solltest dich erstmal mit dem Grundprinzip der OOP vertraut machen, lernen, wie du Klassen und Objekte für dich arbeiten lassen kannst, und dein Abstraktionsvermögen steigern.
    1. Habe meinen Quelltext Post verbessert :D
    2. Habe schon ein Spiel programmiert. Kennst du/sie das Spiel auf Drag Racing für Android?
    3. Wollte ich ja nicht wissen ob ich es nicht ann :P Das der Quelltext nicht ganz Sauber ist gebe ich zu da ich immer wieder Sachen hin zufüge und wieder weg mache. Werde ihn aber nochmal überarbeiten.

    B2T
    Eine gute, abstrakte Programmstruktur zeichnet sich eben dadurch aus, dass sie leicht erweiterbar ist und dabei nicht unübersichtlicher/unsauberer wird. Tut mir leid, das so sagen zu müssen, aber in diesem Zustand kann aus deinem Projekt einfach nichts werden. Ohne ne ordentliche Struktur ist auch der beste Programmierer machtlos, es hätte also überhaupt keinen Sinn, wenn wir dir das jetzt mit irgendwelchen Notlösungen noch weiter zerstückeln.
    @crilind: Wird sind beim Topic. Dahin müssen wir nicht zurück.
    So wie dein Spiel bisher aufgebaut ist, ist es fast nicht möglich es zu beenden.
    Denn der Auwand wird mit jeder Zeile exponentiell (geschätzt, eventuell leicht übertrieben) steigen.

    Das beste was Du hier jetzt machen könntest, ist dem Beitrag von @Artentus: gehör schenken.
    Denn bei solch einem "Ranz"-Code, kann und möchte dir wohl keine helfen.

    Das mit der Objekt Orientierung ist wirklich leicht sobald man es einmal verstanden hast.
    Wenn das sitzt, wirst Du selber staunen wie viel mehr Spaß es macht, ein Spiel zu programmieren.
    Man wird schneller fertig und kann viel mehr an Features etc. hinzufügen.
    1. Dann zeige doch mal dein Spiel Mit Klassen u.s.w oder was genau hast du verbessert ?
    2. glaube ich zwar nicht aber nichts ist unmöglich ;)
    3. nicht ganz sauber ? so kannst du nicht weiter programmieren ;)

    So ich würde dir nur noch Directx2D oder GDI+ empfehlen da Controls sich in der regel nicht eigenen um ein Spiel daraus zu basteln :)
    MFG 0x426c61636b4e6574776f726b426974
    InOffical VB-Paradise IRC-Server
    webchat.freenode.net/
    Channel : ##vbparadise
    Das wird dir hier jetzt keiner erklären können, zumindest nicht so, dass dus verstehst und daraus lernst.
    Ich für meinen Teil kann dir nur nen Rat geben. Fang damit an dieses Buch zu lesen (ist das beste und kostenlos):
    microsoft-press.de/url.asp?cnt=mspress_vb2010
    Dann steigere dich langsam und fang nicht gleich mit sonem Monsterprojekt an.