Compare commits
3 Commits
b182e4b749
...
5534451c1e
| Author | SHA1 | Date | |
|---|---|---|---|
| 5534451c1e | |||
| ee26161108 | |||
| 32e012ca55 |
@@ -4,7 +4,6 @@ import imposter from "/img/imposter.png";
|
|||||||
import style from "./style.module.css";
|
import style from "./style.module.css";
|
||||||
|
|
||||||
type Amogus = {
|
type Amogus = {
|
||||||
key: string;
|
|
||||||
isImposter: boolean;
|
isImposter: boolean;
|
||||||
posX: number;
|
posX: number;
|
||||||
posY: number;
|
posY: number;
|
||||||
@@ -12,11 +11,14 @@ type Amogus = {
|
|||||||
speedY: number;
|
speedY: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const amogusWidth = 70;
|
||||||
|
const amogusHeight = 70;
|
||||||
|
|
||||||
const { innerWidth: width, innerHeight: height } = window;
|
const { innerWidth: width, innerHeight: height } = window;
|
||||||
|
|
||||||
const getImage = (sus: Amogus) => (sus.isImposter ? imposter : amogus);
|
const getImage = (sus: Amogus) => (sus.isImposter ? imposter : amogus);
|
||||||
|
|
||||||
const makeInitialCrewmates: Amogus[] = () => {
|
const makeInitialCrewmates = (): Amogus[] => {
|
||||||
return [
|
return [
|
||||||
makeCrewmate(true),
|
makeCrewmate(true),
|
||||||
makeCrewmate(false),
|
makeCrewmate(false),
|
||||||
@@ -24,22 +26,26 @@ const makeInitialCrewmates: Amogus[] = () => {
|
|||||||
makeCrewmate(false),
|
makeCrewmate(false),
|
||||||
makeCrewmate(false),
|
makeCrewmate(false),
|
||||||
makeCrewmate(false),
|
makeCrewmate(false),
|
||||||
|
makeCrewmate(false),
|
||||||
|
makeCrewmate(false),
|
||||||
|
makeCrewmate(false),
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
const randNum: number = (min: number, max: number) =>
|
const randNum = (min: number, max: number): number =>
|
||||||
Math.random() * (max - min) + min;
|
Math.random() * (max - min) + min;
|
||||||
|
|
||||||
const makeCrewmate: Amogus = (imposter: boolean) => ({
|
const makeCrewmate = (imposter: boolean): Amogus => ({
|
||||||
isImposter: imposter,
|
isImposter: imposter,
|
||||||
posX: randNum(0, width - 90),
|
posX: randNum(0, width - amogusWidth),
|
||||||
posY: randNum(0, height - 120),
|
posY: randNum(0, height - amogusHeight),
|
||||||
speedX: Math.random() > 0.5 ? randNum(5, 15) : randNum(-5, -15),
|
speedX: Math.random() > 0.5 ? randNum(3, 10) : randNum(-3, -10),
|
||||||
speedY: Math.random() > 0.5 ? randNum(5, 15) : randNum(-5, -15),
|
speedY: Math.random() > 0.5 ? randNum(3, 10) : randNum(-3, -10),
|
||||||
});
|
});
|
||||||
|
|
||||||
const intersect: Bool = (c1: Crewmate, c2: Crewmate) =>
|
const intersect = (c1: Amogus, c2: Amogus): boolean =>
|
||||||
Math.abs(c1.posX - c2.posX) < 80 && Math.abs(c1.posY - c2.posY) < 90;
|
Math.abs(c1.posX - c2.posX) < amogusWidth - 20 &&
|
||||||
|
Math.abs(c1.posY - c2.posY) < amogusHeight - 20;
|
||||||
|
|
||||||
const doMove = (crewmates: Amogus[]) =>
|
const doMove = (crewmates: Amogus[]) =>
|
||||||
crewmates.map((c) => ({
|
crewmates.map((c) => ({
|
||||||
@@ -48,19 +54,43 @@ const doMove = (crewmates: Amogus[]) =>
|
|||||||
posY: c.posY + c.speedY,
|
posY: c.posY + c.speedY,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const doCollision = (crewmates: Amogus[]) =>
|
const doCollisionWalls = (crewmates: Amogus[]) =>
|
||||||
crewmates.map((c) => {
|
crewmates.map((c) => {
|
||||||
if (c.posX > width - 90) {
|
if (c.posX > width - amogusWidth) {
|
||||||
return { ...c, posX: width - 90, speedX: c.speedX * -1 };
|
return {
|
||||||
} else if (c.posX < 0) {
|
...c,
|
||||||
return { ...c, posX: 0, speedX: c.speedX * -1 };
|
posX: width - amogusWidth,
|
||||||
} else if (c.posY > height - 120) {
|
speedX: c.speedX * -1,
|
||||||
return { ...c, posY: height - 120, speedY: c.speedY * -1 };
|
};
|
||||||
} else if (c.posY < 0) {
|
} else if (c.posX < -20) {
|
||||||
return { ...c, posY: 0, speedY: c.speedY * -1 };
|
return { ...c, posX: -20, speedX: c.speedX * -1 };
|
||||||
|
} else if (c.posY > height - amogusHeight) {
|
||||||
|
return {
|
||||||
|
...c,
|
||||||
|
posY: height - amogusHeight,
|
||||||
|
speedY: c.speedY * -1,
|
||||||
|
};
|
||||||
|
} else if (c.posY < -20) {
|
||||||
|
return { ...c, posY: -20, speedY: c.speedY * -1 };
|
||||||
} else return c;
|
} else return c;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// TODO: This is ugly
|
||||||
|
const doCollisionOthers = (crewmates: Amogus[]) =>
|
||||||
|
crewmates.map((c) => {
|
||||||
|
const intersections = crewmates
|
||||||
|
.filter((o) => o !== c) // don't collide with yourself pls
|
||||||
|
.filter((o) => intersect(c, o));
|
||||||
|
|
||||||
|
if (intersections.some((o) => Math.abs(o.posX - c.posX) < 50)) {
|
||||||
|
return { ...c, speedX: c.speedX * -1 };
|
||||||
|
}
|
||||||
|
if (intersections.some((o) => Math.abs(o.posY - c.posY) < 50)) {
|
||||||
|
return { ...c, speedY: c.speedY * -1 };
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
});
|
||||||
|
|
||||||
const doKills = (crewmates: Amogus[]) => {
|
const doKills = (crewmates: Amogus[]) => {
|
||||||
const imposters = crewmates.filter((c) => c.isImposter);
|
const imposters = crewmates.filter((c) => c.isImposter);
|
||||||
const alive = crewmates
|
const alive = crewmates
|
||||||
@@ -88,7 +118,8 @@ export default function Amogus() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const timer = setInterval(() => {
|
const timer = setInterval(() => {
|
||||||
setCrewmates((c) => doMove(c));
|
setCrewmates((c) => doMove(c));
|
||||||
setCrewmates((c) => doCollision(c));
|
setCrewmates((c) => doCollisionWalls(c));
|
||||||
|
setCrewmates((c) => doCollisionOthers(c));
|
||||||
setCrewmates((c) => doKills(c));
|
setCrewmates((c) => doKills(c));
|
||||||
setCrewmates((c) => checkReset(c));
|
setCrewmates((c) => checkReset(c));
|
||||||
}, 50);
|
}, 50);
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
.container {
|
.container {
|
||||||
z-index: 100;
|
z-index: 100;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
scale: 50%;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,16 +60,9 @@ export default function Dashboard() {
|
|||||||
<Weather />
|
<Weather />
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<div
|
<Card icon="🍁" name="420">
|
||||||
className={classNames(
|
<FourTwenty />
|
||||||
style.bouncingWindow,
|
</Card>
|
||||||
style.hidden,
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<Card icon="🍁" name="420">
|
|
||||||
<FourTwenty />
|
|
||||||
</Card>
|
|
||||||
</div>
|
|
||||||
</CardRow>
|
</CardRow>
|
||||||
|
|
||||||
<Card icon="🔔" name="Terminal" active={true}>
|
<Card icon="🔔" name="Terminal" active={true}>
|
||||||
|
|||||||
@@ -25,30 +25,3 @@
|
|||||||
.night {
|
.night {
|
||||||
background-color: #2a3f55;
|
background-color: #2a3f55;
|
||||||
}
|
}
|
||||||
|
|
||||||
.amogus {
|
|
||||||
z-index: 100;
|
|
||||||
position: absolute;
|
|
||||||
scale: 60%;
|
|
||||||
animation:
|
|
||||||
x 10s linear infinite alternate,
|
|
||||||
y 7s linear infinite alternate;
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes x {
|
|
||||||
from {
|
|
||||||
left: 0;
|
|
||||||
}
|
|
||||||
to {
|
|
||||||
left: calc(100vw - 70px);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes y {
|
|
||||||
from {
|
|
||||||
top: 0;
|
|
||||||
}
|
|
||||||
to {
|
|
||||||
top: calc(100vh - 90px);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import react from "@vitejs/plugin-react-swc";
|
import react from "@vitejs/plugin-react-swc";
|
||||||
import { defineConfig } from "vite";
|
import { defineConfig } from "vite";
|
||||||
import mkcert from "vite-plugin-mkcert";
|
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [react(), mkcert()],
|
plugins: [react()],
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
"@": path.resolve(__dirname, "src"),
|
"@": path.resolve(__dirname, "src"),
|
||||||
|
|||||||
Reference in New Issue
Block a user