All Projects → dwmkerr → Spaceinvaders

dwmkerr / Spaceinvaders

Licence: mit
Classic Space Invaders game written in JavaScript as a learning exercise.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Spaceinvaders

Free Python Games
Free Python Games
Stars: ✭ 2,166 (+1297.42%)
Mutual labels:  games, learning
Vue Getting Started
This project is seen in demos including the Pluralsight course "Vue: Getting Started" to help represent a fundamental app written with Vue. The heroes and villains theme is used throughout the app.
Stars: ✭ 149 (-3.87%)
Mutual labels:  learning
Yrssf
一个分布式(p2p)云教学/云课堂/直播平台系统CMS,睿易派的开源替代品
Stars: ✭ 141 (-9.03%)
Mutual labels:  learning
Digital video introduction
A hands-on introduction to video technology: image, video, codec (av1, vp9, h265) and more (ffmpeg encoding).
Stars: ✭ 12,184 (+7760.65%)
Mutual labels:  learning
Space Invaders Vhdl
Space Invaders game implemented with VHDL
Stars: ✭ 142 (-8.39%)
Mutual labels:  games
Anyrpgcore
Open source Role Playing Game engine for Unity 3D written in C#.
Stars: ✭ 141 (-9.03%)
Mutual labels:  games
Machine Deep Learning
👋 ML/DL学习笔记(基础+论文)
Stars: ✭ 140 (-9.68%)
Mutual labels:  learning
Howto co34pt livecode
A repository of readmes, techniques, notes and other materials about how i live code in SuperCollider. A (sorta) companion repository to co34pt_livecode
Stars: ✭ 149 (-3.87%)
Mutual labels:  learning
Typelang
🌳 A tiny language interpreter implemented purely in TypeScript's type-system
Stars: ✭ 149 (-3.87%)
Mutual labels:  learning
Translatr
💬 Translate to multiple languages at once
Stars: ✭ 145 (-6.45%)
Mutual labels:  learning
Py Rse
Research Software Engineering with Python course material
Stars: ✭ 145 (-6.45%)
Mutual labels:  learning
Cherry
A PyTorch Library for Reinforcement Learning Research
Stars: ✭ 143 (-7.74%)
Mutual labels:  learning
Bottles
🌠 Easily manage 🍷prefix in a new way! (Run Windows software and games on Linux)
Stars: ✭ 147 (-5.16%)
Mutual labels:  games
Learn Javascript
Learn Plain JavaScript from Top Articles of 2017
Stars: ✭ 142 (-8.39%)
Mutual labels:  learning
Ffmpeg Video Player
An FFmpeg and SDL Tutorial.
Stars: ✭ 149 (-3.87%)
Mutual labels:  learning
Awesome Vehicle Security
🚗 A curated list of resources for learning about vehicle security and car hacking.
Stars: ✭ 1,931 (+1145.81%)
Mutual labels:  learning
Rcade
Games to procrastinate with RStudio
Stars: ✭ 146 (-5.81%)
Mutual labels:  games
Robotcar Dataset Sdk
Software Development Kit for the Oxford Robotcar Dataset
Stars: ✭ 151 (-2.58%)
Mutual labels:  learning
Android Developer Roadmap
Android Developer Roadmap - A complete roadmap to learn Android App Development
Stars: ✭ 2,170 (+1300%)
Mutual labels:  learning
The Zen Of Elixir
Collection of top articles reflecting the Zen of Elixir
Stars: ✭ 148 (-4.52%)
Mutual labels:  learning

Space Invaders

The classic Space Invaders game written in JavaScript as a learning exercise.

No jQuery or any other third party libraries, just raw JavaScript, CSS and HTML.

See it Live: https://dwmkerr.github.io/spaceinvaders/

Space Invaders Screenshot

Intro

Run on Repl.it

What's there to say? It's Space Invaders in JavaScript!

Create 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.

This 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.

Adding Space Invaders to a Web Page

First, drop the spaceinvaders.js file into the website.

Now add a canvas to the page.

<canvas id="gameCanvas"></canvas>

Next, 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!

<script>
//  Setup the canvas.
var canvas = document.getElementById("gameCanvas");
canvas.width = 800;
canvas.height = 600;

//  Create the game.
var game = new Game();

//  Initialise it with the game canvas.
game.initialise(canvas);

//  Start the game.
game.start();

//  Listen for keyboard events.
var pressedKeys = [];
window.addEventListener("keydown", function keydown(e) {
  var keycode = window.event.keycode || e.which;
    if(!pressedKeys[keycode])
      pressedKeys[keycode] = true;
    //  Supress further processing of left/right/space (37/29/32)
    if(keycode == 37 || keycode == 39 || keycode == 32) {
      e.preventDefault();
    }
    game.keyDown(keycode);
});
window.addEventListener("keyup", function keydown(e) {
  var keycode = window.event.keycode || e.which;
    if(pressedKeys[keycode])
      delete pressedKeys[keycode];
    game.keyUp(keycode);
});
</script>

References

Other bits and pieces that are useful can be dropped here.

Publishing

On changes to the master branch, the GitHub Pages site will be automatically updated.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].