ps1.soapyfrog.com

doing inappropriate things with powershell

Pages

  • About
  • Downloads
  • Archives

Search

Popular Posts

  • Grrr 1.1 and Big Invaders
  • Space Invaders
  • Convert images to text (ASCII art)
  • Cmdlet clashes
  • Console screen grabs in html

Recent Posts

  • Grrr source code, including Invaders
  • Google going down the pan
  • Cmdlet clashes
  • Grrr 1.1 and Big Invaders
  • Grrr, Cmdlets and PSInvaders revival

Categories

  • Announce (7)
  • Cmdlets (2)
  • Cool (16)
  • Grrr (6)
  • Hint (2)
  • Invaders (5)
  • Odd (2)
  • PowerShell (27)
  • Quiz (3)
  • Rant (7)
  • Uncategorized (1)
  • Utility (5)

Months

  • August 2007 (1)
  • April 2007 (1)
  • March 2007 (1)
  • February 2007 (3)
  • January 2007 (25)
  • December 2006 (1)

Bookmarks

  • Blogroll
    • $script Fanatics
    • blog.soapyfrog.com
    • Brian Long
    • Lee Holmes
    • Nik Crabtree
    • PowerShell-Scripting (French)
    • Richy Rich
    • The PowerShell Guy
    • Windows PowerShell
  • Links
    • Carbon-neutral web hosting!

Meta

  • Log in
  • Posts RSS
  • Comments RSS
  • Valid XHTML
  • Valid CSS
« PNG and Internet Explorer
Grrr! »
 

Space Invaders

02 Jan 2007 09:47 am// Cool, Invaders, PowerShell    

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 ;-)

Comments (8)

8 comments to “Space Invaders”

  1. On 17 Jan 2007 at 8:18 am, gaech.ToString() said:   

    Поиграем в PowerShell?…

    Для чего только не используют PowerShell. Это только подчеркивает мощность и уни…

  2. On 17 Jan 2007 at 8:38 pm, Bite my bytes said:   

    Space Invaders…

    Space Invaders…

  3. On 18 Jan 2007 at 8:46 am, subject: exchange said:   

    PowerShell Space Invaders…

    This one I got from Paul Flaherty’s blog (aka Flaphead). Someone had the bright idea of writing Space…

  4. On 18 Jan 2007 at 10:09 am, toolz & stuff said:   

    PowerShell Space Invaders…

    …

  5. On 22 Jan 2007 at 3:46 pm, Oops! « Space Invaders said:   

    [...] Anyways, a popular link is Space Invaders in PowerShell. [...]

  6. On 22 Feb 2007 at 5:09 pm, ps1.soapyfrog.com » Grrr 1.1 and Big Invaders said:   

    [...] images to text (ASCII art)Space InvadersMaking noisesWhat colour is yours?Console screen grabs in [...]

  7. On 05 Jul 2007 at 3:43 pm, Virtual machine copying with PowerShell » Just Add Code said:   

    [...] machine copying with PowerShell Believe it or not, PowerShell is more than just fun and games. You can even do productive things with it! A common scenario I run into is the need to create a [...]

  8. On 23 Jul 2007 at 1:17 pm, Paolo TheDrake Linking Blog said:   

    Divertimenti innocui per sistemisti…

    PowerShell Invaders!…

Copyright © 2006-2012 Adrian Milliner

Creative Commons License
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License.