Christopher Pitt has continued his series on the SitePoint PHP blog showing the creation of a game combining PHP & React JS. In this latest part of the series he builds on part one and hows how to procedurally generated game terrain.
Last time, I began telling you the story of how I wanted to make a game. I described how I set up the async PHP server, the Laravel Mix build chain, the ReactJS front-end, and the Web Sockets connecting all this together. Now, let me tell you about what happened when I starting building the game mechanics with this mix of ReactJS, PHP, and Websockets…
He started with the idea of a simple "farm" in the game represented by a set of "patches" in the game (pixels, basically). He includes the code he use to create it and allow for new ones to be created on request (including both the PHP side and the React.js code). He then shows how to modify it to make each farm requested come in with a bit of randomness as far as what kind of terrain (dirt/grass/wheat) it came in with. The post wraps up with the code required to render the farm in the UI and style it based on what kind of terrain it contained.