Navigation

    CreatiCode Scratch Forum

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • CreatiCode

    Multiplayer Network Games - Creating and Joining Games

    2D Blocks
    1
    1
    214
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • info-creaticode
      CreatiCode last edited by admin

      Introduction

       
      In multiplayer games, multiple users can play the same game together over the network. All players run the same project on their own computers. One player is the host who creates a new game, and the other players are the guests who join the game.

      A game server is provided by the CreatiCode platform, which helps to keep track of the games and the players in each game. The game server will also help relay messages between the players over the computer network.

      Multiplayer game programming is a very complex task. However, it has been greatly simplified by CreatiCode, so you can build most types of multiplayer games using a dozen blocks.

       
       

      Create a New Game as the Host

       

      To create a new game as the host, you can use the following block in the “multiplayer” extension:

      41229c9f-9b22-4593-9735-ab36273393f2-image.png

       
      It accepts the following inputs:

      1. Game Name: the host player needs to specify a unique name for the game, so that other players can easily find the game to join from a list of games

      2. Password: the host player can specify a password, which defaults to “123”, and other players will be required to provide this password to join this game. This allows the host to make sure only players he knows can join the game he creates.

      3. Display Name: the host player can specify a name for themselves that will be displayed in the game.

      4. Role: the host player can also specify a role for themselves. The role can be freely defined by the game creator, and its meaning should depend on the type of game. For example, for a 2-player chess game, the roles can be “black” and “white”. For a 2 vs 2 shooting game, the roles can be “red team” and “blue team”.

      5. Server: the host needs to specify a server to be used to run the game. The host should pick a server that is closest so that messages can be transferred quickly between the player computers and the game server.

      6. Capacity: the maximum number of players can play the game together. If this number is reached for a game, new players won’t be able to join that game.

      7. Game World Width and Height: The host can specify the width and height of the game world, and player sprites will not move outside this boundary. By default we can use the stage’s width and height, but if a game has a larger map, you can specify it here.

       
      Note that each host user can only host one game at any given time for a given project. So, if a user tries to create a second game using the same project, the first game will be destroyed.

      Also, if the game has been idle for at least 180 seconds (no messages sent from any player in the game), then it will be destroyed to release the server resource.

       
       

      List All Games

       

      To find out all the existing games created by the current project, we can use the following block:

      b86f9c0f-7382-4682-b569-2fb0032bf0fe-image.png

       

      The first input is the server specified when the game was created.

      The second input is the name of a table, which will store the information on the games currently running.

      For example, suppose 2 games have been created by 2 host players using the same project, you should see 2 games listed in the table like this:

      ca94fdaf-5ad0-4357-ad25-5f372de239f2-image.png

       
      Each row represents one game, including the display name and game name specified when the host creates the game, and also how many players are currently in the game (including the host).

       
       

      Join a Game

       

      To join a game created by another host player, we can use the following block:

      530874d2-6977-4b5c-aab6-f09b5b5f93c9-image.png

       
      It takes the following inputs:

      1. Game Name: The exact name of the game specified by the host.
      2. Host Name: The display name specified by the host.
      3. Server: The server where the game is running.
      4. Password: The exact password of the game specified by the host.
      5. Display Name: The display name of this player
      6. Role: The role of this player.

       
      Note that the game name and host name can both be read from the games table written by the “list multiplayer games” block above, so usually the program should allow the user to choose from a dropdown list instead of typing them manually.

      The password should be input by the user manually, and the host user should tell that to the user.

       
       

      List Players In a Game

       

      We can also find out which players are in a game, using the following block:

      51fda6e0-46ce-48a3-a12a-8bde0e7f5729-image.png

       
      It takes the following inputs:

      1. Game Name: The exact name of the game specified by the host.
      2. Host Name: The display name specified by the host.
      3. Server: The server where the game is running.
      4. Table: The table to store the list of players as a result.

      For example, when 2 players are in a game, the result table may look like this:

      42e50d72-2dbe-44be-b0dc-c187937ab344-image.png

       
       

      Check If Connected to Game

       

      After creating or joining a game, you can use the following boolean block to check if this computer/tab is properly connected to the game server:

      123f20a5-36cc-4854-98fb-967772282d06-image.png

       
      If for any reason this game is no longer running at the game server, or if this user’s computer is no longer connected to the game server via the Internet, this block will become false.

       
       

      Test Your Project with 2 Accounts

       

      To test a multiplayer project, you will need at least 2 user accounts. Here are the detailed steps:

      1. Log in to CreatiCode in your default browser tab. Create the multiplayer project, and share it. You can use the “share unlisted” option so that only you would see it, as only you have the URL of this project.

      2. Click the 3 dots on the top right of the browser (Chrome browser), and open a new browser window in the “incognito” mode:

      494c41e3-20f3-43c1-90c8-c60e373a04df-image.png

      1. In the new browser window, log into CreatiCode using your second account.

      2. In the new browser window, open the shared project.

      After these steps, you can start testing the project. For example, one browser tab can be used as the host user, and the other as the guest user.

       
       

      Demo Project

       

      You can use the following project to test the 4 blocks explained above:

      https://play.creaticode.com/projects/6604937325dc753d5b676424

       
      Run the first stack of blocks in the first account, and then run the second stack of blocks in the second account. Observe the content of the tables for the games and players.

      ac4f59dd-4066-46ad-9fc2-22ed1ee1ec32-image.png

      1 Reply Last reply Reply Quote 0
      • First post
        Last post