Esempio n. 1
0
        private void loadDeletagtes(out NukeDelegate nukeDelegate, out ClosestTargetDelegate closestTargetDelegate)
        {
            nukeDelegate = delegate(Vector2 position, Vector2 origin, float direction, float power, int ownerID) {
                this.nuke.reset(position, origin, direction, power, ownerID);
                StateManager.getInstance().CurrentGameState = StateManager.GameState.Waiting;
            };

            closestTargetDelegate = delegate(Vector2 myPosition, int ID) {
                List <Tracker> distances = new List <Tracker>();
                Vector2        max;
                Vector2        min;
                Vector2        distance;

                foreach (Launcher launcher in this.players)
                {
                    if (launcher != null && ID != launcher.ID)
                    {
                        max = new Vector2(MathHelper.Max(myPosition.X, launcher.Position.X),
                                          MathHelper.Max(myPosition.Y, launcher.Position.Y));
                        min = new Vector2(MathHelper.Min(myPosition.X, launcher.Position.X),
                                          MathHelper.Min(myPosition.Y, launcher.Position.Y));

                        distance = Vector2.Subtract(max, min);
                        distances.Add(new Tracker(launcher.ID, distance.X + distance.Y));
                    }
                }
                distances.Sort();

                return(this.players[distances[0].ID].Position);
            };
        }
Esempio n. 2
0
        public Player(ContentManager content, SFXEngine sfxEngine, Vector2 position, NukeDelegate nukeDelegate, int ownerID)
            : base(content, sfxEngine, position, nukeDelegate, ownerID)
        {
            Text2DParams textParms = new Text2DParams();

            textParms.Font        = LoadingUtils.load <SpriteFont>(content, "SpriteFont1");
            textParms.Position    = new Vector2(10f);
            textParms.LightColour = Color.Black;
            this.powerText        = new Text2D(textParms);
        }
Esempio n. 3
0
        public void reset(bool setState = true)
        {
            if (setState)
            {
                StateManager.getInstance().CurrentGameState = StateManager.GameState.Loading;
            }
            StateManager.getInstance().WhosTurn = StateManager.Player.One;
            SFXEngineParams sfxParms            = new SFXEngineParams();

            sfxParms.Muted = false;
            this.sfxEngine = new SFXEngine(sfxParms);
            this.terrain   = new Terrain(Content);
            this.players   = new Launcher[4];
            this.nuke      = new Nuke(Content, this.sfxEngine);

            NukeDelegate          nukeDelegate   = null;
            ClosestTargetDelegate targetDelegate = null;

            loadDeletagtes(out nukeDelegate, out targetDelegate);

            PositionGenerator.getInstance().reset();
            for (int i = 0; i < this.players.Length; i++)
            {
                if (StateManager.getInstance().TypeOfGame == StateManager.GameType.PlayerVsPlayer)
                {
                    this.players[i] = new Player(Content, this.sfxEngine, PositionGenerator.getInstance().generate(), nukeDelegate, i);
                }
                else if (i == 0)
                {
                    this.players[i] = new Player(Content, this.sfxEngine, PositionGenerator.getInstance().generate(), nukeDelegate, i);
                }
                else
                {
                    this.players[i] = new Enemy(Content, this.sfxEngine, PositionGenerator.getInstance().generate(), nukeDelegate,
                                                i, targetDelegate);
                }
            }

            if (StateManager.getInstance().TypeOfGame == StateManager.GameType.PlayerVsComputers)
            {
                // now that all parties are setup, find initial targets
                for (int i = 1; i < this.players.Length; i++)
                {
                    ((Enemy)this.players[i]).findTarget();
                }
            }
            this.explosionEmitter = new ExplosionParticleEmitter(Content, new BaseParticle2DEmitterParams());

            // sfx
            this.explosionSFX = LoadingUtils.load <SoundEffect>(Content, "Explosion");
        }
Esempio n. 4
0
        public Launcher(ContentManager content, SFXEngine sfxEngine, Vector2 position, NukeDelegate nukeDelegate, int ID)
        {
            this.content      = content;
            this.angle        = 90f;
            this.direction    = Direction.Right;
            this.nukeDelegate = nukeDelegate;
            this.power        = 100f;
            this.ID           = ID;

            StaticDrawable2DParams staticParms = new StaticDrawable2DParams();

            staticParms.Position = position;
            staticParms.Origin   = new Vector2(32f);
            staticParms.Texture  = LoadingUtils.load <Texture2D>(content, "LauncherTruck");
            this.truck           = new StaticDrawable2D(staticParms);

            staticParms.Position = new Vector2(this.truck.Position.X - this.truck.Origin.X, this.truck.Position.Y + BARREL_OFF_SET);
            staticParms.Texture  = LoadingUtils.load <Texture2D>(content, "LauncherBarrelRight");
            staticParms.Origin   = new Vector2(43f, 62f);
            staticParms.Scale    = new Vector2(.75f);
            staticParms.Rotation = MathHelper.ToRadians(this.angle);
            this.rightBarrel     = new StaticDrawable2D(staticParms);

            staticParms.Position = new Vector2(this.truck.Position.X + this.truck.Origin.X, this.truck.Position.Y + BARREL_OFF_SET);
            staticParms.Texture  = LoadingUtils.load <Texture2D>(content, "LauncherBarrelLeft");
            staticParms.Origin   = new Vector2(21f, 65f);
            this.leftBarrel      = new StaticDrawable2D(staticParms);

            this.activeBarrel      = this.rightBarrel;
            this.textureColourData = TextureUtils.getColourData2D(this.truck.Texture);
            setMatrix();

            // sfx
            this.sfxEngine = sfxEngine;
            this.launchSFX = LoadingUtils.load <SoundEffect>(content, "Launch");
            this.aimingSFX = LoadingUtils.load <SoundEffect>(content, "Aiming");
        }
Esempio n. 5
0
 public Enemy(ContentManager content, SFXEngine sfxEngine, Vector2 position, NukeDelegate nukeDelegate,
              int ownerID, ClosestTargetDelegate closestTarget)
     : base(content, sfxEngine, position, nukeDelegate, ownerID)
 {
     this.closestTarget = closestTarget;
 }