none
100% Confuse on what to do here.

    Question

  • Hi,

    At school I am in a coding group (For people in YR 9 and YR 10 (Australia))

    So I am not 100% a genius on it point this out ;)

    I was told have it some what completed as I went on holiday to England for 3 weeks

    So I am making a balloon poping game all working fine when I needed to make a Ball shoot out of the cannon and disappear when it leaves the graphics window AND make the balloon disappear when it hits that.

    The deleting it when it leaves the Graphics window is fine

    Everything else I am stumped on.

    I attempted making the ball shoot. It was fine it made the ball and it tracked the cannon but it was off centered and it went to the left and not up and it stopped everything else from moving and constantly kept moving

    CODE:

    cannon1_x = 375
    cannon1_y = 350
    
    balloon1_x = 0
    balloon1_y = 0
    
    GraphicsWindow.KeyDown = moveCannon
    GraphicsWindow.Width = "800"
    GraphicsWindow.Height = "500"
    GraphicsWindow.Show()
    
    RESOURCE_PATH = Program.Directory + "\resources\"
    CANNON_IMAGE = RESOURCE_PATH + "cannon.png"
    BALLOON_IMG = RESOURCE_PATH + "balloon.png"
    balloon = Shapes.AddImage(BALLOON_IMG)
    cannon = Shapes.AddImage(CANNON_IMAGE)
    Shapes.Move(cannon, cannon1_x, cannon1_y)
    Shapes.Move(balloon, balloon1_x, balloon1_y)
    
    While "True"
      For moveBalloon = 1 To GraphicsWindow.Width-50
        Shapes.Move(balloon, moveBalloon, balloon1_y)
        Program.Delay(3)
      EndFor    
      
      For moveBalloon = GraphicsWindow.Width-50 To 1 Step -1
        Shapes.Move(balloon, moveBalloon, balloon1_y)
        Program.Delay(3)
      EndFor
    EndWhile
    
    While "True"
      Program.Delay(100)
    EndWhile
    Sub moveCannon
      If GraphicsWindow.LastKey = "D" Then
        If cannon1_x < GraphicsWindow.Width-65 Then
        cannon1_x = cannon1_x + 20
        Shapes.Move(cannon, cannon1_x, cannon1_y)
        EndIf
        
      ElseIf GraphicsWindow.LastKey = "A" Then
        If cannon1_x > GraphicsWindow.Width-800 Then
          cannon1_x = cannon1_x - 20
          Shapes.Move(cannon, cannon1_x, cannon1_y)
        EndIf
      EndIf 
    EndSub

     

    I love coding. This is signature is 100% Original. :)

    Saturday, February 11, 2017 6:26 PM

All replies

  • @forbidden duck

    I consider the Small Basic language, as a Toolbox.

    Suppose I want to build a bridge, then I'll take the tools in my tool box that are in relation with the construction of a bridge. But, me personally, in my programs, there are times or I don't take the right tools, and I'm looking for, I'm looking for this tool, but thanks to this forum, there is peoples here who are very advanced in programming and who will tell me what tools take exactly .

    Saturday, February 11, 2017 7:45 PM
    Answerer
  • Forbidden Duck,

    Instead of moving the cannon I thought just use the "F" key to fire the cannon. Try pushing the "F" key to hit the balloon. If you hit it the balloon will disappear and a new one starts from the left with a different color. You do need the litdev extension loaded for this to work.

    cannon1_x = 375
    cannon1_y = 350
    balloon1_x = 0
    balloon1_y = 20
    GraphicsWindow.KeyDown = moveCannon
    GraphicsWindow.Width = "800"
    GraphicsWindow.Height = "500"
    GraphicsWindow.Show()
    'RESOURCE_PATH = Program.Directory + "\resources\"
    'CANNON_IMAGE = RESOURCE_PATH + "cannon.png"
    'BALLOON_IMG = RESOURCE_PATH + "balloon.png"
    'Cannon_image=Shapes.AddRectangle(100,50)
    balloon=Shapes.AddEllipse(50,50)
    ''balloon = Shapes.AddImage(BALLOON_IMG)
    cannon = Shapes.AddRectangle(50,100)
    Shapes.Move(cannon, cannon1_x, cannon1_y)
    Shapes.Move(balloon, balloon1_x, balloon1_y)
    GraphicsWindow.BrushColor="Black"
    Ball=Shapes.AddEllipse(40,40)
    Shapes.Move(Ball,cannon1_x+5,cannon1_y+30)
    Shapes.HideShape(Ball)
    Timer.interval=500
    Timer.tick=OnTimerTick
    Flag="True"
    moveBalloon()
    Sub MoveBalloon
      Shapes.ShowShape(Balloon)
    While "True"
      For moveBalloon = 1 To GraphicsWindow.Width-50
        Shapes.Move(balloon, moveBalloon, balloon1_y)
        Program.Delay(15)
      EndFor   
     
      For moveBalloon = GraphicsWindow.Width-50 To 1 Step -1
        Shapes.Move(balloon, moveBalloon, balloon1_y)
        Program.Delay(15)
      EndFor
    EndWhile
    EndSub
    Sub moveCannon
      If GraphicsWindow.LastKey = "D" Then
        'If cannon1_x < GraphicsWindow.Width-65 Then
        'cannon1_x = cannon1_x + 20
        'Shapes.Move(cannon, cannon1_x, cannon1_y)
        'EndIf
        Shapes.Rotate(cannon,angle+5)
        angle=angle+5
       
      ElseIf GraphicsWindow.LastKey = "A" Then
        'If cannon1_x > GraphicsWindow.Width-800 Then
        '  cannon1_x = cannon1_x - 20
        '  Shapes.Move(cannon, cannon1_x, cannon1_y)
        'EndIf
        Shapes.Rotate(cannon,angle-5)
        angle=angle-5
      ElseIf GraphicsWindow.LastKey="F" then
        Shapes.Animate(ball,GraphicsWindow.width/2,balloon1_y-60,600)
        Shapes.ShowShape(Ball)
    Timer.Resume()
       
      EndIf
    EndSub
    Sub OnTimerTick
      Timer.Pause()
      If moveballoon > (GraphicsWindow.width/2)-15 And moveballoon < (GraphicsWindow.Width/2)+15 then
        'Shapes.HideShape(Balloon)
        LDShapes.BrushColour(Balloon,GraphicsWindow.getrandomcolor())
        moveBalloon() 'rests balloon back to beginning
      EndIf
        Shapes.HideShape(Ball)
      Shapes.Move(Ball,cannon1_x+5,cannon1_y+30)
    EndSub


    JR

    Sunday, February 12, 2017 1:46 PM
  • Doesn't know what LDShapes is at

    LDShapes.BrushColour(Balloon,GraphicsWindow.getrandomcolor())

    line 65


    I love coding. This is signature is 100% Original. :)

    Sunday, February 12, 2017 5:24 PM
  • Forbidden Duck,

    As I said above "You have to have the LitDev Extension loaded for this to work. You can still run the program without it, but you won't get the change color effect. You will see the balloon disappear and start again from the left side when you hit it. 


    JR

    Sunday, February 12, 2017 5:39 PM
  • I decided to do it a different way and I got the ball doing what it's suppose to but yea problems

    1.

    Ball disappears even though I tried If ball > GraphicsWindow.Width-50 and I tried < and <> and = but disappears instantly

    2. When you press F the balloon slows down and moves 1 pixel per second. Which I don't if it's because of performance issues

    3.

    Ball then appears from under graphics window and repeats spawning from there. I'd like it being able to shoot more than one

    CODE:

    cannon1_x = 375
    cannon1_y = 350
    
    balloon1_x = 0
    balloon1_y = 0
    
    ball1_x = cannon1_x+21.5
    ball1_y = cannon1_y
    
    ball_move1 = ball1_x+ball1_y
    
    GraphicsWindow.KeyDown = shootCannon
    GraphicsWindow.Width = "800"
    GraphicsWindow.Height = "500"
    GraphicsWindow.CanResize = "false"
    GraphicsWindow.Show()
    
    RESOURCE_PATH = Program.Directory + "\resources\"
    CANNON_IMAGE = RESOURCE_PATH + "cannon.png"
    BALLOON_IMG = RESOURCE_PATH + "balloon.png"
    balloon = Shapes.AddImage(BALLOON_IMG)
    cannon = Shapes.AddImage(CANNON_IMAGE)
    ball = Shapes.AddEllipse(20, 20)
    Shapes.HideShape(ball)
    Shapes.Move(ball, ball1_x, ball1_y)
    Shapes.Move(cannon, cannon1_x, cannon1_y)
    Shapes.Move(balloon, balloon1_x, balloon1_y)
    
    While "True"
      For moveBalloon = 1 To GraphicsWindow.Width-50
        Shapes.Move(balloon, moveBalloon, balloon1_y)
        Program.Delay(3)
      EndFor    
      
      For moveBalloon = GraphicsWindow.Width-50 To 1 Step -1
        Shapes.Move(balloon, moveBalloon, balloon1_y)
        Program.Delay(3)
      EndFor
    EndWhile
    
    While "True"
      Program.Delay(100)
    EndWhile
    Sub shootCannon
      If GraphicsWindow.LastKey = "F" Then
        Shapes.ShowShape(ball)
        ball_hide()
        For moveBall = ball_move1 To 0 Step -1
          Shapes.Move(ball, ball1_y, moveBall)
          Program.Delay(10)
        EndFor
      EndIf
    EndSub
    Sub ball_hide
      If ball = GraphicsWindow.Height-50 Then 
        Shapes.HideShape(ball)
      EndIf
    EndSub


    I love coding. This is signature is 100% Original. :)




    Sunday, February 12, 2017 5:45 PM
  • It broke the second I pressed a button

    I love coding. This is signature is 100% Original. :)

    Sunday, February 12, 2017 8:06 PM
  • The program of Yled doesn't work because once the F-key is pressed, the LastKey is always True and  shootCannon is continuously called. y is then incremented without limit.

    Jan [ WhTurner ] The Netherlands

    • Proposed as answer by YLedEditor Monday, February 13, 2017 2:41 PM
    Monday, February 13, 2017 1:32 PM
    Answerer
  • And ball_hide() fails.  because ball is shapes name, not value!!!
    Monday, February 13, 2017 2:20 PM
    Answerer
  • @WhTurner

    you are right ! i'll go back to the drawing board :)

    see my new program:

    An Automatic Baseballs Launcher

    • Edited by YLedEditor Monday, February 13, 2017 4:32 PM
    Monday, February 13, 2017 2:42 PM
    Answerer