Ricardo C
Senior HTF Member
- Joined
- Feb 14, 2002
- Messages
- 5,068
- Real Name
- Ricardo C
Game development related question:
Imagine a grid made up of 64-pixel wide squares. It's a 3D world, but z is always zero. The squares start at 0,0 and occupy only the +x/+y axes, no negative values are involved. There is a player standing on a random spot on the grid. I have a function that is in constant use by every square of the grid, in order to determine whether the player is on it or not. To do this, I'm using the following variables:
holder.x and holder.y, which will store the squares x and y coordinates.
my.x and my.y, which hold the square's coordinates
player.x and player.y, which hold the player's position
At the start of the function, I copy my.x and my.y's values to holder.x and holder.y. Then, I substract player.x from my.x and player.y from my.y. I compare the results with the original values stored in holder.x and holder.y. The formula I'm using is this:
if(my.x < holder.x)&&(my.x >= holderx-63)&&(my.y < holder.y)&&(my.y >= holder.y-63)
{
do stuff;
}
The idea is that if the above conditions are true, then the player is within the square's boundaries, and so the function may proceed.
The code compiles without errors, but the "stuff" isn't getting done, which makes me think I screwed up elsewhere in the code, but I wanted to ask as many people as possible to have a look at this, in case it's the formula that is wrong.
If anyone could help with this, I'd be most grateful. And I'll give you a free copy of the finished game
Imagine a grid made up of 64-pixel wide squares. It's a 3D world, but z is always zero. The squares start at 0,0 and occupy only the +x/+y axes, no negative values are involved. There is a player standing on a random spot on the grid. I have a function that is in constant use by every square of the grid, in order to determine whether the player is on it or not. To do this, I'm using the following variables:
holder.x and holder.y, which will store the squares x and y coordinates.
my.x and my.y, which hold the square's coordinates
player.x and player.y, which hold the player's position
At the start of the function, I copy my.x and my.y's values to holder.x and holder.y. Then, I substract player.x from my.x and player.y from my.y. I compare the results with the original values stored in holder.x and holder.y. The formula I'm using is this:
if(my.x < holder.x)&&(my.x >= holderx-63)&&(my.y < holder.y)&&(my.y >= holder.y-63)
{
do stuff;
}
The idea is that if the above conditions are true, then the player is within the square's boundaries, and so the function may proceed.
The code compiles without errors, but the "stuff" isn't getting done, which makes me think I screwed up elsewhere in the code, but I wanted to ask as many people as possible to have a look at this, in case it's the formula that is wrong.
If anyone could help with this, I'd be most grateful. And I'll give you a free copy of the finished game