void Awake() { if(sharedInstance==null){ sharedInstance = this; } else { GameObject.Destroy(gameObject); } }
protected void CriaSessao() { estado_atual = EstadoDeJogo.Loading; try { rede = NetworkSession.Create (NetworkSessionType.SystemLink, 2, 2); estado_atual = EstadoDeJogo.Lobby; ManipulaEventos (); } catch (Exception ex) { Console.WriteLine ("Erro: " + ex.Message); } }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear (Color.Black); spriteBatch.Begin (SpriteSortMode.Deferred, null, null, null, null, null, spriteScale); switch (estado_atual) { case EstadoDeJogo.Splash: splashScr.Draw (spriteBatch); break; case EstadoDeJogo.Menu: string mensagem = "N para nova sessao\nJ para juntar uma existente"; spriteBatch.DrawString (fonte, mensagem, new Vector2 (160f, 160f), Color.Gray); spriteBatch.DrawString (fonte, mensagem, new Vector2 (161f, 161f), Color.White); break; case EstadoDeJogo.Mapa: if (mapa != null) mapa.Draw (spriteBatch); foreach (NetworkGamer gamer in rede.AllGamers) { Personagem player = gamer.Tag as Personagem; player.Draw (spriteBatch, gameTime); } break; case EstadoDeJogo.Lobby: spriteBatch.DrawString (fonte, "Esperando jogadores", new Vector2 (100f, 100f), Color.Gray); spriteBatch.DrawString (fonte, "Esperando jogadores", new Vector2 (101f, 101f), Color.White); break; case EstadoDeJogo.Loading: spriteBatch.DrawString (fonte, "Carregando", new Vector2 (100f, 100f), Color.Gray); spriteBatch.DrawString (fonte, "Carregando", new Vector2 (101f, 101f), Color.White); break; default: estado_atual = EstadoDeJogo.Menu; Console.WriteLine ("Houve um erro bizarro com o EstadodeJogo"); break; } spriteBatch.End (); base.Draw (gameTime); }
void InicializaJogadores() { mapa.LoadContent (Content); foreach (LocalNetworkGamer gamer in rede.LocalGamers) { Personagem player = gamer.Tag as Personagem; player.Initialize (new Vector2 (32.0f, 32.0f)); player.Mapa = mapa; } rede.Update (); if (null == rede) return; estado_atual = EstadoDeJogo.Mapa; }
void CarregaMapa() { foreach (var gamer in rede.LocalGamers) { if (gamer.IsHost && null == mapa) { mapa = new Mapa (new Vector2 (0f, 0f)); mapa.Initialize (); } if (null != mapa) { caixaSaida.Write (mapa.Descricao); Console.WriteLine ("Enviei mapa"); } else caixaSaida.Write (""); gamer.SendData (caixaSaida, SendDataOptions.Reliable); } rede.Update (); if (null == rede) return; String descricaoRemota = ""; bool ok = true; foreach (LocalNetworkGamer gamer in rede.LocalGamers) while (gamer.IsDataAvailable) { NetworkGamer remetente; gamer.ReceiveData (caixaEntrada, out remetente); if (remetente.IsLocal) continue; string descricaoAux = caixaEntrada.ReadString (); if (!String.IsNullOrEmpty (descricaoAux)) descricaoRemota = descricaoAux; ok = ok && !String.IsNullOrEmpty (descricaoAux); } if (!String.IsNullOrEmpty (descricaoRemota) && null == mapa) { mapa = new Mapa (new Vector2 (0.0f, 0.0f)); mapa.Initialize (descricaoRemota); mapa.LoadContent (Content); } if (ok && rede.RemoteGamers.Count > 0 && null != mapa) estado_atual = EstadoDeJogo.Loading; }
protected void JoinSessao() { estado_atual = EstadoDeJogo.Loading; try { using (AvailableNetworkSessionCollection disponiveis = NetworkSession.Find(NetworkSessionType.SystemLink, 2,null)) { if (disponiveis.Count != 0) { rede = NetworkSession.Join (disponiveis [0]); mapa = new Mapa(new Vector2(0f,0f)); mapa.Initialize(); mapa.LoadContent(Content); estado_atual = EstadoDeJogo.Mapa; ManipulaEventos (); } else { return; } } } catch (Exception ex) { // Faca nada } }
public void Update(GameTime gameTime, ref EstadoDeJogo estado) { tempo = gameTime.TotalRealTime; if (tempo > TimeSpan.FromSeconds(total)) estado = EstadoDeJogo.Menu; }