Timers and image switching - re: Kevin's Space Invaders

Hi there :slight_smile:
New to the forum and Java! It’s rather lovely on here so thought I would sign up.
I’ve spent a couple of weeks mulling over tutorials online and I even bought a SAM’s teach yourself java and think I’ve cracked the basics.
However I’ve started writing wee games now. After a couple of really simple projects I happened upon the Space Invaders tutorial and thought I’d play with that.
It went successfully, and i’ve since added a few weapons to the game, created a ‘boss character’ as well that takes 10 shots to kill with a specific weapon that can be acquired after shooting a passing alien/ufo style thing.
However. Despite this I have absolutely no idea how to implement a means of the aliens/boss shooting back.

I figured I needed to set up a timer, and then allow to randomly fire back based on a 1-100 random number allocated to each alien, and based on this timer.
No idea where to start though?
Could anyone point me in the right direction regarding this?

My other issue, is that when shooting at the aliens, I want the shots to change .gif files every alternate shot. So for example calling shot 1 a, and shot 2 b, then looping round from a to b as the rounds are fired in rapid succession. Anyone got a notion of how to do this?

I’m sure it is all very easy but I’m unaware of what statement I should be devising in order to do this.

Hope somebody can help! Thanks :slight_smile:

That’s certainly a reasonable way to do it. If you allocate the per-alien number randomly, then just have them fire when the timer reaches their number, that’ll let them fire in a pattern that the player can predict, which is actually a good thing for this sort of game (it adds to the “hypnotic” factor).

Just use separate textures. Or use different texture coords inside a single texture, which is a technique known as “texture atlasing”. How you keep track of which one to use, that’s basic programming: just store it anywhere that makes sense.

Thanks for the reply, that’s brilliant. I’ve googled texture atlasing for a bit of a walkthrough and that’s going to be rather helpful.
I couldn’t work out how to have each shot pic alternating textures as I wasn’t sure how the coding would work. But it’s good to know it is all rather logical.

Thought I’d share a link actually - in case somebody else is starting out and has a bit of trouble with this - found a wee tutorial that’s absolutely fantastic:

http://rbwhitaker.wikidot.com/texture-atlases-1

:slight_smile: