Sign in to follow this  
moussen15

Working on a Zatacka clone

Recommended Posts

Hello. I'm working on a clone of the old game Zatacka. If you don't know about it it is a game where each player gets to control a worm using two buttons (left and right of course) and the goal is to make all the other players die by colliding with something(the end-of-screen or a worm). I've managed to make the worms move as they should, but now I'm up to the task of collision detection which seems to be quite difficult. The problem is that collision detection is done by comparing pixel values of the underlying SDL_Surface to see if they differ from the background (that was the only method that seemed reasonable to me). This works except that, since each worm consists of a perpetual array of overlapping rectangles, the game will think that the worm has collided with itself each time it checks that overlapping part of the rectangle. I tried to fix that by storing each worm's old position so that I could tell the difference between "real" collisions and "overlapping collisions" which works most of the time, but sometimes the worm collides with a n-game-cycles-old rectangle instead of the one-cycle-old that I thought would be enough to check for. Does anybody see a simpler solution than to store WORM_TURN_ANGLE/COMPLETE_TURN positions? Thanks for your help :)

Share this post


Link to post
Share on other sites
YOu could keep a collision map, made of rectangles, and instead of checking pixel values, check for rectangle intersection.

Share this post


Link to post
Share on other sites
Yeah, what he said. Basically, you need to abstract your worms more. Right now, as far as your code is concerned, a work is basically just a color on the screen. What you should do instead is give each segment of the worm a position - which might or might not translate directly to a pixel coordinate - and then use these positions to check for collisions. In addition, you should only check the "head segment" of each worm for collisions - that way, you avoid the problem you just stated. Hope that helps.

Share this post


Link to post
Share on other sites
Thank you both for your help :) I stopped reading pixel data from my surfaces and instead saved each worm's position in a sort of collision map, like you suggested, and it worked wonderfully ;) if anyone is interested I used a binary tree for faster searches.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this