I thought:Why don’t I make a game for you, that we can all play together, to celebrate this littlecommunity we built this year! You probably know this, but making a multiplayer game is a lot more work than a simple single-player one.
There are way more moving pieces that allneed to work together to make it work (show lego gears with names that need to spin)getting the info from all the different clients and trying to predict what they will do is quite the challenge.
So I though about an easier way to solve this problem: Why don’t I look for a service that already has servers and a way to interact with each other? I could use something like Twitch, You've probably heard of the legendary tale of twitch plays Pokemon, a twitch live stream event where everyone controlled the same character and together they had to complete the game! Everyone was spamming commands in the chat,hoping red would do as they said.
I wanted to do something more personal, butstill keep it online so anyone from all over the world on whatever device they’re oncould still join. Rather than everyone controlling the same character, I wanted to give everyone their own. You’ve seen the title: Discord is the perfect app for that, You can make bots that are programmed to do all kinds of things, including playinggames with you! With Discord, I can get the best of both worlds!:everyone can join, as long as you’re on the server and everyone gets to play fromtheir own perspective! So How do you make a game in discord, youneed a program that can send requests over the internet to the central discord server,this can be done with an Application Programming Interface, or API for short. There are Discord API’s available in justabout any language you can imagine, so I just closed my eyes and picked one:Python it is! I got started with a simple bot to get toknow the ropes and I after a couple of minutes, I already made an epic game:Ping, pong! Whenever you say ping, the bot responds withpong, and then, wait for it, you say ping back! (Show epic ping pong battle anime?) Oke, oke, I’ve got to come clear, that’snot actually a game, it’s just the connection test, but hey, now we know it works at least! I wanted to do a little more than just pingponging, I wanted to involve everyone! So, I thought It would be fun to make somesort of gambling game with a real wheel of fortune, but You know, gambling and kids don’treally mix well, but I liked the real world connection thingy, so I changed my plan todo something where people could change all kinds of things in my room! I set up an Arduino connection, just likehow I’ve been doing for all my other projects, just now in Python.and with the right commands, users could do all kinds of stuff, well, at least changethe color of my LED’s, that’s something alright,But you know…
this isn’t really a game, this is just a light show, It was a fun proofof concept, but If I wanted to involve a lot of people and still keep it personal, I hadto go a different route. Sometimes you’ve got to kill your darlings… Back to the drawing board! I really wanted to make a game where eachplayer could play their own character and battle or race against each other or something. For that 2 things are really important: gettinggood player input, and getting a clear output to make sure everyone knows what’s happeningand to get feedback from your actions. I looked back into the api, and I saw it wasreally easy to get player input in different ways.
Players could send messages, or add reactions,and the bot could then get a bunch of data, like who sent the message or reaction, andwhere it was posted, the biggest hurdle lies in the output, since bots are also discordusers, they are kind of limited to what they can show. You could send a bunch of text, emojis orin the extreme case an image or even a weblink. But I need way more than an image, or shouldI say, I need way more images, that come after each other… I needed a moving picture, or Video as thekids call it these days.
Too bad you can’t render 3D images witha discord bot, because I really wanted to make it 3D… or can you?? You’ve probably seen this coming from amile away, but why don’t I use the incredible Unity Game engine as the host for my bot?? Let’s go! You’re probably wondering why anyone inthere right mind would do this and how this would work,Well, Instead of letting everyone download a game (that would totally defeat the purposeof this little adventure), I just host a single instance of the game on my computer, get thereactions and messages from the discord server through the web. And display the outcome of the game on myscreen. I then just have share my screen in a livestreamso everyone can watch it! It’s kind of like google stadia or xboxone x cloud 360 series the First (or something like that) a.k.a. Gaming in the clouds, whereyou’re just sending button inputs to a server and that server renders your game and sendsthe image back to you. But now, it’s just one game, and like wayslower.. When I saw that Discord already had unityintegration for games, I thought I was good to go! Until I read what it actually does…, it’sjust to show your friend what you’re playing, I need a much deeper connection, to send webrequests to the discord server and back, aka 2 way integration. So, Unity uses the C# scripting language andlike I mentioned before, Discord has api wrappers in just about any language, the c# ones arecalled: discord.net, and DSharpPlus There is just one problem though… althoughUnity uses c# it doesn’t actually use .NET standard, it uses Mono, a multiplatform, opensource implementation from .Net. I have no idea what this all means, but basically:It has the advantages of being multiplatform, but not everything from the .NET standardactually works. so those magnificent frameworks aren’t actuallysupported in Unity…
Finding a framework that worked was quitethe search, I even went to the obscure second page of Google! I mean, it makes sense, who In there rightmind would use a game to host a bot, If you then sell that game, you would have millionsof simultaneous clients sending a whole bunch of messages as the same bot. Was this another stupid idea of mine? Did I not think this through? Should I just go back to the drawing boardagain or, just stop… NO! I Wasn’t giving up, if there is one thingI learned since the first time I got on the internet, it’s that you’re never the onlyone who has a problem, and there is always someone from the other side of the world thathas something useful! When I’m looking for obscure repo’s, andI find what I’m looking for I feel like Indiana jones when he finds treasure, includingthe giant trap at the end because there is always a tiny little problem that needs fixing. Luckily, I was able to find one, DiscordUnity!in this case, the trap was that it hadn’t been updated in over 2 years and they stoppeddeveloping it before it was fully finished (something about that it should be used andyou should use the unity integration instead.. but I knew that already, that ship has sailed),Thiswas perfect to get going! There were only a couple of features incomplete,but since my last video where I improved a” Wiimote to Unity” repo, I am now a masterof adding to obscure Unity Open source projects form years ago. So I got to work and floundered my way throughthe existing code, trying to keep it somewhat consistent(not without the occasional mentalbreakdown of course). I added the missing features that I stillneeded. And with the connection working again, thoughtof a first prototype, The easiest way to control a character with discord is with predetermined reactions, that means you can’t really do fast paced gameslike a racing game of a shooter because getting the reaction over the internet takes a while… So I thought about a turn-based strategy game with little robots, Let me explain:[building montage] So, You’re playing as this little robot right, and there are all these other little robots on the field, and of course, you wantto completely destroy them! And what better way to do that, than witha giant fist! Kaboom! Of course you have to move as well, and inthis game, it’s all about timing. Each movement takes exactly one second, onequarter turn, one attack or moving one tile. Each player gets two actions per round soyou’ll have to strategise to plan where you’ll want to be to hit. Will you be able to dodge in time, or be completelysurrounded by your enemies? There’s only one way to find out! To manage all this, I did a bunch of programming! The first thing I added was some sort of movementsystem to easily control multiple bots with simple commands. If I tell the bot to move up, it’ll go upone tile and if it’s not rotated correctly, then it will do that first! Now I can control a whole bunch of bots witha couple of commands, perfect for my secret robot army! Of course, I’m not the one who’s goingto be controlling all of this, you guys are. I set up one central controller to managethe connection with Discord, It could send messages, reactions and get notified whenthis things come in as well. That controller then sends the data to everythingon the playing field! Well, you can’t actually control a robot,if the bot doesn’t know which bot belongs to you? And right now, they all look the same, andthat’s a little boring… To enter the game, I set it up so you needto react to the starting message with one of the predetermined coloured emojis, thatway I can kill two birds with one stone. I know who’s playing, and what color theylike to be! To manage al the different actions a playercan do, I made a custom action class that has all the necessary information, includingwhat kind of emoji you need to react with, I made a list that contains all the differentoptions and when the game starts, the bot adds reaction for all the possible actionsto its message. all the options are pretty straight forward,there are a bunch of arrows pointing in all four dimensions and a big cross to make ahit! Each player gets 2 actions and can move orhit at either action. The way I achieved this is by sending 2 actionmessages each round where the bot reacts with all the specified actions from my list frombefore. To keep a little pace in the game I addeda timer for each round, I did this by continuously updating the action message with a timer. And once the time hits zero, the next roundstarts This makes sure I don’t have to to manuallyend each round, and a little timer keeps things interesting. The bot also sends a pinned message that containsthe current scoreboard and keeps track of who is alive as well. Because it’s pinned you can always keepan eye on it to pick your next target! Each player has 2 lives and each hit dealsone point of damage, for each hit you make you get one point, and you get an extra pointif you land a finishing blow. To make the game more appealing I added thelittle robot and some animations to make him come to life! And with all of that, it was time for the first testrun! It ws a lot of fun, but there were some nastybugs to squash. So I knew what I had to do before I couldshow it to the world. After I solved the bugs I added some morecool features, like power-ups that can give you double speed, damage and distance. I also added som obstacles like dangerousspikes and a conveyor belt that takes you along for a ride. To fit everyone on the screen, I made thegrid infinity expandable. I start with a very small grid where the firstplayers are added and once a certain amount of tiles are filled, the game board expandsand adds new rows and columns. There really is no limit to how many peoplecan play a once, the only limit is the screen resolution to see your robot big enough… So, after all of that It was finally timeto play with you guys! We gathered at my discord server and had loadsof fun! And of course, if you’re watching this video,chances are we’re playing right now, so check out my discord if you’re not joinedalready to play this game! See you there, but only after you liked andsubscribed, because the more people see this video, more people can join in on the fun! Bye!
إرسال تعليق