LitDev’s "Small Basic: Dynamic Graphics" – Featured Article!

Check out LitDev’s November gold medal winner for the Small Basic Guru contest:

Small Basic: Dynamic Graphics


This is also LitDev’s first gold medal! So congrats go to LitDev!


Here is an excerpt section from the article…




Advanced Collisions

To get sprites to bounce off each other realistically can be complicated.  Basically we need to do the collision in a center of mass reference frame using geometry like the figure below, then convert from the center of mass frame back to the actual frame.

This is an example implementation of this in Small Basic.

Sub CollisionCheck
  For i = 1 To Ball_Number-1
    For j = i+1 To Ball_Number
      dx = Ball_X[i] - Ball_X[j]
      dy = Ball_Y[i] - Ball_Y[j]
      Distance = Math.SquareRoot(dx * dx + dy * dy)
      If Distance < Ball_Diameter Then
        Cx = (Ball_vX[i]+ball_vX[j])/2
        Cy = (Ball_vY[i]+ball_vY[j])/2
        Relative_vX[i] = Ball_vX[i] - Cx
        Relative_vY[i] = Ball_vY[i] - Cy
        Relative_vX[j] = Ball_vX[j] - Cx
        Relative_vY[j] = Ball_vY[j] - Cy
        Nx = dx / Distance
        Ny = dy / Distance
        L[i] = Nx * Relative_vX[i] + Ny * Relative_vY[i]
        L[j] = Nx * Relative_vX[j] + Ny * Relative_vY[j]
        Relative_vX[i] = Relative_vX[i] - (2 * L[i] * Nx)
        Relative_vY[i] = Relative_vY[i] - (2 * L[i] * Ny)
        Relative_vX[j] = Relative_vX[j] - (2 * L[j] * Nx)
        Relative_vY[j] = Relative_vY[j] - (2 * L[j] * Ny)
        Ball_vX[i] = (Relative_vX[i] + Cx)
        Ball_vY[i] = (Relative_vY[i] + Cy)
        Ball_vX[j] = (Relative_vX[j] + Cx)
        Ball_vY[j] = (Relative_vY[j] + Cy)  
        Ball_X[i] = Ball_X[i] + Nx * (Ball_Diameter-Distance)
        Ball_Y[i] = Ball_Y[i] + Ny * (Ball_Diameter-Distance)
        Ball_X[j] = Ball_X[j] - Nx * (Ball_Diameter-Distance)
        Ball_Y[j] = Ball_Y[j] - Ny * (Ball_Diameter-Distance)

If this is not clear then perhaps avoid this or consider trying using a physics engine to do it for you, such as the LDPhysics (Box2D) method.





Here are all the winning Small Basic articles from November:


Guru Award  Small Basic Technical Guru – November 2013  

Gold Award Winner


litdev Dynamic Graphics Ed Price: “Incredibly detailed. A fantastic resource to keep coming back to! From the comments: “Wanted to say WOW – this is great!” and “Awesome. Thanks””

Silver Award Winner


Nonki Takahashi How to Make a Check Box Ed Price: “Well formatted and in-depth how-to article! Great job!”

Bronze Award Winner


Joe Dwyer Why Small Basic is a great programming language for beginners Ed Price: “A well-articulated value statement for Small Basic! Thanks, Joe!”


Congratulations to litdev, Nonki and Joe!

Also worth a mention were the other entries this month:


You can find all the Guru winners (for all the Microsoft technologies) here: TechNet Guru Awards – November 2013


Thanks again to LitDev!

   – Ninja Ed

Comments (1)