Open kiyonlin opened 5 years ago
@kiyonlin I noticed the bug too, tried your fix. The problem is now the speed of turning is much faster than the speed of going straight, and the game gets choppy
The problem with both is:-
combineLatest
- Next tick is not respecting keyevents resulting in multiple steps while making turns.
withLatestFrom
- Key events are getting lost between ticks.
So both combineLatest
and withLatestFrom
are not ideal for this. I think, we need some observable that resets the timer/interval on each key event so that the next tick is generated after N milliseconds of previous keyevent/tick.
PS:- Wrote an operator to achieve the required behaviour. Link
Suppose now that the snake is moving to the "right". I quickly press the "up" and "left" directions keys in the
speed
time. The direction$ will push the "up" and "left", but withLatestFrom only Taking "Left", "Up" will be ignored, causing the snake to immediately go to the "Left" and collide with itself.So both
ticks$
anddirection$
should make the snake moving.I think change
snake$
to be like this will resolve this bug: