none
mussa maina mahreen@yahoo.com haroon rashid RRS feed

  • Question

  •                            hello everybody had posted program for correction had recived help and am thankful i have made the loop but can get the bat and ball inside the graphics window will apreciate help with best wishes the code

      GraphicsWindow.Width = 400
    GraphicsWindow.Height = 400
    GraphicsWindow.BackgroundColor = "darkblue"

    GraphicsWindow.PenColor = "Red"
    GraphicsWindow.DrawRectangle(60, 20, 300, 360)

    GraphicsWindow.BrushColor = "Green"
    GraphicsWindow.FillRectangle(60, 20, 300, 360)

    'net
    GraphicsWindow.BrushColor = "White"
    GraphicsWindow.FillRectangle(60, 176, 300. 35,)
    GraphicsWindow.PenColor = "Blue"
    GraphicsWindow.DrawLine(60, 180, 360, 180)
    GraphicsWindow.DrawLine(60, 184, 360, 184)
    GraphicsWindow.DrawLine(60, 188, 360, 188)
    GraphicsWindow.DrawLine(60, 192, 360, 192)
    GraphicsWindow.DrawLine(60, 196, 360, 196)
    GraphicsWindow.DrawLine(60, 200, 360, 200)
    GraphicsWindow.DrawLine(60, 204, 360, 204)
    GraphicsWindow.DrawLine(60, 208, 360, 208)
    GraphicsWindow.PenColor = "yellow"
    GraphicsWindow.DrawLine(64, 174, 64.1, 215)
    GraphicsWindow.DrawLine(72, 174, 72.1, 215)
    GraphicsWindow.DrawLine(80, 174, 80.1, 215)
    GraphicsWindow.DrawLine(88, 174, 88.1, 215)
    GraphicsWindow.DrawLine(96, 174, 96.1, 215)
    GraphicsWindow.DrawLine(104, 174, 104.1, 215)
    GraphicsWindow.DrawLine(112, 174, 112.1, 215)
    GraphicsWindow.DrawLine(120, 174, 120.1, 215)
    GraphicsWindow.DrawLine(128, 174, 128.1, 215)


    'Player 1
    'head
    GraphicsWindow.PenColor = "white"
    GraphicsWindow.DrawEllipse(105, 50, 10, 10)
    'body
    GraphicsWindow.PenColor = "white"
    GraphicsWindow.DrawEllipse(110, 60, 0.1, 38)
    'hands
    GraphicsWindow.PenColor = "white"
    GraphicsWindow.DrawLine(75, 48, 110, 64)
    GraphicsWindow.PenColor = "white"
    GraphicsWindow.DrawLine(110, 64, 145, 70)
    'legs
    GraphicsWindow.PenColor = "white"
    GraphicsWindow.DrawLine(80, 118, 110, 98)
    GraphicsWindow.PenColor = "white"
    GraphicsWindow.DrawLine(108, 98, 135, 120)
    'recket
    GraphicsWindow.PenColor = "white"
    GraphicsWindow.FillEllipse(70, 20, 10, 15)
    GraphicsWindow.DrawLine(75, 28, 75, 50)

    'Player 2
    'head
    GraphicsWindow.PenColor = "white"
    GraphicsWindow.DrawEllipse(320, 320, 10, 10)
    'body
    GraphicsWindow.PenColor = "white"
    GraphicsWindow.DrawEllipse(325, 330, 0.1, 30)
    'hands
    GraphicsWindow.PenColor = "white"
    GraphicsWindow.DrawLine(295, 350, 325, 335)
    GraphicsWindow.PenColor = "white"
    GraphicsWindow.DrawLine(325, 335, 355, 320)
    'legs
    GraphicsWindow.PenColor = "white"
    GraphicsWindow.DrawLine(300, 375, 325, 360)
    GraphicsWindow.PenColor = "white"
    GraphicsWindow.DrawLine(325, 360, 350, 375)
    paddle = Shapes.AddRectangle(40, 4)
    ball = Shapes.AddEllipse(10, 10)


    GraphicsWindow.MouseMove = OnMouseMove
    Again:  
    x = 0
    y = 0
    deltaX = 1
    deltaY = 1
    RunLoop:
    x = x + deltaX
    y = y + deltaY
    gw = GraphicsWindow.Width
    gh = GraphicsWindow.Height
    If (x >= gw - 8 or x <= 0) Then
    deltaX = -deltaX
    EndIf
    If (y <= 0) Then
    deltaY = -deltaY
    EndIf
    padX = Shapes.GetLeft (paddle)
    If (y = gh - 14 and x >= padX and x <= padX + 60) Then
    deltaY = -deltaY
    EndIf
    Shapes.Move(ball, x, y)
    Program.Delay(5)
    If (y < gh) Then
    Goto RunLoop
    EndIf
    GraphicsWindow.ShowMessage("You Lose", "Paddle")
    Goto Again
    Sub OnMouseMove
    paddleX = GraphicsWindow.MouseX
    Shapes.Move(paddle, paddleX - 30, GraphicsWindow.Height - 6)
    EndSub

    Friday, December 4, 2015 12:24 PM

Answers

  • It is not quite clear what you are trying to do. Do you want to restrict the ball to the green field? The easyest way is to make the green field equal to the graphics window, as the ball bounces off the window border. Or you have to make the borders where the ball reverses direction equal to the red rectangle.

    Please give more information about what your problem is, or what you want to do.



    Jan [ WhTurner ] The Netherlands

    Sunday, December 6, 2015 11:56 AM
    Answerer