Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

2D All the way! / Space Invaders clone help

Author
Message
Cabe
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: Glasgow, Scotland
Posted: 16th Jan 2007 11:15
I'be been working on a simple space invaders clone however I'm having some problems getting my sprites to behave correctly. When they reach the side of the screen they are ment to drop slightly and start heading back in the other direction.
I've fiddled with the code and I either get them turning round and dropping but the last couple sprites overlap each other. Or I get don't get them turning around but they kinda slant off the screen.
I'd appretiate any help with this, I know its probably going to be something simple I've missed >_<

This is my code for moving the enemy sprites


This is the entire code
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 17th Jan 2007 10:09 Edited at: 17th Jan 2007 10:15
Since all the aliens move together in a block, you really only need to store 1 position and control the movement using an array.

waittime=waittime+1
if waittime=45

That's a bad way to control time, because it won't be equal among all computers. Since you count the variable based on game loops, my computer might loop through the code faster than yours. Use timer-based movement instead.

Try this code out:


By controlling the enemies movement based on a single variable, you ensure that they will never overlap. Of course, if you wanted aliens that flew around independently you'd have to change this. But let's stick with basics.

I commented each section of code, but let me know if you don't understand a part.


We also did a space invader challenge a few months ago in the DBP challenge thread. You can view all our entries here. (i think mine's the best)
http://www.dbp-site.com/challenges/space-invaders

Login to post a reply

Server time is: 2026-07-06 13:44:33
Your offset time is: 2026-07-06 13:44:33