MCPcopy
hub / github.com/statelyai/xstate / getGamObjectAtPos

Function getGamObjectAtPos

examples/snake-react/src/snakeMachine.ts:21–35  ·  view source on GitHub ↗
(
  context: SnakeMachineContext,
  p: Point
)

Source from the content-addressed store, hash-verified

19 | { type: 'body'; dir: Dir }
20 | { type: 'apple'; dir: undefined };
21export function getGamObjectAtPos(
22 context: SnakeMachineContext,
23 p: Point
24): GameObject | undefined {
25 let maybeBodyPart: BodyPart | undefined;
26 if (isSamePos(head(context.snake), p)) {
27 return { type: 'head', dir: context.dir };
28 } else if (isSamePos(context.apple, p)) {
29 return { type: 'apple', dir: undefined };
30 } else if ((maybeBodyPart = find(body(context.snake), p))) {
31 return { type: 'body', dir: maybeBodyPart.dir };
32 } else {
33 return undefined;
34 }
35}
36
37const oppositeDir: Record<Dir, Dir> = {
38 Up: 'Down',

Callers 1

AppFunction · 0.90

Calls 4

isSamePosFunction · 0.85
headFunction · 0.85
findFunction · 0.85
bodyFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…