예제 #1
0
        /// <summary>
        /// Move to next screen
        /// </summary>
        public void NextScreen()
        {
            if (curScreenIndex <= 3)
                curScreen = screens[curScreenIndex++];
            else
                curScreen = new GameOverScreen(this, Content, "menubackground");

            if (curScreen is GameScreen)
            {
                level = ((GameScreen)curScreen).CurLevel;
                player = level.MainPlayer;
            }
        }
예제 #2
0
        /// <summary>
        /// Construct
        /// </summary>
        /// <param name="content"></param>
        public Level(ContentManager content)
        {
            _content = content;
            _layers = new List<Layer>();
            _plr = null;

            // Main layer
            _main = AddLayer();

            //load and play the background sound
            _bgMusic = _content.Load<Song>("Audio/Music/LightBG");
            MediaPlayer.IsRepeating = true;
            MediaPlayer.Play(_bgMusic);
        }
예제 #3
0
        /// <summary>
        /// Load level from file
        /// </summary>
        /// <param name="filename"></param>
        /*public static Level LoadLevel(GameScreen screen, ContentManager content, string filename)
        {
            // Load lines

            //string[] lines = System.IO.File.ReadAllLines(filename);

            // Create new level instance
            Level level = new Level(content);
            screen.CurLevel = level;
            level._filename = filename;

            // Read invert, gravity and scroll offset
            string[] toks = lines[0].Split(' ');
            level.Inverted = Convert.ToInt32(toks[0]) > 0;
            level.Gravity = Vector2.UnitY * Convert.ToInt32(toks[1]);
            level._scrollOffset = Convert.ToInt32(toks[2]);

            // Read background
            screen.Background = content.Load<Texture2D>(lines[1]);

            // Read midground
            level.Midground = content.Load<Texture2D>(lines[2]);

            // Read foreground
            level.Foreground = content.Load<Texture2D>(lines[3]);

            // Read pool
            toks = lines[4].Split(' ');
            level.SoupPool = new Soup(content, toks[0]);
            level.SoupPool.Animations = 3;
            level.SoupPool.Frames = 7;
            level.SoupPool.Position = new Vector2(Convert.ToInt32(toks[1]), Convert.ToInt32(toks[2]));

            // Read tree
            toks = lines[5].Split(' ');
            level._tree = new Entity(content, toks[0]);
            level._tree.Position = new Vector2(Convert.ToInt32(toks[1]), Convert.ToInt32(toks[2]));
            level._tree.Animations = 1;
            level._tree.Frames = 7;
            level._tree.Animating = false;

            // Templates
            string[] templ = new string[7];
            for (int i = 0; i < 7; i++)
                templ[i] = lines[i + 6];

            // Read player data
            toks = lines[13].Split(' ');
            string playerAsset = toks[0];
            level._plr = level.LoadPlayer(playerAsset, 4, 25, 0.3f);
            level._plr.Position = new Vector2(Convert.ToInt32(toks[1]), Convert.ToInt32(toks[2]));
            level._plr.Glow = content.Load<Texture2D>("Characters/Glow");
            Player plr = level._plr;

            Layer curLayer = level.MainLayer;

            Random rnd = new Random();

            // Level entities
            for (int i = 15; i < lines.Length; i++)
            {
                string line = lines[i];

                toks = line.Split(' ');

                // Static piece
                if (toks[0] == "NextLayer:")
                {
                    curLayer = level.AddLayer();
                }
                else if (toks[0][0] == 'T')
                {
                    int type = Convert.ToInt32("" + toks[0][1]) - 1;

                    Static ent = curLayer.LoadStatic(templ[type]);
                    ent.Position = new Vector2(Convert.ToInt32(toks[1]), Convert.ToInt32(toks[2]));
                    ent.Scale = Convert.ToInt32(toks[3]) / 100.0f;

                    if (type == 0)
                        ent.SType = Static.StaticType.NORMAL;
                    else if (type == 1)
                        ent.SType = Static.StaticType.BOUNCY;
                    else if (type == 2)
                        ent.SType = Static.StaticType.STICKY;
                    else if (type == 3)
                        ent.SType = Static.StaticType.MULTI;

                    ent.Visible = false;
                }
                else if (toks[0][0] == 'E')
                {
                    int type = Convert.ToInt32("" + toks[0][1]) - 1;

                    Enemy enm = curLayer.LoadEnemy(templ[4 + type]);
                    enm.Animations = 3;
                    enm.Frames = 25;
                    enm.EventListener = screen;
                    enm.Position = new Vector2(Convert.ToInt32(toks[1]), Convert.ToInt32(toks[2]));
                    enm.Scale = Convert.ToInt32(toks[3]) / 100.0f;
                    enm.Rotation = Convert.ToInt32(toks[4]);

                    if (type == 0)
                        enm.EType = Enemy.EnemyType.SPIKEY;
                    else if (type == 1)
                        enm.EType = Enemy.EnemyType.BURSTING;
                    else if (type == 2)
                        enm.EType = Enemy.EnemyType.STICKY;
                }
                else if (toks[0] == "C")
                {
                    Dynamic dyn = curLayer.LoadDynamic(playerAsset, 200 );
                    dyn.Position = new Vector2(Convert.ToInt32(toks[1]), Convert.ToInt32(toks[2]));
                    dyn.Mass = rnd.Next(50, 150);
                    dyn.Scale = 0.19f;
                    dyn.Glow = plr.Glow;
                    dyn.Animations = 4;
                    dyn.Frames = 25;
                }
                else if (toks[0] == "G")
                {
                    Entity ent = curLayer.LoadEntity(toks[1]);
                    ent.Position = new Vector2(Convert.ToInt32(toks[2]), Convert.ToInt32(toks[3]));
                    ent.Scale = Convert.ToInt32(toks[4]) / 100.0f;
                }
                else if (toks[0] == "GA")
                {
                    Entity ent = curLayer.LoadEntity(toks[1]);
                    ent.Position = new Vector2(Convert.ToInt32(toks[2]), Convert.ToInt32(toks[3]));
                    ent.Scale = Convert.ToInt32(toks[4]) / 100.0f;
                    ent.Frames = Convert.ToInt32(toks[5]);
                }
                else if (toks[0] == "BT")
                {
                    Button ent = curLayer.LoadButton(toks[1]);
                    ent.EventListener = screen;
                    ent.PrivateData = Convert.ToInt32(toks[2]);
                    ent.Position = new Vector2(Convert.ToInt32(toks[3]), Convert.ToInt32(toks[4]));
                    ent.Scale = Convert.ToInt32(toks[5]) / 100.0f;
                    ent.Animations = 3;
                    ent.Frames = 25;
                }
            }

            return level;
        }
        */
        /// <summary>
        /// Load Player
        /// </summary>
        /// <param name="asset"></param>
        /// <param name="animations"></param>
        /// <param name="frames"></param>
        /// <param name="scale"></param>
        /// <returns></returns>
        public Player LoadPlayer(String asset, int animations, int frames, float scale)
        {
            _plr = new Player(_content, asset, mass);
            _plr.Animations = animations;
            _plr.Frames = frames;
            _plr.Scale = scale;
            _plr.CurLevel = this;
            return _plr;
        }
예제 #4
0
        /// <summary>
        /// Update game
        /// </summary>
        /// <param name="gameTime">Game time</param>
        protected override void Update(GameTime gameTime)
        {
            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
                this.Exit();

            Vector2 mousePos = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);

            // Update game screens
            if (curScreen is GameScreen)
            {

                // Launch player
                if (!dragging && player.PointIn(mousePos) && Mouse.GetState().LeftButton == ButtonState.Pressed)
                    dragging = true;

                if (dragging)
                {
                    Vector2 diff = player.Position - (mousePos - Vector2.UnitY * level.Scroll);
                    float length = diff.Length();
                    if (length > maxVelocity)
                    {
                        diff.Normalize();
                        diff *= maxVelocity;
                        length = maxVelocity;
                    }

                    player.Tail.Scale = length * 0.001f;
                    player.Tail.Rotation = MathHelper.ToDegrees((float)Math.Atan2(diff.Y, diff.X)) + 90;

                    if (Mouse.GetState().LeftButton == ButtonState.Released)
                    {
                        dragging = false;
                        player.Tail.Scale = 0;

                       // Vector2 diff = player.Position - (mousePos - Vector2.UnitY * level.Scroll);

                        player.AddForce(diff * 40);
                        player.Active = true;
                        player.ApplyGravity = true;
                    }
                }

                // Collide with edges
                if (player.Position.X < 60 || player.Position.X > 740)
                    player.Velocity = new Vector2(-player.Velocity.X, player.Velocity.Y);

                // Screen limits
                if (player.Position.X <= 60)
                    player.Position = new Vector2(60, player.Position.Y);
                if (player.Position.X >= 740)
                    player.Position = new Vector2(740, player.Position.Y);
                if (level.Inverted)
                {
                    if (player.Position.Y <= 200)
                        level.Scroll = 100 - player.Position.Y;
                }
                else
                {
                    if (player.Position.Y <= 100)
                        level.Scroll = 100 - player.Position.Y;     // Scroll
                }
                if (!level.Inverted && player.Position.Y < -1000)
                    player.Position = new Vector2(player.Position.X, -1000);
                else if (level.Inverted && player.Position.Y > 800)
                    player.Position = new Vector2(player.Position.X, 800);

                if (level.Scroll > 1100)
                    level.Scroll = 1100;

                // Collide with soup
                if ((!level.Inverted && player.Position.Y > 800) || (level.Inverted && player.Position.Y < -1200))
                {
                    if (player.ChildCount >= 6)
                    {
                        NextScreen();
                        if (lifeCount < 5)
                            lifes[lifeCount++].Open = true;
                    }
                    else
                    {
                        // Die
                        if (lifeCount > 0)
                        {
                            lifes[--lifeCount].Close();
                           // level = Level.LoadLevel((GameScreen)curScreen, Content, level.Filename);
                            player = level.MainPlayer;
                        }
                        else
                        {
                            // Game over
                            curScreen = new GameOverScreen(this, Content, "menubackground");
                        }
                    }
                }

                // Update level
                level.Update(gameTime);

            }

            base.Update(gameTime);
        }