Ejemplo n.º 1
0
Archivo: Map.cs Proyecto: HaKDMoDz/geff
 private Cell GetNeighborough(Cell cell, int offsetX, int offsetY)
 {
     return Cells.Find(c => c.Coord.X == cell.Coord.X + offsetX && c.Coord.Y == cell.Coord.Y + offsetY);
 }
Ejemplo n.º 2
0
        private void DrawCell(Cell cell, GameTime gameTime)
        {
            //--- TODO : gérer le frustum
            //---
            Vector2 midTexSize = new Vector2(HexaWidth/2,HexaWidth/2);

            Vector2 cellLocation = cell.Location * texHexa2D.Width;
            Color colorChannel = new Color(0.35f, 0.35f, 0.35f);
            Cell cellToDraw = cell;

            if (Context.MovedDestinationCell == cell && Context.MovedSourceCell != null)
                cellToDraw = Context.MovedSourceCell;

            if (Context.MovedSourceCell == cell && Context.MovedDestinationCell != null)
            {
                cellToDraw = new Cell();
                cellToDraw.Life = new float[Context.Map.Channels.Count];
            }

            if (cellToDraw.Channel != null)
                colorChannel = cellToDraw.Channel.Color;

            //--- Calcul de la couleur de la cellule selon ses vies
            float r = 0f, g = 0f, b = 0f, fj = 0f;
            int n = 0;

            for (int i = 0; i < cellToDraw.Life.Length; i++)
            {
                if (cellToDraw.Clip == null && cellToDraw.Life[i] > 0f)
                    fj += cellToDraw.Life[i];
            }

            for (int i = 0; i < cellToDraw.Life.Length; i++)
            {
                if (cellToDraw.Clip == null && cellToDraw.Life[i] > 0f)
                {
                    n++;
                    Color c = Color.Lerp(colorChannel, Context.Map.Channels[i].Color, cellToDraw.Life[i]);

                    r += (float)c.R / 255f * (cell.Life[i] / fj);
                    g += (float)c.G / 255f * (cell.Life[i] / fj);
                    b += (float)c.B / 255f * (cell.Life[i] / fj);
                }
            }

            if (n > 0)
                colorChannel = new Color(r, g, b);
            //---

            if (cell == Context.CopiedCell || cell == Context.SelectedCell || cell == Context.NextCellNote)
            {
                Color colorSelection = Color.White;

                if (cell == Context.CopiedCell)
                    colorSelection = VisualStyle.BackForeColorMouseOver;
                if (cell == Context.NextCellNote)
                    colorSelection = VisualStyle.BackForeColorChecked;

                SpriteBatch.Draw(texHexa2DSelected, cellLocation - new Vector2(texHexa2DSelected.Width - texHexa2D.Width, texHexa2DSelected.Height - texHexa2D.Height) / 2, colorSelection);
            }

            if (cellToDraw.Clip == null)
            {
                SpriteBatch.Draw(texHexa2D, cellLocation, null, colorChannel,0f, Vector2.Zero, cell.Size, SpriteEffects.None, 0f);
            }
            else
            {
                //SpriteBatch.Draw(texHexa2DClip, cellLocation, colorChannel);

                SpriteBatch.Draw(texHexa2DClip, cellLocation, null, colorChannel, 0f, Vector2.Zero, cell.Size, SpriteEffects.None, 0f);

                //--- Instrument
                if (cellToDraw.Clip.Instrument != null)
                {
                    Texture2D texInstrument = null;

                    if (cellToDraw.Clip.Instrument is InstrumentStart)
                    {
                        texInstrument = texMusicianStart;
                    }
                    else if (cellToDraw.Clip.Instrument is InstrumentStop)
                    {
                        texInstrument = texMusicianStop;
                    }
                    else if (cellToDraw.Clip.Instrument is InstrumentSample)
                    {
                        texInstrument = GameEngine.Content.Load<Texture2D>(@"Texture\Icon\Instrument" + cellToDraw.Channel.Name);
                    }
                    else if (cellToDraw.Clip.Instrument is InstrumentCapture)
                    {
                        texInstrument = GameEngine.Content.Load<Texture2D>(@"Texture\Icon\Instrument" + cellToDraw.Channel.Name);
                    }
                    else if (cellToDraw.Clip.Instrument is InstrumentNote)
                    {
                        texInstrument = texInstrumentNote;
                    }

                    if (cellToDraw.Clip.Instrument is InstrumentEffect)
                    {
                        texInstrument = texEffect;

                        string effectName = ((InstrumentEffect)cellToDraw.Clip.Instrument).ChannelEffect.Name;
                        Vector2 deltaEffectName = new Vector2(FontMap.MeasureString(effectName).X / 2, FontMap.MeasureString(effectName).Y / 5);

                        SpriteBatch.DrawString(FontMap, effectName, cellLocation + midCellSize * cell.Size - deltaEffectName, Color.White);
                        SpriteBatch.Draw(texInstrument, cellLocation + midCellSize * cell.Size - new Vector2(texInstrument.Width / 2, texInstrument.Height) * cell.Size, null, Color.White, 0f, Vector2.Zero, cell.Size, SpriteEffects.None, 0f);
                    }
                    else if (cellToDraw.Clip.Instrument is InstrumentSample)
                    {
                        string sampleName = ((InstrumentSample)cellToDraw.Clip.Instrument).Sample.Name;
                        Vector2 deltaSampleName = new Vector2(FontMap.MeasureString(sampleName).X / 2, FontMap.MeasureString(sampleName).Y / 5);

                        SpriteBatch.Draw(texInstrument, cellLocation + midCellSize * cell.Size - new Vector2(texInstrument.Width / 2, texInstrument.Height / 2) * cell.Size - new Vector2(0f, midCellSize.Y * cell.Size * 0.3f), null, Color.White, 0f, Vector2.Zero, cell.Size, SpriteEffects.None, 0f);
                        SpriteBatch.DrawString(FontMap, sampleName, cellLocation + midCellSize * cell.Size - deltaSampleName, Color.White);
                    }
                    else if (cellToDraw.Clip.Instrument is InstrumentNote)
                    {
                        string noteName = ((InstrumentNote)cellToDraw.Clip.Instrument).NoteName;
                        Vector2 deltaSampleName = new Vector2(FontMap.MeasureString(noteName).X / 2, FontMap.MeasureString(noteName).Y / 5);

                        SpriteBatch.Draw(texInstrument, cellLocation + midCellSize * cell.Size - new Vector2(texInstrument.Width / 2, texInstrument.Height / 2) * cell.Size - new Vector2(0f, midCellSize.Y * cell.Size * 0.3f), null, Color.White, 0f, Vector2.Zero, cell.Size, SpriteEffects.None, 0f);
                        SpriteBatch.DrawString(FontMap, noteName, cellLocation + midCellSize * cell.Size - deltaSampleName, Color.White);
                    }
                    else
                    {
                        SpriteBatch.Draw(texInstrument, cellLocation + midCellSize * cell.Size - new Vector2(texInstrument.Width / 2, texInstrument.Height / 2) * cell.Size, null, Color.White, 0f, Vector2.Zero, cell.Size, SpriteEffects.None, 0f);
                    }
                }
                //---

                //--- Direction
                for (int i = 0; i < 6; i++)
                {
                    if (cellToDraw.Clip.Directions[i])
                    {
                        double angle = MathHelper.TwoPi / 6 * i;
                        Vector2 center = new Vector2(0.5f * textDirection.Width, 0.5f * textDirection.Height + 0.34f * HexaWidth);
                        SpriteBatch.Draw(textDirection, cellLocation + midCellSize * cell.Size, null, Color.White, (float)angle, center, cell.Size, SpriteEffects.None, 0f);
                    }
                }
                //---

                //--- Repeater
                for (int i = 0; i < 6; i++)
                {
                    if (cellToDraw.Clip.Repeater.HasValue && i <= cellToDraw.Clip.Repeater.Value)
                    {
                        double angle = MathHelper.TwoPi / 6 * i - MathHelper.TwoPi / 12;
                        Vector2 center = new Vector2(0.5f * texRepeater.Width, 0.5f * texRepeater.Height + 0.4f * HexaWidth);
                        SpriteBatch.Draw(texRepeater, cellLocation + midCellSize * cell.Size, null, Color.White, (float)angle, center, cell.Size, SpriteEffects.None, 0f);
                    }
                }
                //---

                //--- Speed
                //for (int i = 0; i < 4; i++)
                //{
                //    if (
                //        cellToDraw.Clip.Speed.HasValue &&
                //        cellToDraw.Clip.Speed.Value > 0 &&
                //        i < cellToDraw.Clip.Speed.Value)
                //    {
                //        Vector2 center = new Vector2(0.5f * texSpeed.Width, 0.5f * texSpeed.Height);
                //        Vector2 location = new Vector2(-2f * texSpeed.Width + Math.Abs(i) * texSpeed.Width, 0.34f * HexaWidth - texSpeed.Height);
                //        SpriteBatch.Draw(texSpeed, cellLocation + midCellSize + location, null, Color.White, 0f, center, 1f, SpriteEffects.None, 0f);

                //    }
                //    else if (
                //        cellToDraw.Clip.Speed.HasValue &&
                //        cellToDraw.Clip.Speed.Value < 0 &&
                //        i < Math.Abs(cellToDraw.Clip.Speed.Value))
                //    {
                //        Vector2 center = new Vector2(0.5f * texSpeed.Width, 0.5f * texSpeed.Height);
                //        Vector2 location = new Vector2(-2f * texSpeed.Width + Math.Abs(i) * texSpeed.Width, 0.34f * HexaWidth - texSpeed.Height);
                //        SpriteBatch.Draw(texSpeed, cellLocation + midCellSize + location, null, Color.White, 0f, center, 1f, SpriteEffects.FlipHorizontally, 0f);
                //    }
                //}
                //---

                //--- Note duration
                if (cellToDraw.Clip.Duration < 1f)
                {
                    int duration = (int)Math.Log((int)(1f / cellToDraw.Clip.Duration), 2);
                    Vector2 durationPosition = new Vector2(HexaWidth * 0.5f - (float)(duration) * (float)texDuration.Width * 0.5f, 0.76f * HexaWidth - texDuration.Height);
                    Vector2 center = new Vector2(0.5f * texDuration.Width, 0.5f * texDuration.Height);

                    for (int i = 0; i < duration; i++)
                    {
                        Vector2 location = durationPosition + new Vector2(i * texDuration.Width, 0f);
                        SpriteBatch.Draw(texDuration, cellLocation + location *cell.Size, null, Color.White, 0f, center, cell.Size, SpriteEffects.None, 0f);
                    }
                }
                //---
            }
        }
Ejemplo n.º 3
0
Archivo: Map.cs Proyecto: HaKDMoDz/geff
        public void CreateGrid()
        {
            Cells = new List<Cell>();

            Random rnd = new Random();

            float width = 0.5f;
            float height = 0.5f * (float)Math.Sin(MathHelper.Pi / 3);

            for (int y = 1; y <= Height; y++)
            {
                for (int x = 1; x <= Math.Round((double)Width / 2, MidpointRounding.AwayFromZero); x++)
                {
                    float fx = (float)x;
                    float fy = (float)y;

                    fx = fx * width * 3f;
                    fy = fy * height * 2f;

                    Cell cell2 = new Cell(this, x, y * 2,
                         fx,
                         fy);

                    Cells.Add(cell2);
                }

                for (int x = 1; x <= Width / 2; x++)
                {
                    float fx = (float)x;
                    float fy = (float)y;

                    fx = fx * width * 3f + width * 1.5f;
                    fy = fy * height * 2f - height;

                    Cell cell1 = new Cell(this, x, (y * 2) - 1,
                         fx,
                         fy);

                    Cells.Add(cell1);
                }
            }

            CalcNeighborough();
        }
Ejemplo n.º 4
0
        public void EvaluateMuscianGrid()
        {
            //--- Initialisation
            foreach (Channel channel in Context.Map.Channels)
            {
                channel.ListMusician = new List<Musician>();
                channel.ListSpeed = new List<TimeValue<float>>();
                channel.ListSpeed.Add(new TimeValue<float>(new TimeSpan(), 1f));
                channel.InitChannelEffect();

                if (channel.CellStart != null)
                {
                    Musician musician = channel.GetMusicianNotPlaying();
                    musician.IsPlaying = true;
                    musician.NextCell = channel.CellStart;
                }

                foreach (Musician musician in channel.ListMusician)
                {
                    musician.ElapsedTime = TimeSpan.Zero;
                    if (musician.Channel.ListSample.Count > 0)
                        musician.CurrentSample = musician.Channel.ListSample[0];
                    else
                        musician.CurrentSample = null;
                }
            }
            //---

            int musicianCalculationInProgress = 1;

            while (musicianCalculationInProgress > 0)
            {
                musicianCalculationInProgress = 0;

                foreach (Channel channel in Context.Map.Channels)
                {
                    List<Musician> newMusicians = new List<Musician>();

                    foreach (Musician musician in channel.ListMusician)
                    {
                        if (musician.ElapsedTime < Context.Map.PartitionDuration && musician.NextCell != null)
                        {
                            Cell cell = musician.NextCell;
                            float speedFactor = 1f;

                            if (cell != null && (cell.Channel == null || cell.Channel == channel) && cell.Clip != null)
                            {
                                bool ignoreCell = false;

                                //--- Repeater
                                if (cell.Clip.Repeater.HasValue)
                                {
                                    TimeValue<Cell> part = musician.Partition.LastOrDefault(p => p.Value.Clip != null && p.Value.Clip.Instrument != null && p.Value.Clip.Instrument is InstrumentStop);
                                    TimeSpan timePart = TimeSpan.Zero;

                                    if (part != null)
                                        timePart = part.Time;

                                    ignoreCell = musician.Partition.Count(p => p.Time > timePart && p.Value == cell) >= (cell.Clip.Repeater.Value + 1);

                                    if (ignoreCell)
                                    {
                                        int a = 0;
                                    }
                                }
                                //---

                                //--- Note duration
                                speedFactor = cell.Clip.Duration;

                                if (speedFactor == 1 / 8f)
                                {
                                    int a = 0;
                                }
                                //---

                                if (!ignoreCell)
                                {
                                    //--- Speed
                                    if (cell.Clip.Speed.HasValue)
                                    {
                                        float speed = channel.GetSpeedFromTime(musician.ElapsedTime);

                                        speed *= (0.22f * (float)(cell.Clip.Speed.Value)) + 1f;

                                        if (speed < 1f / 16f)
                                            speed = 1f / 16f;
                                        else if (speed > 4f)
                                            speed = 4f;

                                        channel.ListSpeed.Add(new TimeValue<float>(musician.ElapsedTime, speed));
                                    }
                                    //---

                                    //--- Instrument
                                    if (cell.Clip.Instrument is InstrumentStop)
                                    {
                                        musician.IsPlaying = false;
                                        musician.NextCell = null;
                                    }
                                    //---

                                    //--- Effet
                                    if (cell.Clip.Instrument is InstrumentEffect)
                                    {
                                        InstrumentEffect effect = cell.Clip.Instrument as InstrumentEffect;

                                        ChannelEffect channelEffect = cell.Channel.ListEffect.Find(ce => ce.Name == effect.ChannelEffect.Name);

                                        for (int i = 0; i < channelEffect.ListEffectProperty.Count; i++)
                                        {
                                            channelEffect.ListEffectProperty[i].Curve.Keys.Add(new CurveKey((float)musician.ElapsedTime.TotalMilliseconds, effect.ChannelEffect.ListEffectProperty[i].Value));
                                        }
                                    }
                                    //---

                                    //--- Direction
                                    bool divided = false;

                                    for (int i = 0; i < 6; i++)
                                    {
                                        if (cell.Clip.Directions[i])
                                        {
                                            if (divided)
                                            {
                                                Musician newMusician = new Musician(channel);

                                                newMusician.CurrentDirection = i;
                                                newMusician.CurrentCell = cell;
                                                newMusician.NextCell = cell.Neighbourghs[newMusician.CurrentDirection];
                                                newMusician.ElapsedTime = musician.ElapsedTime;

                                                newMusicians.Add(newMusician);
                                            }
                                            else
                                            {
                                                musician.CurrentDirection = i;

                                                divided = true;
                                            }
                                        }
                                    }
                                }
                            }

                            if (cell != null)
                            {
                                //--- Met à jour la partition du musicien
                                musician.Partition.Add(new TimeValue<Cell>(musician.ElapsedTime, cell));
                                musician.ElapsedTime = musician.ElapsedTime.Add(new TimeSpan(0, 0, 0, 0, (int)(Context.Map.TimeDuration * speedFactor / channel.GetSpeedFromTime(musician.ElapsedTime))));

                                if (musician.IsPlaying)
                                    musician.NextCell = cell.Neighbourghs[musician.CurrentDirection];
                                //---

                                musicianCalculationInProgress++;
                            }
                        }
                    }

                    //--- Suppression des doublons de musiciens
                    foreach (Musician musician in channel.ListMusician)
                    {
                        if (musician.IsPlaying && musician.NextCell != null)
                        {
                            List<Musician> doublonMusician = channel.ListMusician.FindAll(
                                m => m.IsPlaying &&
                                    m != musician &&
                                    m.Partition.Last() == musician.Partition.Last() &&
                                    m.NextCell != null &&
                                    m.NextCell.IndexPosition == musician.NextCell.IndexPosition
                                    );

                            foreach (Musician doublon in doublonMusician)
                            {
                                //--- Création d'une cellule fictive pour la suppression du doublon
                                Cell cell = doublon.Partition.Last().Value;
                                Cell cellDoublon = new Cell(Context.Map, cell.Coord.X, cell.Coord.Y, cell.Location.X, cell.Location.Y);

                                cellDoublon.InitClip();
                                cellDoublon.Clip.Instrument = new InstrumentStop();
                                //---

                                doublon.IsPlaying = false;
                                doublon.Partition.Add(new TimeValue<Cell>(doublon.Partition.Last().Time, cellDoublon));
                                doublon.NextCell = null;
                            }
                        }
                    }
                    //---

                    //--- Création des nouveaux musiciens
                    foreach (Musician newMusician in newMusicians)
                    {
                        Musician musician = channel.GetMusicianNotPlaying();

                        if (musician != null)
                        {
                            musician.Partition.Add(new TimeValue<Cell>(newMusician.ElapsedTime, newMusician.CurrentCell));
                            musician.ElapsedTime = newMusician.ElapsedTime.Add(new TimeSpan(0, 0, 0, 0, (int)(Context.Map.TimeDuration * 1f / channel.GetSpeedFromTime(musician.ElapsedTime))));
                            musician.CurrentCell = null;
                            musician.NextCell = newMusician.NextCell;
                            musician.CurrentDirection = newMusician.CurrentDirection;
                            musician.IsPlaying = true;
                            if (musician.Channel.ListSample.Count > 0)
                                musician.CurrentSample = musician.Channel.ListSample[0];
                            else
                                musician.CurrentSample = null;
                        }
                    }
                    //---
                }
            }

            GameEngine.GamePlay.UpdateMusiciansToTime(false);
        }
Ejemplo n.º 5
0
        private void NewBornCell(GameTime gameTime, Cell cell, Channel channel)
        {
            int indexChannel = Context.Map.Channels.IndexOf(channel != null ? channel : cell.Channel);

            cell.Life[indexChannel] = 1f;

            foreach (Cell otherCell in Context.Map.Cells)
            {
                float distance = Tools.Distance(cell.Location, otherCell.Location);

                if (otherCell != cell && otherCell.Clip == null)
                {
                    //--- Vie des cellules voisines
                    if (distance <= rayon)
                    {
                        float newLife = 1f - (distance / rayon);
                        if (otherCell.Life[indexChannel] < newLife)
                            otherCell.Life[indexChannel] = newLife;
                    }
                    //---
                }

                //---
                if (otherCell != cell && distance < rayon)
                {
                    otherCell.ListWave.Add(new TimeValue<Vector2>(gameTime.TotalGameTime, otherCell.Location - cell.Location));
                }
                //---
            }
        }
Ejemplo n.º 6
0
        public void Clone(Cell cellOrigin)
        {
            cellOrigin.Clip = null;

            cellOrigin.Channel = this.Channel;

            if (this.Clip != null)
            {
                cellOrigin.Clip = new Clip();

                for (int i = 0; i < 6; i++)
                {
                    cellOrigin.Clip.Directions[i] = this.Clip.Directions[i];
                }

                cellOrigin.Clip.Repeater = this.Clip.Repeater;
                cellOrigin.Clip.Speed = this.Clip.Speed;
                cellOrigin.Clip.Duration = this.Clip.Duration;

                if (this.Clip.Instrument != null)
                {
                    if (this.Clip.Instrument is InstrumentSample)
                    {
                        cellOrigin.Clip.Instrument = new InstrumentSample(((InstrumentSample)this.Clip.Instrument).Sample);
                    }
                    else if (this.Clip.Instrument is InstrumentEffect)
                    {
                        cellOrigin.Clip.Instrument = new InstrumentEffect(((InstrumentEffect)this.Clip.Instrument).ChannelEffect);
                    }
                    else if (this.Clip.Instrument is InstrumentStart)
                    {
                        cellOrigin.Clip.Instrument = new InstrumentStart();

                        this.Clip.Instrument = null;
                        this.Channel.CellStart = cellOrigin;
                    }
                    else if (this.Clip.Instrument is InstrumentStop)
                    {
                        cellOrigin.Clip.Instrument = new InstrumentStop();
                    }
                    else if (this.Clip.Instrument is InstrumentNote)
                    {
                        cellOrigin.Clip.Instrument = new InstrumentNote(((InstrumentNote)this.Clip.Instrument).NoteKey, ((InstrumentNote)this.Clip.Instrument).NoteName);
                    }
                    else if (this.Clip.Instrument is InstrumentCapture)
                    {
                        cellOrigin.Clip.Instrument = new InstrumentCapture(((InstrumentCapture)this.Clip.Instrument).Sample);
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public CircularMenu CreateMenu(Cell cell, TimeSpan creationTime)
        {
            //---
            CircularMenu menuRoot = new CircularMenu(this, null, creationTime, cell, null, null, true);

            Item itemReset = new Item(menuRoot, "Reset");
            itemReset.Selected += new Item.SelectedHandler(itemReset_Selected);
            menuRoot.Items.Add(itemReset);

            Item itemMenuDirection = new Item(menuRoot, "Direction");
            itemMenuDirection.Selected += new Item.SelectedHandler(itemMenuDirection_Selected);
            menuRoot.Items.Add(itemMenuDirection);

            Item itemMenuRepeater = new Item(menuRoot, "Repeater");
            itemMenuRepeater.Selected += new Item.SelectedHandler(itemMenuRepeater_Selected);
            menuRoot.Items.Add(itemMenuRepeater);

            //Item itemMenuSpeed = new Item(menuRoot, "Speed");
            //itemMenuSpeed.Selected += new Item.SelectedHandler(itemMenuSpeed_Selected);
            //menuRoot.Items.Add(itemMenuSpeed);

            Item itemMenuDuration = new Item(menuRoot, "Duration");
            itemMenuDuration.Selected += new Item.SelectedHandler(itemMenuDuration_Selected);
            menuRoot.Items.Add(itemMenuDuration);

            Item itemMenuInstrument = new Item(menuRoot, "Instrument");
            itemMenuInstrument.Selected += new Item.SelectedHandler(itemMenuInstrument_Selected);
            menuRoot.Items.Add(itemMenuInstrument);

            Item itemMenuChannel = new Item(menuRoot, "Channel");
            itemMenuChannel.Selected += new Item.SelectedHandler(itemMenuChannel_Selected);
            menuRoot.Items.Add(itemMenuChannel);
            //---

            return menuRoot;
        }
Ejemplo n.º 8
0
 public void OpenPannelEffect(GameTime gameTime, ChannelEffect channelEffect, Cell cell)
 {
     EffectPanel effectPanel = new EffectPanel(this, null, gameTime.TotalGameTime, channelEffect, cell);
     this.ListUIComponent.Add(effectPanel);
 }
Ejemplo n.º 9
0
 public void OpenListSample(GameTime gameTime, Cell cell)
 {
     ListSample listSample = new ListSample(this, null, gameTime.TotalGameTime, cell, cell.Channel, new Rectangle(GameEngine.GraphicsDevice.Viewport.Width / 2 - 125, (int)(GameEngine.GraphicsDevice.Viewport.Height * 0.25), 250, (int)(GameEngine.GraphicsDevice.Viewport.Height * 0.6)), GameEngine.Render.FontText, false);
     listSample.Modal = true;
     this.ListUIComponent.Add(listSample);
 }
Ejemplo n.º 10
0
 public void OpenKeyboard(GameTime gameTime, Cell cell)
 {
     NotePanel notePanel = new NotePanel(this, TimeSpan.FromDays(1));
     this.ListUIComponent.Add(notePanel);
 }