Skip to content

Commit 00acaeb

Browse files
committed
Merge branch 'develop' into testing
Conflicts: tests/dom_translate.js
2 parents 4e3328b + 4b8e564 commit 00acaeb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+4995
-3550
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ node_js:
33
- "0.10"
44
before_script:
55
- npm install -g grunt-cli
6+
cache:
7+
directories:
8+
- node_modules

Gruntfile.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,14 @@ var fs = require('fs');
33

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

14-
var getFiles = function (){
15-
return fileList;
16-
};
17-
1814
var docGen = function(){
1915
done = this.async();
2016
buildDir = "build/api/";
@@ -24,7 +20,8 @@ module.exports = function (grunt) {
2420
done();
2521
};
2622
var md = require("./build/api-gen");
27-
md.document(getFiles(), buildDir, "build/template.html", version, callback);
23+
md.document(grunt.file.expand('src/*.js'),
24+
buildDir, "build/template.html", version, callback);
2825
};
2926

3027
// Project configuration.
@@ -47,12 +44,12 @@ module.exports = function (grunt) {
4744
browserify: {
4845
dist: {
4946
files: {
50-
'crafty.js': ['src/*.js']
47+
'crafty.js': ['src/crafty.js']
5148
}
5249
},
5350
debug: {
5451
files: {
55-
'crafty.js': ['src/*.js']
52+
'crafty.js': ['src/crafty.js']
5653
},
5754
options: {
5855
debug: true
@@ -76,23 +73,23 @@ module.exports = function (grunt) {
7673
},
7774

7875
jshint: {
79-
files: ['Gruntfile.js', 'src/**/*.js', 'tests/*.js'],
76+
files: ['Gruntfile.js', 'src/**/*.js', 'tests/**/*.js'],
8077
options: {
8178
trailing: true,
79+
ignores: ['tests/lib/*.js'],
8280
globals: {
8381
}
8482
}
8583
},
8684

8785
qunit: {
8886
all: [
89-
'tests/index.html',
90-
'tests/animation/animation.html'
87+
'tests/index.html'
9188
]
9289
},
9390

9491
jsvalidate: {
95-
files: ['crafty.js', 'tests/*.js']
92+
files: ['crafty.js', 'tests/**/*.js']
9693
},
9794

9895
connect: {

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# Crafty JS
1+
# Crafty JS [![Build Status](https://travis-ci.org/craftyjs/Crafty.png?branch=develop)](https://travis-ci.org/craftyjs/Crafty)
2+
23

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

bower.json

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
{
22
"name": "crafty",
3-
"main": "crafty.js",
43
"version": "0.6.2",
5-
"repository": {
6-
"type": "git",
7-
"url": "git://github.com/craftyjs/Crafty.git"
8-
}
4+
"main": "dist/crafty.js",
5+
"license": "MIT",
6+
"ignore": [
7+
"**/.*",
8+
"build",
9+
"playgrounds",
10+
"test",
11+
"*.md",
12+
"changelog.txt",
13+
"Gruntfile.js",
14+
"package.json"
15+
]
916
}

package.json

Lines changed: 12 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"branches": {
1010
"develop": true
1111
},
12+
"main": "src/crafty.js",
1213
"repository": {
1314
"type": "git",
1415
"url": "https://github.com/craftyjs/Crafty.git"
@@ -33,49 +34,19 @@
3334
},
3435
"jsfiddle": "disable",
3536
"homepage": "https://github.com/craftyjs/Crafty",
36-
"files": [
37-
"src/core.js",
38-
"src/HashMap.js",
39-
"src/2D.js",
40-
"src/scenes.js",
41-
"src/collision.js",
42-
"src/DOM.js",
43-
"src/html.js",
44-
"src/storage.js",
45-
"src/extensions.js",
46-
"src/viewport.js",
47-
"src/device.js",
48-
"src/sprite.js",
49-
"src/canvas.js",
50-
"src/controls.js",
51-
"src/animation.js",
52-
"src/sprite-animation.js",
53-
"src/drawing.js",
54-
"src/isometric.js",
55-
"src/diamondiso.js",
56-
"src/particles.js",
57-
"src/sound.js",
58-
"src/text.js",
59-
"src/loader.js",
60-
"src/math.js",
61-
"src/time.js",
62-
"src/DebugLayer.js",
63-
"src/keycodes.js"
64-
],
6537
"dependencies": {
66-
"grunt": "~0.4.1",
67-
"grunt-contrib-uglify": "0.2.0",
68-
"grunt-contrib-concat": "0.3.0",
69-
"grunt-contrib-jshint": "0.5.2",
70-
"grunt-contrib-qunit": "0.2.1",
71-
"grunt-jsvalidate": "0.2.1",
72-
"marked": "0.2.9",
73-
"coffee-script": "1.6.3",
74-
"grunt-browserify": "~1.2.9",
75-
"grunt-banner": "~0.2.0",
76-
"grunt-contrib-watch": "~0.5.3"
7738
},
7839
"devDependencies": {
79-
"grunt-contrib-connect": "~0.6.0"
40+
"grunt-contrib-connect": "^0.8.0",
41+
"coffee-script": "1.7.1",
42+
"grunt": "^0.4.5",
43+
"grunt-banner": "^0.2.3",
44+
"grunt-browserify": "^2.1.4",
45+
"grunt-contrib-jshint": "^0.10.0",
46+
"grunt-contrib-qunit": "^0.4.0",
47+
"grunt-contrib-uglify": "^0.5.1",
48+
"grunt-contrib-watch": "^0.6.1",
49+
"grunt-jsvalidate": "^0.2.2",
50+
"marked": "^0.3.2"
8051
}
8152
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<!DOCTYPE HTML>
2+
<html>
3+
<head>
4+
<script src="../../../tests/lib/jquery.min.js"></script>
5+
<script type="text/javascript" src="../../../crafty.js"></script>
6+
</head>
7+
<body>
8+
<h1>Collision playground:</h1>
9+
<div id="cr-stage" style="border: solid black 8px;"></div>
10+
<script type="text/javascript" src="collision.js"></script>
11+
<div>
12+
<h4>Hit checks (these are written to the console):</h4>
13+
<style>th,td{border: solid 1px; padding: 4px; text-align: center }</style>
14+
<table style="border-spacing: 0">
15+
<tr>
16+
<th></th>
17+
<th>Trapezoid</th>
18+
<th>Parallelogram</th>
19+
<th>Square (Yellow)</th>
20+
<th>Square (Purple)</th>
21+
<th>Square (Green)</th>
22+
</tr>
23+
<tr>
24+
<th>Trapezoid</th>
25+
<td></td>
26+
<td><input type='checkbox' onclick="setHitEvents(this.checked, trapezoid, 'Parallelogram');"></input></td>
27+
<td><input type='checkbox' onclick="setHitEvents(this.checked, trapezoid, 'Yellow');"></input></td>
28+
<td><input type='checkbox' onclick="setHitEvents(this.checked, trapezoid, 'Purple');"></input></td>
29+
<td><input type='checkbox' onclick="setHitEvents(this.checked, trapezoid, 'Green');"></input></td>
30+
<td><button onclick="trapezoid.resetHitChecks();">Reset check</button></td>
31+
</tr>
32+
<tr>
33+
<th>Parallelogram</th>
34+
<td><input type='checkbox' onclick="setHitEvents(this.checked, parallelogram, 'Trapezoid');"></input></td>
35+
<td></td>
36+
<td><input type='checkbox' onclick="setHitEvents(this.checked, parallelogram, 'Yellow');"></input></td>
37+
<td><input type='checkbox' onclick="setHitEvents(this.checked, parallelogram, 'Purple');"></input></td>
38+
<td><input type='checkbox' onclick="setHitEvents(this.checked, parallelogram, 'Green');"></input></td>
39+
<td><button onclick="parallelogram.resetHitChecks();">Reset check</button></td>
40+
</tr>
41+
<tr>
42+
<th>Square (Yellow)</th>
43+
<td><input type='checkbox' onclick="setHitEvents(this.checked, yellow, 'Trapezoid');"></input></td>
44+
<td><input type='checkbox' onclick="setHitEvents(this.checked, yellow, 'Parallelogram');"></input></td>
45+
<td></td>
46+
<td><input type='checkbox' onclick="setHitEvents(this.checked, yellow, 'Purple');"></input></td>
47+
<td><input type='checkbox' onclick="setHitEvents(this.checked, yellow, 'Green');"></input></td>
48+
<td><button onclick="yellow.resetHitChecks();">Reset check</button></td>
49+
</tr>
50+
<tr>
51+
<th>Square (Purple)</th>
52+
<td><input type='checkbox' onclick="setHitEvents(this.checked, purple, 'Trapezoid');"></input></td>
53+
<td><input type='checkbox' onclick="setHitEvents(this.checked, purple, 'Parallelogram');"></input></td>
54+
<td><input type='checkbox' onclick="setHitEvents(this.checked, purple, 'Yellow');"></input></td>
55+
<td></td>
56+
<td><input type='checkbox' onclick="setHitEvents(this.checked, purple, 'Green');"></input></td>
57+
<td><button onclick="purple.resetHitChecks();">Reset check</button></td>
58+
</tr>
59+
<tr>
60+
<th>Square (Green)</th>
61+
<td><input type='checkbox' onclick="setHitEvents(this.checked, green, 'Trapezoid');"></input></td>
62+
<td><input type='checkbox' onclick="setHitEvents(this.checked, green, 'Parallelogram');"></input></td>
63+
<td><input type='checkbox' onclick="setHitEvents(this.checked, green, 'Yellow');"></input></td>
64+
<td><input type='checkbox' onclick="setHitEvents(this.checked, green, 'Purple');"></input></td>
65+
<td></td>
66+
<td><button onclick="green.resetHitChecks();">Reset check</button></td>
67+
</tr>
68+
</table>
69+
</div>
70+
</body>
71+
</html>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
Crafty.init(600, 600);
2+
3+
var trapezoid = Crafty.e('Trapezoid, 2D, DOM, Collision, SolidHitBox, Mouse, Draggable').setName('Trapezoid').
4+
attr({w: 200, h: 100}).collision(new Crafty.polygon([50, 0], [0, 100], [200, 100], [150, 0]));
5+
var yellow = Crafty.e('Yellow, 2D, DOM, Collision, SolidHitBox, Mouse, Draggable').setName('Yellow').
6+
attr({w: 100, h: 100}).collision(new Crafty.polygon([0, 0], [0, 100], [100, 100], [100, 0]));
7+
var parallelogram = Crafty.e('Parallelogram, 2D, DOM, Collision, SolidHitBox, Mouse, Draggable').setName('Parallelogram').
8+
attr({w: 100, h: 100}).collision(new Crafty.polygon([0, 0], [25, 100], [100, 100], [75, 0]));
9+
var green = Crafty.e('Green, 2D, DOM, Collision, Color, Mouse, Draggable').setName('Green').
10+
attr({w: 100, h: 100}).color('rgb(47, 233, 87)').origin('center');
11+
var purple = Crafty.e('Purple, 2D, DOM, Collision, Color, Mouse, Draggable').setName('Purple').
12+
attr({w: 100, h: 100}).color('rgb(147, 33, 187)').origin('center');
13+
14+
trapezoid.attr({x: 300, y: 150});
15+
yellow.attr({x: 50, y: 50});
16+
parallelogram.attr({x: 350, y: 350});
17+
green.attr({x: 100, y: 500});
18+
purple.attr({x: 500, y: 500});
19+
20+
[trapezoid, yellow, parallelogram, green, purple].forEach(function(e) {
21+
e.bind("HitOn", function(hitInfo) {
22+
console.log("HitOn for " + e._entityName + " - " + hitInfoToText(hitInfo));
23+
});
24+
25+
e.bind("HitOff", function(otherComponent) {
26+
console.log("HitOff for " + e._entityName + " - stopped colliding with " + otherComponent);
27+
});
28+
});
29+
30+
var hitInfoToText = function(hitInfo) {
31+
// Assume a single member in hitInfo
32+
var result = "collided with " + hitInfo[0].obj._entityName + " (" + hitInfo[0].type;
33+
if (hitInfo[0].type === "SAT") {
34+
result += ", " + hitInfo[0].overlap;
35+
}
36+
37+
result += ")";
38+
39+
return result;
40+
};
41+
42+
var setHitEvents = function(on, entity, hitComponent) {
43+
if (on === true) {
44+
entity.checkHits(hitComponent);
45+
}
46+
else {
47+
entity.ignoreHits(hitComponent);
48+
}
49+
};
Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
<!DOCTYPE HTML>
22
<html>
33
<head>
4-
<script src="../lib/jquery.min.js"></script>
5-
<link rel="stylesheet" href="../lib/qunit.css" type="text/css" media="screen" />
6-
<script type="text/javascript" src="../lib/qunit.js"></script>
4+
<script src="../../tests/lib/jquery.min.js"></script>
75
<script type="text/javascript" src="../../crafty.js"></script>
86
</head>
97
<body>
10-
<h1 id="qunit-header">Crafty: Animation</h1>
11-
<h2 id="qunit-banner"></h2>
12-
<div id="qunit-testrunner-toolbar"></div>
13-
<h2 id="qunit-userAgent"></h2>
14-
<ol id="qunit-tests"></ol>
15-
<div id="qunit-fixture">test markup, will be hidden</div>
16-
<h3>Sprite animation playground:</h3>
8+
<h1>Sprite animation playground:</h1>
179
<div id="cr-stage"></div>
1810
<script type="text/javascript" src="sprite-animation.js"></script>
1911
<div>
@@ -25,23 +17,17 @@ <h3>Sprite animation playground:</h3>
2517
<option value="short">Short</option>
2618
<option value="countSlow">Count Slow</option>
2719
</select>
28-
2920
<label for="playRepeatCount">Loops:</label>
3021
<input type="number" id="playRepeatCount"></input>
31-
3222
</div>
3323
<div>
3424
<button onclick="playgroundPosition();">Jump to</button>
3525
<input type="number" id="reelPosition"></input>
3626
</div>
3727
<div>
3828
<button onclick="playgroundPause();">Pause</button>
39-
4029
<button onclick="playgroundResume();">Resume</button>
41-
4230
<button onclick="playgroundReset();">Reset</button>
43-
4431
</div>
45-
4632
</body>
4733
</html>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
Crafty.init(100, 100);
2+
3+
var spriteAnimation = null;
4+
5+
// Initialize a sprite component
6+
Crafty.sprite(64, '../../tests/animation/numbers.png', { 'numbers': [0, 0] });
7+
8+
// Add an animation to the stage
9+
spriteAnimation = Crafty.e('2D, DOM, numbers, SpriteAnimation');
10+
spriteAnimation.attr({ x: 10, y: 10 });
11+
spriteAnimation.reel('count', 200, 0, 0, 10); // 10 frames duration
12+
spriteAnimation.reel('countSlow', 1200, 0, 0, 10); //60 frames duration
13+
spriteAnimation.reel('countEven', 100, [[0, 0], [2, 0], [4, 0], [6, 0], [8, 0]]); // 5 frames
14+
spriteAnimation.reel('short', 60, 0, 0, 3); // 3 frames
15+
16+
spriteAnimation.reel("count").resetAnimation().pauseAnimation();
17+
spriteAnimation.reel("countEven").resetAnimation().pauseAnimation();
18+
spriteAnimation.reel("countSlow").resetAnimation().pauseAnimation();
19+
spriteAnimation.reel("short").resetAnimation().pauseAnimation();
20+
21+
// Some extra functions for the animation playground
22+
playgroundPlay = function() {
23+
reelId = $('#playReelId').val();
24+
25+
loopCount = parseInt($('#playRepeatCount').val());
26+
if (isNaN(loopCount)) loopCount = 1;
27+
28+
spriteAnimation.animate(reelId, loopCount);
29+
}
30+
31+
playgroundPosition = function() {
32+
var pos = parseInt($('#reelPosition').val());
33+
if (isNaN(pos)) pos = 0;
34+
spriteAnimation.reelPosition(pos);
35+
}
36+
37+
playgroundPause = function() {
38+
spriteAnimation.pauseAnimation();
39+
}
40+
41+
playgroundResume = function() {
42+
43+
spriteAnimation.resumeAnimation();
44+
}
45+
46+
playgroundReset = function() {
47+
spriteAnimation.resetAnimation();
48+
}

0 commit comments

Comments
 (0)