A while back I posted about a tutorial series I wrote which showed you how to make a basic tower defence game; Well I decided to take things even further than that and complete the game for the android platform!
Introducing, Lane Defence!
A unique tower defence game in the style of the old Warcraft 3 Line Tower Wars map; you work to build a maze of towers which will stop the 40 waves of enemies from reaching the bottom of the lane!
This is how a tower defence is meant to play; No longer will enemies walk through each other like ghosts or conform to a set path, you are in control.
Create choke points to take full advantage of your splash towers, or encircle the high damage towers to get optimum attack time; the smarter your maze is, the easier the game will become.
You will be defending your lane against 5 types of enemy:
Normal - Nothing special.
Fast - Moves much faster than his friends.
Immune - Will not be slowed by any tower.
Air - Laughs at your mazes as he soars over them.
Boss - Lonesome, but very tough to kill.
To aid you, you will choose two unique 'speciality' towers from:
Ice - Slow's enemies.
Fire - Fast with average damage.
Tech - Very slow, but awesome against bosses.
Earth - Slow with a large splash damage.
Lightning - The bane of air enemies
Each have their strengths, but which combination will work best for you? Completing the game once is no easy feat, but can you beat it using all the combos?
All the tutorials (excluding Tutorial 1 and Tutorial 2) have accompanying source code. The blog also contains source code for a finished Tower Defence (albeit old and slightly different to the final project made using the tutorials). Hopefully you will find the tutorials helpful, and any feedback is welcomed (Good or Bad :P)
I am currently trying to add in collision detection / response between my player (represented by a sphere) and a platform (represented by a box).
I have got it almost working, as long as my platform does not move in any sort of downwards direction. However when my player is standing on a platform that moves down then my player starts jittering up an down and slides around on the platform slightly!
I think it could be to do with the fact that whenever my play lands on any surface he sinks in slightly then gets moved slightly to it's correct position.
Here is the code I am using to handle my collisions:
// velocity is players velocity
// platformV is the platforms velocity
if (sphere.Intersects(boxes[boxes.Count - 1])) // If player is on platform
velocity += platformV;
foreach (BoundingBox box in boxes) // Level collision boxes
if (box.Intersects(sphere)) // Sphere is player sphere
Vector3 closestPoint = box.ClosestPoint(sphere.Center);
Vector3 planeNormal = -Vector3.Normalize(sphere.Center - closestPoint);
float penetrationDepth = Math.Abs(sphere.Radius -
float velocityAlongNormal = Vector3.Dot(velocity, planeNormal);
float velocityCorrection = (penetrationDepth * 0.25f) + float.Epsilon;
if (velocityAlongNormal > -velocityCorrection)
velocity -= planeNormal * (velocityAlongNormal + velocityCorrection);
if (Math.Acos(Vector3.Dot(-planeNormal, Vector3.Up)) < 0.5)
isOnGround = true;
position += velocity;
Can anyone see a problem with this code?
I am really struggling to add in collision response to my collision routine in my XNA game, basically I want to add in a sliding response between my sphere and box. But I'm really not sure how to add this in. I'm guessing you would need to know the collision normal and distance and offset the position using these values. But how do I calculate the Collision Normal and the Collision Distance, the BoundingSphere.Inersects method only gives me a bool and a distance.
Can anyone give me any advice?