//-------- MESAGENS REFERENTES A COMUNICAÇÃO DE REDES -------- public bool ColisaoInimigo(JogadorInimigo jogIni, float nX, float nY) { /* * Verifica se o player local ira se colidir com o outro player. * Se for colidir, retorna um valor verdadeiro. */ return Colisao(jogIni.GetX, jogIni.GetY, jogIni.GetTam, jogIni.GetTam, nX, nY); }
public bool Input(List<Obstaculo> lstObs, JogadorInimigo enemy) { /* * Verifica se está tendo colisão do player com algum obj ou se esta excedento os limites da tela antes de movimenta. * * Considere o seguinte para as comparações: * 1º: verifica a tecla que foi pressionada. * 2º: verifica se o player ira sair dos limites da tela, e for sair, impede a movimentação. * 3º: verifica se tem algum bloco no caminho. Se tiver, impede a movimentação. * * ------------- VERIFICA SE O PLAYER IRA COMLIDIR COM O OUTRO PLAYER * * Se esse player se colidir com o outro player, ele retorna um valor negativo e o programa envia para o outro programa * que havera uma colisão entre os dois jogadores, e interrompe a movimentação entre os dois jogadores. */ //if (System.Windows.Input.Keyboard.IsKeyDown(System.Windows.Input.Key.Up)) //{ // Console.WriteLine("key pressed"); //} //if (e.KeyChar == 'w' && this.yAtual - this.velocidadeAtual > inicioTelaY && !HasBlock(lstObs, 'w', this.xAtual, this.yAtual - this.velocidadeAtual)) if (Keyboard.IsKeyDown(Key.W) && this.yAtual - this.velocidadeAtual > inicioTelaY && !HasBlock(lstObs, 'w', this.xAtual, this.yAtual - this.velocidadeAtual)) { if (ColisaoInimigo(enemy, this.xAtual, this.yAtual - this.velocidadeAtual)) return false; this.proxDirecao = 'c'; EnviaMsgMov(this.xAtual, this.yAtual - this.velocidadeAtual); } //if (e.KeyChar == 's' && this.yAtual + this.velocidadeAtual < this.alturaTela - this.tamX && !HasBlock(lstObs, 's', this.xAtual, this.yAtual + this.velocidadeAtual) ) if (Keyboard.IsKeyDown(Key.S) && this.yAtual + this.velocidadeAtual < this.alturaTela - this.tamX && !HasBlock(lstObs, 's', this.xAtual, this.yAtual + this.velocidadeAtual)) { if (ColisaoInimigo(enemy, this.xAtual, this.yAtual + this.velocidadeAtual)) return false; this.proxDirecao = 'b'; EnviaMsgMov(this.xAtual, this.yAtual + this.velocidadeAtual); } if (Keyboard.IsKeyDown(Key.A) && this.xAtual - this.velocidadeAtual > 0 && !HasBlock(lstObs, 'a', this.xAtual - this.velocidadeAtual, this.yAtual)) { if (ColisaoInimigo(enemy, this.xAtual - this.velocidadeAtual, this.yAtual)) return false; this.proxDirecao = 'e'; EnviaMsgMov(this.xAtual - this.velocidadeAtual, this.yAtual); } if (Keyboard.IsKeyDown(Key.D) && this.xAtual + this.velocidadeAtual < this.larguraTela - this.tamX && !HasBlock(lstObs, 'd', this.xAtual + this.velocidadeAtual, this.yAtual)) { if (ColisaoInimigo(enemy, this.xAtual + this.velocidadeAtual, this.yAtual)) return false; this.proxDirecao = 'd'; EnviaMsgMov(this.xAtual + this.velocidadeAtual, this.yAtual); } return true; }
private void InicializaVariaveis(int qPlayer) { elementosJogo = new List<ElementoJogo>(); //cria a lista com todos os elementos do jogo. this.podeAtirar = true; //define que o jogador pode atirar. this.areaPlay = new AreaPlayers(this.pb.Size.Width, this.pb.Size.Height); //cria a rea de jogo do player. //refere-se a HUD do jogo. this.hud = new Interface(this.pb.Size.Width, this.pb.Size.Height); //cria a hud do jogo. Label[] lab = new Label[] { this.lbl_NomeJog, this.lbl_Placar, this.lbl_TempoRestante, this.lbl_Inativo, this.lbl_FinDeJogo };//pega as labels da hud do jogo que ta no form. this.hud.ConfgLabels(lab); //define as posições e tamanhos das labels que tem no jogo. this.qualPlayer = qPlayer; this.player = new Player(this.pb.Size.Width, this.pb.Size.Height, this.qualPlayer, this.frm_Inicio); playerEnemy = new JogadorInimigo(this.player.tamX, this.player.tamY, this.pb.Size.Width, this.pb.Size.Height, this.qualPlayer); elementosJogo.Add(player); //thread de desenho. this.desenha = new Thread(() => Draw()); this.desenha.Name = "DesenhaTela"; this.desenha.Start(); //timer que controle o tempo de jogo. this.tempoRestante = TIMEOUT; this.tm_UpdtTempoPartida.Start(); //cria as bandeiras que ha no jogo. this.bands = new Bandeira[2]; this.bands[0] = new Bandeira(this.areaPlay, 1); this.bands[1] = new Bandeira(this.areaPlay, 0); this.mB = qPlayer == 1 ? 0 : 1; //dis qual e a minha bandeira. //adicionas as bandeiras a lista de lemento de jogo e eo player. elementosJogo.Add(bands[0]); elementosJogo.Add(bands[1]); //cra a lista de tiros. this.tiros = new List<Tiro>(); this.tirosInimigos = new List<Tiro>(); //cria uma thread que ficara responsavel por verificar se houve alguma colisão do tiro com algum elemento do jogo. this.colisaoBala = new Thread(() => ColisaoDaBala()); this.colisaoBala.Name = "Colicao_Balas"; this.colisaoBala.Start(); //cria uma lista onde ficara armazenado os obstaculos. Cria os obstaculos do jogo. listaObs = new List<Obstaculo>(); CriaObstaculos(); //cria o powerUp do jogo e adiciona a lista de elementos do jogo. this.powerUp = new PowerUp(this.pb.Size.Width, this.pb.Size.Height);//cria o powerUp do jogo e adiciona a lista de elementos do jogo. elementosJogo.Add(powerUp); //atualiza a posição para o outro jogador this.player.ForcaEnvioPos(); //configura o botao que aparece no final da partida para voltar para a tela inicial de jogo. ConfiguraBotaoRetornoMenu(); //carrega a img do chao do campo de batalha e redimensiona para ocupar toda a area dejogo this.chao = Properties.Resources.areaJogo; this.chao = ResizeImage.ScaleImage(chao, LARGURA, ALTURA); }