First tries to function onhitStop()
This commit is contained in:
parent
fad7b3670e
commit
51186cfb30
1 changed files with 25 additions and 12 deletions
|
@ -52,8 +52,17 @@
|
|||
Crafty.c(
|
||||
"Creature", {
|
||||
init: function() {
|
||||
this.addComponent("Thing,Fourway,Draggable,Collision,WiredHitBox,Mouse,player");
|
||||
this.addComponent("Thing,Fourway,Draggable,Collision,WiredHitBox,Mouse,creature");
|
||||
},
|
||||
/* onhitStop: function(comp) {
|
||||
this.stopDrag();
|
||||
var hb;
|
||||
while( (hb=this.hit(comp)) && (this.hit(comp)[0].normal) ) {
|
||||
this.x += Math.ceil(hb[0].normal.x * -hb[0].overlap);
|
||||
this.y += Math.ceil(hb[0].normal.y * -hb[0].overlap);
|
||||
}
|
||||
},*/
|
||||
|
||||
player: function(x,y,w,h,col) {
|
||||
this.h = h || 40;
|
||||
this.w = w || 40;
|
||||
|
@ -63,11 +72,24 @@
|
|||
.onHit("wall", function() {
|
||||
this.stopDrag();
|
||||
var hb;
|
||||
while( (hb=this.hit('wall')) && (this.hit('wall')[0].normal) ) {
|
||||
while( (hb=this.hit("wall")) && (this.hit("wall")[0].normal) ) {
|
||||
this.x += Math.ceil(hb[0].normal.x * -hb[0].overlap);
|
||||
this.y += Math.ceil(hb[0].normal.y * -hb[0].overlap);
|
||||
}
|
||||
})
|
||||
// this.onhitStop('wall')) // Function (see above) would be nicer, but doesn't work.
|
||||
.onHit("creature",function() {
|
||||
this.stopDrag();
|
||||
var hb;
|
||||
while( (hb=this.hit("creature")) && (this.hit("creature")[0].normal) ) {
|
||||
this.x += Math.ceil(hb[0].normal.x * -hb[0].overlap);
|
||||
this.y += Math.ceil(hb[0].normal.y * -hb[0].overlap);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
// this.onhitStop('creature'));
|
||||
this.bind('MouseDown', function(e) {
|
||||
if(e.mouseButton === Crafty.mouseButtons.LEFT) {
|
||||
this.old_pos["x"]=this.x;
|
||||
|
@ -83,15 +105,6 @@
|
|||
}
|
||||
}
|
||||
);
|
||||
/* var fig=Crafty.e('Collision, 2D, Canvas, Color,Fourway,Draggable,WiredHitBox,Mouse,player')
|
||||
.attr({x: 20, y: 20, w: 100, h: 100})
|
||||
.color('#F00')
|
||||
.fourway(4)
|
||||
.collision()
|
||||
.onHit("wall",function() {
|
||||
this.stopDrag();
|
||||
|
||||
});*/
|
||||
|
||||
var start_init = function() {
|
||||
Crafty.init(500,250, document.getElementById('game'));
|
||||
|
|
Loading…
Reference in a new issue