-
Notifications
You must be signed in to change notification settings - Fork 559
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Conflicts: tests/dom_translate.js
- Loading branch information
Showing
52 changed files
with
4,995 additions
and
3,550 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,6 @@ node_js: | |
- "0.10" | ||
before_script: | ||
- npm install -g grunt-cli | ||
cache: | ||
directories: | ||
- node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
Oops, something went wrong.