diff --git a/client/public/assets/gfx/birds.png b/client/public/assets/gfx/birds.png new file mode 100755 index 0000000..8f58063 Binary files /dev/null and b/client/public/assets/gfx/birds.png differ diff --git a/client/src/App.js b/client/src/App.js index 5a02827..d5c0522 100755 --- a/client/src/App.js +++ b/client/src/App.js @@ -27,6 +27,7 @@ import { Trade } from "./Trade.js"; import { Winner } from "./Winner.js"; import { HouseRules } from "./HouseRules.js"; import { Dice } from "./Dice.js"; +import { Flock } from "./Bird.js"; import history from "./history.js"; import "./App.css"; @@ -332,6 +333,7 @@ const Table = () => { return { /* */ }
+
{ dice && dice.length &&
diff --git a/client/src/Bird.css b/client/src/Bird.css new file mode 100644 index 0000000..6d5de8d --- /dev/null +++ b/client/src/Bird.css @@ -0,0 +1,16 @@ +.Flock { + z-index: 50; + position: relative; + top: 5rem; + left: 10rem; + width: 20rem; + height: 20rem; + border: 1px solid purple; +} + +.Bird { + z-index: 50; /* Above Tile (5,10), Road (12), Corner (20) */ + position: absolute; + background-size: 1200% auto; + background-repeat: no-repeat; +} \ No newline at end of file diff --git a/client/src/Bird.js b/client/src/Bird.js new file mode 100644 index 0000000..f281e8c --- /dev/null +++ b/client/src/Bird.js @@ -0,0 +1,105 @@ +import React, { useEffect, useState, useCallback } from "react"; +import { assetsPath } from "./Common.js"; +import "./Bird.css"; + +const + birdAngles = 12, + birdAnimations = 4; +const frames = [0, 1, 2, 3, 3, 3, 2, 1, 0, 0, 0]; + +const useAnimationFrame = callback => { + // Use useRef for mutable variables that we want to persist + // without triggering a re-render on their change + const requestRef = React.useRef(); + + const animate = time => { + callback(time) + requestRef.current = requestAnimationFrame(animate); + } + + React.useEffect(() => { + requestRef.current = requestAnimationFrame(animate); + return () => cancelAnimationFrame(requestRef.current); + }, []); // Make sure the effect runs only once +} + +const Bird = ({ origin, radius, speed, angle, size, style }) => { + const [time, setTime] = useState(0); + const [rotation] = useState(Math.PI * 2 * radius / speed); + const [direction] = useState(Math.floor(birdAngles * (angle ? angle : 0) / 360.)); + const [cell, setCell] = useState(0); + + const previousTimeRef = React.useRef(); + + useAnimationFrame(time => { + if (previousTimeRef.current !== undefined) { + const deltaTime = time - previousTimeRef.current; + setTime(deltaTime); + } else { + previousTimeRef.current = time; + } + }); + + useEffect(() => { + const alpha = (time % speed) / speed; + const frame = Math.floor(frames.length * alpha); + console.log({ alpha, frame }); + setCell(frames[Math.floor(frame)]); + }, [time, setCell, speed]); + + return
; +}; + +const Flock = ({count}) => { + const [birds, setBirds] = useState([]); + useEffect(() => { + const tmp = []; + for (let i = 0; i < count; i++) { + tmp.push() + } + tmp.push(); + tmp.push(); + setBirds(tmp); + }, [count, setBirds]); + + return
{ birds }
; +}; + +export { Bird, Flock }; diff --git a/original/birds.png b/original/birds.png new file mode 100755 index 0000000..8f58063 Binary files /dev/null and b/original/birds.png differ diff --git a/original/birds.xcf b/original/birds.xcf new file mode 100755 index 0000000..c1979ce Binary files /dev/null and b/original/birds.xcf differ