Advertisement

Tactical Battle Engine Help....

Started by June 27, 2003 06:09 PM
11 comments, last by MasterDario 21 years, 6 months ago
Hi everyone, im currently creating a tactical battle engine game in a very simple scripting/programming tool known as RPGMaker2000. It is rather simple to use, so for that reason i have decided to use it for now. My question to you programming experts is the following: In terms of the enemies artificial intelligiance, in your knowledge of programming, how would i go about determining the distance of squares the hero is from the enemy, in terms of x and y coordinates so lets say this is the map: e represents enemy and p represents player, X represents all the possible squares on the map X X X X X X X X X p X X X X X X X X X X X X e X X X X X X X X X X X X X X X X X See, in this example this would be an 8 by 5 area, so how would i determine how far the player is from the enemy so that i can store it into a variable then i can easily tell the player to walk Variable X to the player then Variable Y. I know i might sound confusing lol but give me a break im still kind of new at programming . I appreciate any help given
n/a
Maybe i don''t understand the question. You have a normal old grid world and you just want to know how far the distance is? That''s not really a programming question, it''s just a math one.

Answer: pythagorean theorem (a^2 + b^2 = c^2 where a and b = lenths of a side of a triangle; on your map, draw a vertical line down from p and a line left from e; you want the 3rd line of the triangle, which is the line from p to e)

In your example, you''re at 1,1 and your enemy is at 7,3. So Xs=1 and 7 and Ys=1 and 3. 7-1=6 for X. 3-1=2 for Y. 6*6=36 + 2*2=4 for a total of 40. What''s the square root of that? The calculator claims it''s 6.3

Was that the answer you were looking for?

-baylor
Advertisement
not quite, im need some kind of a math formula to figure out the distance in squares that the player is from the enemy so that when its the enemies turn, he can move to the hero knowing exactly where he is.

Ex: Lets say the player is 1 grid north and 3 grids west of the enemy. That means in order for the enemy to get to the player, he would have to go south 1 then 3 east to be on the same exact spot as the hero. How would i determine the distance between them.
n/a
quote:
Original post by baylor
Maybe i don't understand the question. You have a normal old grid world and you just want to know how far the distance is? That's not really a programming question, it's just a math one.

Answer: pythagorean theorem (a^2 + b^2 = c^2 where a and b = lenths of a side of a triangle; on your map, draw a vertical line down from p and a line left from e; you want the 3rd line of the triangle, which is the line from p to e)

In your example, you're at 1,1 and your enemy is at 7,3. So Xs=1 and 7 and Ys=1 and 3. 7-1=6 for X. 3-1=2 for Y. 6*6=36 + 2*2=4 for a total of 40. What's the square root of that? The calculator claims it's 6.3

Was that the answer you were looking for?

-baylor


I think that's what the OP wanted, but it's not good for a tactical grid based game. Assuming you find the distance, what do you do with it exactly? The unit can't just follow that diagonal, because there is no guarantee that there will be a grid space at the end of it. Instead of determining "real distance" it would be better IMO to make your measurements in terms of "grid squares".

Looks like a good time to use an implemetation of the A* pathfinding algorithm (though I have never used it myself) Google it, or try a search on this forum. From what I understand, it assigns values to each grid square, and it chooses the least "expensive" path from the start to the destination.

EDIT: From your second response, I still think the other person gave you what (I though) you wanted. Alternatively, you could determine the difference in squares between the enemy and the player, and measure it that way.

In the above example... the enemy is on a square (7, 3) while the player is at (2,2). If you take the difference of these.... (2-7),(2-3) = (-5, -1). This tells you that the player is 5 to the left, 1 above the enemy's position.

[edited by - Peon on June 27, 2003 8:41:41 PM]
Peon
.

[edited by - ggoodwin37 on June 27, 2003 8:38:38 PM]
hmm i think i understand what your saying, so lets say that the map has an area of 10 by 10 pixels. Now lets assume that the player is on pixel (1,1) and that the enemy is on pixel (3,8). Now lets say its the enemies turn and he wants to move to the hero, all i would do is subtract the heros x position from the enemies x and same with y?

Also, another question i have is lets say theres two enemies on the map how would i prevent them from overlapping each other when moving

[edited by - MasterDario on June 27, 2003 8:51:07 PM]
n/a
Advertisement
To stop actors overlapping you will need to check the square each actor is moving into for obstacles each time they are to move. Something like:

if (pixel[posX][posY] = ENEMY) then do something else;
else enemy.move(posX, posY);

That''s C++ish/pseudoish, i don''t know what RPGMaker code looks like. Hope that helps.
Not sure if this is what you mean but you can find the distance between 2 points by finding the absolute value of the players x coordinate minus the objects x coordinate and just do the same with the y coords.

so
|X1 - X2|, |Y1 - Y2|
I don''t know if you can do this in RPG Maker.
quote:
Original post by MasterDario
My question to you programming experts is the following:

In terms of the enemies artificial intelligiance, in your knowledge of programming, how would i go about determining the distance of squares the hero is from the enemy, in terms of x and y coordinates so lets say this is the map: e represents enemy and p represents player, X represents all the possible squares on the map

X X X X X X X X
X p X X X X X X
X X X X X X e X
X X X X X X X X
X X X X X X X X

See, in this example this would be an 8 by 5 area, so how would i determine how far the player is from the enemy so that i can store it into a variable then i can easily tell the player to walk Variable X to the player then Variable Y.



Well, I don't know much about RPGMaker2000, but here's a pseudo-answer you can try:

Setting up the game:
create a mapunit(unit) for movement -> unit = .1
create a vector(ev, ev) for enemy velocity -> ev = 1

Move an enemy:
find an enemy coordinate(ex, ey) -> (ex, ey)
find a player coordinate(px, py) -> (px, py)
create a vector(epx, epy) from e to p -> (px-ex, py-ey)
find the distance(dist) between e & p -> sqrt(epx²+epy²)
normalise vector(epx, epy) -> (epx/dist , epy/dist)
transform vector(epx, epy) -> (epx*ev*unit, epy*ev*unit)
create new enemy coordinate(ex, ey) -> (ex+epx, ey+epy)

ReDraw map.


Ok, this might need a little explanation, but so does your question. If I understand you right, you want to be able to tell an enemy, player or other object to move towards some other object or point on your map. Well, the above scheme works just fine for that, and you can even change your objects' speed as well. NOTE: if RPGMaker2000 supports a structured element, I suggest using an object structure for everything in your map. Just find your coordinates for your two objects, and it's basically all math from there on.

Special notes:
All variables should have decimal points.

unit represents your smallest map unit length. Usually, in a tile-based game like yours, this length is smaller than that of one of your map squares, which has a length of 1. The smaller the value the finer the grid, and the more precision of movement you have.

ev is your enemy velocity. To change velocity, just change ev - (or the corresponding object velocity variable). If velocity=1, then object moves 1 map unit per fram (approx.)
NOTE: since we're not dealing with time at all here, this is all sort of half-assed. For your purposes, just think of the velocity as the number of units you want to move an object each time you move it.

That's about all I can help you with without any info on RPGMaker2000. Hope this helps some.


printf( char *MD.LeadG->GetSignature());


[edited by - MDLeadG on June 28, 2003 7:37:36 AM]
This is not an insult in any way. But you may wish to re-invest some time in learning algebra, and if possible calculus. Those are two of the greatest weapons you can have in game development. Rember too however, that these should simply be a starting point in your endeavors.

This topic is closed to new replies.

Advertisement