How good is that? The only very tricky bit of this was getting these numbers. So all the other ones I could find fonts for, but I had to get the original sprite sheet, pull those numbers out. But then in CSS, CSS has support for sprite sheets, which I've completely forgotten. But where you can basically set a URL as a background image. So I did, like, each span has an eight, like, on numbers, one to nine, so that a screen reader can still read them, still very accessible. But then I give it a class of eight or four, and then you basically just set the background image, and then you give it a background position calculated over what number it is. So if it's eight, it moves along that amount, and you get the same things.
Now, I'm sure you're looking at all of those images going, Joe, I don't believe you. I don't think you've done any of those things. So let me have a look quickly at our little UI demo. Because the wonderful thing about doing everything in React is it means you can put them in Storybook. So you have, here's our little ATB gauge, oh, can I grab that? Yep, and you can make, ooh, look at that, going up and down. You can do, I can't see quite that a little bit. You can also get the number display that I talked about earlier. Let me zoom in a little bit for you, sorry. So we've got that there, and then we've got our command panel, which includes... Come on! For the people who just walked in, that would seem incredibly strange. So you also get your party status, where that's just a table rendering things. And then we can put that all together in a pretty good little UI here. So now you can tab in, hit Enter, and go and attack someone. There we go, we've done all of the UI. So if I close that...
Now we get to do the fun part. We want to make it interactive. This is React after all, we want to react to things. So we want to do this battle scene, and we've missed all of this lovely 3D stuff at the back. Now, before we get to the 3D bit, we need to run the game, in the same way that you're building any kind of interface, you need to have some sort of state, and we're React engineers, so we'll have a hook called UseBattleSystem, and you need to keep track of all the different elements and the attacks and all this stuff, so this is more complicated than just using a few use states. So we'll get a really big reducer that does all of this stuff. Trust me, it works. And basically the real trick here is, you take this big reducer, and we're going to create a game loop with it.
Comments