(Multiplayer)Fighting on GameGo With Makecode Arcade

Originally posted on instructables: https://www.instructables.com/MultiplayerFighting-on-GameGo-With-Makecode-Arcade/

GameGo is a Microsoft Makecode compatible retro gaming portable console developed by TinkerGen STEM education. It is based on STM32F401RET6 ARM Cortex M4 chip and made for STEM educators or just people who like having fun creating retro video games.You can follow this tutorial and try the game in Makecode Arcade simulator and then run it on GameGo.

In the articles we published before we already tried our hand on making a platformer game and a Battle City Remake. This time I wanted to use Jacdac interface to connect two GameGo’s together and allow the players to fight for supremacy in a multiplayer fighter game. Unfortunately, I found out that block programming for Jacdac multiplayer is in beta stage as of now and has some bugs – it is still possible to make simpler games, but no luck for my fighting game. So, in this instructable I publish three version of the game(which I called “Cthulhu Combat” ðŸ™‚ )

– single player version with simple AI opponent

– multiplayer version to play in Arcade simulation

– multiplayer version with Jacdac(incomplete, will be updated later)

Supplies:

GameGo

Microsoft Makecode Arcade

Step 1: On Start and Round_setup Functions

I will describe coding single player game in details and then in next steps we discuss how to make it into 

a) simulator multiplayer 

b)Jacdac multiplayer.

We start with setting the tile map to dark dungeon and creating sprites for player and AI bot – both of them will belong to Player kind though. We set their y-axis acceleration to 600 – so they wouldn’t fly after jumping. We also initialize projectiles from bot and player before calling round_setup function. round_setup function takes care of new round preparation for us – the reason we make it a function is because there can be as many as 3 rounds in total in game and we want to avoid repeating the same code. In that function first we check if any of the players has 2 victories – if this condition evaluates as True, then it’s game over. If both players have less than two victories, we increment the round_num variable by one and place players on their starting spots, replenish their lives to 100 and declare the beginning of a new round.

Step 2: Game Flow

In this game the world itself is static and the game flow is tethered to players’ actions. In four blocks we define most of game rules, these blocks are: on up button pressed, on down button pressed, on A button pressed and on B button pressed. Let’s have a look at each of these blocks .

on up button pressed – double jump logic. If we pressed the jump button less than 3 times, then we set player vy velocity to – 140(moving upwards). Our player has vy acceleration set to 600, so once we jump, our velocity will be decreasing fast. Once it reaches 0 (not moving on vertical axis) we set jump_count to 0 again.

on down button pressed – ranged attack shield logic. If down button is pressed player changes his image to “shielded” and sets variable shielded to 1.

on button A pressed – fire a projectile. That one is pretty much self-explanatory.

on button B pressed – melee attack, similar to shield in implementation. 

We set images of players’ sprites and their shielded/attacking variables to 0 every 500 ms in on game update every .. ms block. We could have set independent timers for each action, but for sake of simplicity we’ll just use the main game update loop.

The win conditions here are pretty easy – when player life reaches 0, the other player has won the round, we then store number of wins by player in a variable. 

Finally, there are two blocks that control ranged attack damage and melee attack damage. In each one of them we check for sprite collision and if shielded/attacking variable for the attacking player is set to 0/1.

Step 3: Game 1: AI Opponent

In first game we will create a relatively simple AI opponent to be second player. Inside on game update every 200 ms we first do the distance check between player and AI – if it less than 20 we set our AI in melee mode by raising it’s melee attack chance to 30 and ranged attack chance to 30. If the distance is higher than 20 we set melee attack chance to zero(no pint in melee attack, since player is too far) and move chance to 70. After the variables for action chances have been set we go on executing these actions with the chances specified. If you try playing against this simple AI yourself, you’ll see that despite it’s behavior is very simple, winning against it is not easy – as often in case with computer controlled opponents it wins mostly because it can do more actions per second than a human player.

If you stuck while coding, you can download the full code in our GitHub repository for this project and open it in Makecode Arcade.

Step 4: Game 2: Simulator Multiplayer

The game variant for two players in simulation is very similar to single player version, except that we replace the AI behavior block with four on player 2 button pressed blocks – with content inside of these blocks mirroring the content of same blocks for player 1. Have a look at the screenshot to get better idea what changes do you need to make. Apart from that we also need to add move player 2 with buttons block in on start function and change the end screen for player two game over to WIN instead of LOSE.

Step 5: Game 3: Jacdac Multiplayer

I have found a community implementation of Jacdac multiplayer with Makecode arcade blocks in this forum thread 

https://forum.makecode.com/t/new-extension-real-mu…

I tested the example game there(Space Invaders) and found it to be working very well. Unfortunately, the game mechanics of Cthulhu Combat uses a lot of variables and it seems that the Real Multiplayer extensions doesn’t support syncing variables yet – so I got it to work, the two players actions are synced across devices, but the life could doesn’t drop on opponents device. Also there is something wrong with projectile mechanics, the projectiles don’t seem to disappear after hitting the wall, which causes the game to lose connection after about 10 projectiles have been fired. 

You can try the multiplayer by downloading the .png file from our GitHub repository to try it out – as soon as Jacdac block API matures, I will update this part of the article with working code.

Step 6: Let the Cthulhu Combat Begin!

There are still a lot of improvements that can be made to our simple fighting game – for example, you can add more complicated AI behavior or use extension to add button combos and/or animation sequences. Good luck and have fun while you programming your own games with GameGo and Makecode Arcade.

If you do make an improved version of the game, share it in the comments below! For more information on GameGo and other hardware for makers and STEM educators, visit our website https://tinkergen.com/.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s