Answered Program running help!

  • Monday, July 16, 2012 7:32 PM
    Answerer
     
     

    PZR676.  I'm trying to make a cannon shoot a ball but, as time goes on the program slows down. help! I've asked questions Just like this before and I was generiously given some sample code from gotoloop and litdev. But I was wondering If anyone would explane how to do this so I wouldn't have to ask.

     Thanks in advance!


    Zock77

All Replies

  • Monday, July 16, 2012 9:10 PM
    Moderator
     
     

    You are removing the shapes as the missiles are deleted, but the arrays of positions etc continue to grow and the large array cause the slowing.

    Perhaps something like this, import PZR676-1.

    PS

    Also Add

    Time[i] = ""

    x[i] = ""

    y[i] = ""

    to the cleanup sub

    Also, if the timer calls the computerfire too often the missiles build up and their movement slows and they build up and therefore adding more at the same timer interval causes more missiles and a slow down - perhaps don't add more missiles if there are already more than some limit already in motion.
  • Monday, July 16, 2012 10:24 PM
    Answerer
     
     Answered Has Code

    I remember when I helped  Zock77 in his Missile Turret game, I had to make a garbage collector subroutine snippet to deal w/ the frenetic missile shootings. It was non-stop! :D

    Sub GarbageCleanup
    
      Elapsed = Elapsed + 1
    
      While ii < i-MTrack   ' <--- ii is always behind most recent fired missile #i up to MTrack older ones
        Shapes.Remove( Missile[ii] )
        Missile   [ii] = ""
        TimeStart [ii] = ""
        vCosInit  [ii] = ""
        vSinInit  [ii] = ""
        ii = ii + 1
      EndWhile
    
    EndSub

    And to gain some execution speed, I've removed 4 or 5 arrays from the game as well. Arrays are very slow in SB anyways!

    Zock77, perhaps you should take a look at your old Missile Turret (MJV649-3) source code for some ideas.

    PS: Dunno why Missile Turret stopped working on Silverlight. *_*


    Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)

  • Tuesday, July 17, 2012 4:02 AM
    Answerer
     
     
    Hmm It works but the array keeps getting larger.

    Zock77

  • Tuesday, July 17, 2012 7:52 AM
     
     Answered

    Zock77  ,   Maybe you want to do is like this?

    gui()

    While "true"
      fire()
      Program.Delay(20)
    endwhile

    Sub fire
      For i=1 To 20
        y[i]=y[i]-dy[i]
        x[i]=x[i]+dX[i]
        Shapes.Move(ball[i],X[i],y[i])  '
        If y[i]<0 Then                  
          position()                     
        EndIf 
      EndFor 
    endsub

    Sub position
      x[i]=100                '  starting position
      Y[i]=650
      dX[i]=Math.GetRandomNumber(10)  '
      dy[i]=5+Math.GetRandomNumber(10)
    EndSub

    Sub gui
      GraphicsWindow.Width=1000
      GraphicsWindow.Height=700
      GraphicsWindow.BackgroundColor="Lightcyan"
      GraphicsWindow.BrushColor="Red"
      GraphicsWindow.PenColor="red"
      For i=1 To 20
        ball[i]=Shapes.AddEllipse(2+Math.GetRandomNumber(10),5+Math.GetRandomNumber(20))
        Shapes.Move(ball[i],100,650) '
        position() 
      endFor
    EndSub

     

  • Tuesday, July 17, 2012 4:22 PM
    Answerer
     
     
    Hmm. I see where your going. only track the max ball that can be on the screen with that rate of fire. that way the program would never slow down. ill try that. Thank you All for replying!!

    Zock77