update里
switch(this.direction){
case 'l':
car.x >= 0 ? car.x-- : null;
break;
case 'r':
car.x <= mapWidth ? car.x++ : null;
break;
case 'u':
car.y <= mapHeight ? car.y++ : null;
break;
case 'd':
car.y >= 0 ? car.y-- : null;
break;
default:
break;
}
var x = MAX(car.x, size.width/2);
var y = MAX(car.y, size.height/2);
x = MIN(x, mapWidth - size.width/2);
y = MIN(y, mapHeight - size.height/2);
map.setPosition(size.width/2 - x, size.height/2 - y)
网友评论