Thread: Pong vb.net

  1. #1

    Registered
    03/12/11
    Location
    hasselt
    Posts
    3
    iTrader
    0
    Mentioned
    0 Post(s)
    Reputation
    0/0

    Pong vb.net

    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
    Last edited by Fraggie; 06-06-2012 at 11:03. Reason: code-tags
    no votes  

  2. #2
    Bamboebahr's Avatar
    Registered
    25/07/09
    Location
    Lauwe, West-Vlaanderen
    Posts
    2,347
    iTrader
    80 (100%)
    Mentioned
    0 Post(s)
    Ik kan mis zijn, ben er ook geen krak in, maar moet je bij je cases op het eind niet gewoon afgaan op "Case e.Down" of e.KeyDown ofzo?
    www.pushstart.be > voor info over al onze evenementen.
    Xbox live: Bamboebahr
    no votes  

  3. #3

    Registered
    19/03/09
    Location
    Aalst/Erembodegem
    Posts
    124
    iTrader
    5 (100%)
    Mentioned
    0 Post(s)
    Je gebruikt de KeyDown van de Form. Die werkt enkel zolang er geen andere control op je Form staat die de focus wegsnoept en die Button1 lijkt een kandidaat daarvoor (die de arrowkeys onderdrukt in z'n eigen KeyDown indien je Button1.KeyDown zou proberen).
    no votes  

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Log in

Log in