Monday, September 21, 2009

my first action game

Finally, after lot of issues and bugs, I was able to create a shooting game. It is a very simple game with balloons on screen (dancing pseudo randomly) and with a gun on the bottom of screen which can move left and right capable of shooting one bullet at a time. If the bullet hits a balloon, score is incremented. So simple yet so problematic !!!!
First of all, for the sprites to be displayed, paint() method should not be overridden, at least by a novice like me :-) Once I figured that out, I modified the game to see the balloons on screen. Then came the logical part of arranging it, setting up the gun, fixing the bullets, checking for collisions. Once it was all done, I realized that on pressing Fire the game starts but it also causes a bullet to fire as the bullets are sent on pressing Fire key. When the game starts, the jvm or kvm assumes that the fire key is still pressed (it was pressed to start the game) and so it sends the bullet up. This caused a lot of consternation. I skimmed the net to find some help but it seems there is no way to clear the keys (at least I couldn't find any till now). So I created another form to force the user to click on play to start the game. That solved the problem for now.
The game is running well on my A1200. It lacks a lot of features, mostly sound, and there are some bugs too (once moving the gun caused it to enter an endless loop, that was funny :-)), but yes now I have truly entered the land of sprites. Now I can dream of making some sophisticated game with some real sword fighting (my son has been demanding it for some time now....)
The Navratras are here and there are a lot of things that I wish for and keep on praying for. But these things are between me and my maker. Here is hoping for better times.

No comments: