' SBace-Invaders-25 (v2) - A space invader game in under 25 lines by Davey~Wavey, Nov.2009, for Small Basic Forum.
' ===================================================================================
'
' Alien has increasing speed as it descends to increase difficulty, but you also get more score the faster they are!
' Aliens have different personalities (!) and drop further depending on their agression (i.e. a random number)
' You are rated on your score and your hit accuracy. You have 3 lives. Use your mouse to move your rocket and left mousebutton to fire.
' When an alien gets through your defences, they kill you off, then immediately regroup for another assault.
'
' See below game code for notes. Good Luck, civilization is depending on you!!!!!
' show status in titlebar
GraphicsWindow.Title = "SBace-Invaders-25: SCORE=" + gamearry["score"] + " LIVES=" + gamearry["lives"]
EndWhile
' Game Over!
GraphicsWindow.ShowMessage ("Well Done, you scored: " + gamearry["score"] + " and your Skill = " + Math.Floor((gamearry["score"]/gamearry["ammo"])*100) + "%", "<<< G-A-M-E O-V-E-R >>> ")
' =========================================================================================================
'
' NOTES: This looks more complex than it really is. Instead of defining any variables, I am using the array to handle everything.
' Unfortunately this means that every time I change a variable, I have to completely rebuild the array, hence the long 'gamearry' lines (yeah, they're LONG!)
' If you compare them though, you'll see that only one, or maybe two, values change each time.
' To cut down on lines, I'm also using the ElseIf's to handle the various checks, which means I only need one endif.
'
' moveables = number of sprites to be moved (processed) each mainloop cycle
' The strange '1=-1;-1=1' elements, along with 'md3,4,etc', allow me to simulate a logical 'NOT' type function when I need to bounce the alien. (i.e. md3=NOT md3)
' mxo, myo are the offsets for each object (to centre object over its x,y)
' md3,4,5,etc. are the direction of individual aliens (-1,+1)
'
' Note that the calculations for collisions with alien 1 (m3) are slightly different in the arrays, due to 3 dividing into 3 and 6 without remainders.
' If adding more aliens, the same issue will be found with alien 2 (m4) and new alien 6 (m8), etc.
'
' CALCULATION TO RESET ALIEN WHEN HIT BY BULLET = (gamearry["my3"]-(gamearry["my3"]*(math.Max(0,0-(Math.Remainder(m,3)*2)+1))))
' which 1) calculates the remainder of the alien number being checked divided by the loop number = No remainder for alien being processed!
' then 2) multiplies the remainder by 2. Alien being processed stays as zero (as zero remainder times 2 still = zero)!
' then 3) make value negative, then add one to the result. Alien being processed gets a value of 1, all others remain negative.
' then 4) gets the highest (max) value comparing zero and the above result. Negatives give us zero, while alien being processed gives us 1.
' then 5) multiply the y position of the alien by the above result. Gives us zero if this is not the alien being processed.
' then 6) subtract the result above from the alien y position. If this is the alien being processed, it gets returned to the top of the screen. Yay!
'
' (c) Dave~Wavey, 2009. Please use this code only to produce further examples for the Small Basic forum to help others learn.