Game Description

This multiplayer game supports multiple game lobbies of 4 players each. Collect power-ups, take cover behind walls, and eliminate your opponents to win!

Power-ups include:

Sending Data

The pickle module is used to convert objects into a byte stream that can be transmitted across the network, and then reconstruct the original objects from that byte stream at the receiving end.

Custom Protocol

Client Side Format

n.send(msg_type, msg_data)

player_id, p = n.getp() # Get player ID and initial player object from the server
n.send('PLAYER_READY', None)
n.send('PLAYER_DATA', p)
n.send('GET_PLAYERS', None)

if power_up_type == 'speed_boost':
    p.vel = 6 # Double the player's speed
    n.send('PLAYER_COLLECTED_POWER_UP', power_ups.index(power_up))
    pygame.time.set_timer(pygame.USEREVENT, 5000) # Set a timer for 5 seconds
elif power_up_type == 'med_pack':
    p.health = 100
elif power_up_type == 'shield':
    p.has_shield = True

Server Side

data = pickle.loads(conn.recv(2048))
msgtype, msg_data = data

if msgtype == 'PLAYER_DATA':
    players[game_id][player_id] = msg_data
elif msgtype == 'PLAYER_READY':
    reply = True
elif msgtype == 'GET_PLAYERS':
    reply = players[game_id]
elif msgtype == 'PLAYER_COLLECTED_POWER_UP':
    reply = check_win_condition(msg_data)

Multiple Game Lobbies

What Did I Learn?