Last active
July 11, 2018 13:11
-
-
Save malikkurosaki/7b993cd0e1421fd9880a7473d3569151 to your computer and use it in GitHub Desktop.
Crafty js simple collosion - malik kurosaki
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="crafty-min.js"></script> | |
</head> | |
<body> | |
<div id="game2"></div> | |
<script> | |
Crafty.init(); | |
Crafty.e("2D, Fourway, Collision, DOM, Color, WiredHitBox, player") | |
.attr({x: 32, y: 32, w: 32, h: 32}) | |
.collision([32,0,32,32,0,32,0,0]) | |
.color('green') | |
.fourway() | |
.bind('Move', function(evt) { | |
var hitData,hitDatas; | |
if((hitDatas = this.hit("solid"))){ | |
hitData = hitDatas[.0]; | |
if(hitData.type == "SAT"){ | |
this.x = evt._x; | |
this.y = evt._y; | |
} | |
} | |
}); | |
Crafty.e("2D, Collision, DOM, Color, WiredHitBox, solid") | |
.attr({x: 64, y: 64, w: 64, h: 64}) | |
.collision([64,0,64,64,0,64,0,0]) | |
.color('grey'); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment