跳转至

musicHallConcept.png

Game for Aberdeen Music Hall

This is an untradional game which aims to creating a playable and interactive experience to be displayed on a 4.5 metre LED screen which is located at Aberdeen Music Hall.

The game is played with two players. One player represents the external space in the screen and one player represents the internal space of the screen. The border line between the two parts of the space is the playing field for the players. At the start of the game, a number of hit points and a ball rolling along the junction line appear. When the ball coincides with a hit point, both players need to perform a hitting action. As the ball moves back to its original point, the player who has successfully struck more hit points is the winner of the round and the space he represents is expanded. When the space represented by one player is completely eroded away, he loses and the other player wins. The game is accessed by two players scanning a QR code in the screen and completing the act of hitting it by the button that appears on the phone.

(]QHYE{K}_SC8X@J9D3)V_N.png

Contribution

image-20230516181821787.png

Data Transformation

I built a small server using the System.Net.Sockets library, which includes simple methods to start the server service and respond to data sent from the client. As a visual representation, every time the client sends a message, the server makes a circle in the game scene grow larger. In another Unity project, I set up the client program using the NativeSocket plugin. I also placed a button in the game scene that, when clicked after establishing a successful connection with the server, sends a message to the server. After completing the development of both the server and client parts, I set the server's target platform as Windows and the client's target platform as WebGL. I used Unity's built-in WebGL debugging tool to run the client program for local testing on the same computer. I successfully observed that the client can send messages to the server, and the server responds accordingly in the game. This confirms the feasibility of this approach.

Website Built Up

I took the method that use the built-in IIS (Internet Information Service) in Windows to create a webpage on the computer. To access the webpage, the computer needed to be discoverable by other devices within the dedicated network and have the corresponding port open. Once the compiled client program was deployed on the webpage, users could open the application by entering the computer's IP address and the corresponding open port on their smartphone web browser. Afterward, when they clicked the button on their phone, the server on the computer successfully responded. The foundational network framework was thus established.

For multiplayer mode, I completed a series of tasks.

First, I limited the maximum number of client connections to 2 because our game has a PVP mode with two players competing equally. If a third person tries to join the game, they will be automatically disconnected and denied access until a slot becomes available.

Next, when a player joins the game, the client automatically assigns a player position to each connected ClientID. By performing binary operations, I set a two-bit binary number where the first bit represents Player 1 and the second bit represents Player 2. If a position has a connected player, the corresponding number becomes 1, indicating that the position is occupied. When a new player joins, they are automatically assigned to an unoccupied position with a number 0, prioritizing Player 1 and then Player 2. For example, "01" represents one player currently in the game, and they are Player 1. If another player joins, it becomes "11". When a player leaves, the corresponding position is automatically released. If Player 1 exits the game, the number becomes "10". If Player 2 remains in the game, they will continue as Player 2. This approach prevents frequent switching of Player 1 and Player 2 positions during a single game session, avoiding confusion. Moreover, if there is a need to expand the number of players in the future, it can be easily achieved by adding more bits, ensuring scalability.

Afterward, I implemented a timeout feature for automatic game exit. In the client program, in addition to the "Press" button for communicating with the server, I also added a "Quit" button for players to exit the game. However, to prevent players from forgetting to quit or leaving without successfully exiting the game, the server automatically disconnects players who have been idle for a certain period of time. The specific method involves assigning a timer to each client ID when they connect to the server. The timer starts counting from 0, and if the corresponding client performs a data-sending operation, the timer resets to zero. If the timer reaches the set time limit, the server kicks out the client associated with that timer. When a player exits the game, whether voluntarily or due to being kicked out by the server, the corresponding timer for that client is deleted.


最后更新: November 12, 2025 08:41:16