```-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= How to give birth to Gorilla's -=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Writer: Matthew River Knight Not *those* kind of gorilla's! I mean Microsoft's old but gold GORILLA.BAS which was distributed along-side QBasic and MS-DOS several years ago. MS Gorillas was an utterly fab game for its time. You played the role of a large gorilla standing on top of a building, whose sole purpose in life was to throw an exploding bannana at the enemy gorilla, thus spilling his innards all over the street below. In order to throw the bannana, you would have to enter values for the angle and velocity of the shot, taking gravity and wind into account. The bannana would then be flung into the air, moving in a very realistic fashion. After playing Gorillas, you may be wanting to make a similar game of your own. It's actually fairly simple to code, however, the biggest problem that coders encounter when making these sorts of games, is the algorithm for moving the bannana (or whatever object you choose), taking wind and gravity into account. In this tutorial, we will explore the math behind this algorithm, hopefully helping you to get your own Gorillas style game up and running, with ease! Since I recently made a game called Rockwars 2000, a remake of the original 1995 QB classic by Brennen Bearns, and in that game I used a rock as opposed to Gorillas bannana's, we will speak of rock's from this point on. Rockwars 2000 can be had at http://www.neozones.com/general/rw2000.zip Firstly, we need to create two variables holding the X and Y location of our rock. We'll call these variables BallX and BallY. We also need the X and Y speed values, containing the value's by which BallX and BallY will be incremented when the rock is thrown. We'll call these two variables BallXSpeed and BallYSpeed. But how do we know what values to put in these two variables? In order to calculate these values, we first need to create a vector much like the one shown in the diagram below. ' * ' * ' * ' * *------------ * = Vector The diagram above actually depicts the amount BallX and BallY will be incremented, and the direction. The direction is the angle of the shot. Needless to say, a larger vector will result in a larger increment of the rock, in the specified direction. The values that we put in BallXSpeed and BallYSpeed are the X and Y components of the vector. These may be calculated from the following formula: BallXSpeed = Speed / 100 * COS(Angle * .017453) BallYSpeed = Speed / 100 * SIN(Angle * .017453) Notice that in the formula above, we have made a special variable called Speed. Try experimenting with the value of Speed, and notice the effect it has on the movement of the rock. Finally, we create a loop, and we add the BallXSpeed and BallYSpeed values to BallX and BallY respectively. However, since we wish to take gravitational acceleration and the wind into account, we need to add the following to our loop: BallYSpeed = BallYSpeed + Gravity / 100 BallXSpeed = BallXSpeed + Wind / 100 The final thing that we need to add to our loop is the code to draw the rock: PSET (BallX, BallY), 12 Pretty simple, no? Just in case you are still confused, try out the following QB source code: Angle = -60 'Angle of the shot. BallX = 30 'Initial X coordinate of the rock. BallY = 150 'Initial Y coordinate of the rock. Gravity = 9.8 'Gravitational acceleration constant. Speed = 500 'Speed at which the rock is thrown. Wind = .5 'Wind speed and direction, where + is to the right. BallXSpeed = Speed / 100 * COS(Angle * .017453) 'Set the X speed. BallYSpeed = Speed / 100 * SIN(Angle * .017453) 'Set the Y speed. SCREEN 9 LINE (0, 150)-(640, 150), 2 'Draw the ground. DO BallX = BallX + BallXSpeed BallY = BallY + BallYSpeed BallYSpeed = BallYSpeed + Gravity / 100 BallXSpeed = BallXSpeed + Wind / 100 PSET (BallX, BallY), 12 LOOP UNTIL BallY >= 150 ```