/// <summary>
 /// Adds the logical and graphical representation of the given unit to the game.
 /// Note: This is just a redirection to GameObjectFactory.AddUnit(). Do not extend
 /// the method here, but there.
 /// </summary>
 /// <param name="unit">the unit to be added</param>
 public void AddUnit(GameObject unit)
 {
     // *leys* TODO: Why is the stats call here? Not all unit additions will pass by,
       // I think some are calling factory.AddUnit() directly?
       mStats.AddGameObject(unit);
       mGameObjectFactory.AddUnit(unit);
 }
Exemple #2
0
 protected GraphicObject(GameObject gameObject, Model model, float modelSize, float boundingScale, Vector3 rot)
 {
     mModel = model;
       mGameObject = gameObject;
       mScale = modelSize;
       mBoundingScale = boundingScale;
       mRot = rot;
       mLastPosition = GetPosition() + new Vector3(1, 0, 0);
 }
Exemple #3
0
 public Beam(GameObject gameObject,
     Model model,
     ExplosionObject[] explosions,
     Effect effect,
     float modelSize,
     Vector3 rot)
     : base(gameObject, model, modelSize, 1f, rot)
 {
     mEffect = effect;
       mVertices = new VertexPositionColor[12];
       mExplosions = explosions;
 }
Exemple #4
0
 public ModelObject(GameObject gameObject,
     Model model,
     Texture2D texture,
     Effect effect,
     float modelScale,
     float boundingScale,
     Vector3 rot)
     : base(gameObject, model, modelScale, boundingScale, rot)
 {
     mTexture = texture;
       mEffect = effect;
 }
        /// <summary>
        /// Adds the logical and graphical representation of the given unit to the game.
        /// </summary>
        /// <param name="unit">the unit to be added</param>
        public void AddUnit(GameObject unit)
        {
            unit.mPartOfTheGame = true;
              mGameObjects.Add(unit);
              GameLogic gameLogic = GameLogic.GetInstance();
              // If it's an obstructive unit, register it at the PATHFINDER.
              if (unit is IObstructive)
            ((IObstructive)unit).RegisterBlockedArea();
              // register collidable units at the COLLISION MANAGER:
              CollisionManager collisionManager = gameLogic.GetCollisionManager();
              if (unit is ICollidable && collisionManager != null)
              collisionManager.RegisterUnit((ICollidable) unit);
              // register all units at the FOG MANAGERS for visibility:
              SuperFogManager superFogManager = gameLogic.SuperFogManager;
              if (unit is IVisible && unit.Allegiance != Allegiance.Player && superFogManager != null)
              superFogManager.PlayerFogManager.RegisterUnit((IVisible) unit);
              if (unit is IVisible && unit.Allegiance != Allegiance.Computer && superFogManager != null)
              superFogManager.PcFogManager.RegisterUnit((IVisible)unit);
              // register unit at UNIT SECTOR MANAGER:
              UnitSectorManager unitSectorManager = gameLogic.SectorManager;
              if (unit is IVisible && unitSectorManager != null)
              unitSectorManager.AddUnit((IVisible) unit);
              // If it's a computer unit, note the AI:
              if (unit.Allegiance == Allegiance.Computer)
              gameLogic.mSpaceshipAi.AddAiUnit(unit);
              // Set the DS flag if it is one:
              if (unit is DeathStar)
              {
              if (unit.Allegiance == Allegiance.Player)
              GameObjectManager.GetInstance().mPlayerHasDeathStar = true;
              else if (unit.Allegiance == Allegiance.Computer)
              GameObjectManager.GetInstance().mComputerHasDeathStar = true;
              }

              // Create graphical representation:
              mGraphicObjectManager.CreateGraphicObject(unit);
        }
Exemple #6
0
 // Counting added Spaceships
 public void AddGameObject(GameObject obj)
 {
     if (obj is Interceptor || obj is Defender || obj is Predator)
       {
     if (obj.Allegiance == Allegiance.Player)
     {
      //   Debug.WriteLine("New Player Spaceship counted");
     mCreatedSpaceShipsPlayer++;
     }
     else if (obj.Allegiance == Allegiance.Computer)
     {
      //   Debug.WriteLine("New KI Spaceship counted");
     mCreatedSpaceShipsKi++;
     }
       }
 }
Exemple #7
0
 // Counting removed Spaceships
 public void RemoveGameObject(GameObject obj)
 {
     if (obj is Interceptor || obj is Defender || obj is Predator)
       {
     if (obj.Allegiance == Allegiance.Player)
     {
      //   Debug.WriteLine("Destroyed Player Spaceship counted");
       mDestroyedSpaceShipsKi++;
     }
     else if (obj.Allegiance == Allegiance.Computer)
     {
       //  Debug.WriteLine("Destroyed Ki Spaceship counted");
       mDestroyedSpaceShipsPlayer++;
     }
       }
 }
        /// <summary>
        /// Deletes the specified unit from logic and graphical lists
        /// </summary>
        /// <param name="gameObject"></param>
        public bool RemoveGameObject(GameObject gameObject)
        {
            bool graphicRemoved = mGraphicObjectManager.RemoveGraphicObject(gameObject);
             bool logicRemoved = mObjectList.Remove(gameObject);

             // %maxi% ich lösch mal das object (besonders Laser) nochmal..
             mGraphicObjectManager.RemoveGraphicObject(gameObject);

              // NOTE Added: If it's an obstructive unit, unregister it at the PATHFINDER.
              if (gameObject is IObstructive)
              {
            ((IObstructive) gameObject).UnregisterBlockedArea();
              }

              GameLogic gameLogic = GameLogic.GetInstance();
              // remove the unit from the UNIT SECTOR MANAGER:
              UnitSectorManager unitSectorManager = gameLogic.SectorManager;
              if (gameObject is IVisible && unitSectorManager != null)
              unitSectorManager.RemoveUnit((IVisible) gameObject);

              // unregister the unit at the COLLISION MANAGER:
              CollisionManager collisionManager = gameLogic.GetCollisionManager();
              if (gameObject is ICollidable && collisionManager != null)
              collisionManager.UnregisterUnit((ICollidable) gameObject);

              // unregister the unit at the FOG MANAGERS:
              PlayerFogManager playerFogManager = gameLogic.SuperFogManager.PlayerFogManager;
              if (gameObject is IVisible && gameObject.Allegiance != Allegiance.Player && playerFogManager != null)
            playerFogManager.UnregisterUnit((IVisible) gameObject);
              PcFogManager pcFogManager = gameLogic.SuperFogManager.PcFogManager;
              if (gameObject is IVisible && gameObject.Allegiance != Allegiance.Computer && pcFogManager != null)
              pcFogManager.UnregisterUnit((IVisible)gameObject);
              // unregister unit from AI if its allegiance is computer:
              if (gameObject.Allegiance == Allegiance.Computer)
              gameLogic.mSpaceshipAi.RemoveAiUnit(gameObject);

              // note the statistics about the removal:
              mStats.RemoveGameObject(gameObject);
              gameObject.mPartOfTheGame = false;
              // remove DS flag if it is one:
              if (gameObject is DeathStar)
              {
              if (gameObject.Allegiance == Allegiance.Player)
              mPlayerHasDeathStar = false;
              else if (gameObject.Allegiance == Allegiance.Computer)
              mComputerHasDeathStar = false;
              }

              return graphicRemoved && logicRemoved;
        }
Exemple #9
0
 public EffectObject(GameObject gameObject, Model model, float modelsSize, float boundingScale, Vector3 rot)
     : base(gameObject, model, modelsSize, boundingScale, rot)
 {
 }
        /// <summary>
        /// Creates a new graphical representation
        /// based on the specified logic object
        /// </summary>
        /// <param name="logicRef">reference to the logic representation</param>
        public void CreateGraphicObject(GameObject logicRef)
        {
            Model model;
              Texture2D texture = null;
              var lightShader = mContent.Load<Effect>("Shader/light");
              var basicShader = mContent.Load<Effect>("Shader/basic");
              Vector3 rotation = Vector3.Zero;
              float modelScale = 1f;
              float boundingScale = 1f;

              if (logicRef is Interceptor)
              {
            model = mContent.Load<Model>("Models/Ships/Interceptor");
            texture = mContent.Load<Texture2D>("Textures/interceptor");
            modelScale = 0.2f;
            boundingScale = 0.25f;
              }
              else if (logicRef is Predator)
              {
            model = mContent.Load<Model>("Models/Ships/Predator");
            texture = mContent.Load<Texture2D>("Textures/interceptor");
            modelScale = 0.2f;
            boundingScale = 0.25f;
              }
              else if (logicRef is Defender)
              {
            model = mContent.Load<Model>("Models/Ships/Defender");
            texture = mContent.Load<Texture2D>("Textures/interceptor");
            modelScale = 0.2f;
            boundingScale = 0.25f;
              }
              else if (logicRef is Planet)
              {
            model = mContent.Load<Model>("Models/TerrestricalPlanet");

            switch (((Planet) logicRef).PlanetSize)
            {
              case PlanetSize.Small:
              {
            texture = mContent.Load<Texture2D>("Textures/Planets/planet_tex_1");
            modelScale = 1f;
            boundingScale = 1.2f;
            break;
              }
              case PlanetSize.Medium:
              {
            texture = mContent.Load<Texture2D>("Textures/Planets/planet_tex_2");
            modelScale = 1.5f;
            boundingScale = 1.8f;
            break;
              }
              case PlanetSize.Large:
              {
            texture = mContent.Load<Texture2D>("Textures/Planets/planet_tex_3");
            modelScale = 2.0f;
            boundingScale = 2.4f;
            break;
              }
            }
              }
              else if (logicRef is Minion)
              {
            model = mContent.Load<Model>("Models/Ships/minion2");
            texture = mContent.Load<Texture2D>("Textures/minion");
            modelScale = 0.15f;
            boundingScale = 0f;
            rotation = new Vector3(MathHelper.ToRadians(-90), 0, 0);
              }
              else if (logicRef is DeathStar)
              {
            model = mContent.Load<Model>("Models/Deathstarss");
            modelScale = 100f;
            boundingScale = 2500f;
            rotation = new Vector3(0, 5.3f, 0);
              }
              else if (logicRef is Laser)
              {
            switch (((Laser) logicRef).mLaserType)
            {
              default:
            model = mContent.Load<Model>("Models/shot");
            modelScale = 0.09f;
            mSound.PlayAttackSoundInterceptor();
            break;
              case LaserType.Predator:
            model = mContent.Load<Model>("Models/shot");
            modelScale = 0.09f;
            mSound.PlayAttackSoundPredator();
            break;
              case LaserType.Defender:
            model = mContent.Load<Model>("Models/shot_big");
            modelScale = 0.1f;
            mSound.PlayAttackSoundDefender();
            break;
              case LaserType.DeathStarLaser:
            model = mContent.Load<Model>("Models/shot_big");
            modelScale = 0.1f;
            mSound.PlayAttackSoundDeathstarShip();
            break;
              case LaserType.DeathStarBeam:
            model = mContent.Load<Model>("Models/shot_big");
            modelScale = 0.3f /** (((Laser)logicRef).mLength) / 300*/;
            var tmpLaser = logicRef as Laser;

            Vector2 surfacePoint = tmpLaser.mTargetPosition -
                                   100 / (tmpLaser.mTargetPosition - tmpLaser.mStartPosition).Length() *
                                   (tmpLaser.mTargetPosition - tmpLaser.mStartPosition);

            var explosions = new ExplosionObject[2];

            explosions[0] = new ExplosionObject(new Vector3(surfacePoint, 0),
                                                mExplosionTex,
                                                Color.Blue,
                                                4,
                                                5,
                                                1,
                                                0.5f,
                                                false);
            explosions[1] = new ExplosionObject(new Vector3(surfacePoint, 0),
                                                mExplosionTex,
                                                Color.LightBlue,
                                                4,
                                                5,
                                                0.5f,
                                                0.5f,
                                                false);

            mExplosionList.Add(explosions[0]);
            mExplosionList.Add(explosions[1]);

            mGraphicObjects.Add(new Beam(logicRef, model, explosions, basicShader, 1f, Vector3.Zero));

            mSound.PlayAttackSoundDeathstar();
            break;
            }
            rotation = new Vector3(MathHelper.ToRadians(0), 180, MathHelper.ToRadians(0));
              }
              else if (logicRef is Asteroid)
              {
            model = mContent.Load<Model>("Models/asteroid_01");
            texture = mContent.Load<Texture2D>("Textures/asteroid");
            modelScale = 0.075f + (float) mRandom.NextDouble() * 0.025f;
            rotation = new Vector3((float) (Math.PI * mRandom.NextDouble()), 0, (float) (Math.PI * mRandom.NextDouble()));
            boundingScale = 0f;
              }
              else
              {
            model = mContent.Load<Model>("Models/dummy");
              }

              if (logicRef is Laser)
              {
            if (((Laser) logicRef).mLaserType != LaserType.DeathStarBeam)
              mGraphicObjects.Add(new EffectObject(logicRef, model, modelScale, 0, rotation));
              }
              else
            mGraphicObjects.Add(new ModelObject(logicRef, model, texture, lightShader, modelScale, boundingScale, rotation));
        }
 /// <summary>
 /// Removes a graphical representation from the list.
 /// </summary>
 /// <param name="logicRef">Logic reference of the graphicObject, that is to be removed</param>
 /// <returns>Returns true, if the object has been successfully deleted</returns>
 public bool RemoveGraphicObject(GameObject logicRef)
 {
     foreach (var graphicObject in mGraphicObjects)
       {
     if (graphicObject.mGameObject == logicRef)
     {
       if (graphicObject.mGameObject is ISpaceship)
     CreateShipExplosion(graphicObject.GetPosition());
       else if (graphicObject is Beam)
       {
     foreach (ExplosionObject explosion in (graphicObject as Beam).mExplosions)
       RemoveExplosion(explosion);
       }
       return mGraphicObjects.Remove(graphicObject);
     }
       }
       return false;
 }
Exemple #12
0
        /// <summary>
        /// Draws a little Picture of the selected Unit in the Propertiefield
        /// </summary>
        /// <param name="unit">Specified Unit</param>
        /// <param name="index">Index of the Propertiefield</param>
        /// <param name="state">Current Mouse State</param>
        private void DrawPicto(GameObject unit, int index, MouseState state)
        {
            const int size = 70;
             var rect = new Rectangle((index + 1) * sWidthOfPropertieField - size,
                              (int) mResolution.Y - sFieldPosition.Y - sHeightOfPropertieField +
                              (int) ((sHeightOfPropertieField - size) / 2f),
                              size,
                              size);
             var color = Color.White;

             // specifies the texture
             Texture2D tex = null;
             if (unit is Interceptor) tex = mInterceptorPicto;
             if (unit is Predator) tex = mPredatorPicto;
             if (unit is Defender) tex = mDefenderPicto;
             if (unit is DeathStar) tex = mDeathStarPicto;
             if (unit is Planet)
             {
              // if the planet has an upgrade its texture is set
              var p = unit as Planet;
              if ((p.StarfleetAcademyUpgrade ||
               p.MinionBoostUpgrade ||
               p.PlanetaryShieldUpgrade ||
               p.SateliteStationUpgrade))
               // planets has no pico, but a delete button, which is on the same position
               tex = mDeleteUpgrade;
              // make the hover effect
              color = rect.Contains(new Point(state.X, state.Y)) ? Color.White : new Color(100, 100, 100);
             }

             // if the unit was correct set
             if (tex != null) mSpriteBatch.Draw(tex, rect, color);
        }