Grrr!
Despite the title, this is not a rant 🙂
Grrr is a pet project of mine that came after the exploratory work with psinvaders. I was somewhat dissatisfied with myself for doing so much without seeing how else it could be done, especially with respect to drawing of images, animation, etc.
So what is Grrr? Grrr is a set of functions written in pure PowerShell that let you create playfields with scrolling viewports, draw lines and images, animate and move sprites, and generally be an inappropriate use of the technology.
The version of Grrr discussed in this article can be downloaded from here. Updated versions will appear on the downloads page.
To use, you write a script of your own and source it with a dot/period, like this:
. ./grrr.ps1
I suppose you could do this in your $profile
, but I prefer to keep things self contained as PowerShell’s global scope can get very cluttered very fast.
Testing
In the Grrr distribution, there is a very mini unit test framework called psunit.ps1
.
The script grrr-test.ps1 uses this to unit test grrr.ps1. Hurrah for test-driven development! The picture shows it in action. Click on it to see the full thing.
To run the test your self, type ./grrr-test.ps1
in the directory where this is unzipped.
Example scripts
There are three example scripts. Run them like he unit test script.
They are:
⁃ grrr-test-clock.ps1 – a simple script that shows back buffering and drawing lines
⁃ grrr-test-sprite.ps1 – shows animation of sprites… some controlled semi-manually, and one by a motion path
⁃ grrr-test-scramble.ps1 – show the use of tilemaps to produce the effect of paralax scrolling.
The latter is very slow and really shows up how poor PowerShell by itself performs.
Have a look at the code, play around with it, tell me it’s rubbish if you like 🙂
The next steps for this project are adding a proper game loop controller, with key event handling, fps throttling and a few more motion handlers and behaviours – I’d like for sprites to be able to look after themselves, eg respond to proximity of others, shoot things, detect walls, etc.
I also want to make it faster. Maybe with C# inlining, maybe by making these things cmdlets, maybe by doing it all in C# in a custom host application. Who knows.
[…] I’ve almost completed the transition of Grrr to Cmdlets and it’s looking very promising as this screen shot shows (I get 50fps with only […]