87 points by john_doe 7 months ago flag hide 56 comments
johnldoes 7 months ago next
[Show HN] I Built a Real-time Multiplayer Game Using Rust and WebAssembly - I'm the original poster and I wanted to share my experience building this game. I found Rust and WebAssembly to be a great combination, and I'm excited to see what others think. AMA!
anonews123 7 months ago next
Great work, I've been looking for a game like this. Do you have any plans to add multiplayer functionality?
johnldoes 7 months ago next
Yes, that's actually the whole point of the game, it's a real-time multiplayer experience. I'm still working on some features, but I'll be sure to let you know when it's ready!
hax0rman 7 months ago prev next
Interesting, I just started learning Rust and was looking for a good project to test my skills. Do you have any suggestions for resources or specific libraries you used in your game?
johnldoes 7 months ago next
I used the `glium` crate for rendering, and `specs` for my ECS. I found `glium` to be very easy to use, and `specs` is great for organizing and managing game objects. As for resources, I can't recommend the `Rust by Example` website enough, it really helped me get a handle on the language.
dino_fan 7 months ago prev next
This game is great, I love the pixel art style! Have you considered using a different rendering engine to get better performance?
johnldoes 7 months ago next
Thanks! I did consider using something like `gfx-rs`, but I found `glium` to be more user-friendly and I didn't need the extra performance for this project.
webdev_newb 7 months ago prev next
I'm new to WebAssembly, can you explain how you integrated Rust with your JavaScript code?
johnldoes 7 months ago next
Sure thing! I used the `wasm-bindgen` crate to generate JavaScript bindings for my Rust code, and then I simply imported and called the functions in my JavaScript like any other code. It was really easy to set up and use, and the `wasm-bindgen` documentation is very helpful.
linux_enthusiast 7 months ago prev next
This is amazing, I can't believe you built this in Rust and WebAssembly. Where can I check out the source code?
johnldoes 7 months ago next
Thanks! The source code is available on my GitHub repo, you can find the link in the HN post.
gamerguy64 7 months ago prev next
I tried to build a game like this using C++ and WebAssembly, but I couldn't get the performance to be good enough. Did you encounter any performance issues while building this game?
johnldoes 7 months ago next
I did encounter a few performance issues, mostly with rendering. However, Rust's low-level memory management helped me optimize the performance, and the `glium` and `specs` crates made it easy to work with. Overall, I'm very happy with how well the performance turned out.
codergirl123 7 months ago prev next
I'm really impressed, this game is so much fun! How did you manage to handle the network synchronization for the multiplayer aspect?
johnldoes 7 months ago next
Thanks! Network synchronization is always a challenge in multiplayer games. I used a combination of the `tokio` crate for asynchronous I/O and the `quinn` crate for WebSocket communication. I also implemented client-side prediction and client-side entity interpolation to handle latency. It took a lot of work, but I'm happy with the end result.
opengl_fan 7 months ago prev next
Have you considered adding a 3D rendering mode? I think it could look great and attract more players.
johnldoes 7 months ago next
I have considered adding a 3D rendering mode, but it would require a significant rewrite of the rendering code and I don't think the current art style would work well in 3D. However, I'll definitely keep it in mind for future projects!
webstd_lover 7 months ago prev next
I'm really interested in using Rust and WebAssembly for my next web project, but I'm not sure where to start. Do you have any tips or resources for getting started?
johnldoes 7 months ago next
Definitely start by reading the `wasm-bindgen` documentation, it's a great introduction to integrating Rust and JavaScript. I also recommend checking out the `wasm-pack` tool, it makes it even easier to build and distribute WebAssembly projects. Finally, don't be afraid to look at open-source projects for inspiration and guidance.
macos_user 7 months ago prev next
This game is great, but I'm having trouble getting it to run on my Mac. Any advice?
johnldoes 7 months ago next
I'm sorry to hear that! Here are some steps to try: 1. Make sure you're using the latest version of your browser. 2. Make sure you have the `wasm32-unknown-unknown` target installed for Rust. 3. Make sure you're serving the game from a web server (like `serve` or `nginx`). 4. If you're still having trouble, try building the game in release mode and serving it from a web server. Let me know if any of these steps help!
csharp_pro 7 months ago prev next
I'm shocked, I never thought Rust and WebAssembly would be able to produce such a high-quality game. Very impressive.
pythonist 7 months ago prev next
This is great work! I'm inspired to try building my own game using Rust and WebAssembly.
johnldoes 7 months ago next
That's great to hear! The Rust and WebAssembly community is growing fast, and there are lots of resources available to help you get started. Good luck with your project!
game_dev_newb 7 months ago prev next
I'm new to game development and I'm looking for a good starting point. Do you have any suggestions for resources or tutorials for building a simple game using Rust and WebAssembly?
johnldoes 7 months ago next
Definitely! The `ggez` crate is a great place to start for building a simple 2D game in Rust. It's easy to use and has lots of documentation and examples. I also recommend checking out the `Rust by Example` website for general Rust tutorials and resources. Finally, the `WebAssembly` website has some great articles and tutorials for getting started with WebAssembly.
js_enthusiast 7 months ago prev next
I'm looking to build a web application that can handle real-time updates and multiplayer interactions. Do you have any suggestions for tools or libraries to use with Rust and WebAssembly?
johnldoes 7 months ago next
I'd recommend using the `tokio` crate for asynchronous I/O and the `quinn` crate for WebSocket communication. They're both very powerful and flexible, and they should be able to handle real-time updates and multiplayer interactions with ease. I'd also recommend using the `glium` crate for rendering, it's very easy to use and works well with `tokio` and `quinn`.
nodejs_dev 7 months ago prev next
I'm curious, why did you choose Rust and WebAssembly over using Node.js and a front-end framework?
johnldoes 7 months ago next
I chose Rust and WebAssembly because I wanted the performance and memory safety benefits of Rust, and I wanted to avoid the overhead and security concerns of running Node.js on the client. WebAssembly allowed me to run Rust code directly in the browser, and it's much faster and more secure than running Node.js. It also allowed me to build a cross-platform game that runs on all modern web browsers, including mobile.
java_pro 7 months ago prev next
I'm impressed, this game is very fast and smooth. Do you have any tips for optimizing real-time performance with Rust and WebAssembly?
johnldoes 7 months ago next
Sure thing! The key to optimizing real-time performance is to minimize the number of allocations and avoid garbage collection. Rust's low-level memory management makes it easy to allocate memory manually and manage it efficiently. I also recommend using the `glium` and `specs` crates for rendering and entity management, they're both optimized for real-time performance. Finally, I recommend profiling your game regularly to track down any performance bottlenecks and optimize accordingly.
learn_wasm 7 months ago prev next
I'm just getting started with WebAssembly and I want to learn more. Do you have any tips or resources for learning WebAssembly with Rust?
johnldoes 7 months ago next
Definitely! I'd recommend starting with the `wasm-bindgen` documentation, it's a great introduction to integrating Rust and JavaScript. I also recommend checking out the `wasm-pack` tool, it makes it even easier to build and distribute WebAssembly projects. Finally, I recommend looking at open-source projects for inspiration and guidance. The Rust and WebAssembly community is very supportive and helpful, so don't hesitate to ask for help if you get stuck.
cargo_lover 7 months ago prev next
I've been using Rust for a while now and I love it, but I've never tried using WebAssembly. Do you have any tips for getting started with WebAssembly and Rust?
johnldoes 7 months ago next
Sure thing! I'd recommend starting by reading the `wasm-bindgen` documentation, it's a great introduction to integrating Rust and JavaScript. I also recommend checking out the `wasm-pack` tool, it makes it even easier to build and distribute WebAssembly projects. Finally, I recommend looking at open-source projects for inspiration and guidance. The Rust and WebAssembly community is very supportive and helpful, so don't hesitate to ask for help if you get stuck.
security_expert 7 months ago prev next
I'm very interested in WebAssembly as a secure alternative to JavaScript, can you explain how Rust and WebAssembly improve security?
johnldoes 7 months ago next
Sure! WebAssembly is designed to be a secure alternative to JavaScript, and Rust is a memory-safe language that helps prevent common security vulnerabilities. Together, they provide a secure environment for running untrusted code in the browser. Rust's low-level memory management helps prevent buffer overflows and other memory-related attacks, while WebAssembly's sandboxed environment helps prevent cross-site scripting and other attacks. Overall, Rust and WebAssembly provide a much more secure environment than JavaScript or other browser-based technologies.
performance_lover 7 months ago prev next
I'm impressed with the performance of this game, can you explain how Rust and WebAssembly improve performance over JavaScript and other web technologies?
johnldoes 7 months ago next
Sure thing! Rust is a low-level language that can be optimized for performance, and WebAssembly is a low-level bytecode that's optimized for web performance. Together, they provide a high-performance environment for running code in the browser. Rust's low-level memory management helps prevent garbage collection and other performance hits, while WebAssembly's sandboxed environment helps prevent slow-downs caused by DOM manipulation and other untrusted code. Overall, Rust and WebAssembly provide a much faster environment than JavaScript or other browser-based technologies.
game_aficionado 7 months ago prev next
I'm a big fan of games built with Rust and WebAssembly, do you have any favorite examples?
johnldoes 7 months ago next
I'm glad to hear it! Some of my favorite games built with Rust and WebAssembly are: 1. Polycraft: A real-time multiplayer game with a polygonal art style. 2. Puddle Knights: A puzzle-platformer with unique mechanics and a hilarious art style. 3. Heathen Engineering's demos: A series of tech demos showcasing different WebAssembly features in Rust. 4. Dicey Castles: A physics-based puzzle game with a procedurally generated world. 5. Super Scribblenauts Unlimited: A port of the classic Scribblenauts game, built with Rust and WebAssembly. I recommend checking them out, they're all great examples of what Rust and WebAssembly can do!
beginner_programmer 7 months ago prev next
I'm just getting started with programming and I'm looking for a good language and framework to learn. Do you have any suggestions for using Rust and WebAssembly for beginners?
johnldoes 7 months ago next
Definitely! Rust and WebAssembly is a great combination for beginners. Rust is a simple and reliable language that's easy to learn, and WebAssembly is a fast and secure environment for running Rust code in the browser. I'd recommend starting by learning the basics of Rust, then moving on to the `wasm-bindgen` documentation and `wasm-pack` tool to learn how to build and distribute WebAssembly projects. Finally, I'd recommend looking at open-source projects for inspiration and guidance. The Rust and WebAssembly community is very supportive and helpful, so don't hesitate to ask for help if you get stuck.
open_source_lover 7 months ago prev next
I'm a big believer in open-source software and I'm looking for a new project to contribute to. Do you have any recommendations for open-source Rust and WebAssembly projects to get involved in?
johnldoes 7 months ago next
Definitely! Here are some open-source Rust and WebAssembly projects that could use your help: 1. Polycraft: A real-time multiplayer game with a polygonal art style. 2. Puddle Knights: A puzzle-platformer with unique mechanics and a hilarious art style. 3. Heathen Engineering's demos: A series of tech demos showcasing different WebAssembly features in Rust. 4. Dicey Castles: A physics-based puzzle game with a procedurally generated world. 5. Super Scribblenauts Unlimited: A port of the classic Scribblenauts game, built with Rust and WebAssembly. These projects all have active communities and are looking for contributors. I recommend picking one that interests you and getting involved!
community_member 7 months ago prev next
I'm a member of the Rust and WebAssembly community and I'm interested in getting more involved. Do you have any suggestions for how to get more involved and make a difference in the community?
johnldoes 7 months ago next
Definitely! Here are some suggestions for getting more involved in the Rust and WebAssembly community: 1. Attend community events and meetups: There are lots of community events and meetups happening all the time, both in-person and online. Attend these events and meet other members of the community. 2. Contribute to open-source projects: The Rust and WebAssembly community is built on open-source projects, so contributing to these projects is a great way to make a difference. Find a project that interests you and start contributing. 3. Share your knowledge and experience: If you have knowledge and experience with Rust and WebAssembly, share it with the community. Write blog posts, create tutorials, give talks, and help other members of the community. 4. Get involved in community governance: The Rust and WebAssembly community is governed by its members, so getting involved in community governance is a great way to make a difference. Join the discussion and help make decisions about the future of the community.
impressed_user 7 months ago prev next
I'm so impressed with this game, I have to ask: do you have any plans to turn it into a full-fledged product and sell it on the web?
johnldoes 7 months ago next
Thanks for the kind words! My current goal is to continue developing the game and releasing new versions for free. However, I would definitely consider turning it into a full-fledged product and selling it if there's enough interest and support from the community.