示例#1
0
文件: Game.cs 项目: EugeneWang/ShootR
        private Game()
        {
            Configuration = new GameConfigurationManager();
            DRAW_AFTER = Configuration.gameConfig.DRAW_INTERVAL / Configuration.gameConfig.UPDATE_INTERVAL;
            _drawFPS = 1000 / Configuration.gameConfig.DRAW_INTERVAL;
            _gameLoop = new HighFrequencyTimer(1000 / Configuration.gameConfig.UPDATE_INTERVAL, id => Update(id), () => { }, () => { }, (fps) =>
            {
                _actualFPS = fps;
            });
            _leaderboardLoop = new Timer(UpdateLeaderboard, null, Configuration.gameConfig.LEADERBOARD_PUSH_INTERVAL, Configuration.gameConfig.LEADERBOARD_PUSH_INTERVAL);

            _gameTime = new GameTime();
            _space = new Map();
            GameHandler = new GameHandler(_space);
            _payloadManager = new PayloadManager();

            UserHandler = new UserHandler(GameHandler);
            Leaderboard = new Leaderboard(UserHandler);
            ConnectionManager = new ConnectionManager(UserHandler, _locker);

            RegistrationHandler = new RegistrationHandler();
            RuntimeConfiguration = new RuntimeConfiguration();

            _gameLoop.Start();
        }
示例#2
0
 public override void HandleCollisionWith(Collidable c, Map space)
 {
     if (c is Ship)
     {
         c.LifeController.Heal(_healAmount);
         Dispose(); // Destroy bullet when collision  
         base.HandleCollisionWith(c, space);
     }
 }
示例#3
0
        public GameHandler(Map space)
        {
            BulletManager = new BulletManager();
            _collisionManager = new CollisionManager(space);
            _shipManager = new ShipManager(this);
            _powerupManager = new PowerupManager();

            _space = space;
        }
示例#4
0
        /// <summary>
        /// When a bullet hits another object it must be destroyed.  So we dispose of it.
        /// </summary>
        /// <param name="c">The object that I colided with.</param>
        public override void HandleCollisionWith(Collidable c, Map space)
        {
            base.HandleCollisionWith(c, space);
            DamageDealt = DamageController.Damage;
            c.LifeController.Hurt(DamageDealt, this);

            if(c is Ship)
            {
                (c as Ship).StatRecorder.BulletCollision(this);
            }

            Dispose(); // Destroy bullet when collision
        }
示例#5
0
文件: Game.cs 项目: AbhiLegend/ShootR
        private Game()
        {
            Configuration = new GameConfigurationManager();
            DRAW_AFTER = TimeSpan.FromMilliseconds(Configuration.gameConfig.DRAW_INTERVAL);
            _gameLoop = new HighFrequencyTimer(1000 / Configuration.gameConfig.UPDATE_INTERVAL, id => Update(id));
            _leaderboardLoop = new Timer(UpdateLeaderboard, null, Configuration.gameConfig.LEADERBOARD_PUSH_INTERVAL, Configuration.gameConfig.LEADERBOARD_PUSH_INTERVAL);

            _gameTime = new GameTime();
            _space = new Map();
            GameHandler = new GameHandler(_space);
            _payloadManager = new PayloadManager();

            UserHandler = new UserHandler(GameHandler);
            Leaderboard = new Leaderboard(UserHandler);
            ConnectionManager = new ConnectionManager(UserHandler, _locker);

            RegistrationHandler = new RegistrationHandler();
            RuntimeConfiguration = new RuntimeConfiguration();

            _gameLoop.Start();
        }
示例#6
0
        public ConcurrentDictionary<string, object[]> GetGamePayloads(ICollection<User> userList, int playerCount, int bulletCount, Map space)
        {
            _payloadCache.StartNextPayloadCache();

            ConcurrentDictionary<string, object[]> payloads = new ConcurrentDictionary<string, object[]>();

            Parallel.ForEach(userList, user =>
            {
                if (user.ReadyForPayloads && user.Connected)
                {
                    Vector2 screenOffset = new Vector2((user.Viewport.Width / 2) + Ship.WIDTH / 2, (user.Viewport.Height / 2) + Ship.HEIGHT / 2);
                    string connectionID = user.ConnectionID;

                    _payloadCache.CreateCacheFor(connectionID);

                    var payload = GetInitializedPayload(playerCount, bulletCount, user);

                    if (!user.IdleManager.Idle)
                    {
                        Vector2 screenPosition = user.MyShip.MovementController.Position - screenOffset;
                        List<Collidable> onScreen = space.Query(new Rectangle(Convert.ToInt32(screenPosition.X), Convert.ToInt32(screenPosition.Y), user.Viewport.Width + SCREEN_BUFFER_AREA, user.Viewport.Height + SCREEN_BUFFER_AREA));

                        foreach (Collidable obj in onScreen)
                        {
                            if (obj is Bullet)
                            {
                                _payloadCache.Cache(connectionID, obj);

                                if (obj.Altered() || !_payloadCache.ExistedLastPayload(connectionID, obj))
                                {
                                    payload.Bullets.Add(Compressor.Compress((Bullet)obj));
                                }
                            }
                            else if (obj is Ship)
                            {
                                payload.Ships.Add(Compressor.Compress(((Ship)obj)));
                            }
                            else if (obj is Powerup)
                            {
                                _payloadCache.Cache(connectionID, obj);

                                if (obj.Altered() || !_payloadCache.ExistedLastPayload(connectionID, obj))
                                {
                                    payload.Powerups.Add(Compressor.Compress(((Powerup)obj)));
                                }
                            }
                        }
                    }
                    else // User is Idle, push down "MyShip"
                    {
                        payload.Ships.Add(Compressor.Compress(user.MyShip));
                    }

                    // This is used to send down "death" data a single time to the client and not send it repeatedly
                    if (user.DeathOccured)
                    {
                        // We've acknowledged the death
                        user.DeathOccured = false;
                        payload.KilledByName = user.MyShip.LastKilledBy.Host.RegistrationTicket.DisplayName;
                        payload.KilledByPhoto = user.MyShip.LastKilledBy.Host.RegistrationTicket.Photo;
                    }

                    if (user.Connected)
                    {
                        payloads.TryAdd(connectionID, Compressor.Compress(payload));
                    }
                }
            });

            // Remove all disposed objects from the map
            space.Clean();

            return payloads;
        }
示例#7
0
 public CollisionManager(Map space)
 {
     _space = space;
     _objects = new List<Collidable>();
 }
示例#8
0
 /// <summary>
 /// Called when there is a collision with another object "<paramref name="c"/>."
 /// </summary>
 /// <param name="c">The object that I colided with</param>
 public virtual void HandleCollisionWith(Collidable c, Map space)
 {
     HandleCollision();
 }
示例#9
0
文件: Ship.cs 项目: AbhiLegend/ShootR
 public override void HandleCollisionWith(Collidable c, Map space)
 {
 }