Beispiel #1
0
 //Konstruktor
 public Menu(Texture2D backgroundTexture, Texture2D openTexture, Texture2D newTexture)
 {
     background = new Sprite(backgroundTexture, Vector2.Zero, 0, new Point(backgroundTexture.Width, backgroundTexture.Height));
     openSprite = new AnimatedSprite(openTexture, new Vector2(12, 130), 0, new Point(openTexture.Width / 2, openTexture.Height), new Point(0, 0),
         new Point(2, 0), 16);
     newSprite = new AnimatedSprite(newTexture, new Vector2(12, 144), 0, new Point(newTexture.Width / 2, newTexture.Height), new Point(0, 0),
         new Point(2, 0), 16);
     openSprite2 = new AnimatedSprite(openTexture, new Vector2(12, 130), 0, new Point(openTexture.Width / 2, openTexture.Height), new Point(1, 0),
         new Point(2, 0), 16);
     newSprite2 = new AnimatedSprite(newTexture, new Vector2(12, 144), 0, new Point(newTexture.Width / 2, newTexture.Height), new Point(1, 0),
         new Point(2, 0), 16);
     openNowSprite = openSprite;
     newNowSprite = newSprite;
 }
Beispiel #2
0
 //Konstruktor
 public Player(Game game, Texture2D vanligTexture, Texture2D militarTexture, Texture2D kvinnaTexture, Texture2D babyjerryTexture, Texture2D jkeaTexture, Texture2D vanligaKortTexture, Texture2D finkladdTexture, Texture2D fallTexture, Texture2D vanlig2Texture, Texture2D finkladd2Texture, Texture2D invBackGround, Rectangle clientBounds)
 {
     this.vanligSprite = new AnimatedSprite(vanligTexture, position, 0, new Point(34, 70), new Point(0, 0), new Point(4, 5), 120);
     this.militarSprite = new AnimatedSprite(militarTexture, position, 0, new Point(34, 70), new Point(0, 0), new Point(4, 5), 100);
     this.kvinnaSprite = new AnimatedSprite(kvinnaTexture, position, 0, new Point(34, 70), new Point(0, 0), new Point(4, 5), 100);
     this.babyjerrySprite = new AnimatedSprite(babyjerryTexture, position, 0, new Point(34, 70), new Point(0, 0), new Point(4, 5), 100);
     this.jkeaSprite = new AnimatedSprite(jkeaTexture, position, 0, new Point(34, 70), new Point(0, 0), new Point(4, 5), 100);
     this.vanligaKortSprite = new AnimatedSprite(vanligaKortTexture, position, 0, new Point(34, 70), new Point(0, 0), new Point(4, 5), 100);
     this.finkladdSprite = new AnimatedSprite(finkladdTexture, position, 0, new Point(34, 70), new Point(0, 0), new Point(4, 5), 100);
     this.fallSprite = new AnimatedSprite(fallTexture, position, 0, new Point(34, 70), new Point(0, 0), new Point(4, 5), 100);
     this.vanlig2Sprite = new AnimatedSprite(vanlig2Texture, position, 0, new Point(34, 70), new Point(0, 0), new Point(4, 5), 100);
     finkladd2Sprite = new AnimatedSprite(finkladd2Texture, position, 0, new Point(34, 70), new Point(0, 0), new Point(4, 5), 100);
     this.inventory = new Inventory(invBackGround, clientBounds, game);
     currentSprite = vanligSprite;
     this.scale = 1f;
 }
Beispiel #3
0
        public void Update(Game game, GameTime gameTime, Rectangle clientBounds)
        {
            if (Registry.playersClothes == Registry.WhichClothes.vanliga)
                currentSprite = vanligSprite;
            else if (Registry.playersClothes == Registry.WhichClothes.militar)
                currentSprite = militarSprite;
            else if (Registry.playersClothes == Registry.WhichClothes.babyjerry)
                currentSprite = babyjerrySprite;
            else if (Registry.playersClothes == Registry.WhichClothes.jkea)
                currentSprite = jkeaSprite;
            else if (Registry.playersClothes == Registry.WhichClothes.kvinna)
                currentSprite = kvinnaSprite;
            else if (Registry.playersClothes == Registry.WhichClothes.vanligaKort)
                currentSprite = vanligaKortSprite;
            else if (Registry.playersClothes == Registry.WhichClothes.finkladd)
                currentSprite = finkladdSprite;
            else if (Registry.playersClothes == Registry.WhichClothes.fall)
                currentSprite = fallSprite;
            else if (Registry.playersClothes == Registry.WhichClothes.finkladd2)
                currentSprite = finkladd2Sprite;
            else if (Registry.playersClothes == Registry.WhichClothes.vanliga2)
                currentSprite = vanlig2Sprite;

            //scaleToPosition(clientBounds);
            //Är inventoryn öppen ska spelaren inte röra på sig
            if (Registry.changingRoom)
            {
                position = Registry.nextRoomDoorPosition;
                target = position;
            }
            if (!inventory.InventoryInUse || Registry.changingRoom)
            {
                //Rör spelaren på sig?
                isMoving = true;
                //styrning av spelare
                mouseState = Mouse.GetState();

                //mousePosition = mouseState/3 för att mouseState inte har något med upplösningen (som tredubblas) att göra
                mousePosition.X = (mouseState.X / 3);
                mousePosition.Y = (mouseState.Y / 3);
                if (Mousecontrol.clicked())
                {
                    target.X = mousePosition.X - 15;
                    target.Y = mousePosition.Y - 67;
                }
                if (Registry.pause)
                {
                    target = position;
                }
                direction = target - position;
                direction.Normalize();
                if (position.X != target.X && position.Y != target.Y)
                {
                    position.X += direction.X * speed;
                    position.Y += direction.Y * speed;
                }
                if (position.X < target.X + 1 && position.X > target.X - 1 && position.Y < target.Y + 1 && position.Y > target.Y - 1)
                {
                    speed = 0;
                    //Spelaren rör inte på sig
                    isMoving = false;
                }
                else speed = 1.5f;

                oldState = mouseState;
            }
            //Rör spelaren på sig ska den animeras som vanilgt
            if (isMoving)
            {
                //Skillnad i X-led och skillnad i Y-led
                if (position.Y <= target.Y)
                    deltaY = target.Y - position.Y;
                else
                    deltaY = position.Y - target.Y;

                if (position.X < target.X)
                    deltaX = target.X - position.X;
                else
                    deltaX = position.X - target.X;

                //Bestämmning av vilken animation som ska användas av spelaren
                //Är man påväg åt höger, vänster, up eller ner?
                //Går man mest vertikalt eller horisontellt?
                if (position.X <= target.X && deltaX > deltaY)
                {
                    flip = true;
                    yBounds = 0;
                    rightCurrentFrame = new Point(0, 1);
                    downCurrentFrame = new Point(0, 2);
                    upCurrentFrame = new Point(0, 3);
                }
                else if (position.X >= target.X && deltaX > deltaY)
                {
                    flip = false;
                    yBounds = 0;
                    rightCurrentFrame = new Point(0, 1);
                    downCurrentFrame = new Point(0, 2);
                    upCurrentFrame = new Point(0, 3);
                }
                else if (position.Y >= target.Y && deltaX < deltaY)
                {
                    yBounds = 2;
                    leftCurrentFrame = new Point(0, 0);
                    downCurrentFrame = new Point(0, 2);
                    rightCurrentFrame = new Point(0, 1);
                }
                else
                {
                    yBounds = 1;
                    leftCurrentFrame = new Point(0, 0);
                    rightCurrentFrame = new Point(0, 1);
                    upCurrentFrame = new Point(0, 3);
                }
            }
            //Rör spelaren inte på sig så ska han ha en stillastående sprite
            else
            {
                yBounds = 3;
                leftCurrentFrame = new Point(0, 0);
                rightCurrentFrame = new Point(0, 1);
                downCurrentFrame = new Point(0, 2);
                upCurrentFrame = new Point(0, 3);
            }

            if (inventory.InteractingWithItem && !inventory.InventoryInUse)
            {
                if (Mousecontrol.clicked() && Registry.currentRoom.giveNPCItem(inventory.getItemClickedon))
                {
                    inventory.removeItem(inventory.getItemClickedon);
                }
                else if (Mousecontrol.clicked() && Registry.currentRoom.giveDoorItem(inventory.getItemClickedon))
                {
                    inventory.removeItem(inventory.getItemClickedon);
                }
                else if (Mousecontrol.clicked())
                    addItem(inventory.getItemClickedon);
            }

            inventory.Update();
            currentSprite.Position = position;
            Registry.playerPosition = position;
            updateLayerDepth();
            if(!inventory.InventoryInUse)
                 currentSprite.Update(gameTime, clientBounds, yBounds);
        }
Beispiel #4
0
        /// <summary>
        /// Laddar rummets och de saker i rummets innehåll
        /// </summary>
        public void LoadContent(Game game)
        {
            // Första gången man besöker ett rum, laddas det in
            // Om man redan har besökt ett rum är allting där det var när man lämnade rummet
            if (visited == false)
            {
                soundhasplayed = false;
                this.background = game.Content.Load<Texture2D>(@"Images/Backgrounds/" + backgroundID);
                animbackground = new AnimatedSprite(background, new Vector2(0,0) , 0, new Point(background.Width / (background.Width / 320), background.Height), new Point(0, 0), new Point(2, 1), 100);
                this.mask = game.Content.Load<Texture2D>(@"Images/Backgrounds/" + backgroundID + "mask");
                this.foreground = game.Content.Load<Texture2D>(@"Images/Backgrounds/" + backgroundID + "fg");
                this.maskData = TextureTo2DArray(mask);
                this.game = game;
                int tal = 0;
                int.TryParse(dialogID, out tal);
                this.roomDialog = Registry.dialogs[tal];
                isItemClicked = false;

                toChangeRoom = false;
                roomDialog.setFont(game.Content.Load<SpriteFont>(@"textfont"));
                dialogIsActive = true;
                dialogSound = game.Content.Load<SoundEffect>(@"Sound/Voice/" + dialogID);
                foreach (string id in itemID)
                {
                    Item itemToBeAdded = new Item();
                    itemToBeAdded.loadNewItem(Registry.items[int.Parse(id)]);
                    itemToBeAdded.Initialize(game.Content.Load<Texture2D>(@itemToBeAdded.TextureString));
                    items.Add(itemToBeAdded);
                }
                foreach (string id in npcID)
                {
                    npcs.Add(Registry.npcs[int.Parse(id)]);
                }
                foreach (NPC item in npcs)
                {
                    item.loadContent(game);
                }
                foreach (Door item in doors)
                {
                    item.LoadContent(game);
                }

                int i = 0;
                foreach (Item item in items)
                {
                    string[] temp = itemPosition[i].Split(new char[] { ',' }, 2);
                    item.setPosition(new Vector2(float.Parse(temp[0]), float.Parse(temp[1])));
                    i++;
                }
                visited = true;

            }
            if (song != "null")
            {
                if (Registry.musbol == true)
                {
                    if (!Registry.music.IsDisposed)
                    {
                        MediaPlayer.Stop();
                        Registry.music.Dispose();
                    }
                }
                if (Registry.currentSong != song)
                {
                    Registry.music = game.Content.Load<Song>(@"Sound/BGM/" + song);
                    Registry.currentSong = song;
                    MediaPlayer.Play(Registry.music);
                }
                MediaPlayer.IsRepeating = true;
            }
        }
Beispiel #5
0
 public void LoadContent(Game game)
 {
     texture = game.Content.Load<Texture2D>(@"Images/Sprites/" + textureID);
     sprite = new AnimatedSprite(texture, position, 0, new Point(texture.Width, texture.Height), new Point(0, 0), new Point(1, 0), 1);
 }
Beispiel #6
0
        public void Update(GameTime gameTime, Rectangle clientBounds)
        {
            clickedOnNew = false;
            clickedOnOpen = false;
            if (Mousecontrol.clickedOnItem(openSprite.Position, openSprite.FrameSize, Mousecontrol.clicked()))
            {
                clickedOnOpen = true;
            }

            if (Mousecontrol.clickedOnItem(newSprite.Position, newSprite.FrameSize, Mousecontrol.clicked()))
            {
                clickedOnNew = true;
            }

            if (clickedOnNew)
                newSprite.Update(gameTime, clientBounds);
            if (clickedOnOpen)
                openSprite.Update(gameTime, clientBounds);

            if (Mousecontrol.mouseOverItem(openSprite.Position, openSprite.FrameSize))
            {
                openNowSprite = openSprite2;
            }
            else if (Mousecontrol.mouseOverItem(newSprite.Position, newSprite.FrameSize))
            {
                newNowSprite = newSprite2;
            }
            else
            {
                newNowSprite = newSprite;
                openNowSprite = openSprite;
            }
        }
Beispiel #7
0
        public void Update(GameTime gameTime, Rectangle clientBounds)
        {
            // När man klickar på NPC:n så börjar dialogen
            if (Mousecontrol.clickedOnItem(position, new Point(stillTexture.Width / 3, stillTexture.Height), Mousecontrol.clicked()) && !isTalking && !Registry.inventoryInUse)
            {
                Talk();
            }

            // -- Händelser baserade på dialoger -- //

            if (activeDialog.getActiveLine() == "give")                 // NPC:n ger bort sin item
            {
                giveItem = true;
                dialogNumber++;
            }

            if (activeDialog.getActiveLine() == "0" || Keyboard.GetState().IsKeyDown(Keys.S))                    // Avslutar dialogen
            {
                isTalking = false;
            }

            activeDialog.checkLines();

            // Spriteändringar beroende på om NPC:N pratar
            if (activeDialog.getSpeaker() == "NPC")
            {
                activeSprite = talkSprite;
            }
            else
            {
                activeSprite = stillSprite;
            }

            if (!isTalking)
            {
                activeSprite = stillSprite;
            }

            if (position.Y != 0)
            {
                layerPosition = (1 - (position.Y + activeSprite.Texture.Height) / 180) / 3; //3-D EFFEKTER!!!! NPC:n hamnar bakom och framför saker beroende på vart den står
            }
            else
            {
                layerPosition = 0.2f;
            }

            activeSprite.Update(gameTime, clientBounds);

            // Följ efterspelaren
            if (lookatplayer)
            {
                if (position.X < Registry.playerPosition.X)
                {
                    flip = false;
                }
                else
                {
                    flip = true;
                }
            }
        }
Beispiel #8
0
        /// <summary>
        /// Laddar in karaktärens
        /// • Texturer
        /// • Dialoger
        /// • Ljud
        /// </summary>
        /// <param name="game">Game</param>
        public void loadContent(Game game)
        {
            // Laddar in alla dialogers ljud
            foreach (string id in dialogIDs)
            {
                int temp = 0;
                int.TryParse(id, out temp);
                dialogs.Add(Registry.dialogs[temp]);
                dialogAudio.Add(game.Content.Load<SoundEffect>(@"Sound/Voice/" + temp));
            }
            // Tilldelar dialogen ett typsnitt
            foreach (Dialog dialog in dialogs)
            {
                dialog.setFont(game.Content.Load<SpriteFont>(@"textfont"));
            }
            activeDialog = Registry.dialogs[0];
            this.talkTexture = game.Content.Load<Texture2D>(@"Images/Characters/" + name + "talk");
            this.stillTexture = game.Content.Load<Texture2D>(@"Images/Characters/" + name);
            frameSize = new Point(stillTexture.Width / 4, stillTexture.Height);
            stillSprite = new AnimatedSprite(stillTexture, position, 0, frameSize, new Point(0, 0), new Point(3, 1), 600);
            talkSprite = new AnimatedSprite(talkTexture, position, 0, new Point(talkTexture.Width / 2, talkTexture.Height), new Point(0, 0), new Point(2, 1), 100);

            this.activeSprite = stillSprite;    // Eftersom NPC:n står still i början, blir activeSprite stillSprite i LoadContent
        }