It has been pretty difficult getting things done in the past week or so, for various reasons (excuses include my birthday, the start of the finals period and some pressure at work).
Initially I was trying at doing unit tests for my planned sprites work, in the TDD tradition. This proved to be a major creativity block for me, I’m guessing mostly because I’m not too experienced with writing tests.
So eventually, I decided to take another approach and just get stuff done in a way that could be quickly presented and tweaked.
Today, I managed to get 2 of the planned features ready to be played around with: Anchor points and Better positioning. In addition, I have a simple demo app that showcases the use of these 2 features.
Sprite class is based on a flat-out copy-paste of the original Pygame
Sprite class, along with the relevant additions:
anchorproperty that will be used for positioning and modifying the sprite. It can be set at any point during the game to either:
- A custom
(x, y)tuple relative to the sprite’s rectangle coordinates.
anchor_valuemethod that returns a tuple of the calculated value of the sprite’s anchor at a given moment.
positionproprety consisting of
(x, y)coordinates that, when set, uses the sprite’s anchor property to position the sprite on the screen.
The usage of the new features is demonstrated in the
The demo starts out with a basic grid in which you can move a basketball sprite around with the arrow keys: During the game, you can use the
d keys to switch between
(25, 20) settings for the anchor, respectively.
This is basically it, for now, but I’m pretty satisfied with this small development, as it was integreated easily enough and shouldn’t be breaking any legacy uses of the Pygame’s
The work is maintained in the
Please feel free to check out the code and the demo app and send any relevant feedback my way.
I hope to be able to show further progress by the next weekend.