Last active
May 24, 2021 10:37
-
-
Save ynifamily3/8793ae5674bd06c20c01a42485b803d8 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const WAITING_X_POS = 100; // A+, F가 등장 전 대기하는 안 보이는 오른쪽 좌표 | |
const ACCELERATION = 0.1; | |
const JUMP_POWER = 10; | |
const GETTING_READY_TIME = 1000; | |
const FRUSTRATED_TIME = 1000; | |
const context = { | |
tick: 0, | |
score: 0, | |
gameSpeed: 1, | |
ppusyungYPos: 0, | |
aPlusXPos: WAITING_X_POS, | |
fXPos: WAITING_X_POS, | |
}; | |
const ppusyungMachine = Machine( | |
{ | |
id: "ppusyung", | |
initial: "title", | |
context, | |
states: { | |
title: { | |
on: { | |
START_GAME: "gettingReady", | |
}, | |
}, // 타이틀 스크린 | |
gettingReady: { | |
after: { | |
GETTING_READY_TIME: "playing", | |
}, | |
}, // 시작 전 딜레이 | |
playing: { | |
type: "parallel", | |
invoke: { | |
src: (ctx) => (cb) => { | |
const interval = setInterval(() => { | |
cb("TICK"); | |
}, 16); | |
return () => { | |
clearInterval(interval); | |
}; | |
}, | |
}, | |
states: { | |
ppusyung: { | |
id: "ppusyungCharacter", | |
initial: "walkLeft", | |
states: { | |
// ctx를 감시하여 부딪칠 경우 frustrated로 가게 한다. | |
walkLeft: { | |
on: { | |
JUMP: "jumping", | |
FRUSTRATE: "frustrated", | |
}, | |
after: { | |
STEP_SPEED: "walkRight", | |
}, | |
}, | |
walkRight: { | |
on: { | |
JUMP: "jumping", | |
FRUSTRATE: "frustrated", | |
}, | |
after: { | |
STEP_SPEED: "walkLeft", | |
}, | |
}, | |
jumping: { on: { FRUSTRATE: "frustrated", LAND: "walkLeft" } }, | |
frustrated: {}, | |
}, | |
}, | |
grasses: { | |
id: "grasses", | |
initial: "moving", | |
states: { | |
idle: {}, | |
moving: { | |
on: { STOP_GRASSES: "idle" }, | |
}, | |
}, | |
}, | |
cloudies: { | |
id: "cloudies", | |
initial: "moving", | |
states: { | |
idle: {}, | |
moving: { | |
on: { STOP_CLOUDIES: "idle" }, | |
}, | |
}, | |
}, | |
aPlusObject: {}, | |
fObject: {}, | |
clock: { | |
initial: "idle", | |
on: { | |
TICK: { | |
actions: ["increaseTick"], | |
}, | |
}, | |
states: { | |
ticking: {}, | |
idle: {}, | |
}, | |
}, | |
}, | |
}, // 움직이는 과정 (상호작용 가능, 부딪치는 장면 포함) | |
gameOver: {}, // 게임오버 스크린 | |
}, | |
}, | |
{ | |
delays: { | |
GETTING_READY_TIME, | |
STEP_SPEED: (ctx) => 500 / ctx.gameSpeed, | |
FRUSTRATED_TIME, | |
}, | |
actions: { | |
increaseTick: assign((ctx) => { | |
return { tick: ctx.tick + 1 }; | |
}), | |
increaseScore: assign((ctx) => { | |
return { score: ctx.score + 1 }; | |
}), | |
}, | |
} | |
); | |
// cond를 지속적으로 관찰하여 부딪칠 경우 뿌슝에게 HIT_F, grasses와 cloudies에게 STOP를 send한다. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment