2d racing game barriers

Started by
1 comment, last by Westie007 15 years, 4 months ago
Hi everyone, I am making a 2d racing game from top view for a mobile device. I am stuck for 2 weeks on how to make good barriers. The best I got is an sorted array of coordinates of where the barrier should be (about 6000 items). And what I'll do is that I have for(i=0;i<6000;i++) { here I test position of a car wiv each barrier coordinate and then do some action like change car's speed and angle} I there any simplier way? Because it gets significantly slower if the racing map is bigger and the barriers are longer (about 10 000 items). and of course there will be opponents so I am afraid this is not good solution. it must also be very precise because the graphics are in high detail. thanks for any advice. if you don't understand my system, that's probably because it's crap. :)
Advertisement
hello,
i'm thinking of...
1. Make the sprites "collidable" i.e. those that act as barriers have that special property
2. Make a collision map (perhaps similar of what you're doing) but more like a map of 0's and 1's that represent your actual map of tiles, 0's are not collidable objects and 1's are.

cheers.
Create a grid system based on the car's position in the world. For example, every 5 units is one grid, then only perform your collision tests on barriers that are 'attached' to grids around the car's grid or within the car's grid, this will mean that the rest of the barriers are ignored as the car is not close to them.

You can then have pretty complex barrier collision if you wanted.

This topic is closed to new replies.

Advertisement