Advertisement
Flavio1234

Animação de bolas: Class

Sep 16th, 2020
784
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.86 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ProjetoImagem
  8. {
  9.     public class cl_bola
  10.     {
  11.         public int x = 50;
  12.         public int y = 50;
  13.         public int velocidade_x = 10;
  14.         public int velocidade_y = 10;
  15.  
  16.         public void Mover(int largura, int altura)
  17.         {
  18.             x += velocidade_x;
  19.             y += velocidade_y;
  20.  
  21.             //detecção de colisões
  22.             if(x + 50>= largura)
  23.                 velocidade_x = -velocidade_x;
  24.             //esquerda
  25.             if (x <= 0)
  26.                 velocidade_x = -velocidade_x;
  27.             //topo
  28.             if (y <= 0)
  29.                 velocidade_y = -velocidade_y;
  30.  
  31.             //fundo
  32.             if (y + 50 >= altura)
  33.                 velocidade_y = -velocidade_y;
  34.  
  35.         }
  36.     }
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement