Skip to content

Commit

Permalink
Merge branch 'develop' into testing
Browse files Browse the repository at this point in the history
Conflicts:
	tests/dom_translate.js
  • Loading branch information
kevinsimper committed Oct 31, 2014
2 parents 4e3328b + 4b8e564 commit 00acaeb
Show file tree
Hide file tree
Showing 52 changed files with 4,995 additions and 3,550 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ node_js:
- "0.10"
before_script:
- npm install -g grunt-cli
cache:
directories:
- node_modules
21 changes: 9 additions & 12 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@ var fs = require('fs');

module.exports = function (grunt) {
var pkg = grunt.file.readJSON('package.json');
var fileList = pkg.files, version = pkg.version;
var version = pkg.version;
var banner = '/**\n' +
' * <%= pkg.name %> <%= pkg.version %>\n' +
' * <%= pkg.author.url %>\n *\n' +
' * Copyright <%= grunt.template.today("yyyy") %>, <%= pkg.author.name %>\n' +
' * Dual licensed under the MIT or GPL licenses.\n' +
' */\n\n';

var getFiles = function (){
return fileList;
};

var docGen = function(){
done = this.async();
buildDir = "build/api/";
Expand All @@ -24,7 +20,8 @@ module.exports = function (grunt) {
done();
};
var md = require("./build/api-gen");
md.document(getFiles(), buildDir, "build/template.html", version, callback);
md.document(grunt.file.expand('src/*.js'),
buildDir, "build/template.html", version, callback);
};

// Project configuration.
Expand All @@ -47,12 +44,12 @@ module.exports = function (grunt) {
browserify: {
dist: {
files: {
'crafty.js': ['src/*.js']
'crafty.js': ['src/crafty.js']
}
},
debug: {
files: {
'crafty.js': ['src/*.js']
'crafty.js': ['src/crafty.js']
},
options: {
debug: true
Expand All @@ -76,23 +73,23 @@ module.exports = function (grunt) {
},

jshint: {
files: ['Gruntfile.js', 'src/**/*.js', 'tests/*.js'],
files: ['Gruntfile.js', 'src/**/*.js', 'tests/**/*.js'],
options: {
trailing: true,
ignores: ['tests/lib/*.js'],
globals: {
}
}
},

qunit: {
all: [
'tests/index.html',
'tests/animation/animation.html'
'tests/index.html'
]
},

jsvalidate: {
files: ['crafty.js', 'tests/*.js']
files: ['crafty.js', 'tests/**/*.js']
},

connect: {
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Crafty JS
# Crafty JS [![Build Status](https://travis-ci.org/craftyjs/Crafty.png?branch=develop)](https://travis-ci.org/craftyjs/Crafty)


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

Expand Down
17 changes: 12 additions & 5 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
{
"name": "crafty",
"main": "crafty.js",
"version": "0.6.2",
"repository": {
"type": "git",
"url": "git://github.com/craftyjs/Crafty.git"
}
"main": "dist/crafty.js",
"license": "MIT",
"ignore": [
"**/.*",
"build",
"playgrounds",
"test",
"*.md",
"changelog.txt",
"Gruntfile.js",
"package.json"
]
}
53 changes: 12 additions & 41 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"branches": {
"develop": true
},
"main": "src/crafty.js",
"repository": {
"type": "git",
"url": "https://github.com/craftyjs/Crafty.git"
Expand All @@ -33,49 +34,19 @@
},
"jsfiddle": "disable",
"homepage": "https://github.com/craftyjs/Crafty",
"files": [
"src/core.js",
"src/HashMap.js",
"src/2D.js",
"src/scenes.js",
"src/collision.js",
"src/DOM.js",
"src/html.js",
"src/storage.js",
"src/extensions.js",
"src/viewport.js",
"src/device.js",
"src/sprite.js",
"src/canvas.js",
"src/controls.js",
"src/animation.js",
"src/sprite-animation.js",
"src/drawing.js",
"src/isometric.js",
"src/diamondiso.js",
"src/particles.js",
"src/sound.js",
"src/text.js",
"src/loader.js",
"src/math.js",
"src/time.js",
"src/DebugLayer.js",
"src/keycodes.js"
],
"dependencies": {
"grunt": "~0.4.1",
"grunt-contrib-uglify": "0.2.0",
"grunt-contrib-concat": "0.3.0",
"grunt-contrib-jshint": "0.5.2",
"grunt-contrib-qunit": "0.2.1",
"grunt-jsvalidate": "0.2.1",
"marked": "0.2.9",
"coffee-script": "1.6.3",
"grunt-browserify": "~1.2.9",
"grunt-banner": "~0.2.0",
"grunt-contrib-watch": "~0.5.3"
},
"devDependencies": {
"grunt-contrib-connect": "~0.6.0"
"grunt-contrib-connect": "^0.8.0",
"coffee-script": "1.7.1",
"grunt": "^0.4.5",
"grunt-banner": "^0.2.3",
"grunt-browserify": "^2.1.4",
"grunt-contrib-jshint": "^0.10.0",
"grunt-contrib-qunit": "^0.4.0",
"grunt-contrib-uglify": "^0.5.1",
"grunt-contrib-watch": "^0.6.1",
"grunt-jsvalidate": "^0.2.2",
"marked": "^0.3.2"
}
}
71 changes: 71 additions & 0 deletions playgrounds/2D/collision/collision.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<!DOCTYPE HTML>
<html>
<head>
<script src="../../../tests/lib/jquery.min.js"></script>
<script type="text/javascript" src="../../../crafty.js"></script>
</head>
<body>
<h1>Collision playground:</h1>
<div id="cr-stage" style="border: solid black 8px;"></div>
<script type="text/javascript" src="collision.js"></script>
<div>
<h4>Hit checks (these are written to the console):</h4>
<style>th,td{border: solid 1px; padding: 4px; text-align: center }</style>
<table style="border-spacing: 0">
<tr>
<th></th>
<th>Trapezoid</th>
<th>Parallelogram</th>
<th>Square (Yellow)</th>
<th>Square (Purple)</th>
<th>Square (Green)</th>
</tr>
<tr>
<th>Trapezoid</th>
<td></td>
<td><input type='checkbox' onclick="setHitEvents(this.checked, trapezoid, 'Parallelogram');"></input></td>
<td><input type='checkbox' onclick="setHitEvents(this.checked, trapezoid, 'Yellow');"></input></td>
<td><input type='checkbox' onclick="setHitEvents(this.checked, trapezoid, 'Purple');"></input></td>
<td><input type='checkbox' onclick="setHitEvents(this.checked, trapezoid, 'Green');"></input></td>
<td><button onclick="trapezoid.resetHitChecks();">Reset check</button></td>
</tr>
<tr>
<th>Parallelogram</th>
<td><input type='checkbox' onclick="setHitEvents(this.checked, parallelogram, 'Trapezoid');"></input></td>
<td></td>
<td><input type='checkbox' onclick="setHitEvents(this.checked, parallelogram, 'Yellow');"></input></td>
<td><input type='checkbox' onclick="setHitEvents(this.checked, parallelogram, 'Purple');"></input></td>
<td><input type='checkbox' onclick="setHitEvents(this.checked, parallelogram, 'Green');"></input></td>
<td><button onclick="parallelogram.resetHitChecks();">Reset check</button></td>
</tr>
<tr>
<th>Square (Yellow)</th>
<td><input type='checkbox' onclick="setHitEvents(this.checked, yellow, 'Trapezoid');"></input></td>
<td><input type='checkbox' onclick="setHitEvents(this.checked, yellow, 'Parallelogram');"></input></td>
<td></td>
<td><input type='checkbox' onclick="setHitEvents(this.checked, yellow, 'Purple');"></input></td>
<td><input type='checkbox' onclick="setHitEvents(this.checked, yellow, 'Green');"></input></td>
<td><button onclick="yellow.resetHitChecks();">Reset check</button></td>
</tr>
<tr>
<th>Square (Purple)</th>
<td><input type='checkbox' onclick="setHitEvents(this.checked, purple, 'Trapezoid');"></input></td>
<td><input type='checkbox' onclick="setHitEvents(this.checked, purple, 'Parallelogram');"></input></td>
<td><input type='checkbox' onclick="setHitEvents(this.checked, purple, 'Yellow');"></input></td>
<td></td>
<td><input type='checkbox' onclick="setHitEvents(this.checked, purple, 'Green');"></input></td>
<td><button onclick="purple.resetHitChecks();">Reset check</button></td>
</tr>
<tr>
<th>Square (Green)</th>
<td><input type='checkbox' onclick="setHitEvents(this.checked, green, 'Trapezoid');"></input></td>
<td><input type='checkbox' onclick="setHitEvents(this.checked, green, 'Parallelogram');"></input></td>
<td><input type='checkbox' onclick="setHitEvents(this.checked, green, 'Yellow');"></input></td>
<td><input type='checkbox' onclick="setHitEvents(this.checked, green, 'Purple');"></input></td>
<td></td>
<td><button onclick="green.resetHitChecks();">Reset check</button></td>
</tr>
</table>
</div>
</body>
</html>
49 changes: 49 additions & 0 deletions playgrounds/2D/collision/collision.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
Crafty.init(600, 600);

var trapezoid = Crafty.e('Trapezoid, 2D, DOM, Collision, SolidHitBox, Mouse, Draggable').setName('Trapezoid').
attr({w: 200, h: 100}).collision(new Crafty.polygon([50, 0], [0, 100], [200, 100], [150, 0]));
var yellow = Crafty.e('Yellow, 2D, DOM, Collision, SolidHitBox, Mouse, Draggable').setName('Yellow').
attr({w: 100, h: 100}).collision(new Crafty.polygon([0, 0], [0, 100], [100, 100], [100, 0]));
var parallelogram = Crafty.e('Parallelogram, 2D, DOM, Collision, SolidHitBox, Mouse, Draggable').setName('Parallelogram').
attr({w: 100, h: 100}).collision(new Crafty.polygon([0, 0], [25, 100], [100, 100], [75, 0]));
var green = Crafty.e('Green, 2D, DOM, Collision, Color, Mouse, Draggable').setName('Green').
attr({w: 100, h: 100}).color('rgb(47, 233, 87)').origin('center');
var purple = Crafty.e('Purple, 2D, DOM, Collision, Color, Mouse, Draggable').setName('Purple').
attr({w: 100, h: 100}).color('rgb(147, 33, 187)').origin('center');

trapezoid.attr({x: 300, y: 150});
yellow.attr({x: 50, y: 50});
parallelogram.attr({x: 350, y: 350});
green.attr({x: 100, y: 500});
purple.attr({x: 500, y: 500});

[trapezoid, yellow, parallelogram, green, purple].forEach(function(e) {
e.bind("HitOn", function(hitInfo) {
console.log("HitOn for " + e._entityName + " - " + hitInfoToText(hitInfo));
});

e.bind("HitOff", function(otherComponent) {
console.log("HitOff for " + e._entityName + " - stopped colliding with " + otherComponent);
});
});

var hitInfoToText = function(hitInfo) {
// Assume a single member in hitInfo
var result = "collided with " + hitInfo[0].obj._entityName + " (" + hitInfo[0].type;
if (hitInfo[0].type === "SAT") {
result += ", " + hitInfo[0].overlap;
}

result += ")";

return result;
};

var setHitEvents = function(on, entity, hitComponent) {
if (on === true) {
entity.checkHits(hitComponent);
}
else {
entity.ignoreHits(hitComponent);
}
};
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
<!DOCTYPE HTML>
<html>
<head>
<script src="../lib/jquery.min.js"></script>
<link rel="stylesheet" href="../lib/qunit.css" type="text/css" media="screen" />
<script type="text/javascript" src="../lib/qunit.js"></script>
<script src="../../tests/lib/jquery.min.js"></script>
<script type="text/javascript" src="../../crafty.js"></script>
</head>
<body>
<h1 id="qunit-header">Crafty: Animation</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">test markup, will be hidden</div>
<h3>Sprite animation playground:</h3>
<h1>Sprite animation playground:</h1>
<div id="cr-stage"></div>
<script type="text/javascript" src="sprite-animation.js"></script>
<div>
Expand All @@ -25,23 +17,17 @@ <h3>Sprite animation playground:</h3>
<option value="short">Short</option>
<option value="countSlow">Count Slow</option>
</select>

<label for="playRepeatCount">Loops:</label>
<input type="number" id="playRepeatCount"></input>

</div>
<div>
<button onclick="playgroundPosition();">Jump to</button>
<input type="number" id="reelPosition"></input>
</div>
<div>
<button onclick="playgroundPause();">Pause</button>

<button onclick="playgroundResume();">Resume</button>

<button onclick="playgroundReset();">Reset</button>

</div>

</body>
</html>
48 changes: 48 additions & 0 deletions playgrounds/animation/sprite-animation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Crafty.init(100, 100);

var spriteAnimation = null;

// Initialize a sprite component
Crafty.sprite(64, '../../tests/animation/numbers.png', { 'numbers': [0, 0] });

// Add an animation to the stage
spriteAnimation = Crafty.e('2D, DOM, numbers, SpriteAnimation');
spriteAnimation.attr({ x: 10, y: 10 });
spriteAnimation.reel('count', 200, 0, 0, 10); // 10 frames duration
spriteAnimation.reel('countSlow', 1200, 0, 0, 10); //60 frames duration
spriteAnimation.reel('countEven', 100, [[0, 0], [2, 0], [4, 0], [6, 0], [8, 0]]); // 5 frames
spriteAnimation.reel('short', 60, 0, 0, 3); // 3 frames

spriteAnimation.reel("count").resetAnimation().pauseAnimation();
spriteAnimation.reel("countEven").resetAnimation().pauseAnimation();
spriteAnimation.reel("countSlow").resetAnimation().pauseAnimation();
spriteAnimation.reel("short").resetAnimation().pauseAnimation();

// Some extra functions for the animation playground
playgroundPlay = function() {
reelId = $('#playReelId').val();

loopCount = parseInt($('#playRepeatCount').val());
if (isNaN(loopCount)) loopCount = 1;

spriteAnimation.animate(reelId, loopCount);
}

playgroundPosition = function() {
var pos = parseInt($('#reelPosition').val());
if (isNaN(pos)) pos = 0;
spriteAnimation.reelPosition(pos);
}

playgroundPause = function() {
spriteAnimation.pauseAnimation();
}

playgroundResume = function() {

spriteAnimation.resumeAnimation();
}

playgroundReset = function() {
spriteAnimation.resetAnimation();
}
Loading

0 comments on commit 00acaeb

Please sign in to comment.