diff --git a/src/components/InputHandler.tsx b/src/components/InputHandler.tsx index 5292455..bf85a1a 100644 --- a/src/components/InputHandler.tsx +++ b/src/components/InputHandler.tsx @@ -21,6 +21,7 @@ import { camPosYAtom, camRotYAtom } from "./MainScene/CameraAtom"; import { starfieldPosYAtom } from "./Starfield/StarfieldAtom"; import { currentHUDAtom } from "./HUD/CurrentHUDAtom"; import { SpriteHuds } from "./HUD/HUDElement"; +import { orthoCamPosYAtom } from "./OrthoCamera/OrthoCameraAtom"; type KeyCodeAssociations = { [keyCode: number]: string; @@ -57,6 +58,8 @@ const InputHandler = () => { const setCamPosY = useSetRecoilState(camPosYAtom); const setCamRotY = useSetRecoilState(camRotYAtom); + const setOrthoCamPosY = useSetRecoilState(orthoCamPosYAtom); + const setLainPosY = useSetRecoilState(lainPosYAtom); const setStarfieldPosY = useSetRecoilState(starfieldPosYAtom); @@ -65,9 +68,10 @@ const InputHandler = () => { (val: number) => { setCamPosY((prev: number) => prev + val); setLainPosY((prev: number) => prev - val); - setStarfieldPosY((prev: number) => prev + val); + setStarfieldPosY((prev: number) => prev - val); + setOrthoCamPosY((prev: number) => prev - val); }, - [setCamPosY, setLainPosY, setStarfieldPosY] + [setCamPosY, setLainPosY, setStarfieldPosY, setOrthoCamPosY] ); const rotateCamera = useCallback( @@ -97,7 +101,7 @@ const InputHandler = () => { setLainMoveState(); setTimeout(() => { moveCamera(1.87); - }, 1300); + }, 1400); break; case "left": @@ -128,7 +132,7 @@ const InputHandler = () => { setLainMoveState(); }, (lain_animations as LainAnimations)[key]["duration"]); }, - [moveCamera, rotateCamera, setLainMoveState] + [moveCamera, rotateCamera, setLainMoveState, setLainMoving] ); const updateHUD = useCallback(() => { @@ -137,7 +141,6 @@ const InputHandler = () => { const moveDispatcher = useCallback( (move: string, key: string) => { - console.log(move[0]); switch (move[0]) { // do nothing / cant move case undefined: @@ -205,8 +208,6 @@ const InputHandler = () => { if (key && !lainMoving) { const move = getMove(currentSprite, key); - console.log(key); - moveDispatcher(move, key); } }, diff --git a/src/components/Lain/Lain.tsx b/src/components/Lain/Lain.tsx index 4384b7b..85574fc 100644 --- a/src/components/Lain/Lain.tsx +++ b/src/components/Lain/Lain.tsx @@ -1,16 +1,16 @@ -import { a, Interpolation, useSpring } from "@react-spring/three"; -import React, { Suspense, useState } from "react"; -import { useFrame, useLoader } from "react-three-fiber"; +import {a, useSpring} from "@react-spring/three"; +import React, {Suspense, useState} from "react"; +import {useFrame, useLoader} from "react-three-fiber"; import * as THREE from "three"; -import { PlainSingularAnimator } from "three-plain-animator/lib/plain-singular-animator"; +import {PlainSingularAnimator} from "three-plain-animator/lib/plain-singular-animator"; import moveDownSpriteSheet from "../../static/sprites/jump_down.png"; import moveUpSpriteSheet from "../../static/sprites/jump_up.png"; import moveLeftSpriteSheet from "../../static/sprites/move_left.png"; import moveRightSpriteSheet from "../../static/sprites/move_right.png"; import standingSpriteSheet from "../../static/sprites/standing.png"; import introSpriteSheet from "../../static/sprites/intro.png"; -import { useRecoilValue } from "recoil"; -import { lainMoveStateAtom, lainMovingAtom, lainPosYAtom } from "./LainAtom"; +import {useRecoilValue} from "recoil"; +import {lainMoveStateAtom, lainMovingAtom, lainPosYAtom} from "./LainAtom"; type LainConstructorProps = { sprite: string; diff --git a/src/components/Lights.tsx b/src/components/Lights.tsx index 23d3f10..6ec42ee 100644 --- a/src/components/Lights.tsx +++ b/src/components/Lights.tsx @@ -1,9 +1,13 @@ import React, { memo } from "react"; -const Lights = memo(() => { +type LightProps = { + ambientLightVal: number; +}; + +const Lights = memo((props: LightProps) => { return ( <> - + diff --git a/src/components/MainScene/MainScene.tsx b/src/components/MainScene/MainScene.tsx index d6c4938..ea0593e 100644 --- a/src/components/MainScene/MainScene.tsx +++ b/src/components/MainScene/MainScene.tsx @@ -19,11 +19,12 @@ const MainScene = () => { const setLainMoveState = useSetRecoilState(lainMoveStateAtom); const [isIntro, setIsIntro] = useState(true); - const [mainStarfieldVisible, setMainStarfieldVisible] = useState(false); const camPosY = useRecoilValue(camPosYAtom); const camRotY = useRecoilValue(camRotYAtom); + const [ambientLightVal, setAmbientLightVal] = useState(0.4); + const cameraState = useSpring({ camPosY: camPosY, camRotY: camRotY, @@ -62,6 +63,7 @@ const MainScene = () => { setTimeout(() => { setIsIntro(false); + setAmbientLightVal(1.0); document.getElementsByTagName("canvas")[0].className = "hub-background"; }, 300); @@ -87,11 +89,8 @@ const MainScene = () => { - - + + diff --git a/src/components/OrthoCamera/OrthoCamera.tsx b/src/components/OrthoCamera/OrthoCamera.tsx index 8a30576..c4320dd 100644 --- a/src/components/OrthoCamera/OrthoCamera.tsx +++ b/src/components/OrthoCamera/OrthoCamera.tsx @@ -1,10 +1,11 @@ -import React, {useMemo, useRef} from "react"; -import {useFrame, useThree} from "react-three-fiber"; -import {Scene} from "three"; +import React, { useMemo, useRef } from "react"; +import { useFrame, useThree } from "react-three-fiber"; +import { Scene } from "three"; import HUDElement from "../HUD/HUDElement"; import Orb from "../Orb"; -import {useRecoilValue} from "recoil"; -import {orthoCamPosYAtom} from "./OrthoCameraAtom"; +import { useRecoilValue } from "recoil"; +import { orthoCamPosYAtom } from "./OrthoCameraAtom"; +import { useSpring, a } from "@react-spring/three"; interface OrthoCameraProps { orbVisibility: boolean; @@ -17,6 +18,11 @@ const OrthoCamera = (props: OrthoCameraProps) => { const virtualCam = useRef(); const orthoCameraPosY = useRecoilValue(orthoCamPosYAtom); + const orthoCameraState = useSpring({ + orthoCameraPosY: orthoCameraPosY, + config: { duration: 1200 }, + }); + useFrame(() => { gl.autoClear = false; gl.clear(); @@ -27,10 +33,14 @@ const OrthoCamera = (props: OrthoCameraProps) => { //-0.6 return ( - + - + ); }; diff --git a/src/components/Starfield/Starfield.tsx b/src/components/Starfield/Starfield.tsx index 9b93cc3..0be1ab1 100644 --- a/src/components/Starfield/Starfield.tsx +++ b/src/components/Starfield/Starfield.tsx @@ -1,17 +1,25 @@ import { a, Interpolation, useSpring } from "@react-spring/three"; -import React, {createRef, memo, RefObject, useEffect, useMemo, useRef} from "react"; +import React, { + createRef, + memo, + RefObject, + useEffect, + useMemo, + useRef, + useState, +} from "react"; import { useFrame } from "react-three-fiber"; import * as THREE from "three"; import { starfieldPosYAtom } from "./StarfieldAtom"; +import { useRecoilValue } from "recoil"; -type StarRefsAndIncrementors = [ +type StarRefsAndInitialPoses = [ React.MutableRefObject[]>, - number + number[][] ][]; type StarfieldProps = { introStarfieldVisible: boolean; - mainStarfieldVisible: boolean; }; type StarfieldObjectData = { @@ -35,22 +43,15 @@ type IntroStarfieldObjectData = { const Starfield = memo((props: StarfieldProps) => { const introStarfieldGroupRef = useRef(); + const [mainStarfieldVisible, setMainStarfieldVisible] = useState(false); + + const starfieldPosY = useRecoilValue(starfieldPosYAtom); + const starfieldState = useSpring({ - starfieldPosY: starfieldPosYAtom, + starfieldPosY: starfieldPosY, config: { duration: 1200 }, }); - const uniformConstructor = (col: string) => { - return { - color1: { - value: new THREE.Color("white"), - }, - color2: { - value: new THREE.Color(col), - }, - }; - }; - const vertexShader = ` varying vec2 vUv; @@ -80,6 +81,17 @@ const Starfield = memo((props: StarfieldProps) => { const lcgInstance = LCG(1664525, 1013904223, 2 ** 32, 2); + const uniformConstructor = (col: string) => { + return { + color1: { + value: new THREE.Color("white"), + }, + color2: { + value: new THREE.Color(col), + }, + }; + }; + const [blueUniforms, cyanUniforms, whiteUniforms] = [ "blue", "cyan", @@ -91,11 +103,12 @@ const Starfield = memo((props: StarfieldProps) => { posesBlueFromLeft, posesCyanFromRight, posesCyanFromLeft, + posesWhiteFromRight, posesWhiteFromLeft, - ] = [30, 30, 20, 20, 5].map((x) => + ] = [5, 5, 5, 5, 5, 5].map((x) => Array.from({ length: x }, () => [ lcgInstance() / 1000000000, - lcgInstance() / 1000000000, + lcgInstance() / 1000000000 - 1, lcgInstance() / 1000000000, ]) ); @@ -105,12 +118,14 @@ const Starfield = memo((props: StarfieldProps) => { blueFromLeftRef, cyanFromRightRef, cyanFromLeftRef, + whiteFromRightRef, whiteFromLeftRef, ] = [ posesBlueFromRight, posesBlueFromLeft, posesCyanFromRight, posesCyanFromLeft, + posesWhiteFromRight, posesWhiteFromLeft, ].map((poses) => useRef[]>( @@ -140,48 +155,54 @@ const Starfield = memo((props: StarfieldProps) => { ) ); - // these arrays contain refs to the 3d planes and the increment values that they should move with across - // the screen - const fromRightStarRefsAndIncrementors: StarRefsAndIncrementors = [ - [blueFromRightRef, 7.3], - [cyanFromRightRef, 4.3], + const fromRightStarRefsAndInitialPoses: StarRefsAndInitialPoses = [ + [blueFromRightRef, posesBlueFromRight], + [cyanFromRightRef, posesCyanFromRight], + [whiteFromRightRef, posesWhiteFromRight], ]; - const fromLeftStarRefsAndIncrementors: StarRefsAndIncrementors = [ - [blueFromLeftRef, 8.3], - [cyanFromLeftRef, 3.7], - [whiteFromLeftRef, 3.3], + const fromLeftStarRefsAndInitialPoses: StarRefsAndInitialPoses = [ + [blueFromLeftRef, posesBlueFromLeft], + [cyanFromLeftRef, posesCyanFromLeft], + [whiteFromLeftRef, posesWhiteFromLeft], ]; + const starSpeeds = Array.from( + { length: 60 }, + () => lcgInstance() / 100000000000 + ); + useFrame(() => { if (props.introStarfieldVisible) { introStarfieldGroupRef.current!.position.y += 0.2; } - if (props.mainStarfieldVisible) { + if (mainStarfieldVisible) { // planes (stars) coming from right move to positive X and negative Z direction - fromRightStarRefsAndIncrementors.forEach((el) => { - el[0].current.forEach((posRef: RefObject) => { - if (posRef.current!.position.x < -1) { - posRef.current!.position.x += el[1]; - posRef.current!.position.z -= el[1]; - } else { - posRef.current!.position.x -= 0.03; - posRef.current!.position.z += 0.03; + fromRightStarRefsAndInitialPoses.forEach((el) => { + el[0].current.forEach( + (posRef: RefObject, idx: number) => { + if (posRef.current!.position.x < -1) { + posRef.current!.position.x = el[1][idx][0] + 6; + posRef.current!.position.z = el[1][idx][2] - 2.5; + } + posRef.current!.position.x -= 0.03 + starSpeeds[idx]; + posRef.current!.position.z += 0.035; } - }); + ); }); - // the ones that are coming from left move to negative X and Z - fromLeftStarRefsAndIncrementors.forEach((el) => { - el[0].current.forEach((posRef: RefObject) => { - if (posRef.current!.position.x > 3) { - posRef.current!.position.x -= el[1]; - posRef.current!.position.z -= el[1]; - } else { - posRef.current!.position.x += 0.03; - posRef.current!.position.z += 0.03; + fromLeftStarRefsAndInitialPoses.forEach((el) => { + el[0].current.forEach( + (posRef: RefObject, idx: number) => { + if (posRef.current!.position.x > 3) { + posRef.current!.position.x = el[1][idx][0] - 9; + posRef.current!.position.z = el[1][idx][2] - 0.5; + } else { + posRef.current!.position.x += 0.03 + starSpeeds[idx]; + posRef.current!.position.z += 0.015; + } } - }); + ); }); } }); @@ -190,36 +211,43 @@ const Starfield = memo((props: StarfieldProps) => { { starPoses: posesBlueFromRight, ref: blueFromRightRef, - rotation: [1.7, 0, 0.9], - positionSpecifier: [0, 0, 0], + rotation: [1.7, 0, 1], + positionSpecifier: [6, 0, -2.5], uniform: blueUniforms, }, { starPoses: posesBlueFromLeft, ref: blueFromLeftRef, - rotation: [1.7, 0, -0.9], + rotation: [1.7, 0, -1.2], positionSpecifier: [-2.4, -0.5, 2], uniform: blueUniforms, }, { starPoses: posesCyanFromRight, ref: cyanFromRightRef, - rotation: [1.7, 0, 0.9], - positionSpecifier: [-1.3, 0, 1.5], + rotation: [1.7, 0, 1], + positionSpecifier: [6, 0, -2.5], uniform: cyanUniforms, }, { starPoses: posesCyanFromLeft, ref: cyanFromLeftRef, - rotation: [1.7, 0, -0.9], + rotation: [1.7, 0, -1.2], positionSpecifier: [-1.3, 0, 2.5], uniform: cyanUniforms, }, { starPoses: posesWhiteFromLeft, ref: whiteFromLeftRef, - rotation: [1.7, 0, -0.9], - positionSpecifier: [-1.3, 0.5, 1.5], + rotation: [1.7, 0, -1.2], + positionSpecifier: [-1.3, 0.5, 2.3], + uniform: whiteUniforms, + }, + { + starPoses: posesWhiteFromRight, + ref: whiteFromRightRef, + rotation: [1.7, 0, 1], + positionSpecifier: [-1.3, 0.5, -2.5], uniform: whiteUniforms, }, ]; @@ -243,8 +271,11 @@ const Starfield = memo((props: StarfieldProps) => { ]; useEffect(() => { - console.log('ssd') - }, []) + setTimeout(() => { + setMainStarfieldVisible(true); + console.log("123"); + }, 1800); + }, []); return ( <> @@ -264,7 +295,7 @@ const Starfield = memo((props: StarfieldProps) => { key={pos[0]} renderOrder={-1} > - + { {mainStarfieldObjects.map((obj: StarfieldObjectData) => obj.starPoses.map((pos: number[], idx: number) => { @@ -296,20 +327,18 @@ const Starfield = memo((props: StarfieldProps) => { pos[2] + obj.positionSpecifier[2], ]} rotation={obj.rotation as [number, number, number]} - scale={[0.01, 2, -0.5]} + scale={[0.01, 2, 0.01]} renderOrder={-1} key={pos[0]} > - + ); diff --git a/src/components/Starfield/StarfieldAtom.tsx b/src/components/Starfield/StarfieldAtom.tsx index c25af82..07c593f 100644 --- a/src/components/Starfield/StarfieldAtom.tsx +++ b/src/components/Starfield/StarfieldAtom.tsx @@ -2,6 +2,6 @@ import { atom } from "recoil"; export const starfieldPosYAtom = atom({ key: "starfieldPosYAtom", - default: 0, + default: -1, });