-2
「泥」のようなオブジェクトを作って、プレイヤーのxとyのスピードとジャンプスピードが立つときに遅くなるようにしたいのですが、どうすればいいですか?ここで今、プレイヤーのスピードを扱う私のコードの一部です:プラットフォームゲームでプレイヤーの速度を落とすオブジェクトを作成するにはどうすればよいですか?
var playerXSpeed = 7;
Player.prototype.moveX = function(step, level, keys) {
this.speed.x = 0;
if (keys.left) this.speed.x -= playerXSpeed;
if (keys.right) this.speed.x += playerXSpeed;
var motion = new Vector(this.speed.x * step, 0);
var newPos = this.pos.plus(motion);
var obstacle = level.obstacleAt(newPos, this.size);
if (obstacle)
level.playerTouched(obstacle);
else
this.pos = newPos;
};
var gravity = 34;
var jumpSpeed = 15:
var playerYSpeed = 6;
Player.prototype.moveY = function(step, level, keys) {
// Accelerate player downward (always)
this.speed.y += step * gravity;;
var motion = new Vector(0, this.speed.y * step);
var newPos = this.pos.plus(motion);
var obstacle = level.obstacleAt(newPos, this.size);
// The floor is also an obstacle -- only allow players to
// jump if they are touching some obstacle.
if (obstacle) {
level.playerTouched(obstacle);
if (keys.up && this.speed.y > 0)
this.speed.y = -jumpSpeed;
else
this.speed.y = 0;
} else {
this.pos = newPos;
}
};