AnthoVN
Gebruiker
- Lid geworden
- 8 feb 2012
- Berichten
- 22
Beste programmeurs!
Vandaag besloot ik uit het niets, eens een spelletje te maken.
Aangezien ik echt niets te doen had, besloot ik maar eens pong na te maken.
Dit is mij gelukt
Wel heb ik het probleem, dat de computer onoverwinnelijk is.
Zou iemand mij hiermee kunnen helpen?
code ziet er als volgt uit
Ook wil ik er extra functies bij toevoegen,
zoals een achtergrondmuziekje, afbeelding wanneer men een punt maakt/tegen krijgt
iemand een idee hoe?
Alvast bedankt, Antho

Vandaag besloot ik uit het niets, eens een spelletje te maken.
Aangezien ik echt niets te doen had, besloot ik maar eens pong na te maken.
Dit is mij gelukt
Wel heb ik het probleem, dat de computer onoverwinnelijk is.
Zou iemand mij hiermee kunnen helpen?
code ziet er als volgt uit
Code:
Public Class frmPong
Dim speed As Single = 17 ' snelheid van de bal
Dim rndInst As New Random() ' Random instance
Dim xVel As Single = Math.Cos(rndInst.Next(5, 10)) * speed
Dim yVel As Single = Math.Sin(rndInst.Next(5, 10)) * speed
Dim intscoreSpeler As Integer 'score speler
Dim intscoreComputer As Integer 'score computer
Private Sub frmPong_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
If e.Y > 5 And e.Y < Me.Height - 40 - picPaddleSpeler.Height Then _
picPaddleSpeler.Location = New Point(picPaddleSpeler.Location.X, e.Y)
End Sub
Private Sub tmrSpel_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrSpel.Tick
picBal.Location = New Point(picBal.Location.X + xVel, picBal.Location.Y + yVel)
If picBal.Location.Y < 0 Then
picBal.Location = New Point(picBal.Location.X, 0)
yVel = -yVel
End If
' controleer de onderkant
If picBal.Location.Y > Me.Height - picBal.Size.Height - 45 Then
picBal.Location = New Point(picBal.Location.X, Me.Height - picBal.Size.Height - 45)
yVel = -yVel
End If
' controleer de speler paddle
If picBal.Bounds.IntersectsWith(picPaddleSpeler.Bounds) Then
picBal.Location = New Point(picPaddleSpeler.Location.X - picBal.Size.Width, picBal.Location.Y)
xVel = -xVel
End If
' controleer de computerpaddle
If picBal.Bounds.IntersectsWith(picPaddleComputer.Bounds) Then
picBal.Location = New Point(picPaddleComputer.Location.X + picPaddleComputer.Size.Width + 1, picBal.Location.Y)
xVel = -xVel
End If
' controleer de linker zijkant
If picBal.Location.X < 0 Then
intscoreSpeler += 1
picBal.Location = New Point(Me.Size.Width / 2, Me.Size.Height / 2)
lblScoreSpeler.Text = Convert.ToString(intscoreSpeler)
End If
' controleer de rechter zijkant
If picBal.Location.X > Me.Width - picBal.Size.Width - picPaddleSpeler.Width Then
intscoreComputer += 1
picBal.Location = New Point(Me.Size.Width / 2, Me.Size.Height / 2)
lblScoreComputer.Text = Convert.ToString(intscoreComputer)
End If
If picBal.Location.Y > 5 And picBal.Location.Y < Me.Height - 40 - picPaddleSpeler.Height Then
picPaddleComputer.Location = New Point(picPaddleComputer.Location.X, picBal.Location.Y)
End If
End Sub
Private Sub tmrComputer_Tick(sender As System.Object, e As System.EventArgs) Handles tmrComputer.Tick
If picBal.Location.Y > picPaddleComputer.Location.Y + 64 Then
picPaddleComputer.Location = New Point(picPaddleComputer.Location.X, picPaddleComputer.Location.Y + 2)
End If
If picBal.Location.Y < picPaddleComputer.Location.Y + 64 Then
picPaddleComputer.Location = New Point(picPaddleComputer.Location.X, picPaddleComputer.Location.Y - 2)
End If
End Sub
Private Sub frmPong_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
Dim a As Integer
a = picPaddleSpeler.Location.Y
Select Case e.KeyCode
Case Keys.Up
a -= 20
Case Keys.Down
a += 20
Case Keys.Escape
Me.Close()
End Select
If a > 10 And a < Me.Height - 50 - picPaddleSpeler.Height Then _
picPaddleSpeler.Location = New Point(picPaddleSpeler.Location.X, a)
End Sub
Private Sub frmPong_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Windows.Forms.Cursor.Hide()
End Sub
End Class
Ook wil ik er extra functies bij toevoegen,
zoals een achtergrondmuziekje, afbeelding wanneer men een punt maakt/tegen krijgt
iemand een idee hoe?
Alvast bedankt, Antho


Laatst bewerkt: