-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Shibi Suriya
committed
Sep 27, 2023
1 parent
db48d9e
commit 2c296a5
Showing
8 changed files
with
146 additions
and
47 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
# Classic Slither.io | ||
# Classic Slither.io (WIP) |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import React, { useState, useEffect } from "react"; | ||
|
||
const DIRECTION = { | ||
UP: "up", | ||
DOWN: "down", | ||
LEFT: "left", | ||
RIGHT: "right", | ||
}; | ||
|
||
function Test() { | ||
const up = () => { | ||
setCurrentDirection((prev) => DIRECTION.UP); | ||
}; | ||
|
||
const down = () => { | ||
setCurrentDirection((prev) => DIRECTION.DOWN); | ||
}; | ||
|
||
const right = () => { | ||
setCurrentDirection((prev) => DIRECTION.RIGHT); | ||
}; | ||
|
||
const left = () => { | ||
setCurrentDirection((prev) => DIRECTION.LEFT); | ||
}; | ||
|
||
const [currentDirection, setCurrentDirection] = useState(DIRECTION.RIGHT); | ||
|
||
useEffect(() => { | ||
document.addEventListener("keydown", (event) => { | ||
const key = event.key.toLowerCase(); | ||
if (["w", "arrowup"].includes(key)) { | ||
up(); | ||
} else if (["s", "arrowdown"].includes(key)) { | ||
down(); | ||
} else if (["a", "arrowleft"].includes(key)) { | ||
left(); | ||
} else if (["d", "arrowright"].includes(key)) { | ||
right(); | ||
} | ||
}); | ||
|
||
return () => { | ||
clearInterval(timer); | ||
}; | ||
}, []); | ||
return <div>{currentDirection}</div>; | ||
} | ||
|
||
export default Test; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
.grid { | ||
position: relative; | ||
border: 3px solid black; | ||
} | ||
|
||
:global(*) { | ||
|
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
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
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