locked
How to make moving bullets ? RRS feed

  • Question

  • Well if SB had classes or structures this would be simple and i wouldn't ask, but cause it doesn't have them i have to ask ( i  could use arrays but thats my last call ). Well anyone please.

    I love game design and game programing.

    Sunday, May 27, 2012 9:10 PM

Answers

  • Yes, a class clearly has member variables local to each instance of the class.  SmallBasic has no classes and all variables are global.  Therefore to use SmallBasic for multiple bullets, arrays are required.

    Perhaps one array for each of: storing the bullet shape object, X, Y position and X,Y velocity and other data such as active or not, or other properties.

    Somethomes for bullets we have a pool of these objects and re-use them as required.  For example we may have 20 bullets set up, but usually only a subset of these are active at any one time and we re-use them as required.

    If you want an example of this being done I have several.

    Monday, May 28, 2012 1:20 PM

All replies

  • I'm not quite sure what classes and structures have to do with basic animation, or why arrays solve the problem but you don't want to use them?  If you need classes etc, then move to VB or C# which have all sorts of object constructs (classes etc), but you will still have to program the movement of a bullet, frankly in a much more complex environment.

    If you are looking for high level methods that do all the movement calculations for you, then SB isn't the solution; some extensions may help, but are more complex.

    Unfortunately, C++, C# or other language libraries for graphics animation are much more complex than SB to get started with.

    Perhaps I misunderstand the question (most of the above is just guessing what you mean), so more details and simplified code showing the issue you are trying to solve are needed.

    Sunday, May 27, 2012 9:32 PM
  • Try this:

    Power = 40


    Gravity = 320


    Angle = 50


    Angle2 = Angle - Angle * 2


      Angle1 = Math.GetRadians(Angle2)


      V = Power / 5


      Vh = Math.GetDegrees(Math.Cos(Angle1)) * V

      Vv = Math.GetDegrees(Math.Sin(Angle1)) * V

      Timestart = Clock.ElapsedMilliseconds / 1000


      Ball = Shapes.AddEllipse(10,10)


     

      While 1 = 1


        Program.Delay(5)


      Timenow = Clock.ElapsedMilliseconds / 1000 - Timestart

      '"X" cordinates


      x = Vh * Timenow + 50


      '"Y" cordinates


      y = Vv * Timenow +  (Math.Power(Timenow,2) * (Gravity / 2)) + 200


      Shapes.Move(Ball,x,y)


      EndWhile

    '(Sorry about the spaceing)




    Monday, May 28, 2012 1:17 AM
    Answerer
  • None of you understand my question... ok again if i make a bullet then i set it's speed cause i shot it from somewhere and if i create another it will change them both... if i had classes orr structures such variables would be local to the bullet  or no...

    I love game design and game programing.

    Monday, May 28, 2012 12:07 PM
  • Yes, a class clearly has member variables local to each instance of the class.  SmallBasic has no classes and all variables are global.  Therefore to use SmallBasic for multiple bullets, arrays are required.

    Perhaps one array for each of: storing the bullet shape object, X, Y position and X,Y velocity and other data such as active or not, or other properties.

    Somethomes for bullets we have a pool of these objects and re-use them as required.  For example we may have 20 bullets set up, but usually only a subset of these are active at any one time and we re-use them as required.

    If you want an example of this being done I have several.

    Monday, May 28, 2012 1:20 PM
  • No need yet... i just need some break from this test study test study... and ill make it myself.

    I love game design and game programing.

    Monday, May 28, 2012 2:11 PM