Hello guys,

I am having problem with making tower def game.

I am having a class for Turret where it has

int damage = 65;
int x;
int y;

I am having problem with the function which is going to plant them on the map... Can you give me some ideas about it ?

Thanks in advanced :)

Recommended Answers

All 10 Replies

Hi,
Would you mind to do a big better explanation? From this one I have no clue what do you want.
Thx in advance.

Hello well i want to make function that allow to people to plant turrets on the map, so the players would kill the enemies!!

What are you using to create your Tower Defence Game?
As Mitja said Post more code showing where the problem is?

The game will be connected with php code which is going to be connected with MYSQL...

The other thing is that php send me the battle entrance /how many towers will be able the client to plant on the map how many from each type/ like

<root>
   <tower1>20</tower1>
   <tower2>2</tower2>
</root>

so I get those numbers and then i have to put them ANYWHERE on the map ...
But I dont have idea how to store their location and to make them to stay there.
Next thing is to make them to attack... But the problem now is how to "plant" them on the battle field...

Hope this is enough clear :?

yes but how to track them and how to store them?
How to drag them to the position i want ?

And what, I store the mouse's x,y coordinates ?

Mouse's x,y coordinates on the canvas. If it's a grid, then it's that much easier. Have you coded anything for this yet? Your question is very vague and it seems like you want someone to code the entire system for you. Can we see the code you have for the map so far? Can you simplify the problem? i.e.: something along the lines of "Here is a map I created and here is a doohickey that I created to place on it. How can I use my mouse to plant the doohickey where I want it?"

edit: Also, I'm not sure you're using the right tools for the job. Not sure where php would come into play, since, IIRC, it needs a page refresh to change the content. Unless the tower defense game is turn-based, you're going to need to look more toward HTML5 or (shudder) flash. Why are you using SQL queries?

I don't want anyone to do my code. Just to give me the idea and I will code it my self.

I just can not understand how to plant them yes this time i need a little example how would look like the code but not the entire code...

How it will look like the code for one Turret to put it on coordinates x=10 y=20 ?

I don't want anyone to do my code. Just to give me the idea and I will code it my self.

I just can not understand how to plant them yes this time i need a little example how would look like the code but not the entire code...

How it will look like the code for one Turret to put it on coordinates x=10 y=20 ?

class Turrent {
     private int _x_coordinate;
     private int _y_coordinate;

     public void Turret(int x, int y)
     {
          _x_coordinate = x;
          _y_coordinate = y;
     }
     public int get_x() { return _x_coordinate; }
     public int get_y() { return _y_coordinate; }
}

Your map class will create the turret object with coordinates x and y when the turret is placed. The map class will position the turrets on itself based on the return values of get_x() and get_y() (although really it should do that without having to call those member functions when the turret is placed.) Now it just looks like you need to create the map!

Here are a couple of links to some examples from Tower Defence creation tools.

http://www.flashgametuts.com/tutorials/as3/how-to-create-a-tower-defense-game-in-as3-part-2/
http://www.iphonegametutorials.com/2011/04/15/cocos2d-game-tutorial-how-to-build-a-tower-defense-game-for-the-iphone-part-2-placing-towers/

You need to do some research on the tools you are using to create your program.
Only then can you really find out how to do what you want.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.