function step(who) {
//check to see if the car in question is controlled by the player or by the computer
if (_root["car"+who].code == "player") {
//we will constantly decrease speed by multiplying it with a number below 1
if (this["speed"+who]>0.3) {
this["speed"+who] *= _root.speedDecay;
} else {
this["speed"+who] = 0;
}
//the car will react to certain keys
//accelerate
if (Key.isDown(Key.UP) && this["speed"+who]<_root.maxSpeed) {
this["speed"+who] += _root.acceleration;
}
//brake (reverse)
if (Key.isDown(Key.DOWN)) {
this["speed"+who] -= _root.backSpeed;
}
//steer left
if (Key.isDown(Key.LEFT) && this["speed"+who]>0.3) {
_root["car"+who]._rotation -= _root.rotationStep*(this["speed"+who]/_root.maxSpeed);
}
//steer right
if (Key.isDown(Key.RIGHT) && this["speed"+who]>0.3) {
_root["car"+who]._rotation += _root.rotationStep*(this["speed"+who]/_root.maxSpeed);
}
this["rotation"+who] = _root["car"+who]._rotation;
//we calculate the two components of speed (X axis and Y axis)
this["speedx"+who] = Math.sin(this["rotation"+who]*(Math.PI/180))*this["speed"+who];
this["speedy"+who] = Math.cos(this["rotation"+who]*(Math.PI/180))*this["speed"+who]*-1;
//apply the components on the actual position of the car
_root["car"+who]._x += this["speedx"+who];
_root["car"+who]._y += this["speedy"+who];
//position the shadow of the car
_root["shadow"+who]._x = _root["car"+who]._x-4;
_root["shadow"+who]._y = _root["car"+who]._y+2;
_root["shadow"+who]._rotation = _root["car"+who]._rotation;
}
if (_root["car"+who].code == "computer") {
}
}
Encontrei esse código num tutorial, gostava de saber como colocar awsd em vez das teclas direcionais.
No caso seu, seria para o maker né? Bom, se for cê teria de especificar pra qual. Bom deixarei um code abaixo que funciona, mas precisará do meu core (http://dax-soft.weebly.com/dax-core.html) pra funcionar.
class << Key
#----------------------------------------------------------------------------
# • Movimento em WSAD.
#----------------------------------------------------------------------------
def wsad
return 8 if press?(W)
return 4 if press?(A)
return 6 if press?(D)
return 2 if press?(S)
return 0
end
end
class Game_Player < Game_Character
#--------------------------------------------------------------------------
# * Processamento de movimento através de pressionar tecla
#--------------------------------------------------------------------------
def move_by_input
return if !movable? || $game_map.interpreter.running?
move_straight(Key.wsad) if Key.wsad > 0
end
end
não é para o maker mas para o Flash, se substituir UP por W dá erro
Bom eu não programo nessa linguagem, mas tenta :
function step(who) {
//check to see if the car in question is controlled by the player or by the computer
if (_root["car"+who].code == "player") {
//we will constantly decrease speed by multiplying it with a number below 1
if (this["speed"+who]>0.3) {
this["speed"+who] *= _root.speedDecay;
} else {
this["speed"+who] = 0;
}
//the car will react to certain keys
//accelerate
if (Key.isDown(87) && this["speed"+who]<_root.maxSpeed) {
this["speed"+who] += _root.acceleration;
}
//brake (reverse)
if (Key.isDown(83)) {
this["speed"+who] -= _root.backSpeed;
}
//steer left
if (Key.isDown(65) && this["speed"+who]>0.3) {
_root["car"+who]._rotation -= _root.rotationStep*(this["speed"+who]/_root.maxSpeed);
}
//steer right
if (Key.isDown(68) && this["speed"+who]>0.3) {
_root["car"+who]._rotation += _root.rotationStep*(this["speed"+who]/_root.maxSpeed);
}
this["rotation"+who] = _root["car"+who]._rotation;
//we calculate the two components of speed (X axis and Y axis)
this["speedx"+who] = Math.sin(this["rotation"+who]*(Math.PI/180))*this["speed"+who];
this["speedy"+who] = Math.cos(this["rotation"+who]*(Math.PI/180))*this["speed"+who]*-1;
//apply the components on the actual position of the car
_root["car"+who]._x += this["speedx"+who];
_root["car"+who]._y += this["speedy"+who];
//position the shadow of the car
_root["shadow"+who]._x = _root["car"+who]._x-4;
_root["shadow"+who]._y = _root["car"+who]._y+2;
_root["shadow"+who]._rotation = _root["car"+who]._rotation;
}
if (_root["car"+who].code == "computer") {
}
}
Epah eu fiz exatamente isso e não deu comigo, você só substitui por números certo?
Aham..