Category Archive: Invaders

Grrr source code, including Invaders

As you may have noticed, there has been very little activity here from me in recent months.

This is partly because my full time work does not use nor need PowerShell and my free time has become more precious.

Playing with PS1 has been fun and I’ve learned a lot, but ultimately, it’s just a toy to me, and there comes a time when you must put your toys away — one might argue that, at nearly 40, I should have put my toys away long ago :-)

Now, I’ve been inundated with literally 3 requests for the source code to Grrr, the snapin-based framework behind Big Invaders, so here it is:

Grrr source code

Like the rest of the stuff here, it’s released under the creative commons license.

So long, and thanks for all the fish.

Grrr 1.1 and Big Invaders

So I’ve been spending a bit of time getting to grips with Cmdlets and resurrecting interest in PSInvaders using Grrr and now have something to post.

Grrr 1.1 is now Cmdlet based and comes as a Snap-In. The most obvious benefit from this is performance, as I can now present a playable version of PowerShell Big Invaders.

BigInvaders 1.1 in play

BigInvaders is one of the demo PowerShell scripts that makes use of the Grrr.

Download this prerelease version 1.1 of the Grrr snap-in.

Update: this should now install on Vista – thanks to Chris Warwick for pointing out some issues

There’s no installer (yet) so to get going, follow this instructions:

Unzip the archive where you want to use it and CD to the top level director where the README file is.

Type: ./installgrrr.ps1 -r

The -r switch forces it to re-register the snap-in if a (possibly) older version exists. It then adds the snap-in to the current shell.

From here you can CD into the demos directory and run any of the scripts. Each one shows a feature of Grrr, but perhaps the most interesting is in the biginvaders directory.

To run BigInvaders, you need to have a very large console. To achieve this you probably need to set the font size of your console window to 6×8.

If you want sound, you need to install DirectX DirectSound. More on why later.

It should work without, silently, but this hasn’t had much testing as all my XP boxes have it installed :-) If there are exceptions, start it with the -nosound switch.

Assuming all is well, type ./biginvaders.ps1 and you should see this title screen:

BigInvaders 1.1 intro screen

Hit ESC to quit or Space to play. In play, Space fires a missile and arrow keys move left and right. Hit F to toggle FPS display in the top-righthand corner.

The target FPS is 33. I achieve this easily on my MacPro, and my wife’s Dell (a core 1 duo, 1.66ghz) also just manages.

There are still a few snags to iron out here and I want to add proper PowerShell help and an installer, but it is functional.

I’ve learned a lot about C#, PowerShell SDK and .NET these last weeks and will write about my findings over the next days. It’s not all been rosy.

I’ll also be writing about the features of Grrr, and where I want to go with it.

That’s it for now.

Grrr, Cmdlets and PSInvaders revival

Still not much happening here, again partly due to being busy with other things, and also the final arrival of my Wii.

Anyways, 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 20% cpu load doing this):

Big Invaders

I intend to redo the original PSInvaders using Grrr, with more authentic gameplay and original graphics.

The scrolling tilemap support is looking good, so games like Gauntlet, Scramble and Super Mario Brothers should be possible… all scripted in PowerShell.

So apologies for the low post volume recently and please do watch this space.

Space Invaders with sound!

After yesterday’s attempts to make noises, I added basic sound support to psinvaders.

On my setup, it seems that I can only play one sound at a time, so a new sound stops a previous, and it crackles, but that could be because of poor sound virtualisation in Parallels Desktop (yes, I do all my work on a Mac).

Download it here: psinvaders r94

Unpack the zipfile, then from the directory where psinvaders.ps1 is, type ./psinvaders.ps1

Enjoy!

Space Invaders

In a previous post I said that I always like to try to write space invaders in every language that I learn. Well, PowerShell in the standard Windows console window looked like a great candidate so I set about the task in my spare time. My colleagues Richy King, Nik Crabtree and Brian Long joined in the efforts and between us, after 37 revisions, we came up with something that was:

a) Silly
b) Inappropriate use of PowerShell
c) Quite a bit of fun.

Download it here: psinvaders r94 Update: this version now includes sound.

Unpack the zip file, then from the directory where psinvaders.ps1 is, type ./psinvaders.ps1. Enjoy!

Any future updates may appear on the downloads page.

Here are screen shots of the play screen and the score advance table.

How it works

All the drawing is based on drawing ‘sprites’ on the console screen. No back buffering takes place, so when a sprite is drawn, it erases itself from its most recent position, updates the x,y value, the draws itself in the new position.

The drawing itself is done using [Console]::Write. Since writing this we discovered the joys of BufferCells, and one of the reasons for taking this project no further.

Reading the key events proved to be quite simple: we just check if a key event is available, then consume all the event types, maintaining the down/up state for movement keys and just observing down events for firing and putting in new credits.

The game is quite playable, speed-wise, because very few sprites are moved in the inner loop: the base, one space invader, and any bombs and missiles. This means that:

a) The game moves at a reasonable pace.
b) The alien block gets quicker as more are killed
c) An alien bomb will overdraw an lower alien until next time.

The rest of it is fairly basic game loop logic.

What’s next?

I’m done with psinvaders now. I’ve started working on a better framework for doing back-buffered drawing of sprites, images, tiled backgrounds and lines/points.

Currently, it’s pure PowerShell and unusably slow, but I may start doing some C# or JScript inlining to speed it up. Thanks for Lee Holmes for that inspiration.

Or maybe I’ll just wait for the anticipated performance inprovements in PowerShell 1.1 ;-)