..:: MX Studio Fóruns ::..: tiro com _rotation - ..:: MX Studio Fóruns ::..

Jump to content

Publicidade




Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

tiro com _rotation

#1 User is offline   GabrielM 

  • Group: Membros
  • Posts: 5
  • Joined: 09-September 09

Posted 09 September 2009 - 12:40 AM

estou com uma dúvida, estou desenvolvendo um jogo de uma navesinha que atira e coloquei uma função para que quando
eu aperto para a direita ela se vira(_rotation)para a direita e quando eu aperto pra esquerda ela também se vira(_rotation) pra esquerda,
só que queria que o tiro que ela atirasse saisse em alinhado e em direção da nave, aqui vai o código da nave

class nave extends MovieClip
{
var velocidade
function onLoad()
{
velocidade = 10
}
function onEnterFrame()
{
if( Key.isDown(Key.LEFT)){_x -= velocidade;if(_rotation > -17){ _rotation -= 2
}}
if( Key.isDown(Key.RIGHT)){ _x += velocidade;if(_rotation < 17){_rotation += 2
}}
if( Key.isDown(Key.UP)){ _y -= velocidade; }
if( Key.isDown(Key.DOWN)){ _y += velocidade; }
if(_rotation > - 17, _rotation < 1){_rotation +=1}
if(_rotation < 17, _rotation > - 1){_rotation -=1}
if( Key.isDown(Key.SPACE))
{
var missil = _root.attachMovie("Missil","Missil" + _root.getNextHighestDepth(), _root.getNextHighestDepth());
missil._x = _x + 3;
missil._y = _y - 44;
}

}
}

0

#2 User is offline   D.passoni 

  • Group: Membros
  • Posts: 33
  • Joined: 04-October 08

Posted 14 September 2009 - 05:44 PM

Olá, tudo bem?

Vai no Movieclip missil, aperta F9 e coloca esse código.

CÓDIGO
onClipEvent (load) {
    if (this._name == "missil") {
        this._visible = false;
    } else {
        this._visible = true;
        velocidade = 0;
        this._rotation = _root.nave._rotation;// coloca no lugar da " nave "o nome do Movieclip da nave
    }
}
onClipEvent (enterFrame) {
    if (this._name<>"missil") {
        if (velocidade<6) {
            velocidade += 0.1;
        }
        velX = Math.sin(this._rotation*(Math.PI/180))*velocidade;
        velY = Math.cos(this._rotation*(Math.PI/180))*velocidade;

        this._x += velX;
        this._y -= velY;
    }
}


Não esquece de instanciar seu movieClip nave(se não tiver feito ainda, instancia como "nave"[sem aspas])

0

#3 User is offline   GabrielM 

  • Group: Membros
  • Posts: 5
  • Joined: 09-September 09

  Posted 17 September 2009 - 11:58 PM

muito obrigado, fiz algumas alterações no actionscript para torna-lo outside clip, funcionou certinho, muito obrigado, alterei também a velocidade e adicionei um "if" para ele tirar o missil se el passar de y = 0, ai vai o código de como ficou:
CÓDIGO
class missil extends MovieClip
{
    var velocidade
    var velX
    var velY
    
    function onLoad()
    {
        if (this._name == "missil") {
        this._visible = false;
    } else {
        this._visible = true;
        velocidade = 0;
        this._rotation = _root.naves._rotation;
    }
    }
    function onEnterFrame()
    {
      if (this._name<>"missil") {
        if (velocidade<10) {
            velocidade += 0.5;
        }
        velX = Math.sin(this._rotation*(Math.PI/180))*velocidade;
        velY = Math.cos(this._rotation*(Math.PI/180))*velocidade;

        this._x += velX;
        this._y -= velY;
        if(this._y < 0)
        {
            this.removeMovieClip()
        }
    }
}

queria fazer algumas perguntas, para entender melhor o código, math.sin é o seno? e math . cos é o coseno ? math.pi é o pi de 180 ? poderia explicar melhor essa linha de código:
CÓDIGO
        velX = Math.sin(this._rotation*(Math.PI/180))*velocidade;
        velY = Math.cos(this._rotation*(Math.PI/180))*velocidade;

tenho certeza que ajudaria muita gente muito obrigado desde já

E tenho mais uma dúvida, agra o missil vai em linha certinho só que ele não sai da ponta da arma, n sei como fazer isso poderia me explicar como fazer ele sair da ponta da arma msm com ele girando, e também tá dando um bug, aperto pra ele ir pra frente, pra girar pra um lado(qualquer um) e espaço pra ele atirar ai paro de aperta pra ele i prum lado e aperto pra ele i pra otro ele n vira ¬¬ me ajuda ae, vo manda o código da nave:
CÓDIGO
class nave extends MovieClip
{
    var velX
    var velY
    var vida
    var velocidade
    function onLoad()
    {
        vida = -100
        velocidade = 10
    }
    function onEnterFrame()
    {
        if( Key.isDown(Key.UP)){ _y -= velY, _x += velX; }
        if( Key.isDown(Key.DOWN)){ _y += velY, _x-=velX;}
        if( Key.isDown(Key.SPACE))
            {
                var missil = _root.attachMovie("Missil","Missil" + _root.getNextHighestDepth(), _root.getNextHighestDepth());
                missil._x = _x + 3;
                missil._y = _y - 46;                
            }
            
        if( Key.isDown(Key.LEFT)){_rotation -= 8}
        if( Key.isDown(Key.RIGHT)){_rotation += 8}
            
        velX = Math.sin(this._rotation*(Math.PI/180))*velocidade;
        velY = Math.cos(this._rotation*(Math.PI/180))*velocidade;
        _root.vidas._rotation = vida + 10
        _root.texto.text = vida
        _root.rotations.text = _root.vidas._rotation
    }
}

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic



Publicidade




2 User(s) are reading this topic
0 membro(s), 2 visitante(s) e 0 membros anônimo(s)