How does my PyGame : Bit-Castle work
By Asim Krishna Prasad
Posted on 04/02/15
Tag :
Project
In this post I am going to explain how my pygam, Bit Castle, works. This one was quite a simple one with basic implementation and a little knowledge of Python.
First let's get the game clear from the backend, the things we need to do.
- Place the door in the level.
- Place the obstructions in the level, the walls.
- Place the batteris and deaths in the level.
- Place the movable rectangle, let's say Cursor .
- Manage the difficulty of each level.
- Integrating the text-box.
When the game begins, first a few parameters are set according to the level, for example, speed of cursor, number of deaths and recharges, initial charge of battery, value of recharges etc.
After that, there is a loop which randomly generates the (x,y) coordinates of the obstructions and there lengths, but the random function is stabilzed using some constants so as to avoid any practical error. All these values are stored in different lists.
Similarly coordinates for the deaths, recharges and key, are set and then saved in lists. The coordinates for the door is fixed so that's not a problem.
Once everything is set and precomputed, the main loop for the game starts where we only need to check the collision things, and update everything accordingly. For example, if there is a collision with obstacle, the movement of the cursor needs to be restricted in one direction, collisiojn with death should result in Game-Over and etc. Parallely there is a clock counter which keeps a count-down for the time within which the level needs to be finished. Moving the cursor according to the key-press is very neat when handled with PyGame. The code just modifies the coordinates of the cursor according to the last key-press.
On the implementation part, there is something unique when it comes to code the collisions with the recharges. The recharge which is already taken by the player is needed to be removed from the level. This can be easily done by just removing that coordinate pair from the lists.
One more feature that is implemented here is Store.
It is not any load on the implementation part. This just updates the value of a few global variables and then these variables are used to modify the pre-defined variables for any level. Thus making the desired modifications in the initialization of level-specific-variables.
Another part which is important when it comes to the implementation part is the Tkinter, or the dialog box which is used to take the name of the player. Tkinter is integrated here to take the name of the player and then display the highscore. There are a few minute implementation details like, taking the input with mouse-click and enter-key too, changing the focus to the text-box automatically, etc. The main idea is to use the modularity of Python, making different functions and thus maintaining the different loops for PyGame window and Tkinter window.
That's all that is there in the game on the back-end :) . Hope you enjoyed the game..
The related links are as follows :
- Github project
- Download Link (V-1.0.0)
- ReadMe of the project
Hope it helps :)
Asim Krishna Prasad
COMMENTS :