Beispiel #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);
        }