Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[BUG] Array Of Types
#11
Quote:Then I have no idea what is wrong below...

The compiler says that it found ".sX" when it expected "=".
Code:
With Bullet(UBound(Bullet))
         'Initial coordinates of the bullet
         .sX = Ship.sX
         .sY = Ship.sY
         .iAlive = 1
        
         'Add the bullet and ship vectors, calculate resultant vector components
         sXComp = Ship.sSpeed * Sin(Ship.sHeading) + BULLET_SPEED * Sin(Ship.sFacing)
         sYComp = Ship.sSpeed * Cos(Ship.sHeading) + BULLET_SPEED * Cos(Ship.sFacing)
        
         'Calculate speed using with |ai + bj| = Sqr (a^2 + b^2)
         .sSpeed = Sqr(sXComp ^ 2 + sYComp ^ 2)
        
         'Calculate the resultant heading
         If sYComp > 0 Then .sHeading = Atn(sXComp / sYComp)
         If sYComp < 0 Then .sHeading = Atn(sXComp / sYComp) + PI
      End With

Unecesary ATN here.

Code:
.speed = length of vector
so...
you could just normalize your vector ala:
Code:
nx! = sxcomp/.sspeed
ny! = sycomp/.sspeed
And use those components multiplied by how much speed you want for the bullet.

Or, instead of using ATN and checking which quadrant your vector points to, you could just use atan2.

.sHeading = atan2(sYComp, sxComp)

But I would not combine both processes to do bullets. Either use sqr or atan2.
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#12
Okay, changed, type-less REDIM's will check for already declared arrays (local then global) and use them instead, as in VB (i guess), if nothing is found, it will allocate an array with the lastest DEF### type.
Reply
#13
Thank you so very much... that was my biggest beef with QB (and FreeBASIC, I suppose), and now it's fixed... * choirs of angels sing * Smile
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)