none
help with school project 2? RRS feed

  • Question

  • Hey guys i need to make a second schoolproject now but uhm it's a pong game, and i belive i'm pretty far right now but i cant get the ball bounce on the right pad... i will show what i allready got: DRB520 or just watch this what do i miss or am i doing wrong... PLZ help

     

    GraphicsWindow.Show()

    GraphicsWindow.BackgroundColor = "red"

    GraphicsWindow.Height = 500

    GraphicsWindow.Width = 700

    GraphicsWindow.Title = "Pong"

    GraphicsWindow.PenColor = "white"

    GraphicsWindow.BrushColor = "black"

    GraphicsWindow.Top = "500"

    GraphicsWindow.Width = "700"

    Paddle1 = Shapes.AddRectangle(12,120)

    Paddle2 = Shapes.AddRectangle(12,120)

     

    Shapes.Move(Paddle2, 688,0)

     

    GraphicsWindow.KeyDown = OnLeftKeyDown

     

     

    Sub OnLeftKeyDown

      Key = GraphicsWindow.LastKey

     If (Key = "A") Then

      PaddleY = PaddleY - 20

      Shapes.Move(Paddle1, 0, PaddleY)

     EndIf

     

     If (Key = "Z") Then

      PaddleY = PaddleY + 20

      Shapes.Move(Paddle1, 0, PaddleY)

      EndIf

     

     If (Key = "K") Then

      Paddle2Y = Paddle2Y - 20

      Shapes.Move(Paddle2, 688, Paddle2Y)

     EndIf

     

     If (Key = "M") Then

      Paddle2Y = Paddle2Y + 20

      Shapes.Move(Paddle2, 688, Paddle2Y)

      EndIf

    EndSub

      Ball = Shapes.AddEllipse(25, 25)

    Shapes.Move(Ball, 50, 50)

    SpeedX = 0.15

    SpeedY = 0.15

    BallX = 1

    BallY = 1

    While "True"

      If BallX < 0 Then

        SpeedX = 0.15

      EndIf

     

      If BallX < 12 Then

        If BallY >=  PaddleY then

          If BallY <= PaddleY + 120 then

            SpeedX = 0.15

          EndIf

        EndIf  

      EndIf

     

      If BallX > GraphicsWindow.Width - 12 Then

        If BallY >=  Paddle2Y then

          If BallY <= Paddle2Y + 120 then

            SpeedX = -0.15

          EndIf

        EndIf  

      EndIf

     

     

      If BallX > GraphicsWindow.Width - 25 Then

        SpeedX = -0.15

      EndIf 

     

      If BallY < 0 Then

        SpeedY = 0.15

      EndIf

     

      If BallY > GraphicsWindow.Height - 25 Then

        SpeedY = -0.15

      EndIf 

     

     

     

      ballX = ballX + Speedx

      BallY = BallY + SpeedY

      Shapes.Move(Ball, BallX, BallY)

    EndWhile

    Tuesday, October 12, 2010 7:08 AM

Answers

  • When you make pong game I recommend you to use while statement to get if keys are pressed.

    Here is small sample XZP645. That sample just don't have ball so there is something that you can make.

    To move ball in my sample you can add BallX and BallY variables and move ball inside main loop with  Shapes.Move(Ball, BallX, BallY).


     Sorry My Bad English
    • Marked as answer by -[C]reativ_ Monday, October 18, 2010 1:03 PM
    Tuesday, October 12, 2010 10:47 AM