Git Product home page Git Product logo

jaws's Introduction

Jaws - HTML5 Javascript web game development library

Depends on JavaScript Edition 5. Works with Chrome 9+, Firefox 3.6+, Safari 5+ & IE9.

Licensed under LGPL so you’re free to use it for commercial projects.

Highlights

  • Animation(), Sprite(), SpriteSheet(), TileMap(), Assets() and other useful constructors

  • Easy and robust game state system to switch between menus, play, high score lists and settings

  • JSDOC Documentation & commented examples

Jaws also:

  • Does <canvas>-sprites and exprimental HTML-based sprites

  • Does not depend on any other JavaScript library

  • Doesn’t try to force a certain “JS class pattern” on you, just pure JavaScript as mother nature intended it

  • Tries to make assets (images, music, json data) in webgames as easy as possible

  • Often does object literals as arguments for readabillity (ie. new Sprite({image: “player.png”, x: 100, y: 100})

  • Builds on lessons learned from years of developing github.com/ippa/chingu (Ruby game lib)

Learn more

Jaws is still beta

… So don’t base your commercial projects on it. APIs has started to settle down, but there will still be changes ahead.

Simple examples demonstrating certain features

Check out the sourcecode for comments and explanations:

Games using Jaws

… missing your game here? Msg me on github!

Loading Jaws

  • jaws.js - includes the whole framework in one easy-to-include file.

  • jaws-min.js - same as jaws.js but minified with Googles closure compiler. This is probably what you want to include in your project.

  • jaws-dynamic.js - dynamically loads all separate jaws files. Useful for debugging errors in Jaws. Warning, jaws-dynamic.js loads all jaws source-files asynchronously meaning Jaws might not be fully loaded before the browser

  • reaches your game.js or likewise. Jaws tries to solve this issue by calling jaws.onload() when all files are loaded.

You can also link to invidual files in your HTML:

<script src="/jawsjs/src/core.js"></script>
<script src="/jawsjs/src/sprite.js"></script>

NOTE: core.js is always needed but after that you can pick and choose depending on what you need. A rule of thumb is that a file named “foo.js” will include a contructor named Foo().

Contribute

Jaws accepts contributions, some simple guidelines:

  • Formatting: oneFunction(), OneConstrutor() and one_variable

  • Don’t patch jaws.js or jaws-min.js

  • Please bundle tests with non-trivial patches

  • Naming shouldn’t consist of abbreviations, let’s use “context”, not “ctx”

Jaws has gotten contributions from: github.com/gregmax17 - viewport related stuff

Example

/*
* Jaws will provide powerful functions like jaws.start() to quickly get a robust gameloop running.
* It's also possible to do it more manually, fetch your own canvas context and sent it to new Sprite() for example.
* Nothing stops you from using jaws.assets or other jaws.helpers with your own game loop either.
*
* Below code shows the preferred way, letting jaws worry about most of the boring setup stuff
* so we can get straight to get game logic.
*/
<html>
<script src="jaws.js"></script>
<body>

<canvas width=500 height=300></canvas> <!-- don't set width/height of canvas with CSS -->

<script>
  /*
  * Jaws encourages the use of game states to separate various parts of your game.
  * We send MyGameState to jaws.start() to start with.
  * You can later switch to another game state with jaws.switchGameState(OtherGameState)
  */
  function MyGameState() {
    var player;
    var robot;

    /* Put your one-time initializing here. Will get called once each time this game state is activated. */
    this.setup = function() {
      /*
      * Make a sprite, place it at position 10/200
      * The string "player.png" will resolve to a previously fetched resource
      * We let jaws worry about what canvas to paint to here.
      * If we want we could simple pass {context: my_canvas_context} to Sprite constructor
      */
      player = new jaws.Sprite({image: "player.png", x: 10, y: 200});

      /* Let's create an animated robot sprite */
      robot = new jaws.Sprite({x: 200, y: 200});

      robot.animation = new jaws.Animation({sprite_sheet: "images/droid_11x15.png", frame_size: [11,15], frame_duration: 120});
    }

    /* update() is called each gametick with given FPS. Put your game logic here. */
    this.update = function() {
      if(jaws.pressed("left"))  { player.x--; }
      if(jaws.pressed("right")) { player.x++; }
      robot.image = robot.animation.next();
    }

    /* draw() is called each gametick just after update() is done. Put your drawing/canvas stuff here. */
    this.draw = function() {
      player.draw();
      robot.draw();
    }
  }

  /*
  * jaws.start(YourGameState) is the easiest way to get something up and running. It will in this order:
  *
  * 1) Call jaws.init() that will detect <canvas> (or create one for you) and set up the 2D context
  * - then available in jaws.canvas and jaws.context
  *
  * 2) Pre-load all assets
  * - player.png image is then available with jaws.assets.get("player.png")
  *
  * 3) Create an instance of YourGameState and call setup() on that instance
  * - in setup() you usually create your gameobjects, sprites and so forth
  *
  * 4) Loop calls to update() and draw() with given FPS (default 60) until game ends or another game state is activated
  */
  window.onload = function() {
    /*
    * Add to jaws internal list of assets.
    * You can then either:
    * - have jaws.start() load them automatically for you
    * - or load them manually with jaws.assets.loadAll({loaded: myAssetsAreReadyCall})
    */
    jaws.assets.add("images/droid_11x15.png");
    jaws.assets.add("images/player.png");

    /*
    * ... or nicer when you have a lot of assets:
    * jaws.assets.path = "images/"
    * jaws.assets.add(["droid_11x15.png", "player.png"])
    */

    jaws.start(MyGameState);
  }
</script>
</body>
</html>

jaws's People

Contributors

cco3 avatar jduff avatar

Stargazers

 avatar

Watchers

 avatar

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.