Tag Info

Hot answers tagged

23

Wouldn't it be simpler to use a pathfinding algorithm to check whether the AI still has a clear route? Presumably you use one already to make the enemies navigate from the entrance to the exit, so just run it with the tower added, and if it fails then the tower isn't allowed.


19

In your path scoring just make it so passing through a tower costs the same as going through some big number of tiles. In general it will try to get around them, but if there isn't such a path the output will still be going through the least number of obstacles. You can tune the penalty so that sometimes they will just go through instead of going all the way ...


17

That depends: how do you want them to move? The unnatural option Define a preset path with a series of vertices and have the balloons follow the path strictly. A more natural option Make the balloons boids and implement crowd path following behaviour, which will have them follow the path (and not get too far from it) whilst avoiding collision with each ...


17

I needed to solve a similar problem: pathfinding on a large maze-like grid with constantly changing "costs" and barriers. The thing is, in tower defense game the number of entities that need to have the path solved for them is usually much larger than the number of nodes in the graph. A* is not the most appropriate algorithm for handling this, because ...


15

Approach: Higher simulation rate Your timing for your user interface should be decoupled from your actual game loop, as should your rendering. Say for example your world runs at 4x speed. Lets say that at your basic (1x) speed, your game runs 30 updates per second. You would then have something like the following, when in fast-forward mode: World logic ...


13

I'm assuming that TD is 'Tower Defence' I think A* is going somewhat overboard for this. At the start of the game, flood fill the game area from the exit points to create a movement map: |---------| |5|4|3|3|3| |5|4|3|2|2| ->5|4|3|2|1-> |5|4|3|2|2| |5|4|3|3|3| |---------| and movement is always towards a square with a lower value. When the ...


11

Your reasoning was perfect: use a vector to move from my position to my target. This is the purpose of a vector; you simply forgot the speed! Velocity is a vector: a speed and a direction. However, if you forget to normalize the difference vector and multiply it the bullet speed (a scalar), you are basically saying that if you are close to the target (the ...


11

Game Coding Complete describes an Update loop well. It's simply a while loop running in your main class that does the following (more or less): while( game.isRunning ) { GetInput(); Update( dt ); Render(); } You pass in a dt (delta time) depending on whether you want your game running at a fixed or variable frame rate. For a fixed frame rate, ...


11

When you don't have actual projectile physics, an entity would just damage another entity directly. The update algorithm which is called every game tick would, in pseudocode, look like this: for each object in the game if it has a target if the target is in range and weapon is ready to fire reduce the hit points of the target ...


10

I generally don't think in terms of a memory snapshot, but rather I just make a list of which values need to be saved between sessions and save those values into an external file. This depends of course on the needs of your specific game, but usually I simply save the state of the current level (ie. where all the enemies are, what their health is, etc.) and ...


9

As a general principle, the update of game logic should be decoupled from the update of the game's graphics -- that is, simulation of your gameplay, AI, unit movement, et cetera should not be tied to the speed at which the game is rendering. Usually the main game loop computes how much real time had elapsed since the last game update, and sends that delta ...


9

Basically, I'd say that during the "Loading" process the game tries to load and precompute all operations that cannot be done in runtime. For example, retrieving images (to be used as textures) for the hard drive is usually a slow process. On the "Loading" step these images can be copied to RAM memory, which is muuuuch faster access storage, enabling ...


8

You'll generally want to use A*, unless there's something importantly different you're looking for.


8

I suggest you read Linear algebra for game developers part 1 / part 2 over on Wolfire's blog. They explain linear algebra quite easily - there aren't algorithms, just vector math. I know you linked that tutorial, but if you haven't read part 2 yet, definitely read part 2 because it explains how this works. An overview of how it's done The basic process is ...


7

If the target is moving in a steady direction at a steady pace, and your bullet path is in a straight line at a steady pace, you can use a quadratic equation to predict the exact spot they will intersect and aim your tower's gun at that spot. Since it is a certainty that the bullet will hit it's mark, and you can calculate the exact time it will take from ...


6

You say random, but how much randomness do you want? Is it ok if the enemies pick a path that is 10 times as long as the shortest one? Is it ok if the enemies enter a dead end and have to backtrack? That is, random over what set of paths, and with which probability distribution? Assuming you want the enemies to prefer short paths, you could use A*, but ...


6

Well I did a quick search on unity forum and I found a great example Unity Drag an Object without seeing your code though, I am not 100% sure what you want.


6

The balance I don't think there are shortcuts to balancing the game, it takes time and experimentation to find the best settings. You can increase the level of difficulty differently depending on how good the player is. The game will correct the difficulty to match the player skill. For example, the more lives he has the faster it gets harder. But I don't ...


5

The route algorithm I used on my TD was backwards from normal A* pathing due to the number of entities I had in the game. Instead of routing from the goal to the bad guys, I routed from the goal to every empty square on the board. This doesn't take very long, you just keep iterating the board until you've found your "costs", and it provides good feedback ...


5

I recommend using A* for it's simplicity. You have a relatively small grid, and I presume monsters can only move in cardinal (up, down, left, right) directions. I have an implementation of A* working in Objective-C (C# should translate OK) on my developer's blog here. You can see the monsters currently interacting with a changing landscape on my first ...


5

I would represent Buff/Debuff effects with a single class like this: public class Buff { public BuffType BuffType; public float Value; //The bonus percentage, for example: -12.5 or 25 } enum BuffType { Speed, FireDamage, ColdDamage, Range //etc. } Each and every Tower and Creature instance has a property public List<Buff> CurrentBuffs; ...


4

I can't comment, but first profile in Flex, everything else is conjecture.


4

Pathfinding is fast, and on something the size of a normal tower defense game, you'll have no trouble running a full A* or Dijkstra pass whenever something changes. We're talking well under a millisecond for a full refresh. Any kind of adaptive pathfinding ends up horrifyingly complicated. Just do it the simple way, unless you're making the world's largest ...


4

You need a list of points and a list of balloons class Path { List<Vector2> Points; float[] Lengths; Vector2[] Directions; void Build() { Lengths = new float[Points.Count-1]; Directions = new float[Points.Count-1]; for (int i=0; i<Points.Count-1;i++) { Directions[i] = Points[i+1] - Points[i]; ...


4

I can't tell for sure without seeing more of the code, but what it sounds like is that something involving the later tower is setting the .slow of enemies it's not hitting back to false. I haven't really worked with actionscript, but I'd look into watching when that variable changes to false. If it's getting set to true but when the enemies movement ...


4

This answer is Unity3d specific. In Unity, most classes are serializable, this means you are able to stream complete Unity objects to disk. The follwing UnityScript-Code is a way to serialize an object, save it to disk an load it again (after loading you must cast the object): import System; import System.IO; import System.IO.Stream; import ...


4

There's a few options you have, since your question is fairly high level, I'll provide these high level suggestions: Create a grid in code, and overlay the image on it Using the color of your path, assign the grid spaces that match "path color" as walkable. Use A* to find a path from start to finish. There's some tweaking you can do with this one, ...


4

The problem with adaptive difficulty is that games live from problems the player "overcomes". If you analyze the strength of the player then that is very linear and predictable. Either it is too easy all the time or too hard. I would suggest the opposite: Instead of changing the wave difficulty depending on the player strength let the player adapt to the ...


4

Instead of having all adjacent squares as possible next waypoints, only include squares that do not lead back to the beginning and randomly pick from those. If you did this, it would be impossible to go backwards because going back is not an option. This is a directed graph problem with each waypoint as a vertex, and each path an edge. You just need to ...


4

A* will work, but for a Tower Defense game that has lots of enemies with the same goal and a relatively static geometry, it may actually be cheaper to just run Dijkstra's algorithm backwards from the goal, to find the shortest path tree from anywhere on the map to the goal, and cache the result until the geometry changes (i.e. a tower is built or destroyed). ...



Only top voted, non community-wiki answers of a minimum length are eligible