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]