Hallo,
ik moet voor school het spelletje pong maken. het spel werkt volledig behalve dan het feit dat ik de player niet kan laten bewegen met de toetsen. met de muis werkt dit wel. Weet iemand hoe ik dit kan oplossen?
Hier is mijn code
Code:
Dim paddlespeed As Integer
Dim ballspeedx As Integer
Dim ballspeedy As Integer
Dim intplrscore As Integer = 0
Dim intcompscore As Integer = 0
Private Sub gameTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles gameTimer.Tick
' Bal bewegen
GameBall.Location = New Point(GameBall.Location.X + ballspeedx, GameBall.Location.Y + ballspeedy)
' paddlecomp bewegen
paddleComp.Location = New Point(paddleComp.Location.X, paddleComp.Location.Y + paddlespeed)
' bovenkant
If GameBall.Location.Y < 0 Then
GameBall.Location = New Point(GameBall.Location.X, 0)
ballspeedy = -ballspeedy
End If
' onderkant
If GameBall.Location.Y > Me.Height - GameBall.Size.Height - 45 Then
GameBall.Location = New Point(GameBall.Location.X, Me.Height - GameBall.Size.Height - 45)
ballspeedy = -ballspeedy
End If
'paddlecomp bovenkant
If paddleComp.Location.Y < 0 Then
paddleComp.Location = New Point(paddleComp.Location.X, 0)
paddlespeed = -paddlespeed
End If
'paddlecomp onderkant
If paddleComp.Location.Y > Me.Height - paddleComp.Size.Height - 45 Then
paddleComp.Location = New Point(paddleComp.Location.X, Me.Height - paddleComp.Size.Height - 45)
paddlespeed = -paddlespeed
End If
'player paddle
If GameBall.Bounds.IntersectsWith(paddlePlayer.Bounds) Then
GameBall.Location = New Point(paddlePlayer.Location.X - GameBall.Size.Width, GameBall.Location.Y)
ballspeedx = -ballspeedx
End If
'comp paddle
If GameBall.Bounds.IntersectsWith(paddleComp.Bounds) Then
GameBall.Location = New Point(paddleComp.Location.X - GameBall.Size.Width, GameBall.Location.Y)
ballspeedx = -ballspeedx
End If
'punt player
If GameBall.Location.X < 0 Then
intplrscore += 1
GameBall.Location = New Point(Me.Size.Width / 2, Me.Size.Height / 2)
paddlePlayer.Location = New Point(paddlePlayer.Location.X, Me.Size.Height / 2 - 100)
paddleComp.Location = New Point(paddleComp.Location.X, Me.Size.Height / 2 - 100)
paddlespeed = ballspeedy - 2
PlrScore.Text = intplrscore
CompScore.Text = intcompscore
gameTimer.Enabled = False
Button1.Visible = True
Windows.Forms.Cursor.Show()
End If
'punt comp
If GameBall.Location.X > Me.Width - GameBall.Size.Width - paddlePlayer.Width Then
intcompscore += 1
GameBall.Location = New Point(Me.Size.Width / 2, Me.Size.Height / 2)
paddlePlayer.Location = New Point(paddlePlayer.Location.X, Me.Size.Height / 2 - 60)
paddleComp.Location = New Point(paddleComp.Location.X, Me.Size.Height / 2 - 60)
If ballspeedy = 5 Then
paddlespeed = ballspeedy - 2
Else
paddlespeed = ballspeedy + 2
End If
CompScore.Text = intcompscore
gameTimer.Enabled = False
Button1.Visible = True
Windows.Forms.Cursor.Show()
End If
End Sub
Public Sub Game1plr_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
'controleren van toetsen
Select Case e.KeyCode
Case Keys.Up
paddlePlayer.Location = New Point(paddlePlayer.Location.X, paddlePlayer.Location.Y - 20)
Case Keys.Down
paddlePlayer.Location = New Point(paddlePlayer.Location.X, paddlePlayer.Location.Y + 20)
End Select
End Sub
alvast merci
NM138