public void HandleGameState(BattleGame game) { switch (game.GameState) { case GameState.Handshake: Menu_Loading_Show(waitingForHandshakeText); break; case GameState.Idle when game.IsHost: Menu_Loading_Show(waitingForStartText); break; case GameState.Idle when game.IsHost == false: FadeInMenu(groupJoinClientStartGame); FadeOutMenu(groupHostGame); FadeOutMenu(groupJoinGame); FadeOutMenu(groupLoadingModalWithAbort); break; case GameState.InGame: FadeInMenu(groupGameStarted); textGameStartedTurn.text = game.IsLocalsTurn ? ourTurnText : theirTurnText; FadeOutMenu(groupJoinGame); FadeOutMenu(groupJoinClientStartGame); FadeOutMenu(groupHostGame); FadeOutMenu(groupLoadingModalWithAbort); break; case GameState.Disconnected: FadeInMenu(groupDisconnected); break; } }
void Awake() { game = new BattleGame(); game.Initialize(); em = game.world.EntityManager; Dictionary <int, Entity> createdRealms = new Dictionary <int, Entity>(); foreach (var realmConfig in spawns) { if (!createdRealms.ContainsKey(realmConfig.realmId)) { if (realmConfig.realmColor.a < 1) { Debug.LogWarning($"Alpha of realm {realmConfig.realmId} is below zero {realmConfig.realmColor.a}"); } Entity realm = em.CreateEntity(game.archetypeRealm); em.SetComponentData(realm, new Realm { color = realmConfig.realmColor }); if (realmConfig.playerControlled) { em.AddComponent <PlayerControlled>(realm); } createdRealms.Add(realmConfig.realmId, realm); } realmConfig.spawnCrowd.Init(createdRealms[realmConfig.realmId]); } }
public static void ThrowIfNotHost([NotNull] this BattleGame game, ResponseCode responseCode) { if (!game.IsHost) { throw new ProtocolBoundedResponseException(responseCode, "host"); } }
void OnDestroy() { Assert.assert(_instance == this); _instance = null; TimeHelper.SetTimeScale(1); }
public static void ThrowIfWrongState([NotNull] this BattleGame game, [NotNull] string commandName, GameState expected) { if (game.GameState != expected) { throw new ProtocolInvalidStateCommandException(commandName, expected, game.GameState); } }
public static void ThrowIfWrongState([NotNull] this BattleGame game, ResponseCode responseCode, GameState expected) { if (game.GameState != expected) { throw new ProtocolInvalidStateResponseException(responseCode, expected, game.GameState); } }
public static void ThrowIfNotLocalsTurn([NotNull] this BattleGame game) { if (!game.IsLocalsTurn) { throw new ProtocolPlayerTurnException(false); } }
public static void ThrowIfHost([NotNull] this BattleGame game, [NotNull] string commandName) { if (game.IsHost) { throw new ProtocolBoundedCommandException(commandName, "client"); } }
private void OnDisable() { connectCancellationToken?.Dispose(); connectCancellationToken = null; game?.Disconnect(); game?.Dispose(); game = null; }
public void CancelConnect() { connectCancellationToken?.Cancel(); connectCancellationToken = null; hostCancellationTokenSource?.Cancel(); hostCancellationTokenSource = null; game?.Dispose(); game = null; }
public async Task JoinGame(string address, ushort port, string localPlayerName) { connectCancellationToken = new CancellationTokenSource(millisecondsDelay: 10000); game = await BattleGame.ConnectAsync(new ConnectionSettings { Address = address, Port = port }, board.protocolBoard, localPlayerName, connectCancellationToken.Token); SetupEventHandlers(); print("CLIENT CONNECTED WITH " + game.RemotePlayer.EndPoint); }
static void Main() { try { using (BattleGame game = new BattleGame()) { game.Run(); } } catch (Exception e) { Vortex.Debug.Error(e, "Application failed"); } }
static void Main(string[] args) { Window gameWindow = new Window("Battle Game", 800, 600); BattleGame game = new BattleGame(gameWindow); do { gameWindow.Clear(Color.White); SplashKit.ProcessEvents(); game.HandleInput(); game.Draw(); gameWindow.Refresh(60); }while(!gameWindow.CloseRequested && game.Quit != true); gameWindow.Close(); }
// private TankSpineAttach _spineAttach; public UnitDriver(GameObject owner, GameObject body, float speed) { _unit = owner.GetComponent <Unit> (); _game = BattleGame.instance; _shortPath = new ShortPath(_unit, _game.mapGrid); this._owner = owner; this._body = body; _engine = new TankEngine(_unit); _turningControl = new AimmingControl(body, ROTATION_SPEED); this._speed = speed; // _spineAttach = owner.GetComponent<TankSpineAttach> (); }
public async Task HostGame(ushort port, string localPlayerName) { if (hostCancellationTokenSource != null) { throw new InvalidOperationException("Game is already hosting."); } hostCancellationTokenSource = new CancellationTokenSource(); game = await BattleGame.HostAndWaitAsync(new ConnectionSettings { Port = port }, board.protocolBoard, localPlayerName, hostCancellationTokenSource.Token); SetupEventHandlers(); print("HOST CONNECTED WITH " + game.RemotePlayer.EndPoint); }
// Use this for initialization void Start() { _game = BattleGame.instance; _aimmingControl = new AimmingControl(launcher, AIMMING_ROTATE_SPEED); _gridCorrect = new UnitGridCorrect(this, _game.mapGrid); _targetSelect = new UnitTargetSelect(this, _game.unitGroup); _unitFire = new UnitFire(this); _unitDriver = new UnitDriver(gameObject, body, unit.dataUnit.speed); _collisionDetector = new UnitCollisionDetector(this, _game.unitGroup); _stateMachine.Change(new UnitStateIdle(this)); CreateHPBar(); _unitTrack = new UnitTrack(this); }
public Vector3 LimitCameraCenter(Vector3 center) { BattleGame game = BattleGame.instance; float expectW2 = _sizeControl.expectScreenWidth2; float expectH2 = _sizeControl.expectScreenHeight2; float centerMinX = expectW2; float centerMaxX = game.mapGrid.GetMapWidth() - expectW2; float centerMinZ = game.mapGrid.GetMapHeight() / 2 - VERTICAL_FLOATING_RANGE2; float centerMaxZ = game.mapGrid.GetMapHeight() / 2 + VERTICAL_FLOATING_RANGE2; center.x = Mathf.Max(center.x, centerMinX); center.x = Mathf.Min(center.x, centerMaxX); center.z = Mathf.Max(center.z, centerMinZ); center.z = Mathf.Min(center.z, centerMaxZ); return(center); }
public static UnitLayout CalcAllAliveTanksLayout() { UnitLayout layout = null; BattleGame game = BattleGame.instance; List <Unit> tanks = game.unitGroup.allUnits; for (int i = 0; i < tanks.Count; ++i) { Unit unit = tanks[i]; if (unit.isDead) { continue; } float length = unit.unit.dataUnit.length; if (layout == null) { layout = new UnitLayout(); layout.min = unit.transform.position - new Vector3(length, length, length); layout.max = unit.transform.position + new Vector3(length, length, length); } else { layout.min.x = Mathf.Min(layout.min.x, unit.transform.position.x); layout.min.y = Mathf.Min(layout.min.y, unit.transform.position.y); layout.min.z = Mathf.Min(layout.min.z, unit.transform.position.z); layout.max.x = Mathf.Max(layout.max.x, unit.transform.position.x); layout.max.y = Mathf.Max(layout.max.y, unit.transform.position.y); layout.max.z = Mathf.Max(layout.max.z, unit.transform.position.z); } } return(layout); }
// 战斗损失unit 同步战斗中损失到阵型 public void SyncBattleDamageUnit() { BattleGame game = BattleGame.instance; if (game != null) { int teamId = InstancePlayer.instance.model_User.model_Formation.GetSelectTeamId(); List <Unit> untis = game.unitGroup.GetPlayerDeadUnits(); foreach (Unit unit in untis) { int posId = unit.slotIndex + 1; int deadCount = unit.unit.GetDeadCount(); Model_UnitGroup model_UnitGroup = GetUnitGroup(teamId, posId); if (model_UnitGroup != null) { // deadCount = Mathf.Min(deadCount, model_UnitGroup.maxNum); model_UnitGroup.num -= deadCount; Assert.assert(model_UnitGroup.num >= 0); } } } }
// Use this for initialization void Start() { Assert.assert(_instance == null); _instance = this; if (AppConfig.DEBUGGING) { new MyTest(); } CreateBattleData(); // SceneBattle _camera = GameObject.FindGameObjectWithTag(AppConfig.TAB_MAIN_CAMERA); //todo, use define in mission _unitGroup = new UnitGroup(); _mapGrid = new MapGrid(InstancePlayer.instance.battle.dataMap); _mapAStar = new MapAStar(_mapGrid); _mapCamera = new MapCamera(); _gameEntering = new BattleGameEntering(this); _mouseContorl = new MouseControl(this); _gameSkill = new GameSkill(); _gameSkillControl = new GameSkillControl(this); // MapAStar.PATH path = _mapAStar.Calc (5, 2, 15, 2); // _mapGrid.AddPath (path); AudioGroup.Play(GetComponent <AudioGroup> ().music, _camera, AudioGroup.TYPE.MUSIC); UnitTrackControl.ClearTrackTiles(); BattleGameHelper.PreloadAssets(); }
public CameraSmoothMove(MapCamera mapCamera) { _game = BattleGame.instance; _mapCamera = mapCamera; }
public CameraShowTeam(MapCamera mapCamera) { _game = BattleGame.instance; _mapCamera = mapCamera; }
public HelloCommand(BattleGame game) { _game = game; }
private ForwardErrorsObserver(BattleGame game) { _game = game; }
public static IDisposable SubscribeTo(BattleGame game) { var observer = new ForwardErrorsObserver(game); return(game.PacketConnection.Subscribe(observer)); }
public CameraLookAt(MapCamera mapCamera) { _game = BattleGame.instance; _mapCamera = mapCamera; }
public CameraAutoScale(MapCamera mapCamera) { _game = BattleGame.instance; _mapCamera = mapCamera; }
public BattleGameEntering(BattleGame game) { _game = game; }
public StartCommand(BattleGame game) { _game = game; }
public MouseControl(BattleGame game) { _game = game; _mouseStatus = game.mouseStatus; }
public GameSkillControl(BattleGame game) { this._game = game; _mouseControl = game.mouseContorl; _mouseStatus = game.mouseStatus; }