Home Games News Extras Contact

Zombie Shooter

This game never quite came to fruition.

I intended for this game to be a mix between tower-defense and a top-down shooter. The object of the game was to build a fortress and rescue survivors who could be used to build, defend, and perform other tasks. Different types of people were more skilled at certain tasks. Due to limited supplies and space, the player had to carefully choose which survivors to take in and which to let loose.

I hadn't finished the collision system for the player and zombies, but I did implement a bullet system which used raycasting to determine first all objects hit by a bullet, and then which object was the shortest distance from the starting point. I also used a very simple circle collision system to prevent the zombies from piling on top of one another, and I actually quite liked the mobbing effect that produced with larger amounts of zombies.

Maybe some day I'll continue work on this piece

Line-circle collisions

Line-circle collisions are surprisingly complex to figure out, but rely on fairly simple geometry.

First we need two points of a line segment (l), and the center and radius of a circle

We calculate the slope of the line using m = (y2-y1)/(x2-x1)

Now we will find what is called the collision normal (n). The collision normal is the line perpendicular to l and passing through the center of the circle. We find the slope of this using m2 = -1/m.

The key here is the fact that if a circle collides with a line, the intersection between the line and the collision normal will always be within the circle

So now we find the intersection between the line and collision normal. After a bit of algebra we find that nx (the x coordinate of the collision point) is found with nx = (m1x1-m2x1-y1+y2)/(m1-m2). The y position is found by inserting that value into the point-slope equation ny = m1(nx-x1)+y1.

Now that we have our collision point, we check it's distance from the center of the circle. If it is less than the radius of the circle, the line collides with the circle. But since this is a segment, we also check if the collision point is on the segment.

Finding precise collision points

If we want to know exactly where the circle collides with the segment, we need to use a bit of trigonometry. We find the rotation of the ray extending from the center of the circle to the normal, atan2(ny-cy,nx-cx) and add to that the measure of the angle from the collision normal to the line connecting the center of the circle to the collision points with the segment +/- acos(d/r).

From here we have the absolute angle, so we can find the points by using cx+cos(a), cy+sin(a), where a is the measure in radians of the absolute angle to the collision points.

Please note that these are methods I developed based on high school geometry and algebra knowledge, and that there are probably better ways to do this.

© 2013 aRobeGames