--
You received this message because you are subscribed to the Google Groups "melonJS - A lightweight HTML5 game engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to melonjs+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
/* -----
update the player pos
------ */
update:
function
(dt) {
if
(me.input.isKeyPressed(
'left'
)) {
// flip the sprite on horizontal axis
this
.flipX(
true
); //// ERROR HERE
// update the entity velocity
this
.body.vel.x -=
this
.body.accel.x * me.timer.tick;
// change to the walking animation
if
(!
this
.renderable.isCurrentAnimation(
"walk"
)) {
this
.renderable.setCurrentAnimation(
"walk"
);
}
}
else
if
(me.input.isKeyPressed(
'right'
)) {
// unflip the sprite
this
.flipX(
false
);
// update the entity velocity
this
.body.vel.x +=
this
.body.accel.x * me.timer.tick;
// change to the walking animation
if
(!
this
.renderable.isCurrentAnimation(
"walk"
)) {
this
.renderable.setCurrentAnimation(
"walk"
);
}
}
else
{
this
.body.vel.x = 0;
// change to the standing animation
this
.renderable.setCurrentAnimation(
"stand"
);
}
if
(me.input.isKeyPressed(
'jump'
)) {
// make sure we are not already jumping or falling
if
(!
this
.body.jumping && !
this
.body.falling) {
// set current vel to the maximum defined value
// gravity will then do the rest
this
.body.vel.y = -
this
.body.maxVel.y * me.timer.tick;
// set the jumping flag
this
.body.jumping =
true
;
}
}
// apply physics to the body (this moves the entity)
this
.body.update(dt);
// handle collisions against other shapes
me.collision.check(
this
);
// return true if we moved or if the renderable was updated
return
(
this
._super(me.Entity,
'update'
, [dt]) ||
this
.body.vel.x !== 0 ||
this
.body.vel.y !== 0);
},
this.renderable.flipX(true);
case
me.collision.types.ENEMY_OBJECT:
if
((response.overlapV.y>0) && !
this
.body.jumping) {
// bounce (force jump)
this
.body.falling =
false
;
this
.body.vel.y = -
this
.body.maxVel.y * me.timer.tick;
// set the jumping flag
this
.body.jumping =
true
;
}
else
{
// let's flicker in case we touched an enemy
this
.renderable.flicker(750);
}
return
false
;
break
;
And this is the enemy code:
/**
* colision handler
* (called when colliding with other objects)
*/
onCollision :
function
(response, other) {
if
(response.b.body.collisionType !== me.collision.types.WORLD_SHAPE) {
// res.y >0 means touched by something on the bottom
// which mean at top position for this one
if
(
this
.alive && (response.overlapV.y > 0) && response.a.body.falling) {
this
.renderable.flicker(750);
}
return
false
;
}
// Make all other objects solid
return
true
;
}
Maybe the overlapsV is wrong because the enemy is not flickering when player jumped on them.
I andjusted it and now when I jump on them the enemy dissapears, but the plyer is flickering. Cannot figure out why.
// handle collisions against other shapes
this.collided = false;me.collision.check(this);
case me.collision.types.ENEMY_OBJECT:if (this.collided) {return false;
}if ((response.overlapV.y>0) && !this.body.jumping) {// bounce (force jump)this.body.falling = false;this.body.vel.y = -this.body.maxVel.y * me.timer.tick;// set the jumping flagthis.body.jumping = true;
// play some audiome.audio.play("stomp");// hurt enemyif (response.b.alive) {response.b.renderable.flicker(750);
}}else {// let's flicker in case we touched an enemythis.renderable.flicker(750);}
this.collided = true;return false;
if (response.b.body.collisionType !== me.collision.types.WORLD_SHAPE) {
return false;}// Make all other objects solidreturn true;
To unsubscribe from this group and stop receiving emails from it, send an email to melonjs+unsubscribe@googlegroups.com.