none
Moving multiple shapes from different directions RRS feed

  • Question

  • Hey there, im making a shooting game for my course and i wish to make little shapes move in from all directions to be shot. So far, I can get one shape to come in from one direction at a time, but when I try to bring in more shapes, it just stops working. Help!

     

    This is the code segment I have. The shapes to be moved are called "Strabanimals". Thanks

    Timer.Interval = 10
    Timer.Tick = MoveStrabanimal
    
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'BEGIN - Main Game Code
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Sub buttonclicked
      If Controls.LastClickedButton = info then
        GraphicsWindow.ShowMessage("- This game was created by Caolan McGrath using Microsoft SmallBASIC 1.0        - - It is currently in the BETA Stage","Game Info")
      Endif
      
      If Controls.LastClickedButton = start then
        GraphicsWindow.Clear()
        GraphicsWindow.DrawImage(background,0,0)
        Mouse.HideCursor()
        
        GenerateStrabanimal()
        
        
    
    
    
    crosshairs = Shapes.AddImage("U:\My Game\Strabanimal\gamefiles\crosshairs.png")
    Shapes.Move(crosshairs,410,410)
    
      EndIf
    EndSub 
    
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Sub GenerateStrabanimal
      
      'Direction = Math.GetRandomNumber(4)
      Direction = 1
      Counter = 1
      Strabanimal = "U:\My Game\Strabanimal\gamefiles\strabanimal1.gif"
      Strabanimal2 = "U:\My Game\Strabanimal\gamefiles\strabanimal2.gif"
      Strabanimal[counter] = Shapes.AddImage(Strabanimal)
    
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'Moving From Top to Bottom
    '     If Direction = 1 Then       
    
    '    TopX[Counter] = Math.GetRandomNumber(900)
    '    BottomX[Counter] = Math.GetRandomNumber(900)
      
    '   DiffX[Counter] = BottomX[Counter] - TopX[Counter]
    
     
    '   MoveX[Counter] = DiffX[Counter] / 235
    
    
    '   MoveY[Counter] = 2
    
    
    '   X[Counter] = TopX[counter]
    '   Y[Counter]= 9
       
    
    '   Shapes.Move(Strabanimal[counter], X[Counter], Y[Counter])     
    ' EndIf  
    
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'Moving from Bottom to Top
    '   If Direction = 1 Then    
    
    '   TopX[Counter] = Math.GetRandomNumber(900)
    '   BottomX[Counter] = Math.GetRandomNumber(900)
       
    '    DiffX[Counter] = TopX[Counter] - BottomX[Counter]
    
     
    '    MoveX[Counter] = DiffX[Counter] / 235
    
    
    '    MoveY[Counter] = 2
    
    
    '    X[Counter] = TopX[counter]
    '    Y[Counter]= 460
        
    
    '    Shapes.Move(Strabanimal[counter], X[Counter], Y[Counter])     
    '  EndIf  
    
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 
    'Moving from Left to Right
      If Direction = 1 Then    '   -Coming from Left to Right
        RightY[Counter] = Math.GetRandomNumber(460)
        LeftY[Counter] = Math.GetRandomNumber(460)
       
        DiffY[Counter] = leftY[Counter] - RightY[Counter]
    
     
        MoveY[Counter] = DiffY[Counter] / 225
    
    
        MoveX[Counter] = 2
    
    
        X[Counter] = 0
        Y[Counter] = LeftY[Counter]    
    
        Shapes.Move(Strabanimal[counter], X[Counter], Y[Counter])     
      EndIf  
      
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'Moving from Right to Left
    '  If Direction = 1 Then    '   -Coming from Left to Right
    '    RightY[Counter] = Math.GetRandomNumber(460)
    '    LeftY[Counter] = Math.GetRandomNumber(460)
    
    '    DiffY[Counter] = RightY[Counter] - LeftY[Counter]
    
     
    '    MoveY[Counter] = DiffY[Counter] / 225
    
    
    '    MoveX[Counter] = 2
    
    
    '    X[Counter] = 900
    '    Y[Counter] = RightY[Counter]    
    
    '    Shapes.Move(Strabanimal[counter], X[Counter], Y[Counter])     
    '  EndIf  
     
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 
    EndSub
    
    
    Sub MoveStrabanimal
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  
    ' --------Moving From Top to Bottom
    ' For Counter2 = 1 To Counter     
    '   X[Counter] = X[Counter] + MoveX[Counter]
    '   Y[Counter] = Y[Counter] + MoveY[Counter]
    '   Shapes.Move(Strabanimal[counter2], X[Counter], Y[Counter])
    ' EndFor
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 
    '--------Moving From Bottom to Top
    '  For Counter2 = 1 To Counter    
    '    X[Counter] = X[Counter] + MoveX[Counter]
    '    Y[Counter] = Y[Counter] - MoveY[Counter]
    '    Shapes.Move(Strabanimal[counter2], X[Counter], Y[Counter])
    '  EndFor
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  
    '---------Moving From Left to Right
      For Counter2 = 1 To Counter    
        X[Counter] = X[Counter] + MoveX[Counter]
        Y[Counter] = Y[Counter] + MoveY[Counter]
        Shapes.Move(Strabanimal[counter2], X[Counter], Y[Counter])
      EndFor
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''  
    '---------Moving from Right to Left
    '  For Counter2 = 1 To Counter    
    '    X[Counter] = X[Counter] - MoveX[Counter]
    '    Y[Counter] = Y[Counter] + MoveY[Counter]
    '    Shapes.Move(Strabanimal[counter2], X[Counter], Y[Counter])
    '  EndFor
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 
    EndSub
    
    
    Sub MyMouseMove
     Shapes.Move(crosshairs, GraphicsWindow.MouseX - 30, GraphicsWindow.MouseY - 30)
    EndSub

     

    Tuesday, November 8, 2011 2:05 PM

Answers

  • Make sure you keep your indexes straight. You can start here:

    '---------Moving From Left to Right
      For Counter2 = 1 To Counter    
        X[Counter] = X[Counter] + MoveX[Counter]
        Y[Counter] = Y[Counter] + MoveY[Counter]
        Shapes.Move(Strabanimal[counter2], X[Counter], Y[Counter])
      EndFor

    This will cause all your strabanimals to move to the same spot. Change Counter to Counter2 for X, Y, MoveX, and MoveY. Also watch the indexes when generating you strabanimals.. You don't want to overwrite your information.

    Hope this helps!

    Wednesday, April 18, 2012 1:22 PM