{"id":17254093,"url":"https://github.com/ronf/webrtc-spacewar","last_synced_at":"2025-03-26T07:25:41.753Z","repository":{"id":76043483,"uuid":"303212120","full_name":"ronf/webrtc-spacewar","owner":"ronf","description":"Browser-based version of classic Spacewar! game which uses WebSockets and WebRTC","archived":false,"fork":false,"pushed_at":"2020-10-26T02:56:44.000Z","size":88,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-31T09:13:03.318Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ronf.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-11T21:03:06.000Z","updated_at":"2024-05-14T13:50:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"2ec4e2ba-54c0-4180-82a6-efebf58fcb14","html_url":"https://github.com/ronf/webrtc-spacewar","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ronf%2Fwebrtc-spacewar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ronf%2Fwebrtc-spacewar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ronf%2Fwebrtc-spacewar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ronf%2Fwebrtc-spacewar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ronf","download_url":"https://codeload.github.com/ronf/webrtc-spacewar/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245607673,"owners_count":20643398,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-15T07:06:47.087Z","updated_at":"2025-03-26T07:25:41.726Z","avatar_url":"https://github.com/ronf.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"WebRTC Spacewar\n===============\n\nWebRTC Spacewar is a browser-based recreation of the PDP-1 `Spacewar!`__\ngame, based on an X11 version I wrote in C back in 1992.\n\n__ https://en.wikipedia.org/wiki/Spacewar!\n\n.. image:: images/spacewar.png\n    :target: https://www.timeheart.net/spacewar\n\nMotivation\n----------\n\nI created the original version of Spacewar to show how to build a\nnetwork-based multi-player game without a server. Clients communicated\ndirectly with one another to share game state. For a two player game,\nplayers specified each other's IP address when starting the game. More\nthan two players was also supported, by having all the players specify\na common IP multicast group address. Game updates would be sent to that\naddress and delivered to all other clients which joined that multicast\ngroup. Each client would then independently render a view of all the\nships without the need for a central server. With synchronized clocks,\nthe clients came very close to all showing the same result within the\nlimits of the network latency, and any errors due to latency would\nautomatically be corrected by later game updates.\n\nWith this new version of Spacewar, my initial goals were:\n\n  * Learn something about what Javascript is capable of in modern\n    web browsers\n  * Learn how WebSockets work and what they're capable of\n\nDue to web browser security restrictions, a true peer-to-peer version\nof the game in a browser with no server at all wasn't possible, but I\nwanted to keep all the actual game logic completely within the browser,\nimplementing only a very basic WebSocket \"relay\" that replaced the\nIP multicast communication in my original version. More details on\nthis WebSocket relay can be found `here`__.\n\n__ ws-relay.rst\n\n\nOnce I had the WebSocket version of the game running, I decided it\nwould also be interesting to use this project as an opportunity to\nlearn more about what WebRTC was capable of, getting closer to the\ntrue peer-to-peer nature of my original implementation by using\nWebRTC data channels to send game state directly between clients.\nUnfortunately, WebRTC doesn't support IP multicast, so that had to\nbe simulated by building a mesh of unicast connections between the\nclients. Also, to set up WebRTC, a signaling channel had to be\nprovided, but the WebSocket relay I had already written turned out\nto be perfect for that.\n\nGame Basics\n-----------\n\nThe basic game controls let you turn your ship, thrust in whatever\ndirection you are facing, and fire missiles in that direction. You can\nfire two missiles per second, and they'll deactivate after five seconds,\nor sooner if they hit something.\n\nBe sure to take into account the sun's gravity when maneuvering and\naiming your missiles. If you like, you can slingshot your ship or your\nmissiles around the sun, but don't get too close or you'll be sucked\nin, and be careful not to shoot yourself!\n\nIf a ship collides with the sun, another ship, or a missile, it will be\ndestroyed, causing debris to spread out in the direction the ship was\nmoving. Beware! A ship can also be destroyed by colliding with debris!\nAfter a few seconds, a destroyed ship will be returned back to a\ncircular orbit around the sun.\n\nIf you fly off the edge of the screen, you can use the zoom keys to zoom\nout, and if you really get lost you can hit `Enter` to go into hyperspace,\nreturning back to a circular orbit around the sun a few seconds later.\nThis can also be used to avoid collisions, though there's no guarantee\nyou won't collide with something when you come out of hyperspace.\n\nYou can also drag with the mouse to change your current view, or zoom\nin and out with the scroll wheel or trackpad. Touch gestures can also\nbe used on devices that support them, including pinch to zoom.\n\nClicking on the sun will reset the view back to its initial default (same\nas hitting `R`). Clicking on a ship will lock the view onto that ship,\nkeeping it in the center of the screen for a \"first person\" view of the\naction. This is also a good way to see the details of the ship designs\nby clicking on them and then zooming all the way in.\n\nObserver mode lets you watch a game without having your own ship. You\ncan use `O` to toggle between observing and actively playing.\n\nYou can use `P` to stop and start the game without leaving the web page.\n\nPrimary controls:\n^^^^^^^^^^^^^^^^^\n\n================== ================\nKey                Control          \n================== ================\nA, H, Left Arrow   Rotate left\nS, J, Right Arrow  Rotate right\nD, K, Up Arrow     Thrust\nF, L, Spacebar     Launch missile\nEnter, Return      Enter hyperspace\n================== ================\n\nAdditional controls:\n^^^^^^^^^^^^^^^^^^^^\n\n=========== ====================\nKey         Control\n=========== ====================\nZ           Zoom view in\nX           Zoom view out\nR           Reset view\nC           Toggle config panel\nN           Toggle names\nO           Toggle observer mode\nP           Play/pause game\nT           Toggle timing panel\n=========== ====================\n\nGame Configuration\n------------------\n\nThe configuration panel for the game will be brought up the first time\nyou play, and can also be brought back by hitting `C`. You can configure\na name to show under your ship and also choose whether to use WebRTC\nor WebSockets for sending game updates. If you enable WebRTC, you can\nalso configure a STUN or TURN server. I provide a default TURN server\nfor the version of this game that I host myself.\n\nAny configuration you enter is stored locally using browser local storage,\nso it should be remembered across game sessions.\n\nAcknowledgments\n----------------\n\nI want to thank some of my former coworkers at Xerox PARC for\ncontributing ship designs used in my original implementation of\nSpacewar, which I have carried forward here!\n\n\nNext Steps\n----------\n\nFind out how to install your own instance of Spacewar `here`__, or\nclick on the following to play my existing instance of the game:\n\n__ INSTALL.rst\n\n.. raw:: html\n\n    \u003cdiv align=\"center\"\u003e\n      \u003ca href=\"https://www.timeheart.net/spacewar\"\u003e\n        \u003cimg src=\"images/play.svg\"\u003e\n      \u003c/a\u003e\n    \u003c/div\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fronf%2Fwebrtc-spacewar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fronf%2Fwebrtc-spacewar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fronf%2Fwebrtc-spacewar/lists"}