MCPcopy Index your code
hub / github.com/craftyjs/Crafty

github.com/craftyjs/Crafty @0.9.0 sqlite

repository ↗ · DeepWiki ↗ · release 0.9.0 ↗
257 symbols 546 edges 116 files 16 documented · 6%
README

Crafty JS Travis Build Status AppVeyor Build Status Sauce Test Status

Crafty is a JavaScript game library that can help you create games in a structured way…

Key Features:

  • Entities & Components - A clean and decoupled way to organize game elements. No inheritance needed!
  • Eventbinding - Event system for custom events that can be triggered whenever, whatever and bound just as easily.
  • No dom manipulation or custom drawing routines required.

Other Goodies:

  • Thriving community - Help is readily available in the forum.
  • Community modules - A growing collection of user-generated code you can use.
  • Pure JavaScript - No magic. Works in all major browsers and can be combined with your favorite js library.

Using Crafty

A simple game of pong:

Crafty.init(600, 300);
Crafty.background('rgb(127,127,127)');

//Paddles
Crafty.e("Paddle, 2D, DOM, Color, Multiway")
    .color('rgb(255,0,0)')
    .attr({ x: 20, y: 100, w: 10, h: 100 })
    .multiway(200, { W: -90, S: 90 });
Crafty.e("Paddle, 2D, DOM, Color, Multiway")
    .color('rgb(0,255,0)')
    .attr({ x: 580, y: 100, w: 10, h: 100 })
    .multiway(200, { UP_ARROW: -90, DOWN_ARROW: 90 });

//Ball
Crafty.e("2D, DOM, Color, Collision")
    .color('rgb(0,0,255)')
    .attr({ x: 300, y: 150, w: 10, h: 10,
            dX: Crafty.math.randomInt(2, 5),
            dY: Crafty.math.randomInt(2, 5) })
    .bind('UpdateFrame', function () {
        //hit floor or roof
        if (this.y <= 0 || this.y >= 290)
            this.dY *= -1;

        // hit left or right boundary
        if (this.x > 600) {
            this.x = 300;
            Crafty("LeftPoints").each(function () {
                this.text(++this.points + " Points") });
        }
        if (this.x < 10) {
            this.x = 300;
            Crafty("RightPoints").each(function () {
                this.text(++this.points + " Points") });
        }

        this.x += this.dX;
        this.y += this.dY;
    })
    .onHit('Paddle', function () {
        this.dX *= -1;
    });

//Score boards
Crafty.e("LeftPoints, DOM, 2D, Text")
    .attr({ x: 20, y: 20, w: 100, h: 20, points: 0 })
    .text("0 Points");
Crafty.e("RightPoints, DOM, 2D, Text")
    .attr({ x: 515, y: 20, w: 100, h: 20, points: 0 })
    .text("0 Points");

Left paddle is controlled by W & S, right paddle by UpArrow & DownArrow.
Check it out online and try to modify it yourself here.

Developing

If you want to fix a bug, please submit a pull request against the development branch. Some guides to help you can be found on the wiki

If you would like to make larger contributions please catch us in the forum and we will help you get started. Much appreciated :-)

Quick build instructions

The easiest way to build crafty uses gruntjs, which requires node and npm. If you have grunt, node, and npm already installed, then run npm install from Crafty's root directory. (This will pull down about 30MB of node packages.) From then on, just run grunt to build.

You can also use yarn instead of npm.

(Full instructions here.)

Core symbols most depended-on inside this repo

createEntity
called by 42
tests/unit/spatial/raycast.js
Crafty
called by 37
src/core/core.js
checkResults
called by 34
tests/unit/spatial/raycast.js
hashKeys
called by 30
tests/unit/spatial/spatial-grid.js
escapeText
called by 24
tests/unit/lib/qunit.js
id
called by 23
tests/unit/lib/qunit.js
diagonalDistance
called by 21
tests/unit/spatial/raycast.js
containsKeys
called by 20
tests/unit/spatial/spatial-grid.js

Shape

Function 257

Languages

TypeScript100%

Modules by API surface

tests/unit/lib/qunit.js110 symbols
tests/unit/lib/mockTouchEvents.js18 symbols
tests/unit/spatial/spatial-grid.js11 symbols
tests/unit/core/events.js11 symbols
tests/unit/core/core.js8 symbols
src/graphics/viewport.js8 symbols
src/core/loader.js8 symbols
tests/unit/spatial/collision.js7 symbols
src/graphics/color.js7 symbols
playgrounds/animation/sprite-animation.js6 symbols
tests/webdriver/index-webdriver.js5 symbols
tests/webdriver/color/color-common.js5 symbols

Dependencies from manifests, versioned

brfs1.4.3 · 1×
coffee-script1.10.0 · 1×
director1.2.8 · 1×
git-rev-sync1.8.0 · 1×
grunt1.0.1 · 1×
grunt-banner0.6.0 · 1×
grunt-browserify5.0.0 · 1×
grunt-contrib-connect1.0.2 · 1×
grunt-contrib-copy1.0.0 · 1×
grunt-contrib-jshint1.0.0 · 1×
grunt-contrib-qunit1.2.0 · 1×
grunt-contrib-uglify2.0.0 · 1×

For agents

$ claude mcp add Crafty \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact