GithubHelp home page GithubHelp logo

puppetlabs / asteroids Goto Github PK

View Code? Open in Web Editor NEW

This project forked from xaxis/asteroids

1.0 2.0 1.0 1.05 MB

A JavaScript based Asteroids variation.

License: MIT License

HTML 3.11% JavaScript 96.89%

asteroids's Introduction

Asteroids! ... Or something kind of like it.

Introduction

In my free time I coded a version of Asteroids using JavaScript and the canvas element. This was just a little experiment so it's unlikely I'll improve it much more. I'm posting it on GitHub in case anyone finds any of the bits of code useful. Programming Asteroids is a really great way to get started understanding the basics of 2D video games. Enjoy!

alt text

View demo.

Up and running

Include the asteroids.js file in the header of your page and add a canvas element with an id of asteroids-container, like this:

 <canvas id="asteroids-container" width="800" height="400"></canvas>

Then include the following script to initialize the game.

<script>
    var asteroids = new Asteroids();
    asteroids.init({
        debug_mode: false,
        nyan_mode: true,
        nyan_path_override: '',
        nyan_sound: true,
        levels: {
            1: {
                asteroids: 3,
                asteroid_speed: 1,
                ufos: 2,
                ufo_speed: 2,
                ufo_min_pause_time: 1000,
                ufo_max_pause_time: 3000,
                ufo_missile_fire_rate: 1000
            },
            2: {
                asteroids: 4,
                asteroid_speed: 2,
                ufos: 2,
                ufo_speed: 3,
                ufo_min_pause_time: 1000,
                ufo_max_pause_time: 3000,
                ufo_missile_fire_rate: 1000
            },
            3: {
                asteroids: 5,
                asteroid_speed: 2,
                ufos: 2,
                ufo_speed: 4,
                ufo_min_pause_time: 1000,
                ufo_max_pause_time: 3000,
                ufo_missile_fire_rate: 1000
            }
        },
        gameCompleted: function() {
            alert('You won the game!');
        }
    });
</script>

You can define the parameters and overall difficulty of each level you create.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.