Skip to content

Instantly share code, notes, and snippets.

@Romain-P
Created July 1, 2018 15:33
Show Gist options
  • Select an option

  • Save Romain-P/cf0bc738d336ca87a86cee46af3b09db to your computer and use it in GitHub Desktop.

Select an option

Save Romain-P/cf0bc738d336ca87a86cee46af3b09db to your computer and use it in GitHub Desktop.
typedef enum tile {
none = 0,
forward = 1,
right = 7,
backward = 5,
left = 3
} tile;
typedef enum dir {
dirtop = 1,
dirright = 2,
dirdown = 3,
dirleft = 4
} dir;
static int getBroadcastTile(player_t *emitter, player_t *receiver) {
tile d;
if (emitter->y > receiver->y)
d = backward;
else if (emitter->y < receiver->y)
d = forward;
else if (emitter->y == receiver->y) {
if (emitter->x > receiver->x)
d = right;
else if (emitter->x < receiver->x)
d = left;
else
d = none;
}
switch(d) {
case forward:
switch(receiver->orientation) {
case dirtop:
return forward;
case dirright:
return left;
case dirdown:
return backward;
case dirleft:
return right;
}
break;
case backward:
switch(receiver->orientation) {
case dirtop:
return backward;
case dirright:
return right;
case dirdown:
return forward;
case dirleft:
return left;
}
break;
case left:
switch(receiver->orientation) {
case dirtop:
return left;
case dirright:
return backward;
case dirdown:
return right;
case dirleft:
return forward;
}
case right:
switch(receiver->orientation) {
case dirtop:
return right;
case dirright:
return forward;
case dirdown:
return left;
case dirleft:
return backward;
}
break;
case none:
return none;
}
return none;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment