Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. document.addEventListener("keydown", (e) => {
  2. switch (e.key) {
  3. case "a":
  4. if (this.state.direction != "right") {
  5. this.setState({...this.state, nextDirection: "left"});
  6. }
  7. break;
  8. case "s":
  9. if (this.state.direction != "up") {
  10. this.setState({...this.state, nextDirection: "down"});
  11. }
  12. break;
  13. case "d":
  14. if (this.state.direction != "left") {
  15. this.setState({...this.state, nextDirection: "right"});
  16. }
  17. break;
  18. case "w":
  19. if (this.state.direction != "down") {
  20. this.setState({...this.state, nextDirection: "up"});
  21. }
  22. break;
  23. }
  24. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement