コード例 #1
0
        public void Test_Adding_2_Players_To_Pool()
        {
            // arrange
            Player p1 = new Player()
            {
                Name = "lorem"
            };
            Player p2 = new Player()
            {
                Name = "ipsum"
            };

            GamePool.FreeGames.Clear();
            GamePool.BusyGames.Clear();

            // act
            GamePool.RegisterPlayer(p1);
            GamePool.RegisterPlayer(p2);

            // assert
            Assert.IsTrue(GamePool.FreeGames.Count == 0);
            Assert.IsTrue(GamePool.BusyGames.Count == 1);

            Game g = GamePool.BusyGames[0];

            Assert.IsNotNull(g);
            Assert.IsTrue(g.Players.Contains(p1));
            Assert.IsTrue(g.Players.Contains(p2));
        }
コード例 #2
0
ファイル: ClientLogic.cs プロジェクト: d-huch/NetGameExample
        private void Awake()
        {
            DontDestroyOnLoad(gameObject);
            Random r = new Random();

            _cachedServerState = new ServerState();
            _cachedShootData   = new ShootPacket();
            _userName          = Environment.MachineName + " " + r.Next(100000);
            LogicTimer         = new LogicTimer(OnLogicUpdate);
            _writer            = new NetDataWriter();
            _playerManager     = new ClientPlayerManager(this);
            _shootsPool        = new GamePool <ShootEffect>(ShootEffectContructor, 100);
            _packetProcessor   = new NetPacketProcessor();
            _packetProcessor.RegisterNestedType((w, v) => w.Put(v), reader => reader.GetVector2());
            _packetProcessor.RegisterNestedType <PlayerState>();
            _packetProcessor.SubscribeReusable <PlayerJoinedPacket>(OnPlayerJoined);
            _packetProcessor.SubscribeReusable <JoinAcceptPacket>(OnJoinAccept);
            _packetProcessor.SubscribeReusable <PlayerLeavedPacket>(OnPlayerLeaved);
            _netManager = new NetManager(this)
            {
                AutoRecycle = true,
                IPv6Enabled = IPv6Mode.Disabled
            };
            _netManager.Start();
        }
コード例 #3
0
        public static Enemy Create(int type, Vec3 pos)
        {
            var enemy = Entity.Instantiate <Enemy>(pos, Quat.Identity, 0.5f, EnemyTypes [type].Geometry);

            if (EnemyTypes[type].Material != null)
            {
                enemy.Material = Env.Engine.GetMaterialManager().LoadMaterial(EnemyTypes[type].Material);
            }

            // Rotate Z-Axis in degrees to have enemy facing forward.
            enemy.Rotation = Quat.CreateRotationZ(Utils.Deg2Rad(90f));

            var pfx = Env.ParticleManager.FindEffect("spaceship.Trails.blue_fire_trail");

            enemy.LoadParticleEmitter(1, pfx, 0.5f);

            // Get position of jet on enemy (Note: Non-Existing position means x, y and z are all 0).
            Vec3 jetPosition = enemy.GetHelperPos(0, "particle_01");

            // NOTE ON MATRIX34
            // ----------------
            // First Vec3 parameter indicates scale
            // Second Quat parameter indicate rotation
            // Third Vec3 parameter indicates position

            // Scale, Rotate and Position particle effect to ensure it's shown at the back of the ship.
            enemy.SetTM(1, Matrix34.Create(Vec3.One, Quat.CreateRotationX(Utils.Deg2Rad(270f)), jetPosition));

            // Put into game loop.
            GamePool.AddObjectToPool(enemy);
            return(enemy);
        }
コード例 #4
0
ファイル: GamePool.cs プロジェクト: paulfigiel/Shooter
    //--------------------------------

    void Awake()
    {
        if (instance != null)
            Debug.LogWarning("ObjectPool: There should only be one instance of ObjectPool per Scene!\n", this.gameObject);

        instance = this;
    }
コード例 #5
0
ファイル: LevelGeometry.cs プロジェクト: carldonitz/CRYENGINE
        /// <summary>
        /// Initializes a new instance of the <see cref="CryEngine.Sydewinder.Door"/> class.
        /// </summary>
        /// <param name="position">Position.</param>
        /// <param name="doorType">Door type.</param>
        public static Door Create(Vector3 pos, int doorType)
        {
            if (doorType < 0 && doorType >= DoorTypes.Length)
            {
                throw new ArgumentOutOfRangeException(
                          string.Format("doorType must betwenn 0 and {0}", (DoorTypes.Length - 1).ToString()));
            }

            var door = Entity.Spawn <Door> (pos, Quaternion.Identity, 1);

            var material = DoorTypes[doorType].Material;

            if (material != null)
            {
                door.LoadMaterial(material);
            }

            var geometry = DoorTypes[doorType].Geometry;

            if (geometry != null)
            {
                door.LoadGeometry(0, geometry);
            }

            door.Physics.Physicalize(0, 1, EPhysicalizationType.ePT_Rigid);

            GamePool.AddObjectToPool(door);
            return(door);
        }
コード例 #6
0
        public override void OnTick(Entity[] entities)
        {
            int      playerCount = -1;
            GamePool gamePool    = null;

            try
            {
                gamePool    = ExternalGameHandler.GameRegistrations[_gameName];
                playerCount = gamePool.GetCurrentPlayers();
            }
            catch (Exception e)
            {
                SkyUtil.log($"Looking for '{_gameName}'");
                SkyUtil.log(ExternalGameHandler.GameRegistrations.Keys.ToArray().ToString());
                Console.WriteLine(e);
            }

            if (gamePool != null && gamePool.Active && playerCount >= 0)
            {
                if (gamePool.GetAllInstances().Count > 0)
                {
                    SetNameTag($"§fPlayers Online:§r §e{playerCount}");
                }
                else
                {
                    SetNameTag("§cUnavailable");
                }
            }
            else
            {
                SetNameTag("§a(Coming Soon)");
            }
        }
コード例 #7
0
        public async Task InitGame(List <List <string> > playerCoordinates)
        {
            var playerShips = CreatePlayerShips(playerCoordinates);

            var gameId = GamePool.CreateGame(playerShips);
            await Clients.Caller.SendAsync("gameReadyRequest", gameId);
        }
コード例 #8
0
ファイル: Game1.cs プロジェクト: Nailz/MonoGame-Samples
        protected override void Initialize()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            Type[] types = new Type[] {typeof(Enemy),typeof(Expires),typeof(Health),typeof(SpatialForm),typeof(Transform),typeof(Velocity),typeof(Weapon)};
            pool = new GamePool(100,types);
            pool.Initialize();

            spriteBatch = new SpriteBatch(GraphicsDevice);
            world = new EntityWorld();
            world.GetEntityManager().RemovedComponentEvent += new RemovedComponentHandler(RemovedComponent);
            world.SetPool(pool);

            font = Content.Load<SpriteFont>("Arial");
            SystemManager systemManager = world.GetSystemManager();
            renderSystem = systemManager.SetSystem(new RenderSystem(GraphicsDevice,spriteBatch,Content),ExecutionType.Draw);
            hudRenderSystem = systemManager.SetSystem(new HudRenderSystem(spriteBatch, font), ExecutionType.Draw);
            controlSystem = systemManager.SetSystem(new MovementSystem(spriteBatch), ExecutionType.Update,1);
            movementSystem = systemManager.SetSystem(new PlayerShipControlSystem(spriteBatch),ExecutionType.Update);
            enemyShooterSystem = systemManager.SetSystem(new EnemyShipMovementSystem(spriteBatch), ExecutionType.Update,1);
            enemyShipMovementSystem = systemManager.SetSystem(new EnemyShooterSystem(), ExecutionType.Update);
            collisionSystem = systemManager.SetSystem(new CollisionSystem(), ExecutionType.Update,1);
            healthBarRenderSystem = systemManager.SetSystem(new HealthBarRenderSystem(spriteBatch, font), ExecutionType.Draw);
            enemySpawnSystem = systemManager.SetSystem(new EnemySpawnSystem(500, spriteBatch), ExecutionType.Update);
            expirationSystem = systemManager.SetSystem(new ExpirationSystem(), ExecutionType.Update);

            systemManager.InitializeAll();

            InitPlayerShip();
            InitEnemyShips();

            base.Initialize();
        }
コード例 #9
0
 public override void Destroy(bool withEffect = true)
 {
     DrainLife(MaxLife);
     base.Destroy(withEffect);
     GamePool.FlagForPurge(ID);
     if (Weapon != null)
     {
         GamePool.FlagForPurge(Weapon.ID);
     }
 }
コード例 #10
0
ファイル: LevelGeometry.cs プロジェクト: carldonitz/CRYENGINE
        private void AddToGamePoolWithDoor(Vector3?pos = null)
        {
            GamePool.AddObjectToPool(this);

            Vector3 position;

            if (pos.HasValue)
            {
                position = pos.Value;
            }
            else
            {
                position = this.Position;
            }

            // Create a door case as connector between tunnels.
            _tunnelDoor       = Door.Create(new Vector3(position.x, position.y, position.z), 0);
            _tunnelDoor.Speed = LevelGeometry.GlobalGeomSpeed;

            // Create random door types
            int rand = Random.Next(3);

            if (rand != 0)
            {
                _tunnelDoor       = Door.Create(new Vector3(position.x, position.y, position.z), rand);
                _tunnelDoor.Speed = LevelGeometry.GlobalGeomSpeed;
            }

            ColorF lightColor = new ColorF(Random.Next(0, 255), Random.Next(0, 255), Random.Next(0, 255));

            // Till 'MaxValue' as the for-loop is quit when once the first empty position is discovered.
            for (int i = 1; i < int.MaxValue; i++)
            {
                Vector3 helperPos = GetHelperPos(0, "Light_0" + i.ToString());

                if (helperPos.x != 0 || helperPos.y != 0 || helperPos.z != 0)
                {
                    CDLight light = new CDLight()
                    {
                        m_fRadius = 25f,
                        m_fAttenuationBulbSize = 0.1f,
                        m_BaseColor            = lightColor,
                        m_BaseSpecMult         = 1f
                    };

                    LoadLight(i, light);
                    SetGeometrySlotLocalTransform(i, new Matrix3x4(Vector3.One, Quaternion.Identity, helperPos));
                }
                else
                {
                    break;
                }
            }
        }
コード例 #11
0
ファイル: GamePool.cs プロジェクト: Treyboyland/IGH2020
    private void Awake()
    {
        if (_instance != null && this != _instance)
        {
            Destroy(gameObject);
            return;
        }

        _instance = this;
        DontDestroyOnLoad(gameObject);
    }
コード例 #12
0
        public static Enemy CreateEnemy(Game game, int level, Point pos)
        {
            GamePool <Enemy> enemyPool = new GamePool <Enemy>();

            enemyPool.Add(ScreamerM2.Create(game, level), 25);

            Enemy enemy = enemyPool.Get();

            enemy.X = pos.X;
            enemy.Y = pos.Y;

            return(enemy);
        }
コード例 #13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CryEngine.Sydewinder.Door"/> class.
        /// </summary>
        /// <param name="position">Position.</param>
        /// <param name="doorType">Door type.</param>
        public static Door Create(Vec3 pos, int doorType)
        {
            if (doorType < 0 && doorType >= DoorTypes.Length)
            {
                throw new ArgumentOutOfRangeException(
                          string.Format("doorType must betwenn 0 and {0}", (DoorTypes.Length - 1).ToString()));
            }

            var door = Entity.Instantiate <Door> (pos, Quat.Identity, 1, DoorTypes [doorType].Geometry, DoorTypes[doorType].Material);

            GamePool.AddObjectToPool(door);
            return(door);
        }
コード例 #14
0
        public void Test_Adding_1_Player_To_Pool()
        {
            // arrange
            Player p1 = new Player()
            {
                Name = "Lorem"
            };

            GamePool.FreeGames.Clear();

            // act
            GamePool.RegisterPlayer(p1);

            // assert
            Assert.IsTrue(GamePool.FreeGames.Count > 0);

            Game g = GamePool.FreeGames.Dequeue();

            Assert.IsNotNull(g);
            Assert.IsTrue(g.Players.Contains(p1));
        }
コード例 #15
0
        public static PoolContainer GetTankPool(this GamePool pool, TankType tankType)
        {
            PoolContainer container;

            switch (tankType)
            {
            case TankType.TANK_GREEN:
                container = pool.TankGreen;
                break;

            case TankType.TANK_RED:
                container = pool.TankRed;
                break;

            case TankType.TANK_PURPLE:
                container = pool.TankPurple;
                break;

            default:
                throw new Exception($"{typeof(PoolExtension)} => TankType: {tankType} No pool was found with this type");
            }

            return(container);
        }
コード例 #16
0
ファイル: Enemy.cs プロジェクト: blockspacer/CRYENGINE-LFS
        public static Enemy Create(int type, Vector3 pos)
        {
            var enemy = Entity.SpawnWithComponent <Enemy>(pos, Quaternion.Identity, 0.5f);

            enemy.Entity.LoadGeometry(0, EnemyTypes[type].Geometry);

            enemy.Entity.Physics.Physicalize(0, 1, EPhysicalizationType.ePT_Rigid);

            if (EnemyTypes [type].Material != null)
            {
                enemy.Entity.Material = Engine.Engine3D.GetMaterialManager().LoadMaterial(EnemyTypes [type].Material);
            }

            // Rotate Z-Axis in degrees to have enemy facing forward.
            enemy.Entity.Rotation = Quaternion.CreateRotationZ(MathHelpers.DegreesToRadians(90f));

            var pfx = Engine.ParticleManager.FindEffect("spaceship.Trails.blue_fire_trail");

            enemy.Entity.LoadParticleEmitter(1, pfx, 0.5f);

            // Get position of jet on enemy (Note: Non-Existing position means x, y and z are all 0).
            Vector3 jetPosition = enemy.Entity.GetHelperPos(0, "particle_01");

            // NOTE ON Matrix3x4
            // ----------------
            // First Vector3 parameter indicates scale
            // Second Quaternion parameter indicate rotation
            // Third Vector3 parameter indicates position

            // Scale, Rotate and Position particle effect to ensure it's shown at the back of the ship.
            enemy.Entity.SetGeometrySlotLocalTransform(1, new Matrix3x4(Vector3.One, Quaternion.CreateRotationX(MathHelpers.DegreesToRadians(270f)), jetPosition));

            // Put into game loop.
            GamePool.AddObjectToPool(enemy);
            return(enemy);
        }
コード例 #17
0
 public DayIncrementer(GamePool gamePool, AllPlayersReady allPlayersReady)
 {
     _gamePool        = gamePool;
     _allPlayersReady = allPlayersReady;
 }
コード例 #18
0
ファイル: GamePool.cs プロジェクト: WeeirJoe/Joe
 private void OnDestroy()
 {
     _Instance = null;
 }
コード例 #19
0
ファイル: GamePool.cs プロジェクト: WeeirJoe/Joe
 private void Awake()
 {
     _Instance = this;
 }
コード例 #20
0
ファイル: Results.cs プロジェクト: angar4ik/cluz-server
 public Results(IHubContext <PlayersHub> hubContext, GamePool gamePool)
 {
     _hubContext = hubContext;
     _gamePool   = gamePool;
 }
コード例 #21
0
 public static BLL.Models.Game RegisterPlayer(Player p1)
 {
     return(GamePool.RegisterPlayer(p1));
 }
コード例 #22
0
ファイル: LevelGeometry.cs プロジェクト: carldonitz/CRYENGINE
 public void Purge()
 {
     GamePool.FlagForPurge(Id);
     GamePool.FlagForPurge(_tunnelDoor.Id);
 }
コード例 #23
0
 public MasterMindGameHandler()
 {
     GamePool = new GamePool();
 }
コード例 #24
0
 public PlayersHub(GamePool gamePool, PlayerPool playerPool, IHubContext <PlayersHub> hubContext)
 {
     _gamePool   = gamePool;
     _playerPool = playerPool;
     _hubContext = hubContext;
 }
コード例 #25
0
ファイル: Broadcaster.cs プロジェクト: angar4ik/cluz-server
 public Broadcaster(GamePool gamePool, IHubContext <PlayersHub> hubContext, Results results)
 {
     _hubContext = hubContext;
     _gamePool   = gamePool;
     _results    = results;
 }
コード例 #26
0
 public DiagController(GamePool gamePool, IHubContext <PlayersHub> hubContext)
 {
     _gamePool   = gamePool;
     _hubContext = hubContext;
 }
コード例 #27
0
ファイル: GamePool.cs プロジェクト: zhoubiwen/games
 private void Awake()
 {
     Instance = this;
     vars     = ManagerVars.GetManagerVars();
     Init();
 }