【发布时间】:2020-08-13 08:21:48
【问题描述】:
所以游戏关卡数组是这样的,其中"@"是玩家
[".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."]
[".", ".", "#", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "#", ".", "."]
[".", ".", "#", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "=", ".", "#", ".", "."]
[".", ".", "#", ".", ".", ".", ".", ".", ".", ".", ".", ".", "o", ".", "o", ".", ".", ".", ".", "#", ".", "."]
[".", ".", "#", ".", "@", ".", ".", ".", ".", ".", ".", "#", "#", "#", "#", "#", ".", ".", ".", "#", ".", "."]
[".", ".", "#", "#", "#", "#", "#", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "#", ".", "."]
[".", ".", ".", ".", ".", ".", "#", "+", "+", "+", "+", "+", "+", "+", "+", "+", "+", "+", "+", "#", ".", "."]
[".", ".", ".", ".", ".", ".", "#", "#", "#", "#", "#", "#", "#", "#", "#", "#", "#", "#", "#", "#", ".", "."]
[".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "."]
class Vec {
constructor(x, y) {
this.x = x
this.y = y
}
plus(other) {
return new Vec(this.x + other.x, this.y + other.y)
}
times(factor) {
return new Vec(this.x * factor, this.y * factor)
}
}
class Player {
constructor(pos, speed) {
this.pos = pos;
this.speed = speed;
}
get type() { return "player"; }
static create(pos) {
return new Player(pos.plus(new Vec(0, -0.5)),
new Vec(0, 0));
}
}
Player.prototype.size = new Vec(0.8, 1.5);
我知道这是一个数学问题,而不是一个 js 问题,但是谁能告诉我这里的 x 和 y 坐标是如何选择的?我的意思是(0, -0.5)、(0,0) 和(0.8, 1.5)
static create(pos) {
return new Player(pos.plus(new Vec(0, -0.5)),
new Vec(0, 0));
}
Player.prototype.size = new Vec(0.8, 1.5);
因为玩家的高度是一个半方格,所以它的初始位置被设置为比@字符出现的位置高半个方格。这样,它的底部与它出现的正方形的底部对齐。
有人可以为我澄清这个疑问吗?谢谢。
【问题讨论】:
标签: javascript oop object math game-development