第一次做游戏。 我怎样才能使碰撞连接到我所有的怪物,而不必为缓冲区中的每个怪物设置碰撞功能。 我正在尝试做一个
collision.collisionTouch(monsters, missiles)
这是一个例子
class Collision{
constructor(){
this.position = {
x : 0,
y : 0
}
}
collisionObjects( object1, object2){
//collision work
}
}
class Monster {
constructor(){
this.position = {
x : 0,
y : 0
}
playerUpdate(){
// player update content here
}
}
}
class Missile {
constructor(){
this.position = {
x : 0,
y : 0
}
}
missileUpdate(){
//missile update draw ect
}
}
// GAME SET
const collision = new Collision();
const monster = new Monster();
const monsterTwo = new Monster();
const missile = new Missile();
function buffer(){
collision.collisionTouch(monster, missile);
collision.collisionTouch(monsterTwo, missile);
}
我不知道我是否会被允许这样做,或者我是否会被迫一一设置。我只是想减少编码。 对不起,如果你们不明白我说西班牙语在这里工作英语=)