Show HN: I made a browser-based RTS game
212 points| Gluten | 3 years ago |battle-of-flags.com
Game is based on JavaScript/Canvas and WebSockets. On the browser side the map is pre-rendered (as a background image), just the mobile units/buildings and animations are dynamically rendered. The lobby server is made in node.js, but the game server is C++ for performance reasons (mainly the pathfinding). I found the C++ WebSocket libraries out there to be too difficult to use so I made my own based on the rfc. Overall I think making a game like this is quite easy with the browser performance/features nowadays. The game server and client side JavaScript are around 5000 lines of code each.
If you have any questions about the tech I'm happy to answer them.
smegma2|3 years ago
* Does the server have a tick rate and it updates clients at a set interval, or does it only update when things happen?
* Did you ever run into any issues getting enough throughput from the server? e.g. maybe too many events happening at once to update everyone?
* Do you have to manage situations where two clients have a different view of the game state (due to extra latency for example)? If so, how do you resolve it? For example, I know that Team Fortress 2 follows the rule for guns that "if the shooter thinks it hit, then it hit", which means that people get shot around corners sometimes.
I'm working on a turn-based game using websockets which has been hard enough, a real-time game seems much harder to make! Thanks for sharing!
mizzao|3 years ago
https://www.gamedeveloper.com/programming/1500-archers-on-a-...
Gluten|3 years ago
closedloop129|3 years ago
dt3ft|3 years ago
bmacho|3 years ago
hejpadig|3 years ago
mrstone|3 years ago
iWillOffshoreU|3 years ago
Edit: How long did it take you to create?
bmacho|3 years ago
I believe that this could have be done ~20 years ago with about the same effort.
Websocket is maybe minimally easier than AJAX + 20 years old javascript, and the newer ECMA standards also have some nice syntactic sugars, but nothing radical. Objects, classes, closures, passing and modifying functions, javascript was so powerful and easy to work with from the beginning. People just didn't used it back then.
I remember playing e.g. travianer 15 years ago, different genre, but the technology was given.
Gluten|3 years ago
emteycz|3 years ago
mLuby|3 years ago
I know multiplayer games generally need a server to "referee" (and to matchmake) but I wonder if games ever offload most of that work so the client does the heavy lifting (e.g. find a path from A to B) and then submits its work for the server to validate (e.g. this path from A to B works) and broadcast rather than the server doing all the game simulation work. My understanding is that multiplayer game clients generally just do graphics/sound and user interaction processing.
(yeah yeah distributed consensus don't say the B word)
Matheus28|3 years ago
It works really well with RTSes because of the number of things moving around. Unfortunately the drawback is that the client knows everything that's going on in the game. So fog of war is entirely client-side too. Another drawback is that rejoining a game (or a new player joining) is much harder (need a way to encode/decode the entire game state, or client needs to replay the game inputs up until that point to be able to play).
It has some really elegant side effects (tiny replay files, easy to reproduce most bugs, easy to check if a bug is fixed by playing a replay file with a new version, etc.)
lolinder|3 years ago
As far as I can tell there's no way to have the server prevent this while still saving any compute time, so you would have to design your game around the idea that this metagame exists. It could be really interesting for a certain type of player, but frustrating for many others.
junon|3 years ago
oneoff786|3 years ago
bytehowl|3 years ago
mLuby|3 years ago
A recent web game on HN ("Pounce") did the first part well: https://news.ycombinator.com/item?id=31073332
Also I suggest making it really easy to invite someone else to play with you by sending them a link. That's more complex though.
Also since you already have a spectator mode, it'd be cool if people see an active game when they go to the home page, like lichess.org. That might be even harder to do that invite links.
Nice that you can share the result of a game! http://www.battle-of-flags.com/match/index/695
adventured|3 years ago
You could automatically assign a throw-away generic name, and then slap a 'try it right now' type button prominently on the home page. If the game is good, then I'd be willing to create an account.
Ruthalas|3 years ago
I opened a tab to give it a try, but backed out when I had to provide an email to see how it played. Assuming I enjoyed it, I'd then be motivated to make an account to keep track of my play.
z3t4|3 years ago
unknown|3 years ago
[deleted]
Gluten|3 years ago
caretak3r|3 years ago
all2|3 years ago
holografix|3 years ago
visox|3 years ago
does not work in most browsers, think in safari it works :D
http://diablo-forever.com/
crickcreek|3 years ago
DistrictFun7572|3 years ago
* By JavaScript/Canvas I suppose you are talking about WebGL?
* Is the source code available for public viewing?
* Did you use any of the popular frameworks like ThreeJS?
* Do you use differently sized textures depending on whether the user is on a mobile phone or desktop?
Gluten|3 years ago
Sujeto|3 years ago
https://i.imgur.com/5AcAD66.jpg
mikenew|3 years ago
8note|3 years ago
Eg. Red alert 2
gavmor|3 years ago
Is there a documented standard for RTS controls, at least for baseline features?
mLuby|3 years ago
all2|3 years ago
hombre_fatal|3 years ago
crickcreek|3 years ago
smegsicle|3 years ago
dandigangi|3 years ago
strongbond|3 years ago
kwhitefoot|3 years ago
unknown|3 years ago
[deleted]
aliswe|3 years ago
unknown|3 years ago
[deleted]
ttty|3 years ago
I wonder what performance issues you had with node.js that justified a bridge to c++ (including the increase of complexity of the architecture). Pathfinder is not terrible in node.