如何解决在javascript平台游戏中为玩家选择x和y坐标
所以游戏级别数组是这里,"@"
是玩家
[".",".","."]
[".","#","=","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));
}
Player.prototype.size = new Vec(0.8,1.5);
由于玩家的身高为一个半正方形,因此其初始位置设置为比@字符出现的位置高半个正方形。这样,它的底部与它出现的正方形的底部对齐。
有人可以为我澄清这个疑问吗?谢谢。
解决方法
发生了什么事,玩家的高度为1.5平方。因此,如果您希望玩家的脚在8点,那么玩家的头必须在6.5(8-1.5)。当您运行Player.create(pos) //Pos is a vector
时,它会返回一个新的Player对象,该对象的Player脚位于传递到Player.create(pos)
的原始位置。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。