Within Range?
Displaying 1-9 of 9 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
rao_dao_zao

Been trying to create a bit of a battle system, Zelda-style...

I need to "kill" entities within a certain area; roughly one tile in front of my character.

However, I'm not quite sure how to do this; since you can't practically use exact X and Y coords. Is there some way using an IF that I can say "killx is within 10 of entity.x"?

Posted on 2005-12-13 14:36:50

CrazyAznGamer

YES.
From the manual:
"int entity.x[entity];
int entity.y[entity];"

"entity.x and entity.y: (read/write) The coordinates of the entity on the map. This is a pixel value from the top left corner of the map to the top left corner of the entity's hotspot. To get an x,y coord of the entity on the screen subtract xwin and ywin."

USE IT. =) I BELIEVE IN YOU.

EDIT:
Sorry, I don't think I answered your question correctly.

Anyways, if you have 2 entities: player and enemy

...
//check player is facing which direction
if(entity.face[player] == 1)
{
if(entity.y[player] - 10 < entity.y[enemy] &&
entity.y[player] > entity.y[enemy] &&
entity.x[player] - 5 < entity.x[enemy] + 5 &&
entity.x[player] + 5 > entity.x[enemy] - 5)
{
//DO STUFF
}
}
else if(entity.face[player] == 2)
//...and do all the other crap

Posted on 2005-12-13 17:47:52 (last edited on 2005-12-13 18:01:10)

Omni

There's also the good ole' mathematical distance formula.

You know,

distance = square_root( a^2 + b^2 )

Where A is the difference in X between the player and the target, and B is the difference in Y.

so a = player.x - enemy.x
b = player.y - enemy.y.

And if the resulting distance is less than ten or whatever, we deal some damage.

Posted on 2005-12-13 20:31:38

resident

I did a rather brute force method of checking that sort of thing for the weapons in 100 zombies.

But Omni's looks like the better option. I wish I'd known about it then :)

Posted on 2005-12-13 21:24:49

CrazyAznGamer

Quote:
Originally posted by Omni

There's also the good ole' mathematical distance formula.

You know,

distance = square_root( a^2 + b^2 )

Where A is the difference in X between the player and the target, and B is the difference in Y.

so a = player.x - enemy.x
b = player.y - enemy.y.

And if the resulting distance is less than ten or whatever, we deal some damage.


Though keep in mind you'll still need to check where the character is facing and where the location of the enemy is to that.
But Omni, God, why didn't I think of it? It's positively brilliant.

Posted on 2005-12-13 22:00:35

Omni

Any day that Omni == Smart is a good day for me.

Posted on 2005-12-13 22:18:06

Kildorf

I'll just add to Omni's thingy:

sqrt() is actually a less-than-fast function. If you're only doing it occasionally then it's not a big deal, but if you're going to do it every single frame, you could probably find better things for those CPU cycles to do.

So, you should just square the distance your checking. In other words:
// Don't use
if(sqrt( (a*a) + (b*b) ) < 10) {
// Use
if((a*a) + (b*b) < 100) {


It'll be faster. You might want to use a weapon_length variable of some kind if you intend to allow different weapon lengths. In this case, just set weapon_length_sq = weapon_length * weapon_length when you switch the weapon, and check against that.

Pre-computation is where it's at! :D

Posted on 2005-12-14 05:50:57

rao_dao_zao

Mmm, horrible maths. Didn't even think of that. Thanks guys, I'll take a wee look at all that and see what I can do.

Posted on 2005-12-14 10:33:58

pthaloearth

I'm doing something similar:

first i check if attack is possible, then I play the attack animation if it was. Next I do a simple rectangle collision check in the direction the player is facing and in front for the weapons total reach (wont work for thinks that shoot projectiles as it's checking the entire area at once) next I deduct the HP (if any). Finally check for kills and play animations as nessary and move the entites out.

collision detection is pretty simple with rectangles just do a quick google on it and you should find sufficient information.

Posted on 2005-12-17 01:16:56


Displaying 1-9 of 9 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.