Exemplo n.º 1
0
 public void SwitchMap(int number, Point pos, Mario.Size size)
 {
     Console.WriteLine("Switching map to{0}", number);
     maps[currentmap].KillSound();
     currentmap = number;
     maps[currentmap].SetMarioPosition(pos);
     maps[currentmap].StartSound();
     maps[currentmap].mario.SetSize(size);
 }
Exemplo n.º 2
0
        public Map(SpriteBatch batch, ContentManager manager, string world, string filename)
        {
            this.manager = manager;
            this.batch = batch;
            teleports = new List<Globals.Teleport>();
            sounds = new List<SoundEffectInstance>();
            staticobjects = new List<Sprite>();
            moveableobjects = new List<Sprite>();
            bool readingtStart = false;
            bool readingSounds = false;
            bool readingBackground = false;
            bool readingColission = false;
            bool readingObjects = false;
            bool readingFlag = false;
            bool readingTeleports = false;

            using (StreamReader reader = new StreamReader("Content/worlds/"+world+"/"+filename))
            {
                while (!reader.EndOfStream)
                {
                    string line = reader.ReadLine().Trim();

                    if (string.IsNullOrEmpty(line))
                        continue;
                    if(line.Contains("[START]"))
                    {
                        readingtStart = true;
                        readingSounds = false;
                        readingBackground = false;
                        readingColission = false;
                        readingObjects = false;
                        readingFlag = false;
                        readingTeleports = false;
                    }
                    else if (line.Contains("[FLAG]"))
                    {
                        readingtStart = false;
                        readingSounds = true;
                        readingBackground = false;
                        readingColission = false;
                        readingObjects = false;
                        readingFlag = true;
                        readingTeleports = false;
                    }
                    else if (line.Contains("[TELEPORTS]"))
                    {
                        readingtStart = false;
                        readingSounds = false;
                        readingBackground = false;
                        readingColission = false;
                        readingObjects = false;
                        readingFlag = false;
                        readingTeleports = true;
                    }
                    else if (line.Contains("[SOUNDS]"))
                    {
                        readingtStart = false;
                        readingSounds = true;
                        readingBackground = false;
                        readingColission = false;
                        readingObjects = false;
                        readingFlag = false;
                        readingTeleports = false;
                    }
                    else if (line.Contains("[BACKGROUND]"))
                    {
                        readingtStart = false;
                        readingSounds = false;
                        readingBackground = true;
                        readingColission = false;
                        readingObjects = false;
                        readingFlag = false;
                        readingTeleports = false;
                    }
                    else if (line.Contains("[COLISSION]"))
                    {
                        readingtStart = false;
                        readingSounds = false;
                        readingBackground = false;
                        readingColission = true;
                        readingObjects = false;
                        readingFlag = false;
                        readingTeleports = false;
                    }
                    else if (line.Contains("[OBJECTS]"))
                    {
                        readingtStart = false;
                        readingSounds = false;
                        readingBackground = false;
                        readingColission = false;
                        readingObjects = true;
                        readingFlag = false;
                        readingTeleports = false;
                    }

                    else if (readingtStart)
                    {
                        string[] tmp = line.Split(' ');
                        start = new Point(int.Parse(tmp[0]), int.Parse(tmp[1]));
                    }
                    else if (readingFlag)
                    {
                        flagexists = true;
                        string[] tmp = line.Split(' ');
                        flagposition = new Point(int.Parse(tmp[0]), int.Parse(tmp[1]));
                        flagpositionbackup = new Point(int.Parse(tmp[0]), int.Parse(tmp[1]));
                    }
                    else if (readingTeleports)
                    {

                        string[] tmp = line.Split(' ');
                        Globals.Teleport tmp2 = new Globals.Teleport(int.Parse(tmp[0]),
                                                                        int.Parse(tmp[1]),
                                                                        int.Parse(tmp[2]),
                                                                        new Point(int.Parse(tmp[3]), int.Parse(tmp[4])));
                        teleports.Add(tmp2);
                    }
                    else if (readingSounds)
                    {
                        SoundEffect tmp = manager.Load<SoundEffect>("sounds/"+line);
                        SoundEffectInstance sound = tmp.CreateInstance();
                        sounds.Add(sound);
                    }
                    else if (readingBackground)
                    {
                        background = manager.Load<Texture2D>("worlds/" + world + "/" + line);
                    }
                    else if (readingColission)
                    {
                        colission = ColissionLayer.FromFile("worlds/" + world + "/" + line);
                    }
                    else if (readingObjects)
                    {
                        ObjectsLayer tmp = ObjectsLayer.FromFile("worlds/" + world + "/" + line);

                        for (int x = 0; x < tmp.width; x++)
                        {
                            for (int y = 0; y < tmp.height; y++)
                            {
                                if (tmp.GetCellIndex(x, y) == 0)
                                    continue;
                                if (tmp.GetCellIndex(x, y) > 0 && tmp.GetCellIndex(x, y) < 5)
                                {
                                    Box tmp3 = new Box(batch, manager, tmp.GetCellIndex(x, y), new Point(Globals.ConvertCellToX(x), Globals.ConvertCellToY(y)));
                                    staticobjects.Add(tmp3);
                                }
                                else if (tmp.GetCellIndex(x, y) > 4 && tmp.GetCellIndex(x, y) < 7)
                                {
                                    Brick tmp3 = new Brick(batch, manager, tmp.GetCellIndex(x, y), new Point(Globals.ConvertCellToX(x), Globals.ConvertCellToY(y)));
                                    staticobjects.Add(tmp3);
                                }
                                else if (tmp.GetCellIndex(x, y) == 7)
                                {
                                    Goomba tmp3 = new Goomba(batch, manager, colission, tmp.GetCellIndex(x, y), new Point(Globals.ConvertCellToX(x), Globals.ConvertCellToY(y)));
                                    moveableobjects.Add(tmp3);
                                }
                                else if (tmp.GetCellIndex(x, y) == 8)
                                {
                                    Coin tmp3 = new Coin(batch, manager, tmp.GetCellIndex(x, y), new Point(Globals.ConvertCellToX(x), Globals.ConvertCellToY(y)));
                                    moveableobjects.Add(tmp3);
                                }

                            }
                        }

                    }

                }
            }

            flag = manager.Load<Texture2D>("images/flag");
            size = new Point(this.background.Width, this.background.Height);
            camera = new Camera(size.X, size.Y);
            mario = new Mario(batch, manager, start, colission, staticobjects, moveableobjects);
        }
Exemplo n.º 3
0
 public void SetSize(Mario.Size size)
 {
     if (size == Size.small)
     {
         position.Y += 16;
         feetoffset = 16;
         flagpole1 = 169;
         centeroffset = new Point(8, 8);
         curstate3 = Size.small;
         ReloadTexture("marios");
         animations.Clear();
         FrameAnimation anim = new FrameAnimation(3, 15, 16, 0, 0);
         anim.FramesPerSecond = 20;
         animations.Add("runright", anim);
         anim = new FrameAnimation(3, 15, 16, 0, 17);
         anim.FramesPerSecond = 20;
         animations.Add("runleft", anim);
         anim = new FrameAnimation(1, 16, 16, 48, 0);
         anim.FramesPerSecond = 20;
         animations.Add("jumpright", anim);
         anim = new FrameAnimation(1, 16, 16, 48, 17);
         anim.FramesPerSecond = 20;
         animations.Add("jumpleft", anim);
         anim = new FrameAnimation(1, 16, 16, 66, 0);
         anim.FramesPerSecond = 20;
         animations.Add("frictionright", anim);
         anim = new FrameAnimation(1, 16, 16, 66, 17);
         anim.FramesPerSecond = 20;
         animations.Add("frictionleft", anim);
         anim.FramesPerSecond = 20;
         anim = new FrameAnimation(1, 16, 16, 80, 0);
         anim.FramesPerSecond = 20;
         animations.Add("stopright", anim);
         anim = new FrameAnimation(1, 16, 16, 80, 17);
         anim.FramesPerSecond = 20;
         animations.Add("stopleft", anim);
         anim = new FrameAnimation(1, 16, 16, 0, 34);
         anim.FramesPerSecond = 20;
         animations.Add("die", anim);
         anim = new FrameAnimation(1, 16, 16, 16, 34);
         animations.Add("slideright", anim);
         anim = new FrameAnimation(1, 16, 16, 32, 34);
         animations.Add("slideleft", anim);
     }
     else if (size == Size.big)
     {
         position.Y -= 16;
         feetoffset = 32;
         flagpole1 = 169-16;
         centeroffset = new Point(8, 16);
         curstate3 = Size.big;
         ReloadTexture("mariob");
         animations.Clear();
         FrameAnimation anim = new FrameAnimation(3, 16, 32, 0, 0);
         anim.FramesPerSecond = 20;
         animations.Add("runright", anim);
         anim = new FrameAnimation(3, 16, 32, 0, 32);
         anim.FramesPerSecond = 20;
         animations.Add("runleft", anim);
         anim = new FrameAnimation(1, 16, 32, 48, 0);
         anim.FramesPerSecond = 20;
         animations.Add("jumpright", anim);
         anim = new FrameAnimation(1, 16, 32, 48, 32);
         anim.FramesPerSecond = 20;
         animations.Add("jumpleft", anim);
         anim = new FrameAnimation(1, 16, 32, 64, 0);
         anim.FramesPerSecond = 20;
         animations.Add("frictionright", anim);
         anim = new FrameAnimation(1, 16, 32, 64, 32);
         anim.FramesPerSecond = 20;
         animations.Add("frictionleft", anim);
         anim.FramesPerSecond = 20;
         anim = new FrameAnimation(1, 16, 32, 80, 0);
         anim.FramesPerSecond = 20;
         animations.Add("stopright", anim);
         anim = new FrameAnimation(1, 16, 32, 80, 32);
         anim.FramesPerSecond = 20;
         animations.Add("stopleft", anim);
         anim = new FrameAnimation(1, 16, 32, 0, 64);
         anim.FramesPerSecond = 20;
         animations.Add("duck", anim);
         anim = new FrameAnimation(1, 16, 32, 16, 64);
         animations.Add("slideright", anim);
         anim = new FrameAnimation(1, 16, 32, 32, 64);
         animations.Add("slideleft", anim);
     }
 }