Intro...
Its over. I finally finished my 0.4 release PR, pushed it, and it was accepted. I successfully created connect four using the LiteCanvas engine.
My Goals...
Of the goals I had listed and as mentioned in my progress update, I implemented the following.
- Successfully created a Connect Four LiteCanvas game.
- Studied the documentation as well as prior implementations of games and examples.
- Added a dropping piece animation.
- Having a simple UI and with friendly controls.
- Having the game be 2 player back and forth.
Features...
- A dropping piece animation using state changes of arrays.
- 2 Player turn based gameplay.
- Selector with movement animations to select columns to drop in using the left and right arrow keys.
- Drop piece activated with down arrow key.
- Victory and Draw screens after game ends, with ability to replay the game by hitting the 'r' key.
- Turn descriptors, with colour coordinated user text.
- User score counter for both players.
- Sounds for moving selector left/right, dropping a piece, winning a game, drawing a game, and replaying the game.
- 1 point given for a win to the winning player.
- 1 point given to BOTH players for a draw.
Accomplished...
In making this connect four game, I will walk through how I accomplished it.
Initializations:
- Set up all necessary factors for the screen.
- Set up the delays to be used for player moves with keyboard.
- Set up the selector coordinates to be moved to on the board.
- Set up the initialization of beginner game states.
- Set up colours and positions to be used.
- Set the game state.
Selector graphics:
- Used a pre-used arrow drawing and modified to become a triangle.
- Triangle gets rotated to look as it does later on.
Update/draw loop:
- Set up the update loop, checking for update helpers depending on game state with every run of the game loop.
- Set up the helper methods for updating as well as the drop piece.
Draw method:
- Drew the parts of the board.
- Drew the selector.
- Set conditions based on game state.
Win/Draw methods:
- Set up conditions for checking win based on vertical/horizontal/left diagonal/right diagonal.
- Set up condition to update state based on draw.
Learnt...
Overall I learnt quite a bit about game development in this process. Although I have used PyGame in the past to create a similar implementation, I dod not use it at all as a reference and instead went into this project from scratch, wanting to learn about the LiteCanvas engine. First, I learnt how to create a game loop using the pre-defined classes. Then I learnt how to create objects using the engine. Then I learnt how to create a simple animation that was effective for my use case. Then, I learned how to make the possibly simplest method of checking rows, columns, and diagonals that I have come up with yet. Finally I learned how to add sounds and create them using the ZzFX library mentioned by the maintainer Luiz. In this process I think the only thing I could have done better would be to implement a more object oriented approach with classes and objects similar to my approach with PyGame that I made. In the end, I am happy with my game, and encourage you to pull and test it out for yourself. If you'd like to view the other games as part of the engine as well as mine, visit here. If you'd like to see my PR as mentioned at the start, visit here.
Top comments (0)