예제 #1
0
        protected override void OnCollision(GameSession gameSession, ColliderInfo collidedInfo, ColliderInfo colliderInfo, Vector2 collisionPosition, bool amCollided)
        {
            if (amCollided)
            {
                //Knockback
                float   angleOfCollision = (float)Math.Atan2(colliderInfo.colliderPosition.Y - rigidBody.CollisionPolygon.CenterPoint.Y, colliderInfo.colliderPosition.X - rigidBody.CollisionPolygon.CenterPoint.X);
                Vector2 velocityVector   = new Vector2(-(float)Math.Cos(angleOfCollision), -(float)Math.Sin(angleOfCollision) - .5F);
                rigidBody.AddTranslationalVelocity(velocityVector);

                if (colliderInfo.colliderPosition.X < rigidBody.CollisionPolygon.CenterPoint.X)
                {
                    SpriteManager.FacingState = SpriteManager.FacingStates.Left;
                }
                else
                {
                    SpriteManager.FacingState = SpriteManager.FacingStates.Right;
                }

                //Damage
                //rigidBody.Mass = (CurrentHealth / 200) + .5F;

                //Spawn blood
                playerParticleManager.SpawnBlood(gameSession.gameMap);

                //Spawn damage indicator
                playerParticleManager.SpawnDamageNotifier(-colliderInfo.CollisionDamage, gameSession.gameMap);
            }
            else
            {
                RectangleF            boundaryRectangle = rigidBody.CollisionPolygon.BoundaryRectangle;
                PlayerParticleManager PPM = new PlayerParticleManager(PlayerTexturePack, new RotationRectangle(new RectangleF(collidedInfo.colliderPosition.X - (boundaryRectangle.Width / 2), collidedInfo.colliderPosition.Y - (boundaryRectangle.Height / 2), boundaryRectangle.Width, boundaryRectangle.Height)), drawDimensions);
                PPM.SpawnBlood(gameMap);
                PPM.SpawnDamageNotifier(colliderInfo.CollisionDamage, gameMap);
            }
        }
예제 #2
0
        public Player(PlayerTexturePack texturePack, GameTime gameTime, RigidBody rigidBody, Vector2 drawDimensions, GameMap gameMap) : base(PLAYER_HEALTH, PLAYER_LIVES, rigidBody.CollisionPolygon, gameMap)
        {
            playerParticleManager          = new PlayerParticleManager(texturePack, rigidBody.CollisionPolygon, drawDimensions);
            PlayerTexturePack              = texturePack;
            this.gameMap                   = gameMap;
            SpriteManager                  = new SpriteManager(texturePack, gameTime);
            this.drawDimensions            = drawDimensions;
            this.rigidBody                 = rigidBody;
            ClientCollider.CollisionDamage = DEFAULT_PLAYER_DAMAGE;

            healthBar = gameMap.gameSession.graphicsUI.HealthBarManager.AddHealthBar(gameMap.gameSession.DatabaseManager.Username, PLAYER_HEALTH, gameTime);
        }
예제 #3
0
        public void LoadPlayer(PlayerStandards.PlayerType playerType, GameSession gameSession, Lobby lobby, int clientIndex, int entityIndex)
        {
            //Ensure unloaded
            if (spriteManager == null)
            {
                this.playerType = playerType;
                PlayerTexturePack texturePack = PlayerStandards.PlayerTypes[(int)playerType].LoadTexturePack(Content, graphicsDevice);
                spriteManager           = new SpriteManager(texturePack, gameSession.LatestGameTime);
                drawDimensions          = new Vector2(PlayerStandards.PlayerTypes[(int)playerType].GetPlayerScale() * MapStandards.PLAYER_SCALE, PlayerStandards.PlayerTypes[(int)playerType].GetPlayerScale() * MapStandards.PLAYER_SCALE);
                polygonalRepresentation = new RotationRectangle(new RectangleF(PlayerPosition.X - (DrawDimensions.X / 2), PlayerPosition.Y - (DrawDimensions.Y / 2), DrawDimensions.X, DrawDimensions.Y));

                playerParticleManager = new PlayerParticleManager(texturePack, polygonalRepresentation, DrawDimensions);
                clientInfo            = gameSession.NetworkManager.GetClientInfo(clientIndex);
                if (clientInfo != null)
                {
                    healthBar = gameSession.graphicsUI.HealthBarManager.AddHealthBar(clientInfo.Username, Player.PLAYER_HEALTH, gameSession.LatestGameTime);
                }
                else
                {
                    throw new Exception("Error with client info!");
                }
            }
        }