개인 과제로 인해 늦은 퇴실로 10월 4일인 지금 10월 1일 TIL을 작성한다.
그날은 Stage 이동을 구현했다.
import stageJson from './assets/stage.json' with { type: 'json' };
import itemJson from './assets/item.json' with { type: 'json' };
currentStage = this.stages[0];
targetStage = this.stages[this.currentStage.scorePerSecond];
update(deltaTime) {
this.score += deltaTime * 0.001 * this.currentStage.scorePerSecond;
// 1초당 scorePerSecond 만큼 점수 얻음
const currendScore = Math.floor(this.score);
//console.log('다음 스테이지 : ', this.targetStage.score, ', 현재 스테이지 : ', this.score);
if (this.targetStage) {
if (this.targetStage.score <= currendScore && this.stageChange) {
// 0 아닌 100 배수 단위 점수이면,
console.log('동작 유무 확인');
this.stageChange = false;
// 중복 실행 방지
stageTextView(this.currentStage.scorePerSecond - 1);
// 다음 스테이지 점수 배율
unLockItem(this.targetStage.id);
sendEvent(11, { currentStage: this.currentStage, targetStage: this.targetStage });
sendEvent(101, {
currentStageId: this.currentStage.id,
targetStageId: this.targetStage.id,
});
this.currentStage = this.targetStage;
this.targetStage = this.stages[this.currentStage.scorePerSecond];
}
}
// 100의 배수가 아니면 스테이지 이동 허용 가능 상태로 만든다.
if (currendScore % 100 !== 0 && !this.stageChange) this.stageChange = true;
}
먼저 JSON 파일을 {type : 'json"}으로 import 받고
현재 업데이트 문이 유니티와 같이 1초에 60프레임 동작하는 상황에서
JSON 에서 가져온 다음 스테이지인 targetStage.score로 다음 스코어를
와 현재 currnetScore(점수)를 비교해 조건에 충족할 경우
unLockItem으로 클라이언트의 다음 스테이지 언락을 해주고,
sendEvent로 서버에 클라이언트가 다음 스테이지로 넘어갈 수 있는지
검증 및 서버도 다음 스테이지로 클라이언트가 넘어간다는 사실을
알려줍니다.
그 후, 클라이언트 부분에서 그 다음 스테이지를 targetStage로
반복적으로 동작할 수 있게 만들었다.
'TIL' 카테고리의 다른 글
Jump And Run TIL (0) | 2024.10.07 |
---|---|
2024년 10월 4일 TIL (0) | 2024.10.05 |
2024년 9월 30 TIL (0) | 2024.10.01 |
2024년 9월 27일 TIL (0) | 2024.09.27 |
2024년 9월 26일 TIL (0) | 2024.09.26 |