mspraggs / potentia

Southampton Game Jam 2015
0 stars 0 forks source link

Add isBelow, isAbove, isLeft, isRight functions to Object #53

Closed mspraggs closed 9 years ago

mspraggs commented 9 years ago

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

mspraggs commented 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).

mspraggs commented 9 years ago

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)) {
    ...
}
DivFord commented 9 years ago

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.

Fyll commented 9 years ago

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?

DivFord commented 9 years ago

Not exactly intuitive, given the perspective is side-on...

Fyll commented 9 years ago

Fair enough.

Fyll commented 9 years ago

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.

DivFord commented 9 years ago

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.

Fyll commented 9 years ago

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.

DivFord commented 9 years ago

Is this done now?

mspraggs commented 9 years ago

In a way, yes. We have the nextToDir function, which does a similar thing.