{"id":15354069,"url":"https://github.com/dwmkerr/spaceinvaders","last_synced_at":"2025-04-06T12:09:34.236Z","repository":{"id":10158151,"uuid":"12238324","full_name":"dwmkerr/spaceinvaders","owner":"dwmkerr","description":"Classic Space Invaders game written in JavaScript as a learning exercise.","archived":false,"fork":false,"pushed_at":"2023-11-19T22:43:56.000Z","size":119,"stargazers_count":206,"open_issues_count":5,"forks_count":140,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-03-30T10:09:41.832Z","etag":null,"topics":["games","javascript","learning","space-invaders"],"latest_commit_sha":null,"homepage":"https://dwmkerr.github.io/spaceinvaders","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dwmkerr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"dwmkerr"}},"created_at":"2013-08-20T08:31:10.000Z","updated_at":"2025-03-24T11:39:56.000Z","dependencies_parsed_at":"2024-10-16T02:41:18.173Z","dependency_job_id":"b59b74b4-daee-47c1-b236-97ea4b36e1fa","html_url":"https://github.com/dwmkerr/spaceinvaders","commit_stats":{"total_commits":40,"total_committers":5,"mean_commits":8.0,"dds":"0.30000000000000004","last_synced_commit":"c1bf211a2ea0f78ae61956b38ac176e89c82a77c"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwmkerr%2Fspaceinvaders","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwmkerr%2Fspaceinvaders/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwmkerr%2Fspaceinvaders/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dwmkerr%2Fspaceinvaders/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dwmkerr","download_url":"https://codeload.github.com/dwmkerr/spaceinvaders/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247478323,"owners_count":20945266,"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":["games","javascript","learning","space-invaders"],"created_at":"2024-10-01T12:17:05.547Z","updated_at":"2025-04-06T12:09:34.208Z","avatar_url":"https://github.com/dwmkerr.png","language":"JavaScript","readme":"# Space Invaders\n\nThe classic Space Invaders game written in JavaScript as a learning exercise.\n\nNo jQuery or any other third party libraries, just raw JavaScript, CSS and HTML.\n\nSee it Live: [https://dwmkerr.github.io/spaceinvaders/](https://dwmkerr.github.io/spaceinvaders/)\n\n[![Space Invaders Screenshot](./screenshot.jpg \"Space Invaders Screenshot\")](https://dwmkerr.github.io/spaceinvaders/)\n\n## Intro\n\n[![Run on Repl.it](https://repl.it/badge/github/dwmkerr/spaceinvaders)](https://repl.it/github/dwmkerr/spaceinvaders)\n\nWhat's there to say? It's Space Invaders in JavaScript!\n\nCreate the game, give it a `div` to draw to, tell it when the keyboard is mashed and that's all you need to add Space Invaders to a website.\n\nThis is a simple learning exercise, so the JavaScript is deliberate kept all one file. There's no linting, testing, CI, or anything like that. If you want to see such patterns in front-end JavaScript, check out something like [angular-modal-service](https://github.com/dwmkerr/angular-modal-service).\n\n## Adding Space Invaders to a Web Page\n\nFirst, drop the `spaceinvaders.js` file into the website.\n\nNow add a canvas to the page.\n\n```html\n\u003ccanvas id=\"gameCanvas\"\u003e\u003c/canvas\u003e\n```\n\nNext, add the Space Invaders game code. You create the game, initialise it with the canvas, start it and make sure you tell it when a key is pressed or released. That's it!\n\n```html\n\u003cscript\u003e\n//  Setup the canvas.\nvar canvas = document.getElementById(\"gameCanvas\");\ncanvas.width = 800;\ncanvas.height = 600;\n\n//  Create the game.\nvar game = new Game();\n\n//  Initialise it with the game canvas.\ngame.initialise(canvas);\n\n//  Start the game.\ngame.start();\n\n//  Listen for keyboard events.\nvar pressedKeys = [];\nwindow.addEventListener(\"keydown\", function keydown(e) {\n  var keycode = window.event.keycode || e.which;\n    if(!pressedKeys[keycode])\n      pressedKeys[keycode] = true;\n    //  Supress further processing of left/right/space (37/29/32)\n    if(keycode == 37 || keycode == 39 || keycode == 32) {\n      e.preventDefault();\n    }\n    game.keyDown(keycode);\n});\nwindow.addEventListener(\"keyup\", function keydown(e) {\n  var keycode = window.event.keycode || e.which;\n    if(pressedKeys[keycode])\n      delete pressedKeys[keycode];\n    game.keyUp(keycode);\n});\n\u003c/script\u003e\n```\n\n## References\n\nOther bits and pieces that are useful can be dropped here.\n\n- The sounds came from [http://www.classicgaming.cc/classics/spaceinvaders/sounds.php](http://www.classicgaming.cc/classics/spaceinvaders/sounds.php)\n\n## Publishing\n\nOn changes to the `master` branch, the GitHub Pages site will be automatically updated.\n","funding_links":["https://github.com/sponsors/dwmkerr"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdwmkerr%2Fspaceinvaders","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdwmkerr%2Fspaceinvaders","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdwmkerr%2Fspaceinvaders/lists"}