Wednesday, July 2, 2008

Browser Based games III

Yes, I actually managed to write the third version of my browser based games tutorials. Today I am going to discuss the second type of browser games: small Animation games. Like I discussed last time, small animations games are like tetris, frogger, bricks which require moving objects but very less AI and have static backgrounds. These games require a lot of memory space to store the position and status of various objects along with the objects' properties.

There are a few points that one can consider while planning the game for development:
  • Firstly, examine the game very carefully and be very clear with all the rules/ instructions of the game to be developed. This will help you decide the data structures to be used. Usually most of the data is stored in javascript Arrays. So, we need to be very careful while designing the game to optimise the utilisation of memory (try to use minimum memory space and use local variables as much as possible)
  • The idea behind using Arrays is to find patterns among the objects. For example, the image objects in the frogger game which move along the road can be stored in the arrays. By finding the right quantity of those objects we can define the size of the array. By deleting the old objects which have crossed the screen and inserting new objects in those places. Similarly.. we could store the empty and filled spaces of the screen in an array in the game of Bricks.
  • Moving the objects is fairly simple now.. if we have a constant speed, we could just move objects by using a set interval command, and calling a function which moves all objects on the screen.
    timer=setInterval("functionName()",50);//This function is called periodically after aevery 50 ms.
    function funtionName()
    {
    for(i=0;i<size;i++)
    arr[i].style.left=parseInt(arr[i].style.left)+moveRight;
    }
  • This will move the array objects to the right by moveRight pixels every 50 ms. If you have to move both ways.. u might need an array to store a boolean value indicating left or right. and move accordingly.
  • Similarly to detect collision both the objects coordinates have to be matched. Generally all objects could be considered as rectangles and hence they could be checked for their areas of intersection by their end points easily.
I think rest is dependent on your imagination and creativity. Just try to make game as light as possible (in complexity and memory used).. so that it could be played on low end systems as well.

No comments: