コード例 #1
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            KeyboardState kstate = Keyboard.GetState();
            MouseState    mstate = Mouse.GetState();



            if (first)
            {
                play  = new Player(f.Bredd, f.Höjd);
                first = false;
                for (int i = 0; i < 14; i++)
                {
                    worldedit.Add(new Worldedit(i, f.Bredd - 21, 121 + i * 21));
                }
                weh         = new Rectangle(f.Bredd - 21, 121, 21, worldedit.Count * 21);
                wetoggle    = new Rectangle(f.Bredd - 21, 100, 21, 21);
                wef         = 0;
                health      = 100;
                hpbarbor    = new Rectangle(f.Bredd - 320, 10, 210, 30);
                hpbarbak    = new Rectangle(f.Bredd - 315, 15, 200, 20);
                hpbar       = new Rectangle(f.Bredd - 315, 15, health * 2, 20);
                healthheart = new Rectangle(f.Bredd - 330, 7, 30, 30);
                ghosts.Clear();
                inventory[0] = new Slot();
                inventory[0].Inventory(inventory);
                trash         = new Rectangle(inventory[19].Hitb.X + 50, inventory[19].Hitb.Y, 40, 40);
                mus           = new Mus(mstate);
                inventoryhitb = new Rectangle(0, 0, 450, 50);
                hmenytext     = new Menuchoice(50, "Main Menu", stortext, f.Bredd / 2, false, 70, false, false);
                hmenytext.Mainmenucreate(huvudmeny, menytext, f.Bredd / 2);
                wmenytext = new Menuchoice(10, "Create custom world", menytext, f.Bredd / 2, false, 70, false, false);
                wmenytext.Worldmenucreate(worldmeny, unclickablew, clickablew, text, mellantext, f.Bredd / 2, wg);
                for (int i = 0; i < itemlist.Count; i++)
                {
                    total.Add(new Craftcheck(i, 0));
                }
                List <Craftcheck> temp = new List <Craftcheck>();
                temp.Add(new Craftcheck(1, 2));
                allcrafts.Add(new Crafting(temp, 3));
                allcrafts[0].Craftingcreation(allcrafts);
                gamemenuout = new Rectangle(f.Bredd / 2 - 125, 70, 250, 300);
                gamemenuin  = new Rectangle(gamemenuout.X + 5, gamemenuout.Y + 5, gamemenuout.Width - 10, gamemenuout.Height - 10);
                ingamemeny  = new Menuchoice(90, "Paused", menytext, f.Bredd / 2, false, 50, false, false);
                ingamemeny.Ingamemenucreate(gamemenu, mellantext, f.Bredd / 2);
            }
            mus.Musposchange(mstate.X, mstate.Y);
            if (meny)
            {
                if (hmeny)
                {
                    foreach (Menuchoice m in huvudmeny)
                    {
                        m.Active = false;
                        if (mus.Hitb.Intersects(m.Hitb))
                        {
                            m.Active = true;
                        }
                    }
                    if (mstate.LeftButton == ButtonState.Pressed && oldmus.LeftButton == ButtonState.Released)
                    {
                        bool end = false;
                        mus.Huvudmenyklick(huvudmeny, ref meny, ref hmeny, ref normal, ref l, wg, rand, f, ref wmeny, ref lorg, ref end);
                        if (end)
                        {
                            Exit();
                        }
                    }
                }
                if (wmeny)
                {
                    foreach (Menuchoice m in worldmeny)
                    {
                        m.Active = false;
                        if (mus.Hitb.Intersects(m.Hitb))
                        {
                            m.Active = true;
                        }
                    }
                    foreach (Menuchoice m in clickablew)
                    {
                        m.Active = false;
                        if (mus.Hitb.Intersects(m.Hitb))
                        {
                            m.Active = true;
                        }
                    }
                    if (mstate.LeftButton == ButtonState.Pressed && oldmus.LeftButton == ButtonState.Released)
                    {
                        mus.Worldmenyklick(worldmeny, unclickablew, clickablew, ref l, wg, rand, mus, mellantext, f, ref meny, ref wmeny, ref normal, ref hmeny, ref lorg);
                    }
                }
            }
            if (inmeny)
            {
                if (kstate.IsKeyDown(Keys.Escape) && oldstate.IsKeyUp(Keys.Escape))
                {
                    inmeny     = false;
                    normal     = true;
                    loopcancel = false;
                }
                foreach (Menuchoice m in gamemenu)
                {
                    m.Active = false;
                    if (mus.Hitb.Intersects(m.Hitb))
                    {
                        m.Active = true;
                    }
                }
                if (mstate.LeftButton == ButtonState.Pressed && oldmus.LeftButton == ButtonState.Released)
                {
                    bool end = false;
                    mus.Ingamemenuklick(gamemenu, ref inmeny, ref normal, ref l, wg, rand, f.Höjd, f.Bredd, ref hmeny, ref end, ref lorg, ref meny);
                    if (end)
                    {
                        Exit();
                    }
                }
            }
            if (normal)
            {
                if (inv)
                {
                    inventoryhitb.Height = 105;
                }
                else
                {
                    inventoryhitb.Height = 50;
                }
                activeslot = misc.Inventoryselect(activeslot, kstate, oldstate);

                mus.Update(l, worldedit, kstate, mstate, oldmus, inventory, wetoggle, ref we, weh, ref wef, inventoryhitb, f, wg, itemlist, total, ref craftable, allcrafts, ref craftingoutline, ref craftinginside, activeslot, rand, play.Pos, trash, inv);
                play.Update(ref l, kstate, mstate, ref xauto, ref yauto, ref xautoscd, ref yautoscd, ref xautohcd, ref yautoncd, ref xautovcd, ref yautoucd, ghosts);
                if (kstate.IsKeyDown(Keys.Back) && oldstate.IsKeyDown(Keys.Back) == false)
                {
                    l = wg.Generate(f.Höjd, f.Bredd, rand, ref lorg);
                }
                if (kstate.IsKeyDown(Keys.Tab) && oldstate.IsKeyUp(Keys.Tab))
                {
                    if (inv)
                    {
                        inv = false;
                    }
                    else
                    {
                        inv = true;
                    }
                }
                if (mus.Hitb.Intersects(craftingoutline) && inv)
                {
                    muscraft = true;
                    for (int i = 0; i < craftable.Count; i++)
                    {
                        if (mus.Hitb.Intersects(craftable[i].Place.Hitb))
                        {
                            craftable[i].Requirementshow(ref craftarrow, ref craftshow);
                            muscrafting = i;

                            break;
                        }
                    }
                }
                else
                {
                    muscraft = false;
                }
                if (kstate.IsKeyDown(Keys.O) && health > 0)
                {
                    health--;
                }
                if (kstate.IsKeyDown(Keys.P) && health < 100)
                {
                    health++;
                }
                if (kstate.IsKeyDown(Keys.L))
                {
                    ghosts.Add(new Ghost(rand, l));
                }
                for (int i = 0; i < ghosts.Count; i++)
                {
                    bool bo = ghosts[i].Update(play);
                    if (bo)
                    {
                        ghosts.Remove(ghosts[i]);
                        health -= 5;
                    }
                }
                hpbar.Width = health * 2;
                if (kstate.IsKeyDown(Keys.Escape) && oldstate.IsKeyUp(Keys.Escape) && loopcancel)
                {
                    inmeny = true;
                    normal = false;
                }
                loopcancel = true;
            }

            oldstate = kstate;
            oldmus   = mstate;
            // TODO: Add your update logic here

            base.Update(gameTime);
        }
コード例 #2
0
ファイル: Mus.cs プロジェクト: Arvid-TT/2Dspel
        /// <summary>
        /// Bestämmer vad som händer när man klickar i världsmenyn.
        /// </summary>
        /// <param name="m"></param>
        /// <param name="u"></param>
        /// <param name="c"></param>
        /// <param name="l"></param>
        /// <param name="wg"></param>
        /// <param name="slump"></param>
        /// <param name="mus"></param>
        /// <param name="sf"></param>
        /// <param name="f"></param>
        /// <param name="meny"></param>
        /// <param name="wmeny"></param>
        /// <param name="n"></param>
        /// <param name="hmeny"></param>
        /// <param name="lorg"></param>
        public void Worldmenyklick(List <Menuchoice> m, List <Menuchoice> u, List <Menuchoice> c, ref List <Block> l, WorldGen wg, Random slump, Mus mus, SpriteFont sf, Fonster f, ref bool meny, ref bool wmeny, ref bool n, ref bool hmeny, ref List <Block> lorg)
        {
            bool b = false;

            if (m[0].Active)
            {
                if (mus.Hitb.X > m[0].Hitb.X + m[0].Hitb.Width / 2 && wg.Antalsjöar <= 9)
                {
                    wg.Antalsjöar++;
                }
                else if (mus.Hitb.X < m[0].Hitb.X + m[0].Hitb.Width / 2 && wg.Antalsjöar >= 1)
                {
                    wg.Antalsjöar--;
                }
                m[0] = new Menuchoice(m[0].Hitb.Y, Convert.ToString(wg.Antalsjöar), sf, m[0].Hitb.X + m[0].Hitb.Width / 2, true, m[0].Hitb.Height, true, true);
                b    = true;
            }
            else if (m[1].Active)
            {
                if (mus.Hitb.X > m[1].Hitb.X + m[1].Hitb.Width / 2 && wg.Antalfloder <= 9)
                {
                    wg.Antalfloder++;
                }
                else if (mus.Hitb.X < m[1].Hitb.X + m[1].Hitb.Width / 2 && wg.Antalfloder >= 1)
                {
                    wg.Antalfloder--;
                }
                m[1] = new Menuchoice(m[1].Hitb.Y, Convert.ToString(wg.Antalfloder), sf, m[1].Hitb.X + m[1].Hitb.Width / 2, true, m[1].Hitb.Height, true, true);
                b    = true;
            }
            else if (m[2].Active)
            {
                if (mus.Hitb.X > m[2].Hitb.X + m[2].Hitb.Width / 2 && wg.Antalskogar <= 9)
                {
                    wg.Antalskogar++;
                }
                else if (mus.Hitb.X < m[2].Hitb.X + m[2].Hitb.Width / 2 && wg.Antalskogar >= 1)
                {
                    wg.Antalskogar--;
                }
                m[2] = new Menuchoice(m[2].Hitb.Y, Convert.ToString(wg.Antalskogar), sf, m[2].Hitb.X + m[2].Hitb.Width / 2, true, m[2].Hitb.Height, true, true);
                b    = true;
            }
            else if (m[3].Active)
            {
                if (mus.Hitb.X > m[3].Hitb.X + m[3].Hitb.Width / 2 && wg.Antalsnöar <= 9)
                {
                    wg.Antalsnöar++;
                }
                else if (mus.Hitb.X < m[3].Hitb.X + m[3].Hitb.Width / 2 && wg.Antalsnöar >= 1)
                {
                    wg.Antalsnöar--;
                }
                m[3] = new Menuchoice(m[3].Hitb.Y, Convert.ToString(wg.Antalsnöar), sf, m[3].Hitb.X + m[3].Hitb.Width / 2, true, m[3].Hitb.Height, true, true);
                b    = true;
            }
            else if (m[4].Active)
            {
                if (mus.Hitb.X > m[4].Hitb.X + m[4].Hitb.Width / 2 && wg.Havsstorlek <= 9500)
                {
                    wg.Havsstorlek += 500;
                }
                else if (mus.Hitb.X < m[4].Hitb.X + m[4].Hitb.Width / 2 && wg.Havsstorlek >= 500)
                {
                    wg.Havsstorlek -= 500;
                }
                m[4] = new Menuchoice(m[4].Hitb.Y, Convert.ToString(wg.Havsstorlek), sf, m[4].Hitb.X + m[4].Hitb.Width / 2, true, m[4].Hitb.Height, true, true);
                b    = true;
            }
            else if (m[5].Active)
            {
                if (mus.Hitb.X > m[5].Hitb.X + m[5].Hitb.Width / 2 && wg.Sjöstorlek <= 1900)
                {
                    wg.Sjöstorlek += 100;
                }
                else if (mus.Hitb.X < m[5].Hitb.X + m[5].Hitb.Width / 2 && wg.Sjöstorlek >= 100)
                {
                    wg.Sjöstorlek -= 100;
                }
                m[5] = new Menuchoice(m[5].Hitb.Y, Convert.ToString(wg.Sjöstorlek), sf, m[5].Hitb.X + m[5].Hitb.Width / 2, true, m[5].Hitb.Height, true, true);
                b    = true;
            }
            else if (m[6].Active)
            {
                if (mus.Hitb.X > m[6].Hitb.X + m[6].Hitb.Width / 2 && wg.Flodbredd <= 9)
                {
                    wg.Flodbredd++;
                }
                else if (mus.Hitb.X < m[6].Hitb.X + m[6].Hitb.Width / 2 && wg.Flodbredd >= 1)
                {
                    wg.Flodbredd--;
                }
                m[6] = new Menuchoice(m[6].Hitb.Y, Convert.ToString(wg.Flodbredd), sf, m[6].Hitb.X + m[6].Hitb.Width / 2, true, m[6].Hitb.Height, true, true);
                b    = true;
            }
            else if (m[7].Active)
            {
                if (mus.Hitb.X > m[7].Hitb.X + m[7].Hitb.Width / 2 && wg.Skogsstorlek <= 9500)
                {
                    wg.Skogsstorlek += 500;
                }
                else if (mus.Hitb.X < m[7].Hitb.X + m[7].Hitb.Width / 2 && wg.Skogsstorlek >= 500)
                {
                    wg.Skogsstorlek -= 500;
                }
                m[7] = new Menuchoice(m[7].Hitb.Y, Convert.ToString(wg.Skogsstorlek), sf, m[7].Hitb.X + m[7].Hitb.Width / 2, true, m[7].Hitb.Height, true, true);
                b    = true;
            }
            else if (m[8].Active)
            {
                if (mus.Hitb.X > m[8].Hitb.X + m[8].Hitb.Width / 2 && wg.Snöstorlek <= 9500)
                {
                    wg.Snöstorlek += 500;
                }
                else if (mus.Hitb.X < m[8].Hitb.X + m[8].Hitb.Width / 2 && wg.Snöstorlek >= 500)
                {
                    wg.Snöstorlek -= 500;
                }
                m[8] = new Menuchoice(m[8].Hitb.Y, Convert.ToString(wg.Snöstorlek), sf, m[8].Hitb.X + m[8].Hitb.Width / 2, true, m[8].Hitb.Height, true, true);
                b    = true;
            }
            else if (c[0].Active)
            {
                b = true;
            }
            else if (c[1].Active)
            {
                l     = wg.Generate(f.Höjd, f.Bredd, slump, ref lorg);
                meny  = false;
                wmeny = false;
                n     = true;
                return;
            }
            else if (c[2].Active)
            {
                wmeny = false;
                hmeny = true;

                wg = new WorldGen();
            }
            if (b)
            {
                l = wg.Generate(f.Höjd, f.Bredd, slump, ref lorg);
                foreach (Block bb in l)
                {
                    bb.Mapposchange(-f.Bredd / 4, 100);
                    bb.Double();
                }
            }
        }