17
loading...
This website collects cookies to deliver better user experience
Create React App (CRA): This is a library that I have used previously for other games/projects, this is an easy starting point for a react project because we have all our environment configured, for example, we have webpack, hot reloading, service workers (via workbox) and other features ready to be used, for this type of project I think is the best way to learn React.
React Spring: Another library in my toolbox of favorite libraries, this library allows us to create animations, in my case I use this library for cubes movements, I like how we can use a hook to indicate movement, for this project I used useSpring hook, in this hook we can indicate the type of animation that we need, also we have an event (onRest) that indicates when the animation ends.
Nuka Carousel: This is a good library to manage carousels, I like the simplicity that this library has. I have used this library in the list of levels.
Reach Router: This is a library from the same developers of react-router, as the name implies it’s possible to set different routers/pages, in the case of the game we have five routes.
qrcode-decoder and qrcode.react: The first library helps to read the information of our QR code, with the second we can create the QR, in this QR we save our level (actually the information we save is the URL, as mentioned in the first part the level created in the editor is saved in the URL).
howler: Is an audio library. It defaults to Web Audio API and falls back to HTML5 Audio. This makes working with audio in JavaScript easy and reliable across all platforms.
react-keyboard-event-handler: A React component for handling keyboard events (keyup, keydown and keypress), it's only available in the desktop version.
sweetalert: A beautiful, responsive, customizable, accessible replacement for Javascript's popup boxes (alert, confirm and prompt).
share-api-polyfill: This is a polyfill for Web Share API which can also be used on the desktop, it is very useful because if the browser does not support the Web Share API, the user can still share the information without problems.
devDependencies
used were:Vercel: This package help to publish the game in the service with the same name, this service is very good, it’s simple to publish a project, I’m using this service for several years (even when the name of the service was now
)
Serve: Sometimes was necessary to test the game on real devices, in that case, I used this package to create an URL that I can use on my local (when I needed to share the URL with other people I used ngrok)
CodeSpaces This is a great tool, because this allows us to have a complete development environment in the cloud, I had the option to open the project on different devices through the browser or open it in VS code, this was very useful for me, because I had the option to develop the game on different computers (even on an iPad).
props
import "./styles.css";
import { SIZE_FLOOR } from "../../../utils/constants";
import PropTypes from "prop-types";
import React from "react";
import Variants from "./variants";
const Floor = React.memo(
({
style = {},
size = SIZE_FLOOR,
type = "",
animated = true,
shake = false,
up = false,
}) => (
<div
className={`floor-wrapper ${shake ? "shake" : ""} ${up ? "up" : ""}`}
style={{ ...style, width: size, height: size + 20 }}
>
{type && <Variants type={type} animated={animated} />}
<div className="floor-base" />
<div className="floor" />
</div>
)
);
Floor.propTypes = {
style: PropTypes.object,
size: PropTypes.number,
type: PropTypes.string,
animated: PropTypes.bool,
shake: PropTypes.bool,
up: PropTypes.bool,
};
export default Floor;
<Floor />
component, but also we can see the <Variants />
component.import { SUFIX_ARRIVAL_POINT } from "../../../../utils/constants";
import ArrivalPoint from "./arrivalPoint";
import Portal from "./portal";
import Switch from "./switch";
const Variants = (props) => {
let finalType = props.type || "";
const extendprops = {
...props,
};
if (props.type.includes(SUFIX_ARRIVAL_POINT)) {
finalType = SUFIX_ARRIVAL_POINT;
extendprops.color = props.type.split("-")[2] || "white";
}
const variants = {
switch: <Switch />,
"arrival-point": <ArrivalPoint {...extendprops} />,
portal: <Portal {...extendprops} />,
};
return variants[finalType] || null;
};
export default Variants;
import "./styles.css";
import { SIZE_FLOOR } from "../../../utils/constants";
import PropTypes from "prop-types";
import React from "react";
const Cube = React.memo(
({ style = {}, size = SIZE_FLOOR - 25, color = "", opacity = false }) => {
return (
<div
className={`cube ${color}${opacity ? " opacity" : ""}`}
style={{ ...style, width: size, height: size + 20 }}
/>
);
}
);
Cube.propTypes = {
style: PropTypes.object,
color: PropTypes.string,
opacity: PropTypes.bool,
size: PropTypes.number,
};
export default Cube;
37
means that it's necessary move the cube seven times to the position 3 (right-top)