Monday, June 24, 2013

Game loop for Gorillas

I have recently realized that I will have to completely restructure the game loop for my gorillas.bas clone to have it make any sense.

       function taketurn(form){
            //starts a turn by passing the initial vector states to a missile object for the turn.
            //alert('hello!');
            console.log('taking a turn');
            var nextTurn = null;
           // alert(form[2].value);
           
            if(form[2].value== 'player1'){
                this.angle = Number(form[0].value);
               
this.power = Number(form[1].value);
               
this.whichGor = 1;
                nextTurn = "player2";
            }
            else if(form[2].value =='player2'){
               
this.angle = Number(180 - form[0].value);
               
this.power = Number(form[1].value);
               
this.whichGor = 2;
                nextTurn = "player1";
            }
            
var missile = new aMissile(this.whichGor, this.angle, this.power); missile.shoot(); 
            if(missile.hitMonkey){
                cleanUp();
            }
            document.getElementById("shotInput")[2].value = nextTurn;
       }

As you can see, there is no loop to update the graphics. I want this to be the main function that handles the turn. I am shunting everything to the missile object. The missile object is just supposed to be values and methods relating to the exploding babies. It should not be updating and repainting the background.  Right now the whole thing is a mess. The missile object is a mess. All this figuring out whose turn it is crap that the function starts with should be delegated to a helper function and this should contain the main loop that occurs every time you press fire.

The  loop should probably go like this:
1. update missile position
2. draw background
3. check to see if missile hit something
4. If it did
      a.have the missile explode.
      b. check to see if the explosion hit a gorilla
            i. if it did terminate the game.
      c. terminate the loop
5. draw the missile.
6. clear everything for the next frame.


No comments:

Post a Comment