Ejemplo n.º 1
0
 /// <summary>
 /// Evènements du timer (1 sec) pour la gestion des tours.
 /// </summary>
 public void OnTimerElapsed(object state, ElapsedEventArgs e)
 {
     _counter--;
     _timerTextBox.Text = _counter.ToString() + " sec";
     if (_counter <= 3)
     {
         _bigTimerTextBox.Text    = _counter.ToString();
         _bigTimerTextBox.Visible = true;
     }
     if (_counter <= 0)
     {
         _bigTimerTextBox.Visible = false;
         if (_inTour)
         {
             _counter = TIME_BETWEEN_TOUR;
             IndexTeam++;
             Team t = Teams[IndexTeam];
             _currentTeamTextBox.Text = t.ToString();
             _currentTeamTextBox.ApplyColor(t.TeamColor, Color.Black);
             _timerTextBox.ApplyColor(Color.Red, Color.Black);
             _bigTimerTextBox.ApplyColor(Color.White, Color.Black);
             _currentTankTextBox.Text = t.Tanks[t.IndexTank].Name;
             Drop d = new Drop(this, (Drop.eDropType)utils.MathRnd(0, 3), AssetManager.TanksSpriteSheet, new Vector2(utils.MathRnd(20, (int)MapSize.X - 20), 1), Vector2.Zero, Vector2.One);
             while (!CanAppear(d))
             {
                 d.Position = new Vector2(utils.MathRnd(20, (int)MapSize.X - 20), 1);
             }
             MainGame.Camera.SetCameraOnActor(d, true, false);
             OnTourTimerEnd?.Invoke(this, EventArgs.Empty);
         }
         else
         {
             if (IATrainingMode)
             {
                 _counter = TIME_PER_TOUR_IA_TRAINING;
             }
             else
             {
                 _counter = TIME_PER_TOUR;
             }
             _timerTextBox.ApplyColor(Color.Green, Color.Black);
             _bigTimerTextBox.ApplyColor(Color.Orange, Color.Black);
             Team t = Teams[IndexTeam];
             t.NextTank();
             t.RefreshCameraOnSelection();
         }
         _inTour = !_inTour;
     }
 }
Ejemplo n.º 2
0
        public override void Load()
        {
            /*
             #region Chargement de la musique
             * sndMusic = AssetManager.mscMenu;
             * MediaPlayer.Play(sndMusic);
             * MediaPlayer.IsRepeating = true;
             #endregion
             */
            #region Image de background
            _backgroundColor = Color.Transparent;
            _background      = AssetManager.HowToPlay;
            #endregion

            #region Création des éléments la GUI
            SpriteFont font         = AssetManager.MenuFont;
            int        screenWidth  = MainGame.Screen.Width;
            int        screenHeight = MainGame.Screen.Height;

            string text = "RETOUR";
            _menu = new Textbox(new Vector2(10, 10), font, text);
            _menu.ApplyColor(Color.Red, Color.Gray);
            _menu.Color_Hover    = Color.Yellow;
            _menu.ColorBck_Hover = Color.Red;
            _menu.OnClick       += Textbox_OnClick;
            #endregion

            base.Load();
        }
Ejemplo n.º 3
0
            public Grenada(Tank pShooter, Vector2 pPosition, Vector2 pVelocity, Action.eActions pBulletType) : base()
            {
                #region Initialisation des valeurs
                Layer += 0.2f;
                Sender = pShooter;
                switch (pBulletType)
                {
                case TankArmageddon.Action.eActions.Grenada:
                    Radius          = 80;
                    Force           = 25;
                    BounceLimit     = 30;
                    _timerExplosion = 5;
                    Image           = AssetManager.Grenada;
                    Scale           = Vector2.One * 0.1f;
                    break;

                case TankArmageddon.Action.eActions.SaintGrenada:
                    Radius          = 80;
                    Force           = 50;
                    BounceLimit     = 30;
                    _timerExplosion = 5;
                    Image           = AssetManager.SaintGrenada;
                    Scale           = Vector2.One * 0.08f;
                    break;

                default:
                    break;
                }
                Position   = pPosition;
                Velocity   = pVelocity;
                BulletType = pBulletType;
                Origin     = new Vector2(Image.Width / 2, Image.Height);
                #endregion

                #region Initialisation de la GUI
                Vector2 p = new Vector2(BoundingBox.Left, BoundingBox.Top - BoundingBox.Height);
                _textBox = new Textbox(p, AssetManager.MainFont, _timerExplosion.ToString());
                _textBox.ApplyColor(Color.Red, Color.White);
                #endregion

                #region Initialisation du timer d'explosion
                _timer         = new Timer(1000);
                _timer.Enabled = true;
                #endregion

                #region Abonnement aux évènements
                OnExplosion    += Sender.Parent.Parent.CreateExplosion;
                _timer.Elapsed += OnTimerExplosionElapsed;
                #endregion
            }
Ejemplo n.º 4
0
        public override void Load()
        {
            #region Chargement de la musique
            sndMusic = AssetManager.mscVictory;
            MediaPlayer.Play(sndMusic);
            MediaPlayer.IsRepeating = true;
            #endregion

            #region Image de background
            _backgroundColor = Color.Transparent;
            _background      = AssetManager.Victory;
            #endregion

            #region Création des éléments la GUI
            SpriteFont font         = AssetManager.MenuFont;
            int        screenWidth  = MainGame.Screen.Width;
            int        screenHeight = MainGame.Screen.Height;

            _groupMenu = new GroupSelection();

            string text = "MENU";
            _menu = new Textbox(new Vector2(-200, (screenHeight - font.MeasureString(text).Y) / 2 - 40), font, text);
            _groupMenu.AddElement((IIntegrableMenu)_menu);

            text  = "QUITTER";
            _exit = new Textbox(new Vector2(-2200, (screenHeight - font.MeasureString(text).Y) / 2 + 40), font, text);
            _groupMenu.AddElement((IIntegrableMenu)_exit);

            text    = "L'" + MainGame.Winner + " gagne !";
            _winner = new Textbox(new Vector2(-3000, 50), font, text);
            _winner.ApplyColor(Color.Green, Color.Black);

            _groupMenu.RefreshColors();
            _groupMenu.CurrentSelection = 0;

            foreach (Textbox txt in _groupMenu.Elements)
            {
                txt.OnHover += Textbox_OnHover;
                txt.OnClick += Textbox_OnClick;
            }
            #endregion

            #region Création du tweening
            _tweeningMenu   = new Tweening(Tweening.Tween.InSine, (int)_menu.Position.X, (int)(screenWidth - _menu.Size.X) / 2, new TimeSpan(0, 0, 0, TIMER_INTRO));
            _tweeningExit   = new Tweening(Tweening.Tween.InSine, (int)_exit.Position.X, (int)(screenWidth - _exit.Size.X) / 2, new TimeSpan(0, 0, 0, TIMER_INTRO));
            _tweeningWinner = new Tweening(Tweening.Tween.InSine, (int)_winner.Position.X, (int)(screenWidth - _winner.Size.X) / 2, new TimeSpan(0, 0, 0, TIMER_INTRO));
            #endregion

            base.Load();
        }
Ejemplo n.º 5
0
        public override void Load()
        {
            #region Initialisation de la population (en cas de mode entrainement IA)
            IATrainingMode = MainGame.IATrainingMode;
            if (IATrainingMode)
            {
                if (File.Exists("Population.json"))
                {
                    Population = Population.OpenFromFile("Population");
                }
                else
                {
                    Population = new Population();
                    Population.MutationRate = 0.05f;
                }
                Population.OnGenomesDeletion += Population_OnGenomesDeletion;
                Population.OnGenomesChanged  += Population_OnGenomesChanged;
            }
            #endregion

            #region Démarrage des musiques
            sndMusic = AssetManager.mscGameplay;
            MediaPlayer.Play(sndMusic);
            MediaPlayer.Volume      = 0.5f;
            MediaPlayer.IsRepeating = true;
            #endregion

            #region Ajout des bruitages
            _sndexplosion = AssetManager.sndExplosion;
            #endregion

            #region Création du ciel
            _skyTexture = new Texture2D(MainGame.spriteBatch.GraphicsDevice, (int)MapSize.X, _skyHeight);
            Color[] skyData = new Color[_skyTexture.Width * _skyTexture.Height];
            int     skyH    = _skyTexture.Height;
            int     skyW    = _skyTexture.Width;
            for (int y = 0; y < skyH; y++)
            {
                Color skyColor = Color.Lerp(Color.Black, new Color(119, 181, 254), (float)y / skyH);
                for (int x = 0; x < skyW; x++)
                {
                    skyData[x + y * skyW] = skyColor;
                }
            }
            _skyTexture.SetData(skyData);
            #endregion

            #region Création de la map et relevé des points d'eau pour le réseau de neurone
            WaterPosition = new List <Rectangle>();
            bool beginWater         = false;
            int  beginWaterPosition = 0;
            _perlinNoise = PerlinNoise.Generate1DMap((int)MapSize.X, 550f);
            _mapTexture  = new Texture2D(MainGame.spriteBatch.GraphicsDevice, (int)MapSize.X, (int)MapSize.Y);
            MapData      = new byte[(int)(MapSize.X * MapSize.Y)];
            MapColors    = new Color[MapData.Length];

            Color[] colors = new Color[5];
            colors[0] = Color.White;
            colors[1] = Color.Green;
            colors[2] = Color.DarkGreen;
            colors[4] = new Color(132, 73, 44);
            colors[3] = new Color(62, 28, 0);

            for (ushort i = 0; i < _perlinNoise.Length; i++)
            {
                float  noiseVal = _perlinNoise[i];
                ushort x        = (ushort)(i % MapSize.X);
                ushort h        = (ushort)Math.Floor((noiseVal + 1) * MapSize.Y * 0.5f);
                h = (ushort)MathHelper.Clamp(h, 0, WaterLevel + 1);
                int min = (int)Math.Floor((_perlinNoise.Min() + 1) * MapSize.Y * 0.5f);
                int dif = (int)MapSize.Y - min;
                for (ushort y = h; y < MapSize.Y; y++)
                {
                    uint index = (uint)(x + y * MapSize.X);
                    if (y <= WaterLevel)
                    {
                        float pourcent = (float)(y - min) / dif;
                        float p1       = 0.25f;
                        float p2       = 0.5f;
                        float p3       = 0.75f;
                        float p4       = 1f;
                        if (pourcent < p1)
                        {
                            MapColors[index] = Color.Lerp(colors[0], colors[1], pourcent / p1);
                        }
                        else if (pourcent < p2)
                        {
                            MapColors[index] = Color.Lerp(colors[1], colors[2], (pourcent - p1) / (p2 - p1));
                        }
                        else if (pourcent < p3)
                        {
                            MapColors[index] = Color.Lerp(colors[2], colors[3], (pourcent - p2) / (p3 - p2));
                        }
                        else if (pourcent < p4)
                        {
                            MapColors[index] = Color.Lerp(colors[3], colors[4], (pourcent - p3) / (p4 - p3));
                        }
                        MapData[index] = 1;
                    }
                    else
                    {
                        MapColors[index] = Color.Brown;
                    }
                }
                if (!IsSolid(new Vector2(x, WaterLevel - 1)))
                {
                    if (!beginWater)
                    {
                        beginWater         = true;
                        beginWaterPosition = x;
                    }
                }
                else
                {
                    if (beginWater)
                    {
                        beginWater = false;
                        WaterPosition.Add(new Rectangle(beginWaterPosition, WaterLevel, x - beginWaterPosition, (int)MapSize.Y - WaterLevel));
                    }
                }
            }
            _mapTexture.SetData(MapColors);
            #endregion

            #region Création de l'eau
            Vector2 p = new Vector2(0, WaterLevel);
            WaterHeight = (int)(MapSize - p).Y;
            Vector2 s = new Vector2(MapSize.X, WaterHeight);
            _water = new Water(this, p, s);
            #endregion

            #region Paramétrage de la Caméra
            Camera c = MainGame.Camera;
            c.CameraSize   = new Vector3(MapSize.X, MapSize.Y, 0);
            c.CameraOffset = new Vector3(0, MapSize.Y - MainGame.Screen.Height, 0);
            c.Enable       = true;
            c.Speed        = 10;
            #endregion

            #region Création d'un timer de tours
            _timerSecond           = new Timer(1000);
            _timerSecond.Elapsed  += OnTimerElapsed;
            _timerSecond.AutoReset = true;
            _timerSecond.Enabled   = true;
            _counter = TIME_BETWEEN_TOUR;
            #endregion

            #region Création des éléments de GUI
            GUIGroup = new Group();
            Texture2D texture = AssetManager.GameBottomBar;
            _gameBarImage        = new Image(texture, new Vector2(MainGame.Screen.Width / 2, MainGame.Screen.Height - texture.Height / 2));
            _gameBarImage.Layer -= 0.1f;
            _gameBarImage.SetOriginToCenter();
            GUIGroup.AddElement(_gameBarImage);

            texture      = AssetManager.Cursor;
            _cursorImage = new Image(texture, new Vector2(_gameBarImage.Position.X - _gameBarImage.Origin.X + (_gameBarImage.Position.X / MapSize.X), _gameBarImage.Position.Y - texture.Height * 0.75f));
            _cursorImage.SetOriginToCenter();
            GUIGroup.AddElement(_cursorImage);

            Viewport   screen = MainGame.Screen;
            SpriteFont font   = AssetManager.MenuFont;
            _bigTimerTextBox = new Textbox(new Vector2((screen.Width - font.MeasureString("3").X) / 2, (screen.Height - font.MeasureString("3").Y) / 2), font, "3");
            _bigTimerTextBox.ApplyColor(Color.White, Color.Black);
            _bigTimerTextBox.Visible = false;
            _bigTimerTextBox.Layer  += 0.2f;
            GUIGroup.AddElement(_bigTimerTextBox);

            font          = AssetManager.MainFont;
            _timerTextBox = new Textbox(new Vector2(382, 725), font, TIME_BETWEEN_TOUR.ToString() + "sec");
            _timerTextBox.ApplyColor(Color.Red, Color.Black);
            GUIGroup.AddElement(_timerTextBox);

            _currentTeamTextBox = new Textbox(new Vector2(25, 725), font, "Equipe des rouges");
            GUIGroup.AddElement(_currentTeamTextBox);

            _currentTankTextBox = new Textbox(new Vector2(196, 725), font, ".");
            _currentTankTextBox.ApplyColor(Color.Yellow, Color.Black);
            GUIGroup.AddElement(_currentTankTextBox);

            _infoBulle = new Textbox(new Vector2(925, 725), font, "InfoBulle :");
            _infoBulle.ApplyColor(Color.Yellow, Color.Black);
            GUIGroup.AddElement(_infoBulle);

            if (IATrainingMode)
            {
                _fittingScoreTextBox = new Textbox(Vector2.One, font, "Fitness Score : 0 Generation : " + Population.Generation);
                _fittingScoreTextBox.ApplyColor(Color.Yellow, Color.Black);
                GUIGroup.AddElement(_fittingScoreTextBox);
            }

            GUIGroupButtons = new GroupSelection();
            for (int i = 0; i < Enum.GetValues(typeof(Action.eActions)).Length; i++)
            {
                ButtonAction btn;
                if (i == 0)
                {
                    btn = new ButtonAction(this, (Action.eActions)i, Vector2.Zero, Vector2.Zero, AssetManager.MainFont, string.Empty);
                }
                else
                {
                    btn = new ButtonAction(this, (Action.eActions)i, new Vector2(442 + 37 * (i - 1), 725), Vector2.Zero, AssetManager.MainFont, string.Empty);
                }
                GUIGroupButtons.AddElement((IIntegrableMenu)btn);
                btn.OnHover += OnButtonHover;
                btn.OnClick += OnButtonClicked;
            }
            c.OnPositionChange += OnCameraPositionChange;
            #endregion

            #region Remplissage du sac à loot
            _lootBag = new List <Action.eActions>();
            FillLootBag();
            #endregion

            #region Création des équipes
            Teams = new List <Team>();
            Texture2D img = AssetManager.TanksSpriteSheet;
            Team      t;
            int       numberOfTeam        = MainGame.NumberOfTeam;
            int       numberOfTankPerTeam = MainGame.NumberOfTank;
            Random    rnd = new Random();

            for (byte i = 0; i < numberOfTeam; i++)
            {
                eControlType controlType;
                if (IATrainingMode)
                {
                    controlType = eControlType.NeuralNetwork;
                }
                else
                {
                    //if (i < 1)
                    controlType = eControlType.Player;     // MainGame.ControlTypes[i];
                    //else
                    //controlType = eControlType.NeuralNetwork;
                }
                t = new Team(this, img, numberOfTankPerTeam, i, rnd, controlType);
                Teams.Add(t);
                if (IATrainingMode)
                {
                    NeuralNetworkControl nn = (NeuralNetworkControl)t.Control;
                    if (Population.Genomes.Count > i)
                    {
                        nn.Genome = Population.Genomes[i % Population.Genomes.Count];
                        nn.Genome.OnFitnessScoreChange += Genome_OnFitnessScoreChange;
                    }
                    else
                    {
                        Population.Genomes.Add(nn.Genome);
                        nn.Genome.OnFitnessScoreChange += Genome_OnFitnessScoreChange;
                    }
                }
                t.OnTankSelectionChange += OnTankSelectionChange;
            }
            t = Teams[IndexTeam];
            t.RefreshCameraOnSelection();
            _currentTeamTextBox.ApplyColor(t.TeamColor, Color.Black);
            _currentTankTextBox.Text = t.Tanks[t.IndexTank].Name;
            RefreshActionButtonInventory();
            #endregion

            base.Load();
        }