Space Invaders Tutorial Game

Spent an hour tonight putting this together:

http://www.cokeandcode.com/spaceinvaders/si101.jnlp

Or for the web start fearing

http://www.cokeandcode.com/spaceinvaders/si101.jar

Obviously its not a full game but I was going to use it to write a tutorial and hoped I could solicit feedback on OS compatibility and whether it covers enough for the super beginner?

At the moment it should cover:

  • Accelerated Mode Graphics
  • Simple OO Concepts in relations to games
  • Game Loop
  • Input control
  • Timing
  • Game Logic / AI
    EDIT: * Brute force collision detection

All at very simple levels.

Comments welcome, tutorial should be out tomorrow assuming no-one mentions a reason not to.

Kev

EDIT2: Controls, cursors for left/right movement, space to shoot, ESC to quit.

[quote]Spent an hour tonight putting this together:

  • Input control
    [/quote]
    A bit screwed… Holding down left I often had the ship go what looked like “two steps left, one step right, 2 left, 1 right, …” etc. It moved left, but slowly, and kept shaking as though it had caffeine-withdrawal symptoms.

Sometimes I was faster than the aliens, sometimes slower, sometimes the same speed - and it seemed I sped up and slowed down randomly, even when I was merely moving across the screen and firing but not hitting anything.

Also, when the game restarted (I killed all the nasties) I hit space to restart but after the restart my ship would ONLY go left, no matter if I tapped keys, held down keys, etc.

There were some “interesting” layout patterns with the aliens too - some of them were slightly overlapping, as if they’d been jittered out of a regular grid ?

Apart from that, worked fine. 1.4.2_04 linux.

Nice idea, worked well for me on
Windows 2000
1.5b

Only complaint was I lost keyboard focus, and wasn’t able to get it back

Coo, that’ll teach me not to test all multi-platform before putting it out to the public ;D

Most of those problems “could” be explained by the lack of a high-res timer on windows (but of course you’re on linux so I’m baffled). As normal, its a “works perfectly” here case.

Time to boot up the linux box.

Kev

Version 2 uploaded, might resolve some issues. Heh, might cause some new ones :wink:

Kev

Nice :slight_smile:

Found two minior thingies:
-the bullet offset is slightly off (looks like you forgot the width of the bullet)

-and a slight input glitch (reproducable)

  1. shoot em all exept one
  2. move left or right (holding)
  3. shoot the last one
  4. release direction key
  5. press space to continue

Then your ship moves into that pressed direction until you press that key again (and thus triggering a release event)

Version 3, just uploaded. Should fixed the Onyx Bugs :wink:

Just commenting the source in preperation for writing the tutorial

Kev

Should fixed the Onyx Bugs :wink:

Affirmative! ;D

Something odd (poke poke)… if I don’t move there is autofire and if I move there isn’t autofire. Hm :slight_smile:

Ping! And as if by magic, version 4 appeared (which supported auto-fire when moving) :slight_smile:

Kev

And finally, heres the source, all perty:

http://www.cokeandcode.com/spaceinvaders/spaceinvaders.zip

I’ll write a tutorial around it if anyone wants, assuming I get up tomorrow.

Kev

Yes, write a tutorial. This is exactly the type of intro tutorial thats needed for java; j2d, bufferstrategies, input handling, oop for games, a game as an application etc…

You might add a fps counter so people can see the 100+ frames per sec this surely runs at —> help dispell that unfortunate lack of performance myth!

Good job!

Yep, works as it should. Good work Kevin :slight_smile:

And about the tut… it would be (could be) a nice idea to add some “homework” at the end, like adding a score counter, levels, lives, whatsoever. Just mention some things, wich the readers should try to implement by themselfes.

If you ever make a second part… eventually about mouse handling, slicing images and dunno. You could use these images, I did a year ago:

(Frame 1 is based on a scan from a very very very old [~60yrs+] medicine book and the following frames are just edits of the previous frame.)

(Kinda from vcop (::)) rescaled, bitmask, lots of cleanup on pixel level - really a major PITA. Took about 3 hours. Doh.)

Well, they look kinda nice and were alot of work… and I thought it would have been a waste if I just let em rot on my hdd :wink:

So…you’d be happy to see them used in a game ? :slight_smile:

And, once I’ve seen the tutorial, I might even feel it’s sufficiently easy to finally use it as a launch pad for a full example of adding NIO networking to a game, in a non-trivial way (unfortunately, I’m working throughout easter, and got ill over the weekend, so practially no free time for me to do such worthy things :frowning: ).

[still hoping to get around to finishing my NIO articles with full source to a networked multi-player tetris. But, right now, I’m so damned sick of NIO networking, having been nose-to-monitor in it for a week, that I don’t think I could face it right now :(]

PS: I saw some things this week that indicate Sun may have fixed the performance bug in gathering writes. More news when I have a final answer (or…someone could go through the old Networking topics, dig out my testcase for the performance bug, and check it on the current VM’s)

[quote]So…you’d be happy to see them used in a game ? :slight_smile:
[/quote]
I’m wondering if that is one of those indirect “then make a game goddamnit” invitations.

I know you want to get more submissions for that external games page. You’ll get one from me pretty soonish poke :slight_smile:

Was going to leave this one as homework task, so the reader gets a nice surprise :slight_smile:

Kev

Why, I hadn’t thought of that! Good idea…why don’t you? ;D

Actually, though, I was just thinking that the skull could work quite well in quite a lot of games, could be worked into a player-death animation. Although I haven’t seen it animated yet, of course.

Having spent the day getting my new pond set up :wink: I finally managed to secure a couple of hours this evening to type this up.

First draft of the tutorial is here:

http://www.cokeandcode.com/info/tut2d.html

Kev

EDIT: Apologies, its turned into a bit of an epic.

Suggestion: “pretty-print” the source into syntax-highlighted HTML. If your IDE doesn’t do this, there’s a JEdit plugin that does and I can export the sources for you.

Then post each .java file as an html page. This makes reading the source whilst reading the tutorial much easier for a lot of people (especially those without good IDE’s ;)).

;D

Hello - I am new to this forum

Thank you for producing such an excellent tutorial - I have been looking for just such a tutorial to explain the basics of coding 2D games using Java and this has given me everything I need to get started

Consider me to be a very, very happy bunny indeed