Skip to content

Privacy preferences

Choose whether this site may use optional analytics. You can change this at any time from Privacy preferences at the bottom of every page.

Necessary

Always on

Remembers your privacy choice in this browser’s local storage, so the site can respect it. The choice stays on your device and is never sent anywhere. Analytics is not part of this.

Google Analytics 4: page views and clicks on project and contact links, so I can see how the portfolio is used. It sets Google Analytics cookies on this site. Off unless you turn it on.

Work3D Asteroid Multiplayer

01Course project, Uppsala University, 2026

3D Asteroid Multiplayer

A two-player Asteroids duel in a 3D arena. Play a friend on the same network, or play the computer.

My part
The game itself: gameplay, the HUD, menus and lobby, the bot, and the game’s side of multiplayer
Team
Two. Marius-Raul Filipiuc built the networking layer and the relay
Play
1v1 on a local network, or against a bot
Built with
C++ · SDL2 · OpenGL · Winsock2
Runs on
Windows

View source

VS Bot gameplay: the player’s cyan ship and the bot’s red ship among grey cube asteroids in a gridded arena. The HUD shows the round timer at 22, round 1, and each side’s score and lives.
VS BotA round against the bot, the red ship.

The game

Everything happens on one screen.

Fly your ship, shoot asteroids for points, and shoot the other ship to take its lives. The best of three 30-second rounds wins.

VS Bot gameplay: the player’s cyan ship and the bot’s red ship among grey cube asteroids in a gridded arena, with the round timer at the top and each side’s score and lives at the sides.
VS BotRound 1 of a best of three.
  1. Your shipThe cyan one. W thrusts, A and D turn, Space fires.
  2. The opponentA friend on another computer, or the bot when you play alone.
  3. AsteroidsBig ones break into two medium ones, medium ones into two small; small ones shatter. A hit scores 5, 10 or 20 points.
  4. Round timerEach round lasts 30 seconds. Win two rounds to take the match.
  5. Score and livesThree lives each. After a hit, a ship can’t be hurt for 1.5 seconds.

A match

From the lobby to a rematch.

Against a friend, both games meet in a lobby first. Against the bot, a match starts straight from the menu.

LAN lobby: “Welcome, Loany”, HOST GAME and JOIN GAME, “Connected to raul!”, both players READY, waiting for the host to start.
Meet in the lobbyEach player picks a nickname; one hosts, the other joins, and both press ready. (Earlier build.)
LAN match between raul (cyan) and Loany (red): two ships and grey cube asteroids, round timer 27, round 1, a 6 ms ping, and both players’ score and lives.
Play three roundsThirty seconds each, on two machines. The ping sits under the timer: 6 ms here. (Earlier build.)
VS Bot result: a “YOU WIN!” panel with “Final: 2 - 1” and REMATCH and MAIN MENU buttons over the arena.
Win twoThen a rematch, without reconnecting, or back to the menu.

If a player leaves mid-match, the one who stayed wins.

Who built what

I made the game. Marius made the network under it.

A two-person course project at Uppsala University, spring 2026. Later I added the bot on my own.

Okan Ozcan

The game

Everything you see and play: the ships, asteroids, collisions and scoring; the HUD, menus and lobby; the bot; and the game’s side of multiplayer, from the host running the match to keeping both screens in sync.

C++, SDL2 and OpenGL. The Game class and its state machine; host simulation, joiner input and state sync.

Marius-Raul Filipiuc

The networking layer

The code that carries messages between the two games.

Winsock2 sockets. A receive thread keeps only the newest state or input message, so a game never works through a backlog; Nagle’s algorithm is off on both ends.

Marius-Raul Filipiuc

The relay

A small server that pairs the two players and passes their messages along.

server.py, in Python: pairs a host and a joiner over TCP, then forwards every line between them.

Multiplayer

One player hosts, so both see the same match.

Only the host’s game runs the match. The other game sends its key presses and shows what the host sends back. Both connect through a small relay, which pairs them up.

On a local network that round trip takes only a few milliseconds (6 ms in the LAN match above), so the delay is hard to notice.

Technical detail
Authoritative host
The host applies the joiner’s latest input and runs the same UpdatePlaying as an offline match. The joiner simulates nothing.
Rates
The joiner sends its input about 30 times a second; the host sends a full snapshot of the game state about 30 times a second.
Between snapshots
The joiner moves ships, asteroids and shots along their last velocities, then takes each snapshot as the truth.
No client-side prediction
The joiner’s own ship responds after a round trip to the host: fine on a LAN, not over the internet.
Full snapshots
The host resends the whole state rather than changes, so a joiner that misses a message is correct again at the next one.

The bot

The bot plays with the same controls as you.

Every ship is steered by the same four inputs, whether they come from a keyboard, the network or the bot. So the bot only had to press buttons: its ship moves, fires and gets hit through the same code as yours.

Four inputsInputState

thrust · turn left · turn right · fire

The same ship rulesUpdatePlayer

movement, cooldown and firing, for both ships in every mode

The matchUpdatePlaying

collisions, damage and score

How it plays

It thinks in moments
It picks a new plan every 0.15 to 0.30 seconds, not every frame.
It dodges first
It works out which asteroid would hit it soonest and gets out of the way.
Then it hunts
It chases and shoots you, or shoots asteroids for points while you can’t be hurt.
It misses on purpose
Only a partial lead on moving targets, a few degrees of random error, and a short pause between shots.

A handful of simple rules with timers and randomness. It doesn’t plan ahead.

Details

Small rules that keep it fair.

last framethis framehit

Fast shots can’t skip through

A shot is checked along the whole path it travelled since the last frame, in up to 20 small steps, so it can’t pass through a small asteroid or a ship between two frames.

bigtwo mediumtwo small each

The field refills itself

Asteroids break apart as they’re hit, and new ones drift in from the edges when the field thins out.

One set of rules

The host runs the match, the other game never does, and the bot only supplies input, so the rules can’t drift apart between modes.

Technical detail: one frame

Main loop

Main.cpp, once per frame, with the frame time dt

Game::Update(dt)

menunicknamelobbyplayinground endmatch end

UpdatePlaying(dt)

ships move from their InputState; shots and asteroids move; collisions, scoring, the round timer

Game::Draw()

the OpenGL arena, the SDL2_ttf HUD and menus

One Game class. The bot goes straight from the menu into a match; a LAN game goes through the lobby first.

Limits

What it doesn’t do.

  • LAN only. Both games connect to the relay by typing its IP address; there is no matchmaking or online play.
  • No client-side prediction. On a LAN you won’t notice; over the internet the joining player’s ship would feel a step behind.
  • Windows only, because of Winsock2 and the Visual Studio project.
  • A simple bot. A few rules with timers and randomness, not a planner.