antiblock
Elveron
  • Chatbox

    You don't have permission to chat.
    Load More
Sign in to follow this  
xavier1400

Actionscript 3.0 ajuda

4 posts in this topic

Boas, eu estou a criar um jogo de pong para um trabalho da escola mas tenho um problema.

Eu saquei da net um código para o jogo mas reparei que tem uns bugs quando a bola bate no jogador 1 ou no computador, só metade da barra do jogador é que está a funcionar, a outra não, ou seja metade da barra deixa a bola passar e não colide, eu acho que o erro está aqui mas não percebo muito bem disto.

 

    if(ball.x - bHalfWidth <= player.x + pHalfWidth) {
            if(Math.abs(ball.y - player.y) <= pHalfHeight) {
            vx = ballspeed;
            if(v1!=0){
                vy = 2*v1;
            }
            }
        }else if(ball.x + bHalfWidth >= computer.x - pHalfWidth) {
            if(Math.abs(ball.y - computer.y) <= pHalfHeight) {
            vx = -ballspeed;
            if(v2!=0){
                vy = v2;
            }
            }
        }

   
O mesmo acontece nas paredes verticais, se eu meter a barra do player 1 para baixo metade da barra desaparece, se eu meter para cima metade da barra fica invisivel.

       

 if(player.y + pHalfHeight > stage.stageHeight) {
            player.y = stage.stageHeight - pHalfHeight;
        }else if(player.y - pHalfHeight < 0) {
            player.y = 0 + pHalfHeight;
        }

        if(computer.y + pHalfHeight > stage.stageHeight) {
            computer.y = stage.stageHeight - pHalfHeight;
        }else if(computer.y - pHalfHeight < 0) {
            computer.y = 0 + pHalfHeight;
        }

 

Share this post


Link to post
Share on other sites
antiblock
Elveron

Torna-se difícil alguém dizer-te onde está o problema quando mandas apenas parte do código. Ninguém consegue adivinhar como pensaste isso e como construíste.

Além disso, uma sugestão minha era meteres prints e/ou gifs dos problemas que estás a ter, torna-se mais fácil de se perceber. 

Share this post


Link to post
Share on other sites

Concordo com o Loading devias ter metido o codigo inteiro.

Uma coisa que aprendi desde que comecei a programar, é fazer prints das variaveis em certas zonas do codigo para perceber que valores elas estao a tomar. Ajuda a descobrir o bug. 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this