-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
player waiting scene 레이아웃/스타일링 #137
Changes from 3 commits
02870a0
b80653f
ae19643
dea4c95
25266c5
cebb3d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -147,6 +147,60 @@ const GameObject = class { | |
this.animationFrame = requestAnimationFrame(animateFunction); | ||
} | ||
|
||
roll( | ||
x = 0, | ||
y = 0, | ||
duration = TIME.ONE_SECOND / 2, | ||
rollCount = 1, | ||
rollClockwise = Math.random() < 0.5, | ||
) { | ||
// TODO: move()와 겹치는 부분들 refactor... | ||
this.position = [x, y]; | ||
const xString = makeUnitString(x, '%'); | ||
const yString = makeUnitString(y, '%'); | ||
|
||
if (this.animationFrame) cancelAnimationFrame(this.animationFrame); | ||
if (!xString && !yString) { | ||
this.instance.style.removeProperty('top'); | ||
this.instance.style.removeProperty('left'); | ||
} | ||
if (duration === 0) { | ||
this.instance.style.top = yString; | ||
this.instance.style.left = xString; | ||
return; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오 이런 코드라면 위에서 하나씩 떨어지는거 말고 실제 게임처럼 각자 플레이어의 방향에서 카드가 날아오게 할 수도 있겠네요! 예를 들어 플레이어가 4명 있으면 상하좌우에서 하나씩 날아오는...? 갑자기 생각나서 이야기 해봤습니다! ㅋㅋ |
||
const initialY = makeFloat(this.instance.style.top) || 0; | ||
const initialX = makeFloat(this.instance.style.left) || 0; | ||
const targetY = y; | ||
const targetX = x; | ||
|
||
let start = null; | ||
const animateFunction = (timestamp) => { | ||
if (!start) start = timestamp; | ||
const elapsed = timestamp - start; | ||
if (elapsed > duration) { | ||
this.instance.style.top = yString; | ||
this.instance.style.left = xString; | ||
this.animationFrame = null; | ||
return; | ||
} | ||
const newY = initialY + (targetY - initialY) * (elapsed / duration); | ||
const newX = initialX + (targetX - initialX) * (elapsed / duration); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. newY newX 로직이 같아서 이것도 별도 함수로 빼면 좋겠군용 |
||
this.angle = rollClockwise | ||
? this.angle + rollCount * 4 * (elapsed / duration) | ||
: this.angle - rollCount * 4 * (elapsed / duration); | ||
ramram1048 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this.rotateStyle = makeUnitString(this.angle, 'deg'); | ||
|
||
this.instance.style.left = makeUnitString(newX, '%'); | ||
this.instance.style.top = makeUnitString(newY, '%'); | ||
this.instance.style.transform = `rotateZ(${this.rotateStyle}) ${this.originStyle}`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. y -> top / x -> left 이 관계가 있어서 이것도 뭔가 객체같은 걸로 빼면 편할 것 같아요!~ |
||
|
||
requestAnimationFrame(animateFunction); | ||
}; | ||
|
||
this.animationFrame = requestAnimationFrame(animateFunction); | ||
} | ||
|
||
rotate(angle = 0, duration = TIME.ONE_SECOND / 5) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TIME.TWO_HUNDREDS_MILI_SEC 는 넘 길까요 ㅋ.ㅋ 흠 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 애매하긴 하다.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 음 개인적으로는 1초를 가장 작은 단위로 두고 이걸 사용하는게 오히려 util로써 의미를 가지지 않을까 싶기도 하네요! 위의 코드에도 argument 기본값이 TIME.ONE_SECOND / 2 로 설정되어 있는데 TIME.FIVE_HUNDREDS_MILI_SEC 이렇게 하나하나 다 나누면 오히려 이상할 것 같기도 합니다! |
||
this.angle = angle; | ||
const angleString = makeUnitString(angle, 'deg'); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,56 @@ | ||
import rendePlayerWaiting from './render'; | ||
import './style.scss'; | ||
import CardObject from '@engine/CardObject'; | ||
import DuckObject from '@engine/DuckObject'; | ||
import { DUCK_TYPE } from '@utils/type'; | ||
import PlayerManager from '@utils/PlayerManager'; | ||
import { $id } from '@utils/dom'; | ||
import renderPlayerWaiting from './render'; | ||
import { moveMyDuck } from '../waitingRoom/events'; | ||
|
||
const createDuck = ({ | ||
color = '', | ||
x = 25 + Math.random() * 50, | ||
y = 25 + Math.random() * 50, | ||
} = {}) => { | ||
const duck = new DuckObject({ type: DUCK_TYPE.CURSOR }); | ||
duck.setColor(color); | ||
duck.createElement(); | ||
duck.setOriginCenter(); | ||
duck.move(x, y, 0); | ||
duck.setDepth(2); | ||
duck.attachToRoot(); | ||
return duck; | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오늘 말씀해주신것처럼 오리는 waitingRoom에서 한번 만든 뒤, 안 사용하는 화면에서는 숨기는 식으로 하면 될거같아요 |
||
|
||
const PlayerWaiting = class { | ||
constructor() { | ||
this.cards = []; | ||
this.ducks = new Map(); | ||
|
||
PlayerManager.forEach(({ socketID, ...duckData }) => { | ||
const duck = createDuck(duckData); | ||
this.ducks.set(socketID, duck); | ||
}); | ||
const myDuck = this.ducks.get(PlayerManager.currentPlayerID); | ||
myDuck.setDepth(3); | ||
this.duckMoveEvent = (e) => moveMyDuck(e, myDuck); | ||
$id('root').addEventListener('click', this.duckMoveEvent); | ||
this.dropNewCard(); | ||
} | ||
|
||
dropNewCard() { | ||
const newCard = new CardObject(); | ||
newCard.move(50, -50, 0); | ||
newCard.setWidth(150); | ||
newCard.angle = Math.random() * 360 - 180; | ||
newCard.roll(40 + Math.random() * 20, 65 + Math.random() * 20, 3000); | ||
newCard.attachToRoot(); | ||
|
||
this.cards = [...this.cards, newCard]; | ||
} | ||
|
||
render() { | ||
const { arrayToBeRemoved = [] } = rendePlayerWaiting(); | ||
const { arrayToBeRemoved } = renderPlayerWaiting(); | ||
this.arrayToBeRemoved = arrayToBeRemoved; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
@import '@utils/common'; | ||
|
||
.player-waiting-helper-text { | ||
position: absolute; | ||
z-index: $z-index-layouts; | ||
top: 30%; | ||
left: 50%; | ||
font-size: x-large; | ||
text-align: center; | ||
transform: translateX(-50%); | ||
white-space: nowrap; | ||
} | ||
ramram1048 marked this conversation as resolved.
Show resolved
Hide resolved
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아예 roll 메소드를 구현하셨군요! move와는 다르게 중간에 끊길 일이 없어서 CSS로도 충분하지 않았나 생각해봅니다
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
그렇네요 생각해보니...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Front-line-dev 시도해봤는데 transform rotateZ를 적용하는 과정에서 이유를 알 수 없게 의도치않은 동작이 나왔습니다. 예를들어 keyframe에 rotateZ(360deg)를 주면 카드가 1바퀴를 돌아야되는데 가만히 있는 동작을 보여주네요. transition을 이용하면 잘 되는데 animate()를 이용하면 안 되는게 저도 황당하네요. 일단은 보류하게 해주세요.