Closed mspraggs closed 9 years ago
It could also be useful to have getNeighbour, which returns an enum denoting the position of the coordinate (left, right, above, below). If it's not one block away, then return a null value (also in the enum).
Example enum (forgot how to define, don't shun me):
enum NeighbourType {DIR_RIGHT, DIR_LEFT, DIR_UP, DIR_DOWN, DIR_NONE}
Could potentially have these as powers of 2 in case we want to use bitwise ops in some way later.
EDIT: If DIR_NONE = 0, then you'd have a nice proxy for determining if an Object is a neighbour:
if (obj.neighbourDirection(obj2)) {
...
}
Powers of 2 would definitely help with tiling. We could shorten that function considerably. Ideally we'd need the diagonal neighbors as well.
Currently:
up = 1 right = 2 down = 4 left = 8 top-right = 16 bottom-right = 32 bottom-left = 64 top-left = 128
If you could use those same values, I can avoid redoing all the index compression maths.
I'll have a shot at this at some point (unless someone else is doing it). I'll use the values given if it'll simplify things.
Would it be nicer to use compass points (e.g. North, North-East) instead? I think this is just my personal preference, but what say you all?
Not exactly intuitive, given the perspective is side-on...
Fair enough.
Would it be better to have up-right be (using the numbers above) 3, rather than 16? That way they can just be or'd.
Nope. Tiling needs to be able to combine corners with sides. Left, right and down shouldn't be the same as left-down and right.
Okay. I've pushed a version with a nextToDir() function that I believe works. I tested it by standing on various sides of the enemy, and it seemed to correctly determine which side I was on.
Is this done now?
In a way, yes. We have the nextToDir function, which does a similar thing.
We check the positions of stuff a lot, and having these functions will improve the readability of the code significantly. Perhaps there need to be two overloads: one for Object and one for Vector.
Addresses #6