Beispiel #1
0
 public bool Add(NonPlayerCharacter NPC)
 {
     lock (NPCDictionary)
     {
         if (!NPCDictionary.ContainsKey(NPC.UID))
         {
             NPCDictionary.Add(NPC.UID, NPC);
             NonPlayerCharacter[] tmp = new NonPlayerCharacter[NPCDictionary.Count];
             NPCDictionary.Values.CopyTo(tmp, 0);
             ScreenNPCs = tmp;
             return true;
         }
     }
     return false;
 }
Beispiel #2
0
        public void CreateNpcExplicitly()
        {
            var npc = new NonPlayerCharacter(3, 2, 2, 4, 2, 3, 3,
                                             new Alignment(Enumerations.LawfulnessType.Lawful, Enumerations.DispositionType.Good));

            Assert.IsNotNull(npc);
            Assert.AreEqual(3, npc.Constitution.Value);
            Assert.AreEqual(2, npc.Dexterity.Value);
            Assert.AreEqual(2, npc.Intelligence.Value);
            Assert.AreEqual(4, npc.Luck.Value);
            Assert.AreEqual(2, npc.Attunement.Value);
            Assert.AreEqual(3, npc.Strength.Value);
            Assert.AreEqual(3, npc.Willpower.Value);
            Assert.AreEqual(Enumerations.LawfulnessType.Lawful, npc.Alignment.Lawfulness);
            Assert.AreEqual(Enumerations.DispositionType.Good, npc.Alignment.Disposition);
        }
Beispiel #3
0
        public void CreateNpcByRandomRoll()
        {
            var randomNpc = new NonPlayerCharacter("Mage",
                                                   6,
                                                   new Alignment(Enumerations.LawfulnessType.Neutral, Enumerations.DispositionType.Evil));

            var currentLevel = Helpers.GetLevel(6);
            var nextLevel = Helpers.GetLevel(7);
            var minimumSumOfAttributes = currentLevel.MinimumSumOfAttributes;
            var maximumSumOfAttributes = nextLevel.MinimumSumOfAttributes - 1;

            Assert.IsNotNull(randomNpc);
            Assert.AreEqual(6, randomNpc.Level.Number);
            Assert.IsTrue(randomNpc.SumOfAttributes >= minimumSumOfAttributes);
            Assert.IsTrue(randomNpc.SumOfAttributes <= maximumSumOfAttributes);
            Assert.AreEqual(Enumerations.LawfulnessType.Neutral, randomNpc.Alignment.Lawfulness);
            Assert.AreEqual(Enumerations.DispositionType.Evil, randomNpc.Alignment.Disposition);
        }
Beispiel #4
0
 public static void Add(NonPlayerCharacter NPC)
 {
     ushort Map = NPC.Location.MapID;
     lock (NPCs)
     {
         List<NonPlayerCharacter> npcs;
         if (NPCs.ContainsKey(Map))
         {
             npcs = NPCs[Map];
             npcs.Add(NPC);
             NPCs[Map] = npcs;
         }
         else
         {
             npcs = new List<NonPlayerCharacter>();
             npcs.Add(NPC);
             NPCs.Add(Map, npcs);
         }
     }
     //NPCs.ThreadSafeAdd(NPC.UID, NPC);
 }
Beispiel #5
0
        private void LoadWorld()
        {
            RpgLibrary.WorldClasses.LevelData levelData =
                Game.Content.Load <RpgLibrary.WorldClasses.LevelData>(@"Game\Levels\Starting Level");

            RpgLibrary.WorldClasses.MapData mapData =
                Game.Content.Load <RpgLibrary.WorldClasses.MapData>(@"Game\Levels\Maps\" + levelData.MapName);


            string[] fileNames = Directory.GetFiles(
                Path.Combine("Content/Game/Items", "Armor"),
                "*.xnb");

            foreach (string a in fileNames)
            {
                string path = "Game/Items/Armor/" + Path.GetFileNameWithoutExtension(a);

                ArmorData armorData = Game.Content.Load <ArmorData>(path);
                ItemManager.AddArmor(new Armor(armorData));
            }

            fileNames = Directory.GetFiles(
                Path.Combine("Content/Game/Items", "Shield"),
                "*.xnb");

            foreach (string a in fileNames)
            {
                string path = "Game/Items/Shield/" + Path.GetFileNameWithoutExtension(a);

                ShieldData shieldData = Game.Content.Load <ShieldData>(path);
                ItemManager.AddShield(new Shield(shieldData));
            }

            fileNames = Directory.GetFiles(
                Path.Combine("Content/Game/Items", "Weapon"),
                "*.xnb");

            foreach (string a in fileNames)
            {
                string path = "Game/Items/Weapon/" + Path.GetFileNameWithoutExtension(a);

                WeaponData weaponData = Game.Content.Load <WeaponData>(path);
                ItemManager.AddWeapon(new Weapon(weaponData));
            }

            CharacterLayerData charData =
                Game.Content.Load <CharacterLayerData>(@"Game\Levels\Chars\Starting Level");
            CharacterLayer characterLayer = new CharacterLayer();

            TileMap map = TileMap.FromMapData(mapData, Game.Content);

            foreach (var c in charData.Characters)
            {
                Character character;

                if (c.Value is NonPlayerCharacterData)
                {
                    Entity entity = new Entity(c.Value.Name, c.Value.EntityData, c.Value.Gender, EntityType.NPC);

                    using (Stream stream = new FileStream(c.Value.TextureName, FileMode.Open, FileAccess.Read))
                    {
                        Texture2D      texture = Texture2D.FromStream(GraphicsDevice, stream);
                        AnimatedSprite sprite  = new AnimatedSprite(texture, AnimationManager.Instance.Animations)
                        {
                            Position = new Vector2(c.Key.X * Engine.TileWidth, c.Key.Y * Engine.TileHeight)
                        };

                        character = new NonPlayerCharacter(entity, sprite);

                        ((NonPlayerCharacter)character).SetConversation(
                            ((NonPlayerCharacterData)c.Value).CurrentConversation);
                    }

                    characterLayer.Characters.Add(c.Key, character);
                }
            }

            map.AddLayer(characterLayer);

            Level level = new Level(map);

            ChestData chestData = Game.Content.Load <ChestData>(@"Game\Chests\Plain Chest");

            Chest chest = new Chest(chestData);

            BaseSprite chestSprite = new BaseSprite(
                containers,
                new Rectangle(0, 0, 32, 32),
                new Point(10, 10));

            ItemSprite itemSprite = new ItemSprite(
                chest,
                chestSprite);

            level.Chests.Add(itemSprite);

            World world = new World(GameRef, GameRef.ScreenRectangle);

            world.Levels.Add(level);
            world.CurrentLevel = 0;

            AnimatedSprite s = new AnimatedSprite(
                GameRef.Content.Load <Texture2D>(@"SpriteSheets\Eliza"),
                AnimationManager.Instance.Animations);

            s.Position = new Vector2(0 * Engine.TileWidth, 5 * Engine.TileHeight);

            EntityData ed = new EntityData("Eliza", 1, 10, 10, 10, 10, 10, 10, "20|CON|12", "16|WIL|16",
                                           "0|0|0");

            Entity e = new Entity("Eliza", ed, EntityGender.Female, EntityType.NPC);

            NonPlayerCharacter npc = new NonPlayerCharacter(e, s);

            npc.SetConversation("eliza1");
            //world.Levels[world.CurrentLevel].Characters.Add(npc);

            s = new AnimatedSprite(
                GameRef.Content.Load <Texture2D>(@"SpriteSheets\Eliza"),
                AnimationManager.Instance.Animations);
            s.Position = new Vector2(10 * Engine.TileWidth, 0);

            ed = new EntityData("Barbra", 2, 10, 10, 10, 10, 10, 10, "20|CON|12", "16|WIL|16", "0|0|0");

            e = new Entity("Barbra", ed, EntityGender.Female, EntityType.Merchant);

            Merchant  m     = new Merchant(e, s);
            Texture2D items = Game.Content.Load <Texture2D>("ObjectSprites/roguelikeitems");

            m.Backpack.AddItem(new GameItem(ItemManager.GetWeapon("Long Sword"), "FullSheet", new Rectangle(1696, 1408, 32, 32)));
            m.Backpack.AddItem(new GameItem(ItemManager.GetWeapon("Short Sword"), "FullSheet", new Rectangle(800, 1504, 32, 32)));

            world.Levels[world.CurrentLevel].Characters.Add(m);
            ((CharacterLayer)world.Levels[world.CurrentLevel].Map.Layers.Find(x => x is CharacterLayer)).Characters.Add(new Point(10, 0), m);
            GamePlayScreen.World = world;

            CreateConversation();

            // ((NonPlayerCharacter)world.Levels[world.CurrentLevel].Characters[0]).SetConversation("eliza1");
        }
    // Update is called once per frame
    void Update()
    {
        if (!gameOverState)
        {
            horizontal = Input.GetAxis("Horizontal");
            vertical   = Input.GetAxis("Vertical");


            Vector2 position = rigidbody2d.position;
            position.x = position.x + speed * horizontal * Time.deltaTime;
            position.y = position.y + speed * vertical * Time.deltaTime;

            Vector2 move = new Vector2(horizontal, vertical);


            if (!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f))
            {
                lookDirection.Set(move.x, move.y);
                lookDirection.Normalize();
                startedRunning = true;
            }
            else if (Mathf.Approximately(move.x, 0.0f) || Mathf.Approximately(move.y, 0.0f))
            {
                isRunning      = false;
                startedRunning = false;
                runningAudio.Stop();
            }

            if (startedRunning && !isRunning)
            {
                isRunning = true;
                runningAudio.Play();
            }


            animator.SetFloat("Look X", lookDirection.x);
            animator.SetFloat("Look Y", lookDirection.y);
            animator.SetFloat("Speed", move.magnitude);

            position = position + move * speed * Time.deltaTime;

            rigidbody2d.MovePosition(position);

            if (isInvincible)
            {
                invincibleTimer -= Time.deltaTime;
                if (invincibleTimer < 0)
                {
                    isInvincible = false;
                }
            }

            if (Input.GetKeyDown(KeyCode.C))
            {
                Launch();
                characterOneShot(cogThrowClip);
            }

            if (Input.GetKeyDown(KeyCode.X))
            {
                RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC"));
                if (hit.collider != null)
                {
                    NonPlayerCharacter character = hit.collider.GetComponent <NonPlayerCharacter>();
                    if (character != null)
                    {
                        character.DisplayDialog();
                    }
                }
            }

            DamagaeFlash(false);
            HealFlash(false);
        }
    }
Beispiel #7
0
    // Update is called once per frame
    void Update()
    {
        horizontal = Input.GetAxis("Horizontal");
        vertical   = Input.GetAxis("Vertical");

        Vector2 move = new Vector2(horizontal, vertical);

        if (!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f))
        {
            lookDirection.Set(move.x, move.y);
            lookDirection.Normalize();
        }

        animator.SetFloat("Look X", lookDirection.x);
        animator.SetFloat("Look Y", lookDirection.y);
        animator.SetFloat("Speed", move.magnitude);

        if (isInvincible)
        {
            invincibleTimer -= Time.deltaTime;
            if (invincibleTimer < 0)
            {
                isInvincible = false;
            }
        }

        if (Input.GetKeyDown(KeyCode.C))
        {
            Launch();
        }

        if (health == 0)
        {
            winText.text = "You lost! Press R to restart";
        }

        if (Input.GetKey("escape"))
        {
            Application.Quit();
        }

        if (Input.GetKey(KeyCode.R))
        {
            if (gameOver == true)
            {
                SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); // this loads the currently active scene
            }
        }


        if (Input.GetKeyDown(KeyCode.X))
        {
            RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC"));
            if (hit.collider != null)
            {
                NonPlayerCharacter character = hit.collider.GetComponent <NonPlayerCharacter>();
                if (character != null)
                {
                    character.DisplayDialog();
                }
            }
        }
    }
Beispiel #8
0
    void Start()
    {
        //Initialises Variables
        //Response Arrays
        speechData = new JSONObject(speechFile.text);
        Debug.Log("Accessing JSON: ");
        foreach (var character in speechData.keys)
        {
            if (character == "Pirate")
            {
                pirateResponses = SpeechHandler.AccessData(speechData, character).ToList().ToList();
            }
            else if (character == "Mime")
            {
                mimeResponses = SpeechHandler.AccessData(speechData, character).ToList().ToList();
            }
            else if (character == "Millionaire")
            {
                millionaireResponses = SpeechHandler.AccessData(speechData, character).ToList();
            }
            else if (character == "Cowgirl")
            {
                cowgirlResponses = SpeechHandler.AccessData(speechData, character).ToList();
            }
            else if (character == "Roman")
            {
                romanResponses = SpeechHandler.AccessData(speechData, character).ToList();
            }
            else if (character == "Wizard")
            {
                wizardResponses = SpeechHandler.AccessData(speechData, character).ToList();
            }
            else if (character == "Chubbie")
            {
                chubbieResponses = SpeechHandler.AccessData(speechData, character).ToList();
            }
            else if (character == "HeMan")
            {
                hemanResponses = SpeechHandler.AccessData(speechData, character).ToList();
            }
            else if (character == "Reginald")
            {
                reginaldResponses = SpeechHandler.AccessData(speechData, character).ToList();
            }
            else if (character == "Scientist")
            {
                scientistResponses = SpeechHandler.AccessData(speechData, character).ToList();
            }


            //Saving and loading
        }

        //Weaknesses
        List <string> pirateWeaknesses = new List <string> {
            "Forceful", "Wisecracking", "Kind"
        };
        List <string> mimeWeaknesses = new List <string> {
            "Intimidating", "Coaxing", "Inspiring"
        };
        List <string> millionaireWeaknesses = new List <string> {
            "Forceful", "Rushed", "Kind"
        };
        List <string> cowgirlWeaknesses = new List <string> {
            "Condescending", "Wisecracking", "Inspiring"
        };
        List <string> romanWeaknesses = new List <string> {
            "Condescending", "Coaxing", "Inquisitive"
        };
        List <string> wizardWeaknesses = new List <string> {
            "Intimidating", "Rushed", "Inquisitive"
        };
        List <string> chubbieWeaknesses = new List <string> {
            "Condescending", "Wizecracking", "Kind"
        };                                                                                                      //ADDITION BY WEDUNNIT
        List <string> scientistWeaknesses = new List <string> {
            "Forceful", "Coaxing", "Inspiring"
        };                                                                                                              //ADDITION BY WEDUNNIT
        List <string> reginaldWeaknesses = new List <string> {
            "Forceful", "Coaxing", "Inspiring"
        };                                                                                                                      //ADDITION BY WEDUNNIT
        List <string> hemanWeaknesses = new List <string> {
            "Condescending", "Rushed", "Kind"
        };                                                                                                                      //ADDITION BY WEDUNNIT



        //Defining NPC's
        NonPlayerCharacter reginald    = new NonPlayerCharacter("Reginald Montgomery IV", reginaldSprite, "Reginald M IV", reginaldPref, reginaldWeaknesses, reginaldResponses);        //ADDITION BY WEDUNNIT
        NonPlayerCharacter pirate      = new NonPlayerCharacter("Captain Bluebottle", pirateSprite, "Salty Seadog", piratePref, pirateWeaknesses, pirateResponses);
        NonPlayerCharacter mimes       = new NonPlayerCharacter("The Mime Twins", mimesSprite, "mimes", mimesPref, mimeWeaknesses, mimeResponses);
        NonPlayerCharacter millionaire = new NonPlayerCharacter("Sir Worchester", millionaireSprite, "Money Bags", millionarePref, millionaireWeaknesses, millionaireResponses);
        NonPlayerCharacter cowgirl     = new NonPlayerCharacter("Jesse Ranger", cowgirlSprite, "Outlaw", cowgirlPref, cowgirlWeaknesses, cowgirlResponses);
        NonPlayerCharacter roman       = new NonPlayerCharacter("Celcius Maximus", romanSprite, "Legionnaire", romanPref, romanWeaknesses, romanResponses);
        NonPlayerCharacter wizard      = new NonPlayerCharacter("Randolf the Deep Purple", wizardSprite, "Dodgy Dealer", wizardPref, wizardWeaknesses, wizardResponses);
        NonPlayerCharacter chubbie     = new NonPlayerCharacter("Tinky Wobbly", chubbieSprite, "Telechubbie", chubbiePref, chubbieWeaknesses, chubbieResponses);                        //ADDITION BY WEDUNNIT
        NonPlayerCharacter heman       = new NonPlayerCharacter("HisMan", hemanSprite, "Superhero", hemanPref, hemanWeaknesses, hemanResponses);                                        //ADDITION BY WEDUNNIT
        NonPlayerCharacter scientist   = new NonPlayerCharacter("Dr Emmanuel Brown", scientistSprite, "Mad scientist", scientistPref, scientistWeaknesses, scientistResponses);         //ADDITION BY WEDUNNIT



        //Defining Scenes
        Scene controlRoom         = new Scene("Control Room");
        Scene kitchen             = new Scene("Kitchen");
        Scene lectureTheatre      = new Scene("Lecture Theatre");
        Scene lakehouse           = new Scene("Lakehouse");
        Scene islandOfInteraction = new Scene("Island of Interaction");
        Scene roof           = new Scene("Roof");
        Scene atrium         = new Scene("Atrium");
        Scene undergroundLab = new Scene("Underground Lab");
        Scene factory        = new Scene("Factory");

        //Defining Items
        MurderWeapon cutlass       = new MurderWeapon(cutlassPrefab, "Cutlass", "A worn and well used cutlass", cutlassSprite, "SD");
        MurderWeapon poison        = new MurderWeapon(poisonPrefab, "Empty Poison Bottle", "This had poison in once ", poisonSprite, "SD");
        MurderWeapon garrote       = new MurderWeapon(garrotePrefab, "Garrote", "Used for strangling someone... to death!", garroteSprite, "SD");
        MurderWeapon knife         = new MurderWeapon(knifePrefab, "Knife", "A sharp tool meant for cutting meat", knifeSprite, "SD");
        MurderWeapon laserGun      = new MurderWeapon(laserGunPrefab, "Laser Gun", "It's still warm, implying it has been recently fired", laserGunSprite, "SD");
        MurderWeapon leadPipe      = new MurderWeapon(leadPipePrefab, "Lead Pipe", "It's a bit battered with a few dents on the side", leadPipeSprite, "SD");
        MurderWeapon westernPistol = new MurderWeapon(westernPistolPrefab, "Western Pistol", "The gunpowder residue implies it has been recently fired", westernPistolSprite, "SD");
        MurderWeapon wizardStaff   = new MurderWeapon(wizardStaffPrefab, "Wizard Staff", "The gems still seem to be glow as if it has been used recently", wizardStaffSprite, "SD");

        Item beret          = new Item(beretPrefab, "Beret", "A hat most stereotypically worn by the French", beretSprite);
        Item footprints     = new Item(footprintsPrefab, "Bloody Footprints", "Bloody footprints most likely left by the murderer", footprintsSprite);
        Item gloves         = new Item(glovesPrefab, "Bloody Gloves", "Bloody gloves most likely used by the murderer", glovesSprite);
        Item wine           = new Item(winePrefab, "Fine Wine", "An expensive vintage that's close to 100 years old", wineSprite);
        Item shatteredGlass = new Item(shatteredGlassPrefab, "Shattered Glass", "Broken glass shards spread quite close together", shatteredGlassSprite);
        Item shrapnel       = new Item(shrapnelPrefab, "Shrapnel", "Shrapnel from an explosion or gun being fired", shrapnelSprite);
        Item smellyDeath    = new Item(smellyDeathPrefab, "Smelly Ashes", "All that remains of the victim", smellyDeathSprite);
        Item spellbook      = new Item(spellbookPrefab, "Spellbook", "A spellbook used by those who practise in the magic arts", spellbookSprite);
        Item tripwire       = new Item(tripwirePrefab, "Tripwire", "A used tripwire most likely used to immobilize the victim", tripwireSprite);
        Item chefHat        = new Item(chefHatPrefab, "Chef's Hat", "A clean and fresh smelling hat, worn by chefs.", chefHatSprite);                          //ADDITION BY WEDUNNIT
        Item whistle        = new Item(whistlePrefab, "Whistle", "A bright, shiny whistle that's as clean as... well.", whistleSprite);                        //ADDITION BY WEDUNNIT
        Item toast          = new Item(toastPrefab, "Toast", "A slice of well buttered toast. It's slightly warm.", toastSprite);                              //ADDITION BY WEDUNNIT
        Item stapler        = new Item(staplerPrefab, "Stapler", "A bright red stapler, with no staples in it.", staplerSprite);                               //ADDITION BY WEDUNNIT
        Item seaweed        = new Item(seaweedPrefab, "Seaweed", "Oceanman, take me by the hand lead me to the land, that you understand.", seaweedSprite);    //ADDITION BY WEDUNNIT
        Item sandwitch      = new Item(sandwichPrefab, "Sandwich", "A ham sandwich with cheese and lettuce on white bread.", sandwitchSprite);                 //ADDITION BY WEDUNNIT
        Item purse          = new Item(pursePrefab, "Fancy Purse", "A finely made, hand crafted, now-empty purse.", purseSprite);                              //ADDITION BY WEDUNNIT
        Item plunger        = new Item(plungerPrefab, "Plunger", "A toilet plunger. It hasn't been used recently.", plungerSprite);                            //ADDITION BY WEDUNNIT
        Item monocle        = new Item(monoclePrefab, "Monocle", "A finely made monocle, complete with gold chain.", monocleSprite);                           //ADDITION BY WEDUNNIT
        Item feather        = new Item(featherPrefab, "Feather", "A goose feather, apparently freshly plucked.", featherSprite);                               //ADDITION BY WEDUNNIT
        Item glasses        = new Item(glassesPrefab, "Safety Glasses", "Safety glasses good for keeping splinters and acid out of the eyes.", glassesSprite); //ADDITION BY WEDUNNIT
        Item dumbbell       = new Item(dumbbellPrefab, "Dumbbbell", "Dumbbells; the source of pure strength.", dumbbellSprite);                                //ADDITION BY WEDUNNIT

        murderWeapons = new MurderWeapon[8] {
            cutlass, poison, garrote, knife, laserGun, leadPipe, westernPistol, wizardStaff
        };
        itemClues = new Item [21] {
            beret,
            footprints,
            gloves,
            wine,
            shatteredGlass,
            shrapnel,
            smellyDeath,
            spellbook,
            tripwire,
            whistle,
            chefHat,
            toast,
            stapler,
            seaweed,
            sandwitch,
            purse,
            plunger,
            monocle,
            feather,
            dumbbell,
            glasses
        };
        characters = new NonPlayerCharacter[10] {
            pirate,
            mimes,
            millionaire,
            cowgirl,
            roman,
            wizard,
            heman,
            chubbie,
            scientist,
            reginald
        };
        scenes = new Scene[9] {
            atrium, lectureTheatre, lakehouse, controlRoom, kitchen, islandOfInteraction, roof, undergroundLab, factory
        };
    }
Beispiel #9
0
    // Update is called once per frame, i.e. every time the game computes a new image (an uncertain rate)
    // It could be 20 images per second on a slow computer, or 3000 on a very fast one
    // To give the impression of movement, a game (just like a movie) is still images that are shown at high speed. Typically in games, 30 or 60 images show in one second. Each of those images is called a frame.
    // In this Update function, you will write anything you want to happen continuously in the game (for example, reading input from the player, moving GameObjects, or counting time passing).
    void Update()
    {
        // make the Ruby GameObject move
        horizontal = Input.GetAxis("Horizontal");                                     // be ready to tie the character's movement to keyboard input
                                                                                      // keyboard input through axes
                                                                                      // It stores the result that Input.GetAxis ("Horizontal") provides
                                                                                      // using the Unity Input System, which is composed of Input Settings and input code
                                                                                      // which Unity gives you to query the value of an axis for that frame
        vertical = Input.GetAxis("Vertical");                                         // The default axis corresponding to the key up and down is called Vertical

        /*Debug.Log(horizontal);*/                                                    // Debug contains all functions that help debug your game

        Vector2 move = new Vector2(horizontal, vertical);                             // Instead of doing x and y independently for the movement, you store the input amount in a Vector2 called move

        if (!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f)) // Check to see whether move.x or move.y isn’t equal to 0
        // Use Mathf.Approximately instead of == because the way computers store float numbers means there is a tiny loss in precision
        // you should never test for perfect equality
        // because an operation that should end up giving 0.0f could instead give something like 0.0000000001f instead
        {
            lookDirection.Set(move.x, move.y); // If either x or y isn’t equal to 0, then Ruby is moving, set your look direction to your Move Vector and Ruby should look in the direction that she is moving.
                                               // If she stops moving (Move x and y are 0) then that won’t happen and look will remain as the value it was just before she stopped moving.
                                               // equal to lookDirection = move
            lookDirection.Normalize();         // In general, you will normalize vectors that store direction because length is not important, only the direction is
        }

        animator.SetFloat("Look X", lookDirection.x); // send the direction you look in and the speed (the length of the move vector) to the Animator
        // If Ruby doesn’t move, it will be 0, but if she does then it will be a positive number.
        animator.SetFloat("Look Y", lookDirection.y);
        animator.SetFloat("Speed", move.magnitude);

        if (isInvincible)
        {
            invincibleTimer -= Time.deltaTime; // if Ruby is invincible, you remove deltaTime from your timer
            if (invincibleTimer < 0)           // When that time is less than or equal to zero, the timer reaches its end and Ruby’s invincibility is finished,
            {
                isInvincible = false;          // so you remove her invincibility by resetting the bool to false
            }
        }

        if (Input.GetKeyDown(KeyCode.C)) // when the player presses a key, and call Launch when they do
        {
            Launch();                    // launch a Cog
        }

        if (Input.GetKeyDown(KeyCode.X)) // if the “talk” button is pressed, enter the if block and start your Raycast
        {
            // RaycastHit2D is a variable stores the result of a Raycast, which is given to us by Physics2D.Raycast
            RaycastHit2D hit = Physics2D.Raycast(rigidbody2D.position + Vector2.up * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC"));
            // The starting point is an upward offset from Ruby’s position because you want to test from the centre of Ruby’s Sprite, not from her feet.
            // The direction, which is the direction that Ruby is looking
            // A layer mask which allows us to test only certain layers. Any layers that are not part of the mask will be ignored during the intersection test.
            if (hit.collider != null)                                                            // If the Raycast didn’t intersect anything, this will be null so do nothing
                                                                                                 // Otherwise, RaycastHit2D will contain the Collider the Raycast intersected
            {
                /*Debug.Log("Raycast has hit the object " + hit.collider.gameObject);*/          // log the object you have just found with the Raycast
                NonPlayerCharacter character = hit.collider.GetComponent <NonPlayerCharacter>(); // trying to find a NonPlayerCharacter script on the object the Raycast hit
                if (character != null)                                                           // if that script exists on that object, you will display the dialog
                {
                    character.DisplayDialog();
                }
            }
        }
    }
 //Setters
 public void SetInterrogationCharacter(NonPlayerCharacter character)
 {
     this.character = character;
 }
Beispiel #11
0
    void Start()
    {
        //Initialises Variables
        //Responce Arrays
        string[] pirateResponses = new string[9] {
            "Shiver me timbers I know nothing!",
            "Arrr matey it ain’t that difficult to understand.",
            "Shiver me timbers, how dare ye threaten me!",
            "Arrr, no matey I really don’t think I do. I saw nothing!",
            "Ho ho ho, Arr matey I didn’t see anything!",
            "Shiver me timbers ye need to plan ye lunch breaks better!",
            "Arrr matey I saw nothing of import.",
            "Arr, matey I suppose ye do, but I saw nothing.",
            "Arrr matey I don’t think ye need my help to solve this conundrum."
        };

        string[] mimeResponses = new string[9] {
            "The mimes are taken aback, but contribute nothing more.",
            "The mimes shake their heads.",
            "The mimes flinch, but tell you nothing.",
            "The mimes shake their heads.",
            "The mimes imitate laughter but tell you nothing.",
            "The mimes look at their wrist watches with a puzzled expression.",
            "The mines mime out some routine which doesn’t make sense and contribute nothing.",
            "The mimes look at you with passing curiosity but contribute nothing more.",
            "The mimes shake their heads. They tell you nothing."
        };

        string[] millionaireResponses = new string[9] {
            "Don’t try and force me to tell you anything. I’ve got more money than you.",
            "Don’t patronise me you cretin. I’ve got more money than you.",
            "How dare you threaten me you lunatic, I’ve got more money than you.",
            "No my dear fellow for you see I have more money than you.",
            "Ha ha ha. Not that funny dear fellow, you’ll need more money to make it funnier.",
            "My good man, I know that time is money, but you can’t rush magnificence!",
            "My good man, there isn’t enough money around here to warrant seeing anything.",
            "I thank you for your kindness, but it would be better with some patronage!",
            "My good man, you don’t need my help to solve this. Not to mention there’s no money involved."
        };

        string[] cowgirlResponses = new string[9] {
            "I appreciate your candour pardner but I didn’t see anything.",
            "Pardner I do understand, I just didn’t see anything.",
            "Pardner I don’t appreciate threats so don’t try it.",
            "Pardner I didn’t see anything, I wasn’t paying attention.",
            "Ha ha ha, funny pardner but I still didn’t see anything.",
            "I don’t know nuthin'. If you’ve got to be gone by high noon, I’d go ask someone else.",
            "I understand pardner but I didn’t see anything",
            "Thank you pardner, but I didn’t see anything. ",
            "Pardner, you’ll have to solve this one without my help, I didn’t see anything."
        };

        string[] romanResponses = new string[9] {
            "What Ho! I understand you want to solve the problem but I saw nothing!",
            "What Ho! Yes I understand, but I saw nothing!",
            "What Ho! Don’t try and threaten me you madman!",
            "What Ho! I didn’t see anything.",
            "What Ho ho ho ho! That’s funny but I saw nothing of interest.",
            "What Ho! I feel you’re trying to rush an answer out of me! Nay I say, Nay!",
            "What Ho! My good man you are inquisitive but I don’t know anything.",
            "What Ho! Thanks my good man but I didn’t see anything.",
            "What Ho!  My good man I’m sorry but I saw nothing."
        };

        string[] wizardResponses = new string[9] {
            "Errrm...are you sure I can’t interest you in some merchandise instead?",
            "Errrm...I do understand what is going on, I just didn’t see anything.",
            "Errrm...I think you might need to calm down, I’ve got something for that.",
            "Errrm...I saw nothing but I have seen some of my merchandise, would you like some?",
            "Hee hee hee...that's funny. Errrm...but I still saw nothing though.",
            "*Looks around shiftily* Sorry mate, I don’t know anything.",
            "Errrm...I understand, but wouldn’t you prefer to buy some merchandise instead?",
            "Errrm...yes there was something…. But I’ve forgotten it now.",
            "Errrm...are you sure? I’m not that useful really."
        };

        // NEW FOR ASSSESSMENT 3 - REPOSNES FOR ADDING NEW NPCS

        string[] astrogirlResponses = new string[9] {
            "Hah, as if you can force me to say anything incriminating, earthling!",
            "Hey, careful. You don't know who you're talking to!",
            "Okay, friend, you ain't fooling anyone with that scary attitude!",
            "I'd like to help a respectable man such as yourself, but I haven’t seen anything.",
            "Hahaha, I might just steal that joke! Yet, I haven't seen anything.",
            "Hold your horses, mate, I haven't seen anything of note!",
            "All of these questions aren't going to magically make me remember something I haven't seen.",
            "Well, aren't you a kind fellow? Still, I haven't seen anything.",
            "Hey, you know more than me about this, so you clearly don't need my help."
        };

        string[] chefRepsonses = new string[9] {
            "Sacré bleu! You are very rude, monsieur detective!",
            "How dare you patronise me, monsieur! I am the best Chef in the world!",
            "Oh! No need for this, my friend! I have not seen one thing!",
            "Qui, qui! I would love to help, but I know nothing.",
            "Hahaha, very funny, monsieur! However, I don't know anything aside from the culinary arts!",
            "Monsieur, slow down, please! English is not my first language!",
            "So many questions, but I don't have the answer for any of them.",
            "Oh! That is very kind, monsieur, but the only thing I know is how great my food is!",
            "What did you say, monsieur? Would you like to taste this freshly baked baguette?"
        };

        string[] madscientistRepsonses = new string[9] {
            "Do you know who you are talking to! Watch your language, peasant!",
            "This patronising attitude of yours is annoying, I don't know anything that would interest you!",
            "Hahaha, as if someone like you could intimidate someone like me!",
            "I have no interest in this affair. It's not like I am the guilty one this time!",
            "Your childish humour doesn’t compel me to help you at all…",
            "I have no respect for people who lack patience! There's nothing I can tell you!",
            "You ask too many questions for a pathetic commoner such as yourself.",
            "You’re too kind for your own good, detective. I have no information regarding this case.",
            "Very inspiring, but I have no interest in solving this murder."
        };

        string[] robotResponses = new string[9] {
            "Goodness me! I am not programmed to answer to this kind of attitude, beep boop.",
            "Don't you dare patronise me, you mean glob of grease! Beep boop.",
            "Oh my, you are scary… I don't know anything, unfortunately. Beep boop.",
            "Helping humans is part of my protocol. However, I haven't seen anything important. Beep boop.",
            "You humans and your weird sense of humour… I could never understand it. Beep boop.",
            "I can perform thousands of calculations every second… Even so I don't have any important information about this terrible crime. Beep boop.",
            "If I told you half of the things I've heard about all of the people here, you'd short circuit… Oh wait, humans don't short circuit.",
            "Oh my, that is very kind of you to say, detective! I haven't seen anything important though.",
            "I'm sorry, detective, but there's nothing that I can do to help you. I'm sure you'll manage on your own."
        };

        // NEW FOR ASSESSEMNT 3 - IGNORE
        NonPlayerCharacter[] ignoredNPCs = new NonPlayerCharacter[6];

        //Weaknesses
        List <string> pirateWeaknesses = new List <string> {
            "Forceful", "Wisecracking", "Kind"
        };
        List <string> mimeWeaknesses = new List <string> {
            "Intimidating", "Coaxing", "Inspiring"
        };
        List <string> millionaireWeaknesses = new List <string> {
            "Forceful", "Rushed", "Kind"
        };
        List <string> cowgirlWeaknesses = new List <string> {
            "Condescending", "Wisecracking", "Inspiring"
        };
        List <string> romanWeaknesses = new List <string> {
            "Condescending", "Coaxing", "Inquisitive"
        };
        List <string> wizardWeaknesses = new List <string> {
            "Intimidating", "Rushed", "Inquisitive"
        };
        List <string> robotWeaknesses = new List <string> {
            "Intimidating", "Coaxing", "Kind"
        };
        List <string> astrogirlWeaknesses = new List <string> {
            "Forceful", "Wisecracking", "Inspiring"
        };
        List <string> chefWeaknesses = new List <string> {
            "Condescending", "Coaxing", "Inquisitie"
        };
        List <string> madscientistWeaknesses = new List <string> {
            "Forceful", "Rushed", "Kind"
        };


        //Defining NPC's
        NonPlayerCharacter pirate      = new NonPlayerCharacter("Captain Bluebottle", pirateSprite, "Salty Seadog", piratePref, pirateWeaknesses, pirateResponses);
        NonPlayerCharacter mimes       = new NonPlayerCharacter("The Mime Twins", mimesSprite, "mimes", mimesPref, mimeWeaknesses, mimeResponses);
        NonPlayerCharacter millionaire = new NonPlayerCharacter("Sir Worchester", millionaireSprite, "Money Bags", millionarePref, millionaireWeaknesses, millionaireResponses);
        NonPlayerCharacter cowgirl     = new NonPlayerCharacter("Jesse Ranger", cowgirlSprite, "Outlaw", cowgirlPref, cowgirlWeaknesses, cowgirlResponses);
        NonPlayerCharacter roman       = new NonPlayerCharacter("Celcius Maximus", romanSprite, "Legionnaire", romanPref, romanWeaknesses, romanResponses);
        NonPlayerCharacter wizard      = new NonPlayerCharacter("Randolf the Deep Purple", wizardSprite, "Dodgy Dealer", wizardPref, wizardWeaknesses, wizardResponses);

        // NEW FOR ASSESSMETN 3 - ADDING NEW NPCS //
        NonPlayerCharacter robot        = new NonPlayerCharacter("Droid Mayweather", robotSprite, "Mean Machine", robotPref, robotWeaknesses, robotResponses);
        NonPlayerCharacter astrogirl    = new NonPlayerCharacter("Astrigirl", astrogirlSprite, "Spacegirl", astrogirlPref, astrogirlWeaknesses, astrogirlResponses);
        NonPlayerCharacter chef         = new NonPlayerCharacter("Philip Mingot", chefSprite, "The Gastronomer", chefPref, chefWeaknesses, chefRepsonses);
        NonPlayerCharacter madscientist = new NonPlayerCharacter("Professor Bon Vose", madscientistSprite, "Dr. Evil", madscientistPref, madscientistWeaknesses, madscientistRepsonses);

        //Defining Scenes
        Scene controlRoom         = new Scene("Control Room");
        Scene kitchen             = new Scene("Kitchen");
        Scene lectureTheatre      = new Scene("Lecture Theatre");
        Scene lakehouse           = new Scene("Lakehouse");
        Scene islandOfInteraction = new Scene("Island of Interaction");
        Scene roof           = new Scene("Roof");
        Scene atrium         = new Scene("Atrium");
        Scene undergroundLab = new Scene("Underground Lab");

        //Defining Items
        MurderWeapon cutlass        = new MurderWeapon(cutlassPrefab, "Cutlass", "A worn and well used cutlass", cutlassSprite, "SD");
        MurderWeapon poison         = new MurderWeapon(poisonPrefab, "Empty Poison Bottle", "An empty poison bottle ", poisonSprite, "SD");
        MurderWeapon garrote        = new MurderWeapon(garrotePrefab, "Garrote", "Used for strangling a victim to death", garroteSprite, "SD");
        MurderWeapon knife          = new MurderWeapon(knifePrefab, "Knife", "An incredibly sharp tool meant for cutting meat", knifeSprite, "SD");
        MurderWeapon laserGun       = new MurderWeapon(laserGunPrefab, "Laser Gun", "It's still warm which implies it has been recently fired", laserGunSprite, "SD");
        MurderWeapon leadPipe       = new MurderWeapon(leadPipePrefab, "Lead Pipe", "It's a bit battered with a few dents on the side", leadPipeSprite, "SD");
        MurderWeapon westernPistol  = new MurderWeapon(westernPistolPrefab, "Western Pistol", "The gunpowder residue implies it has been recently fired", westernPistolSprite, "SD");
        MurderWeapon wizardStaff    = new MurderWeapon(wizardStaffPrefab, "Wizard Staff", "The gems still seem to be glow as if it has been used recently", wizardStaffSprite, "SD");
        Item         beret          = new Item(beretPrefab, "Beret", "A hat most stereotypically worn by the French", beretSprite);
        Item         footprints     = new Item(footprintsPrefab, "Bloody Footprints", "Bloody footprints most likely left by the murderer", footprintsSprite);
        Item         gloves         = new Item(glovesPrefab, "Bloody Gloves", "Bloody gloves most likely used by the murderer", glovesSprite);
        Item         wine           = new Item(winePrefab, "Fine Wine", "An expensive vintage that's close to 100 years old", wineSprite);
        Item         shatteredGlass = new Item(shatteredGlassPrefab, "Shattered Glass", "Broken glass shards spread quite close together", shatteredGlassSprite);
        Item         shrapnel       = new Item(shrapnelPrefab, "Shrapnel", "Shrapnel from an explosion or gun being fired", shrapnelSprite);
        Item         smellyDeath    = new Item(smellyDeathPrefab, "Smelly Death", "All that remains of the victim", smellyDeathSprite);
        Item         spellbook      = new Item(spellbookPrefab, "Spellbook", "A spellbook used by those who practise in the magic arts", spellbookSprite);
        Item         tripwire       = new Item(tripwirePrefab, "Tripwire", "A used tripwire most likely used to immobilize the victim", tripwireSprite);

        // NEW FOR ASSESSMENT 3 - LOCKED ROOM FEATURE
        Item key = new Item(keyPrefab, "Key", "Key has the words underground lab on it", keySprite);

        murderWeapons = new MurderWeapon[8] {
            cutlass, poison, garrote, knife, laserGun, leadPipe, westernPistol, wizardStaff
        };
        itemClues = new Item[9] {
            beret, footprints, gloves, wine, shatteredGlass, shrapnel, smellyDeath, spellbook, tripwire
        };
        characters = new NonPlayerCharacter[10] {
            pirate, mimes, millionaire, cowgirl, roman, wizard, robot, astrogirl, chef, madscientist
        };
        scenes = new Scene[8] {
            atrium, lectureTheatre, lakehouse, controlRoom, kitchen, islandOfInteraction, roof, undergroundLab
        };
        keyobj = key;
    }
Beispiel #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ResetCharacterAction"/> class.
 /// </summary>
 /// <param name="player">Player to reset.</param>
 /// <param name="npc">Npc thats call the reset action.</param>
 public ResetCharacterAction(Player player, NonPlayerCharacter npc = null)
 {
     this.player = player;
     this.npc    = npc;
 }
Beispiel #13
0
    // Update is called once per frame
    void Update()
    {
        float horizontal = Input.GetAxis("Horizontal");
        float vertical   = Input.GetAxis("Vertical");

        //Vector2 position = rigidbody2d.position; this is old
        //What we're doing here is storing our vertical and horizontal movement into a vector of length 2
        Vector2 move = new Vector2(horizontal, vertical);

        if (!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f)) //Using approximately, because of computer precision problems with using ==
        {
            lookDirection.Set(move.x, move.y);
            lookDirection.Normalize(); //Normalizing here to store directional information from the vector, but excluding vector magnitude as it's unimportant for this usage
        }

        //Send data to the animator
        animator.SetFloat("Look X", lookDirection.x);
        animator.SetFloat("Look Y", lookDirection.y);
        animator.SetFloat("Speed", move.magnitude);

        //deltaTime is a movement adjustment which makes the game handle identically despite the chance of computers having different framerates.
        //position.x = position.x + movement_speed * horizontal * Time.deltaTime;
        //position.y = position.y + movement_speed * vertical * Time.deltaTime;
        //transform.position = position; No longer need this for movement, as we are incorporating physics now

        //Now moving with some great animation
        Vector2 position = rigidbody2d.position;

        position = position + move * movement_speed * Time.deltaTime;
        rigidbody2d.MovePosition(position);

        if (isInvincible)
        {
            invincibleTimer -= Time.deltaTime;
            if (invincibleTimer < 0)
            {
                isInvincible = false;                      //endif
            }
        }

        if (Input.GetKeyDown(KeyCode.C))
        {
            Launch();
        }

        if (Input.GetKeyDown(KeyCode.X))
        {
            RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC"));

            if (hit.collider != null)
            {
                //UnityEngine.Debug.Log("Raycast has hit the object " + hit.collider.gameObject);
                NonPlayerCharacter character = hit.collider.GetComponent <NonPlayerCharacter>();

                if (character != null)
                {
                    character.DisplayDialog();
                }
            }
        }
    }
Beispiel #14
0
 public void TestSetup()
 {
     verbalClue = new VerbalClue(null, null);
     owner      = new NonPlayerCharacter(null, null, null, null, null, null);
     verbalClue.SetOwner(owner);
 }
Beispiel #15
0
    // Update is called once per frame
    void Update()
    {
        if (count == 10)
        {
            speed        = 0.0f;
            WinText.text = "You Win! Game created by Jacob Stuart. Press R to Restart";
            PlaySound(WinSound);
            //Destroy(gameObject);
            if (Input.GetKeyDown(KeyCode.R))
            {
                SceneManager.LoadScene("MainScene 1");
            }
            //Destroy(gameObject);
        }

        if (speed == 6.0f && speeduptimer > 0.0)
        {
            speeduptimer -= Time.deltaTime;
        }
        else if (speed == 6.0f && speeduptimer <= 0.0)
        {
            speed = 3.0f;
        }

        scene = SceneManager.GetActiveScene();
        if (count == 5 && scene.name == "MainScene 1")
        {
            cam       = GameObject.Find("CM vcam1");
            secretCam = GameObject.Find("CM vcam2");

            if (cam == true)
            {
                WinText.text = "Talk to Jambi to visit stage two!";
            }

            if (Input.GetKeyDown(KeyCode.X))
            {
                RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC"));
                if (hit.collider != null)
                {
                    secretCam.SetActive(true);
                    cam.SetActive(false);

                    //confiner.InvalidatePathCache();
                    SceneManager.LoadScene("Scene2");
                    WinText.text = "";
                    PlaySound(frogchat);
                    //transform.position = new Vector3(53.0f, 4.0f, 0f);
                }
            }
        }

        if (currentHealth == 0)
        {
            speed = 0.0f;
            PlaySound(LossSound);
            if (Input.GetKeyDown(KeyCode.R))
            {
                SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
            }
        }

        if (Input.GetKey("escape"))
        {
            Application.Quit();
        }

        horizontal = Input.GetAxis("Horizontal");
        vertical   = Input.GetAxis("Vertical");

        Vector2 move = new Vector2(horizontal, vertical);

        if (!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f))
        {
            lookDirection.Set(move.x, move.y);
            lookDirection.Normalize();
        }

        animator.SetFloat("Look X", lookDirection.x);
        animator.SetFloat("Look Y", lookDirection.y);
        animator.SetFloat("Speed", move.magnitude);

        if (isInvincible)
        {
            invincibleTimer -= Time.deltaTime;
            if (invincibleTimer < 0)
            {
                isInvincible = false;
            }
        }

        if (Input.GetKeyDown(KeyCode.C) && cog > 0)
        {
            Launch();
            cog          = cog - 1;
            CogText.text = "Cogs:" + cog.ToString();
        }

        if (Input.GetKeyDown(KeyCode.X))
        {
            RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC"));
            if (hit.collider != null)
            {
                NonPlayerCharacter character = hit.collider.GetComponent <NonPlayerCharacter>();
                if (character != null)
                {
                    character.DisplayDialog();
                    PlaySound(frogchat);
                }
            }
        }
    }
Beispiel #16
0
        /// <summary>
        /// Generates a new NPC based on parents' statistics
        /// </summary>
        /// <returns>NonPlayerCharacter or null</returns>
        /// <param name="mummy">The new NPC's mother</param>
        /// <param name="daddy">The new NPC's father</param>
        public static NonPlayerCharacter GenerateNewNPC(Character mummy, Character daddy)
        {
            NonPlayerCharacter newNPC = new NonPlayerCharacter();

            // charID
            newNPC.charID = Globals_Game.GetNextCharID();
            // first name
            newNPC.firstName = "Baby";
            // family name
            newNPC.familyName = daddy.familyName;
            // date of birth
            newNPC.birthDate = new Tuple <uint, byte>(Globals_Game.clock.currentYear, Globals_Game.clock.currentSeason);
            // sex
            newNPC.isMale = Birth.GenerateSex();
            // nationality
            newNPC.nationality = daddy.nationality;
            // whether is alive
            newNPC.isAlive = true;
            // maxHealth
            newNPC.maxHealth = Birth.GenerateKeyCharacteristics(mummy.maxHealth, daddy.maxHealth);
            // virility
            newNPC.virility = Birth.GenerateKeyCharacteristics(mummy.virility, daddy.virility);
            // goTo queue
            newNPC.goTo = new Queue <Fief>();
            // language
            newNPC.language = daddy.language;
            // days left
            newNPC.days = 90;
            // stature modifier
            newNPC.statureModifier = 0;
            // management
            newNPC.management = Birth.GenerateKeyCharacteristics(mummy.management, daddy.management);
            // combat
            newNPC.combat = Birth.GenerateKeyCharacteristics(mummy.combat, daddy.combat);
            // traits
            newNPC.traits = Birth.GenerateTraitSetFromParents(mummy.traits, daddy.traits, newNPC.isMale);
            // if in keep
            newNPC.inKeep = mummy.inKeep;
            // if pregnant
            newNPC.isPregnant = false;
            // familyID
            newNPC.familyID = daddy.familyID;
            // spouse
            newNPC.spouse = null;
            // father
            newNPC.father = daddy.charID;
            // mother
            newNPC.mother = mummy.charID;
            // fiancee
            newNPC.fiancee = null;
            // location
            newNPC.location = null;
            // titles
            newNPC.myTitles = new List <string>();
            // armyID
            newNPC.armyID = null;
            // ailments
            newNPC.ailments = new Dictionary <string, Ailment>();
            // employer
            newNPC.employer = null;
            // salary/allowance
            newNPC.salary = 0;
            // lastOffer (will remain empty for family members)
            newNPC.lastOffer = new Dictionary <string, uint>();
            // inEntourage
            newNPC.setEntourage(false);
            // isHeir
            newNPC.isHeir = false;

            return(newNPC);
        }
Beispiel #17
0
    void Start()
    {
        scriptNPC = this.GetComponent <NonPlayerCharacter>();

        materialColor = GetComponent <Renderer>().material.color;
    }
Beispiel #18
0
    private void Update()
    {
        mouseDir = (mousePos - rigidbody2d.position).normalized;

        float horizontal = Input.GetAxis("Horizontal");
        float vertical   = Input.GetAxis("Vertical");

        move = new Vector2(horizontal, vertical).normalized;

        if (Input.GetKeyDown(KeyCode.Space) && !dash && move != Vector2.zero && dashCdTimer <= 0)
        {
            dashCdTimer = cooldownDash;
            dash        = true;
            Instantiate(dashEffect, transform.position, Quaternion.identity);
        }


        if (attackTime > 0)
        {
            attackTime -= Time.deltaTime;
        }

        if (launchCdTimer > 0)
        {
            launchCdTimer -= Time.deltaTime;
        }

        if (dashCdTimer > 0)
        {
            dashCdTimer -= Time.deltaTime;
        }

        Stab();

        if (Input.GetButtonDown("Fire1") && launchCdTimer <= 0)
        {
            launchCdTimer = cooldownLaunch;
            Launch();
        }
        else if (Input.GetButton("Fire2") && attackTime <= 0)
        {
            if (!Mathf.Approximately(mouseDir.x, 0.0f) || !Mathf.Approximately(mouseDir.y, 0.0f))
            {
                lookDirection.Set(mouseDir.x, mouseDir.y);
                lookDirection.Normalize();
            }

            attackTime = startTimeAttack;
            animator.SetTrigger("Launch");

            stabPos = mousePos;
            stabDir = mouseDir;
        }


        if (Input.GetKeyDown(KeyCode.X))
        {
            RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC"));
            if (hit.collider != null)
            {
                NonPlayerCharacter character = hit.collider.GetComponent <NonPlayerCharacter>();
                if (character != null)
                {
                    character.DisplayDialog();
                }

                Hostage hostage = hit.collider.GetComponent <Hostage>();
                if (hostage != null)
                {
                    if (hostage.target == null)
                    {
                        hostage.SetDestination(transform);
                    }
                    else
                    {
                        hostage.Heal(this);
                    }
                }
            }
        }
    }
        void openLevelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofDialog = new OpenFileDialog();

            ofDialog.Filter          = "Level Files (*.xml)|*.xml";
            ofDialog.CheckFileExists = true;
            ofDialog.CheckPathExists = true;

            DialogResult result = ofDialog.ShowDialog();

            if (result != DialogResult.OK)
            {
                return;
            }

            string path = Path.GetDirectoryName(ofDialog.FileName);

            LevelData          newLevel = null;
            MapData            mapData  = null;
            CharacterLayerData charData = null;

            try
            {
                newLevel = XnaSerializer.Deserialize <LevelData>(ofDialog.FileName);
                mapData  = XnaSerializer.Deserialize <MapData>(path + @"\Maps\" + newLevel.MapName +
                                                               ".xml");
                charData = XnaSerializer.Deserialize <CharacterLayerData>(path + @"\Chars\" + newLevel.LevelName + ".xml");
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message, "Error reading level");
                return;
            }

            tileSetImages.Clear();
            tileSetData.Clear();
            tileSets.Clear();

            layers.Clear();

            lbTileset.Items.Clear();
            clbLayers.Items.Clear();

            collisionLayer.Collisions.Clear();
            animatedLayer.AnimatedTiles.Clear();
            characters.Characters.Clear();

            levelData = newLevel;

            foreach (TilesetData data in mapData.Tilesets)
            {
                Texture2D texture = null;

                tileSetData.Add(data);
                lbTileset.Items.Add(data.TilesetName);

                GDIImage image = (GDIImage)GDIBitmap.FromFile(data.TilesetImageName);
                tileSetImages.Add(image);
                using (Stream stream = new FileStream(data.TilesetImageName, FileMode.Open,
                                                      FileAccess.Read))
                {
                    texture = Texture2D.FromStream(GraphicsDevice, stream);

                    tileSets.Add(
                        new Tileset(
                            texture,
                            data.TilesWide,
                            data.TilesHigh,
                            data.TileWidthInPixels,
                            data.TileHeightInPixels));
                }
            }

            using (Stream textureStream = new FileStream(mapData.AnimatedTileset.TilesetImageName,
                                                         FileMode.Open, FileAccess.Read))
            {
                Texture2D aniamtedTexture = Texture2D.FromStream(GraphicsDevice, textureStream);

                animatedSet = new AnimatedTileset(
                    aniamtedTexture,
                    mapData.AnimatedTileset.FramesAcross,
                    mapData.AnimatedTileset.TilesHigh,
                    mapData.AnimatedTileset.TileWidthInPixels,
                    mapData.AnimatedTileset.TileHeightInPixels);
                animatedSetData = mapData.AnimatedTileset;
            }

            foreach (MapLayerData data in mapData.Layers)
            {
                clbLayers.Items.Add(data.MapLayerName, true);
                layers.Add(MapLayer.FromMapLayerData(data));
            }

            lbTileset.SelectedIndex = 0;
            clbLayers.SelectedIndex = 0;
            nudCurrentTile.Value    = 0;
            sbAnimatedTile.Maximum  = 0;

            map = new TileMap(tileSets[0], animatedSet, (MapLayer)layers[0]);

            for (int i = 1; i < tileSets.Count; i++)
            {
                map.AddTileset(tileSets[i]);
            }

            for (int i = 1; i < layers.Count; i++)
            {
                map.AddLayer(layers[i]);
            }

            foreach (var collision in mapData.Collisions.Collisions)
            {
                collisionLayer.Collisions.Add(collision.Key, collision.Value);
            }

            foreach (var tile in mapData.AnimatedTiles.AnimatedTiles)
            {
                animatedLayer.AnimatedTiles.Add(tile.Key, tile.Value);
            }

            foreach (var c in charData.Characters)
            {
                Character character;

                if (c.Value is NonPlayerCharacterData)
                {
                    Entity entity = new Entity(c.Value.Name, c.Value.EntityData, c.Value.Gender, EntityType.NPC);

                    using (Stream stream = new FileStream(c.Value.TextureName, FileMode.Open, FileAccess.Read))
                    {
                        Texture2D      texture = Texture2D.FromStream(GraphicsDevice, stream);
                        AnimatedSprite sprite  = new AnimatedSprite(texture, Animations);
                        sprite.Position = new Vector2(c.Key.X * Engine.TileWidth, c.Key.Y * Engine.TileHeight);
                        character       = new NonPlayerCharacter(entity, sprite);

                        ((NonPlayerCharacter)character).SetConversation(
                            ((NonPlayerCharacterData)c.Value).CurrentConversation);

                        characters.Characters.Add(c.Key, character);
                    }
                }
            }
            tilesetToolStripMenuItem.Enabled    = true;
            mapLayerToolStripMenuItem.Enabled   = true;
            charactersToolStripMenuItem.Enabled = true;
            chestsToolStripMenuItem.Enabled     = true;
            keysToolStripMenuItem.Enabled       = true;
        }
    // Creates two lists of clues, one containing 3 verbal clues (two relevant, one useless) and one containing 6 item clues (2 relevent, 4 useless).
    public void BuildCluePools(string motive, NonPlayerCharacter murderer, MurderWeapon weapon)
    {
        // one of the relevant item clues is the murder weapon, there is only ever one MurderWeapon item present in the game.
        item_clue_pool.Add(weapon);
        relevant_item_clues.Add(weapon);

        int verbalClueWithMotive = Random.Range(0, 2);                  // UPDATED BY WEDUNNIT either 'old friends' or 'altercation' for the first verbal clue

        verbal_clue_pool.Add(verbal_clues [verbalClueWithMotive]);      //ADDITION BY WEDUNNIT
        relevant_verbal_clues.Add(verbal_clues [verbalClueWithMotive]); //ADDITION BY WEDUNNIT

        int verbalClueWithWeapon = Random.Range(2, 6);                  // UPDATED BY WEDUNNIT any of the remaining verbal clues for the second verbal clue

        verbal_clue_pool.Add(verbal_clues [verbalClueWithWeapon]);
        relevant_verbal_clues.Add(verbal_clues [verbalClueWithWeapon]);

        switch (murdererName)           //REFACTORED BY WEDUNNIT
        {
        case "Salty Seadog":
            item_clue_pool.Add(item_clues [4]);              // shattered glass
            relevant_item_clues.Add(item_clues [4]);
            break;

        case "mimes":
            item_clue_pool.Add(item_clues [0]);              // beret
            relevant_item_clues.Add(item_clues [0]);
            break;

        case "Money Bags":
            item_clue_pool.Add(item_clues [2]);              // gloves
            relevant_item_clues.Add(item_clues [2]);
            break;

        case "Outlaw":
            item_clue_pool.Add(item_clues [8]);              // tripwire
            relevant_item_clues.Add(item_clues [8]);
            break;

        case "Legionnaire":
            item_clue_pool.Add(item_clues [3]);              // wine
            relevant_item_clues.Add(item_clues [3]);
            break;

        case "Dodgy Dealer":
            item_clue_pool.Add(item_clues [7]);              // spellbook
            relevant_item_clues.Add(item_clues [7]);
            break;

        case "Superhero":
            item_clue_pool.Add(item_clues [19]);                        //Dumbbells     //ADDITION BY WEDUNNIT
            relevant_item_clues.Add(item_clues [19]);                   //ADDITION BY WEDUNNIT
            break;

        case "Mad scientist":
            item_clue_pool.Add(item_clues [18]);                        // glasses	//ADDITION BY WEDUNNIT
            relevant_item_clues.Add(item_clues [18]);                   //ADDITION BY WEDUNNIT
            break;

        case "Telechubbie":
            item_clue_pool.Add(item_clues [15]);                //purse			//ADDITION BY WEDUNNIT
            relevant_item_clues.Add(item_clues [15]);           //ADDITION BY WEDUNNIT
            break;

        case "Reginald M IV":
            item_clue_pool.Add(item_clues [17]);                //monocle			//ADDITION BY WEDUNNIT
            relevant_item_clues.Add(item_clues [17]);           //ADDITION BY WEDUNNIT
            break;

        default:
            throw new System.ArgumentException(murdererName + " does not have any clues associated with them.");
        }

        // add the 4 irrelevant verbal clues
        while (item_clue_pool.Count() < 6)
        {
            int index = Random.Range(0, item_clues.Count() - 1);
            if (item_clue_pool.Contains(item_clues [index]) == false)
            {
                item_clue_pool.Add(item_clues [index]);
            }
        }

        // add 'red herring' verbal clue
        int    weapon_index       = Random.Range(0, weapons.Count() - 1);
        string red_herring_weapon = weapons [weapon_index].getID();

        while (red_herring_weapon == weapon.getID())
        {
            weapon_index       = Random.Range(0, weapons.Count() - 1);
            red_herring_weapon = weapons [weapon_index].getID();
        }
        int    npc_index             = Random.Range(0, npcs.Count() - 1);
        string red_herring_character = npcs [npc_index].getCharacterID();

        while (red_herring_character == murderer.getCharacterID())
        {
            npc_index             = Random.Range(0, npcs.Count() - 1);
            red_herring_character = npcs [npc_index].getCharacterID();
        }


        // create and then choose one of two irrelevant verbal clues
        VerbalClue police_failure = new VerbalClue("Lack of Evidence", "The police think the victim was killed using a " + red_herring_weapon + ", but they can’t find evidence of one.");

        VerbalClue shifty_looking = new VerbalClue("Looking Shifty", "I think I saw " + red_herring_character + " acting suspiciously.");

        VerbalClue[] red_herring_verbal_clues = new VerbalClue[2] {
            police_failure, shifty_looking
        };
        int herring_index = Random.Range(0, 1);

        verbal_clue_pool.Add(red_herring_verbal_clues [herring_index]);
    }
        public override void Update(GameTime gameTime)
        {
            world.Update(gameTime);
            player.Update(gameTime);
            player.Camera.LockToSprite(player.Sprite);

            if (InputHandler.KeyReleased(Keys.Space) ||
                InputHandler.ButtonReleased(Buttons.A, PlayerIndex.One))
            {
                foreach (ILayer layer in World.Levels[World.CurrentLevel].Map.Layers)
                {
                    if (layer is CharacterLayer)
                    {
                        foreach (Character c in ((CharacterLayer)layer).Characters.Values)
                        {
                            float distance = Vector2.Distance(
                                player.Sprite.Center,
                                c.Sprite.Center);

                            if (distance < Character.SpeakingRadius && c is NonPlayerCharacter)
                            {
                                NonPlayerCharacter npc = (NonPlayerCharacter)c;

                                if (npc.HasConversation)
                                {
                                    StateManager.PushState(GameRef.ConversationScreen);

                                    GameRef.ConversationScreen.SetConversation(
                                        player,
                                        npc,
                                        npc.CurrentConversation);

                                    GameRef.ConversationScreen.StartConversation();
                                }
                            }
                            else if (distance < Character.SpeakingRadius && c is Merchant)
                            {
                                StateManager.PushState(GameRef.ShopScreen);
                                GameRef.ShopScreen.SetMerchant(c as Merchant);
                            }
                        }
                    }
                }
            }

            MobLayer mobLayer = World.Levels[World.CurrentLevel].Map.Layers.Find(x => x is MobLayer) as MobLayer;

            foreach (var mob in mobLayer.Mobs.Where(kv => kv.Value.Entity.Health.CurrentValue <= 0).ToList())
            {
                mobLayer.Mobs.Remove(mob.Key);
            }

            foreach (Rectangle r in mobLayer.Mobs.Keys)
            {
                float distance = Vector2.Distance(mobLayer.Mobs[r].Sprite.Center, player.Sprite.Center);

                if (distance < Mob.AttackRadius)
                {
                    GameRef.CombatScreen.SetMob(mobLayer.Mobs[r]);

                    StateManager.PushState(GameRef.CombatScreen);
                    Visible = true;
                }
            }

            if (InputHandler.KeyReleased(Keys.I))
            {
                StateManager.PushState(GameRef.InventoryScreen);
            }

            if (InputHandler.KeyReleased(Keys.C))
            {
                StateManager.PushState(GameRef.StatsScreen);
                Visible = true;
            }

            if (Player.Character.Entity.Level < Mechanics.Experiences.Length)
            {
                if (Player.Character.Entity.Experience >= Mechanics.Experiences[Player.Character.Entity.Level])
                {
                    Player.Character.Entity.LevelUp();
                    StateManager.PushState(GameRef.LevelScreen);
                    Visible = true;
                }
            }

            base.Update(gameTime);
        }
        private void LoadWorld()
        {
            RpgLibrary.WorldClasses.LevelData levelData =
                Game.Content.Load <RpgLibrary.WorldClasses.LevelData>(@"Game\Levels\Starting Level");

            RpgLibrary.WorldClasses.MapData mapData =
                Game.Content.Load <RpgLibrary.WorldClasses.MapData>(@"Game\Levels\Maps\" + levelData.MapName);

            CharacterLayerData charData =
                Game.Content.Load <CharacterLayerData>(@"Game\Levels\Chars\Starting Level");
            CharacterLayer characterLayer = new CharacterLayer();

            TileMap map = TileMap.FromMapData(mapData, Game.Content);

            foreach (var c in charData.Characters)
            {
                Character character;

                if (c.Value is NonPlayerCharacterData)
                {
                    Entity entity = new Entity(c.Value.Name, c.Value.EntityData, c.Value.Gender, EntityType.NPC);

                    using (Stream stream = new FileStream(c.Value.TextureName, FileMode.Open, FileAccess.Read))
                    {
                        Texture2D      texture = Texture2D.FromStream(GraphicsDevice, stream);
                        AnimatedSprite sprite  = new AnimatedSprite(texture, AnimationManager.Instance.Animations)
                        {
                            Position = new Vector2(c.Key.X * Engine.TileWidth, c.Key.Y * Engine.TileHeight)
                        };

                        character = new NonPlayerCharacter(entity, sprite);

                        ((NonPlayerCharacter)character).SetConversation(
                            ((NonPlayerCharacterData)c.Value).CurrentConversation);
                    }

                    characterLayer.Characters.Add(c.Key, character);
                }
            }

            map.AddLayer(characterLayer);

            Level level = new Level(map);

            ChestData chestData = Game.Content.Load <ChestData>(@"Game\Chests\Plain Chest");

            Chest chest = new Chest(chestData);

            BaseSprite chestSprite = new BaseSprite(
                containers,
                new Rectangle(0, 0, 32, 32),
                new Point(10, 10));

            ItemSprite itemSprite = new ItemSprite(
                chest,
                chestSprite);

            level.Chests.Add(itemSprite);

            World world = new World(GameRef, GameRef.ScreenRectangle);

            world.Levels.Add(level);
            world.CurrentLevel = 0;

            AnimatedSprite s = new AnimatedSprite(
                GameRef.Content.Load <Texture2D>(@"SpriteSheets\Eliza"),
                AnimationManager.Instance.Animations);

            s.Position = new Vector2(0 * Engine.TileWidth, 5 * Engine.TileHeight);

            EntityData ed = new EntityData("Eliza", 1, 10, 10, 10, 10, 10, 10, "20|CON|12", "16|WIL|16",
                                           "0|0|0");

            Entity e = new Entity("Eliza", ed, EntityGender.Female, EntityType.NPC);

            NonPlayerCharacter npc = new NonPlayerCharacter(e, s);

            npc.SetConversation("eliza1");
            world.Levels[world.CurrentLevel].Characters.Add(npc);

            GamePlayScreen.World = world;

            CreateConversation();

            ((NonPlayerCharacter)world.Levels[world.CurrentLevel].Characters[0]).SetConversation("eliza1");
        }
    // Update is called once per frame
    void Update()
    {
        isGrounded = Physics2D.OverlapCircle(feetPos.position, checkRadius, whatIsGround);


        if (isGrounded == true && Input.GetKeyDown(KeyCode.Space))
        {
            IsJumping       = true;
            jumpTimeCounter = jumpTime;
            rb.velocity     = Vector2.up * jumpForce;
        }

        if (Input.GetKey(KeyCode.Space) && IsJumping == true)
        {
            SfxManager.sfxInstance.Audio.PlayOneShot(SfxManager.sfxInstance.Ejimas1);
            if (jumpTimeCounter > 0)
            {
                rb.velocity      = Vector2.up * jumpForce;
                jumpTimeCounter -= Time.deltaTime;
            }
            else
            {
                IsJumping = false;
            }
        }

        if (Input.GetKeyUp(KeyCode.Space))
        {
            IsJumping = false;
        }

        if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.RightArrow))
        {
            anim.SetBool("isRunning", true);
        }
        else
        {
            anim.SetBool("isRunning", false);
        }

        if (Input.GetKey(KeyCode.Space))
        {
            anim.SetTrigger("jumping");
        }

        if (Input.GetKeyDown(KeyCode.X))
        {
            RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 5f, LayerMask.GetMask("NPC"));
            if (hit.collider != null)
            {
                NonPlayerCharacter character = hit.collider.GetComponent <NonPlayerCharacter>();
                if (character != null)
                {
                    character.DisplayDialog();
                }
            }
        }


        if (maxHealth <= 0)
        {
            //Destroy(gameObject);
            SceneManager.LoadScene(sceneName: "Lose");
        }
    }
Beispiel #24
0
 //Sets the character
 public void SetCharacter(NonPlayerCharacter character)
 {
     this.character = character;
 }
        private void CreateWorld()
        {
            Texture2D tilesetTexture = Game.Content.Load <Texture2D>(@"Tilesets\tileset1");
            Tileset   tileset1       = new Tileset(tilesetTexture, 8, 8, 32, 32);

            tilesetTexture = Game.Content.Load <Texture2D>(@"Tilesets\tileset2");

            Tileset  tileset2 = new Tileset(tilesetTexture, 8, 8, 32, 32);
            MapLayer layer    = new MapLayer(100, 100);

            for (int y = 0; y < layer.Height; y++)
            {
                for (int x = 0; x < layer.Width; x++)
                {
                    Tile tile = new Tile(0, 0);
                    layer.SetTile(x, y, tile);
                }
            }

            MapLayer splatter = new MapLayer(100, 100);
            Random   random   = new Random();

            for (int i = 0; i < 100; i++)
            {
                int x     = random.Next(0, 100);
                int y     = random.Next(0, 100);
                int index = random.Next(2, 14);

                Tile tile = new Tile(index, 0);

                splatter.SetTile(x, y, tile);
            }

            splatter.SetTile(1, 0, new Tile(0, 1));
            splatter.SetTile(2, 0, new Tile(2, 1));
            splatter.SetTile(3, 0, new Tile(0, 1));

            TileMap map = new TileMap(tileset1, layer);

            map.AddTileset(tileset2);
            map.AddLayer(splatter);
            map.CollisionLayer.Collisions.Add(new Point(1, 0), CollisionType.Impassable);
            map.CollisionLayer.Collisions.Add(new Point(3, 0), CollisionType.Impassable);

            Level level = new Level(map);

            ChestData chestData = Game.Content.Load <ChestData>(@"Game\Chests\Plain Chest");
            Chest     chest     = new Chest(chestData);

            BaseSprite chestSprite = new BaseSprite(
                containers,
                new Rectangle(0, 0, 32, 32),
                new Point(10, 10));

            ItemSprite itemSprite = new ItemSprite(
                chest,
                chestSprite);

            level.Chests.Add(itemSprite);

            World world = new World(GameRef, GameRef.ScreenRectangle);

            world.Levels.Add(level);
            world.CurrentLevel = 0;

            AnimatedSprite s = new AnimatedSprite(
                GameRef.Content.Load <Texture2D>(@"SpriteSheets\Eliza"),
                AnimationManager.Instance.Animations);

            s.Position = new Vector2(5 * Engine.TileWidth, 5 * Engine.TileHeight);

            EntityData         ed  = new EntityData("Eliza", 10, 10, 10, 10, 10, 10, "20|CON|12", "16|WIL|16", "0 | 0 | 0");
            Entity             e   = new Entity("Eliza", ed, EntityGender.Female, EntityType.NPC);
            NonPlayerCharacter npc = new NonPlayerCharacter(e, s);

            world.Levels[world.CurrentLevel].Characters.Add(npc);

            GamePlayScreen.World = world;
        }
    // Update is called once per frame
    void Update()
    {
        horizontal = Input.GetAxis("Horizontal");
        vertical   = Input.GetAxis("Vertical");

        Vector2 move = new Vector2(horizontal, vertical);

        if (!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f))
        {
            lookDirection.Set(move.x, move.y);
            lookDirection.Normalize();
        }

        animator.SetFloat("Look X", lookDirection.x);
        animator.SetFloat("Look Y", lookDirection.y);
        animator.SetFloat("Speed", move.magnitude);

        if (isInvincible)
        {
            invincibleTimer -= Time.deltaTime;
            if (invincibleTimer < 0)
            {
                isInvincible = false;
            }
        }

        if (Input.GetKeyDown(KeyCode.C))
        {
            Launch();
        }

        if (Input.GetKeyDown(KeyCode.X))
        {
            RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC"));
            if (hit.collider != null)
            {
                NonPlayerCharacter character = hit.collider.GetComponent <NonPlayerCharacter>();
                if (character != null)
                {
                    character.DisplayDialog();
                }
            }
        }

        if (currentHealth == 0) //lose function
        {
            speed         = 0;
            gameOver      = true;
            loseText.text = "You lose! Press R to restart. Game created by Chase Rook.";
            backgroundMusic.SetActive(false);
            musicSource.clip = musicClipTwo;
            musicSource.Play();
            musicSource.loop = false;

            if (Input.GetKey(KeyCode.R))
            {
                if (gameOver == true)
                {
                    SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); // this loads the currently active scene
                }
            }
        }

        if (scoreValue == 4) //win function
        {
            winText.text = "Talk to Jambi to visit stage two!";

            if (Input.GetKeyDown(KeyCode.X))
            {
                RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC"));
                if (hit.collider != null)
                {
                    // you could probably add your IF statement here
                    NonPlayerCharacter character = hit.collider.GetComponent <NonPlayerCharacter>();
                    if (character != null)
                    {
                        SceneManager.LoadScene("Stage 2");
                        level = 2;
                    }
                }
            }
        }

        if (level == 2) //win function level 2
        {
            if (scoreValue == 4)
            {
                winText.text = "You Win! Press R to restart. Game created by Chase Rook.";
                gameOver     = true;
                backgroundMusic.SetActive(false);
                musicSource.clip = musicClipOne;
                musicSource.Play();
                musicSource.loop = false;

                if (Input.GetKey(KeyCode.R))
                {
                    if (gameOver == true)
                    {
                        SceneManager.LoadScene("Stage 1");
                        level = 1; // this loads the currently active scene
                    }
                }
            }
        }
    }
        private void LoadWorld()
        {
            RpgLibrary.WorldClasses.LevelData levelData =
                Game.Content.Load <RpgLibrary.WorldClasses.LevelData>(@"Game\Levels\Starting Level");

            RpgLibrary.WorldClasses.MapData mapData =
                Game.Content.Load <RpgLibrary.WorldClasses.MapData>(@"Game\Levels\Maps\" + levelData.MapName);

            CharacterLayerData charData =
                Game.Content.Load <CharacterLayerData>(@"Game\Levels\Chars\Starting Level");
            CharacterLayer characterLayer = new CharacterLayer();
            MobLayer       mobLayer       = new MobLayer();

            TileMap map = TileMap.FromMapData(mapData, Game.Content);

            foreach (var c in charData.Characters)
            {
                Character character;

                if (c.Value is NonPlayerCharacterData data)
                {
                    Entity entity = new Entity(c.Value.Name, c.Value.EntityData, c.Value.Gender, EntityType.NPC);

                    using (Stream stream = new FileStream(c.Value.TextureName, FileMode.Open, FileAccess.Read))
                    {
                        Texture2D      texture = Texture2D.FromStream(GraphicsDevice, stream);
                        AnimatedSprite sprite  = new AnimatedSprite(texture, AnimationManager.Instance.Animations)
                        {
                            Position = new Vector2(c.Key.X * Engine.TileWidth, c.Key.Y * Engine.TileHeight)
                        };

                        character = new NonPlayerCharacter(entity, sprite);

                        ((NonPlayerCharacter)character).SetConversation(
                            data.CurrentConversation);
                    }

                    characterLayer.Characters.Add(c.Key, character);
                }
            }

            map.AddLayer(characterLayer);
            map.AddLayer(mobLayer);

            Level level = new Level(map);

            ChestData chestData = Game.Content.Load <ChestData>(@"Game\Chests\Plain Chest");

            Chest chest = new Chest(chestData);

            BaseSprite chestSprite = new BaseSprite(
                containers,
                new Rectangle(0, 0, 32, 32),
                new Point(10, 10));

            ItemSprite itemSprite = new ItemSprite(
                chest,
                chestSprite);

            level.Chests.Add(itemSprite);

            World world = new World(GameRef, GameRef.ScreenRectangle);

            world.Levels.Add(level);
            world.CurrentLevel = 0;

            AnimatedSprite s = new AnimatedSprite(
                GameRef.Content.Load <Texture2D>(@"SpriteSheets\Eliza"),
                AnimationManager.Instance.Animations)
            {
                Position = new Vector2(0 * Engine.TileWidth, 5 * Engine.TileHeight)
            };

            EntityData ed = new EntityData("Eliza", 1, 10, 10, 10, 10, 10, 10, "20|CON|12", "16|WIL|16",
                                           "0|0|0");

            Entity e = new Entity("Eliza", ed, EntityGender.Female, EntityType.NPC);

            NonPlayerCharacter npc = new NonPlayerCharacter(e, s);

            npc.SetConversation("eliza1");
            //world.Levels[world.CurrentLevel].Characters.Add(npc);

            s = new AnimatedSprite(
                GameRef.Content.Load <Texture2D>(@"SpriteSheets\Eliza"),
                AnimationManager.Instance.Animations)
            {
                Position = new Vector2(10 * Engine.TileWidth, 0)
            };

            ed = new EntityData("Barbra", 2, 10, 10, 10, 10, 10, 10, "20|CON|12", "16|WIL|16", "0|0|0");

            e = new Entity("Barbra", ed, EntityGender.Female, EntityType.Merchant);

            Merchant  m     = new Merchant(e, s);
            Texture2D items = Game.Content.Load <Texture2D>("ObjectSprites/roguelikeitems");

            m.Backpack.AddItem(GameItemManager.GetItem("Long Sword"));
            m.Backpack.AddItem(GameItemManager.GetItem("Short Sword"));
            m.Backpack.AddItem(GameItemManager.GetItem("Apprentice Staff"));
            m.Backpack.AddItem(GameItemManager.GetItem("Acolyte Staff"));
            m.Backpack.AddItem(GameItemManager.GetItem("Leather Armor"));
            m.Backpack.AddItem(GameItemManager.GetItem("Chain Mail"));
            m.Backpack.AddItem(GameItemManager.GetItem("Studded Leather Armor"));
            m.Backpack.AddItem(GameItemManager.GetItem("Light Robes"));
            m.Backpack.AddItem(GameItemManager.GetItem("Medium Robes"));
            world.Levels[world.CurrentLevel].Characters.Add(m);
            ((CharacterLayer)world.Levels[world.CurrentLevel].Map.Layers.Find(x => x is CharacterLayer)).Characters.Add(new Point(10, 0), m);
            GamePlayScreen.World = world;

            for (int i = 0; i < 25; i++)
            {
                ed = new EntityData("Bandit", 1, 10, 12, 12, 10, 10, 10, "20|CON|10", "12|WIL|12", "0|0|0");

                e = new Entity("Bandit", ed, EntityGender.Male, EntityType.Monster);

                s = new AnimatedSprite(
                    GameRef.Content.Load <Texture2D>(@"PlayerSprites/malerogue"),
                    AnimationManager.Instance.Animations);

                Mob mob = new Bandit(e, s);

                Rectangle r = new Rectangle(Mechanics.Random.Next(10, 50) * 32, Mechanics.Random.Next(10, 50) * 32, 32, 32);

                mob.Sprite.Position = new Vector2(r.X, r.Y);

                if (!mobLayer.Mobs.ContainsKey(r))
                {
                    mobLayer.Mobs.Add(r, mob);
                }

                mob.Entity.Equip(GameItemManager.GetItem("Short Sword"));
                mob.Drops.Add(GameItemManager.GetItem("Short Sword"));
                mob.Drops.Add(GameItemManager.GetItem("Minor Healing Potion"));
            }
        }
Beispiel #28
0
    // Update is called once per frame
    void Update()
    {
        //Create variables which are the values(-1 and 1) received between input (controller or keyboard)
        float horizontal = Input.GetAxis("Horizontal");
        float vertical   = Input.GetAxis("Vertical");

        Vector2 move = new Vector2(horizontal, vertical);

        //Check to see that move x or y is not equal to zero, then set ruby looking in the appropriate direction
        if (!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f))
        {
            lookDirection.Set(move.x, move.y);
            lookDirection.Normalize();
        }

        //Get the correct direction for the animator
        animator.SetFloat("Look X", lookDirection.x);
        animator.SetFloat("Look Y", lookDirection.y);
        animator.SetFloat("Speed", move.magnitude);

        //Variable which contains values of x,y and z
        Vector2 position = rigidbody2d.position;

        //Value which changes position on press of key/stick movement (Time.deltaTime = time it takes for frame to be rendered)
        position = position + move * speed * Time.deltaTime;
        //Will move character to where you want, but will stop the jittering of gameobject against gameobject
        rigidbody2d.MovePosition(position);

        //Removed Time.deltaTime, essentially creates a timer, and when timer is finished it sets her invincibility back to false
        if (isInvincible)
        {
            invincibleTimer -= Time.deltaTime;
            if (invincibleTimer < 0)
            {
                isInvincible = false;
            }
        }

        if (Input.GetKeyDown(KeyCode.C))
        {
            Launch();
        }


        //Check to see if you pressed the X key, "talk" button
        if (Input.GetKeyDown(KeyCode.X))
        {
            //There are multiple was to check raycast
            //This one creates a raycast that  is slightly higher than the collision box which is at Ruby's feet.
            //It then checks which way Ruby is looking
            //Then the maxium reach distance is 1.5f units
            //Finally it is making sure that the object that it is interacting with in on the NPC layer
            RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC"));
            if (hit.collider != null)
            {
                if (hit.collider != null)
                {
                    NonPlayerCharacter character = hit.collider.GetComponent <NonPlayerCharacter>();
                    if (character != null)
                    {
                        character.DisplayDialog();
                    }
                }
            }
        }
    }
Beispiel #29
0
        public static Record CreateRecord(string Tag)
        {
            Record outRecord;

            switch (Tag)
            {
            case "TES4":
                outRecord = new Header();
                break;

            case "GMST":
                outRecord = new GameSetting();
                break;

            case "TXST":
                outRecord = new TextureSet();
                break;

            case "MICN":
                outRecord = new MenuIcon();
                break;

            case "GLOB":
                outRecord = new GlobalVariable();
                break;

            case "CLAS":
                outRecord = new Class();
                break;

            case "FACT":
                outRecord = new Faction();
                break;

            case "HDPT":
                outRecord = new HeadPart();
                break;

            case "HAIR":
                outRecord = new Hair();
                break;

            case "EYES":
                outRecord = new Eyes();
                break;

            case "RACE":
                outRecord = new Race();
                break;

            case "SOUN":
                outRecord = new Sound();
                break;

            case "ASPC":
                outRecord = new AcousticSpace();
                break;

            case "MGEF":
                outRecord = new MagicEffect();
                break;

            case "SCPT":
                outRecord = new Script();
                break;

            case "LTEX":
                outRecord = new LandscapeTexture();
                break;

            case "ENCH":
                outRecord = new ObjectEffect();
                break;

            case "SPEL":
                outRecord = new ActorEffect();
                break;

            case "ACTI":
                outRecord = new ESPSharp.Records.Activator();
                break;

            case "TACT":
                outRecord = new TalkingActivator();
                break;

            case "TERM":
                outRecord = new Terminal();
                break;

            case "ARMO":
                outRecord = new Armor();
                break;

            case "BOOK":
                outRecord = new Book();
                break;

            case "CONT":
                outRecord = new Container();
                break;

            case "DOOR":
                outRecord = new Door();
                break;

            case "INGR":
                outRecord = new Ingredient();
                break;

            case "LIGH":
                outRecord = new Light();
                break;

            case "MISC":
                outRecord = new MiscItem();
                break;

            case "STAT":
                outRecord = new Static();
                break;

            case "SCOL":
                outRecord = new StaticCollection();
                break;

            case "MSTT":
                outRecord = new MoveableStatic();
                break;

            case "PWAT":
                outRecord = new PlaceableWater();
                break;

            case "GRAS":
                outRecord = new Grass();
                break;

            case "TREE":
                outRecord = new Tree();
                break;

            case "FURN":
                outRecord = new Furniture();
                break;

            case "WEAP":
                outRecord = new Weapon();
                break;

            case "AMMO":
                outRecord = new Ammunition();
                break;

            case "NPC_":
                outRecord = new NonPlayerCharacter();
                break;

            case "CREA":
                outRecord = new Creature();
                break;

            case "LVLC":
                outRecord = new LeveledCreature();
                break;

            case "LVLN":
                outRecord = new LeveledNPC();
                break;

            case "KEYM":
                outRecord = new Key();
                break;

            case "ALCH":
                outRecord = new Ingestible();
                break;

            case "IDLM":
                outRecord = new IdleMarker();
                break;

            case "NOTE":
                outRecord = new Note();
                break;

            case "COBJ":
                outRecord = new ConstructibleObject();
                break;

            case "PROJ":
                outRecord = new Projectile();
                break;

            case "LVLI":
                outRecord = new LeveledItem();
                break;

            case "WTHR":
                outRecord = new Weather();
                break;

            case "CLMT":
                outRecord = new Climate();
                break;

            case "REGN":
                outRecord = new Region();
                break;

            case "NAVI":
                outRecord = new NavigationMeshInfoMap();
                break;

            case "DIAL":
                outRecord = new DialogTopic();
                break;

            case "QUST":
                outRecord = new Quest();
                break;

            case "IDLE":
                outRecord = new IdleAnimation();
                break;

            case "PACK":
                outRecord = new Package();
                break;

            case "CSTY":
                outRecord = new CombatStyle();
                break;

            case "LSCR":
                outRecord = new LoadScreen();
                break;

            case "ANIO":
                outRecord = new AnimatedObject();
                break;

            case "WATR":
                outRecord = new Water();
                break;

            case "EFSH":
                outRecord = new EffectShader();
                break;

            case "EXPL":
                outRecord = new Explosion();
                break;

            case "DEBR":
                outRecord = new Debris();
                break;

            case "IMGS":
                outRecord = new ImageSpace();
                break;

            case "IMAD":
                outRecord = new ImageSpaceAdapter();
                break;

            case "FLST":
                outRecord = new FormList();
                break;

            case "PERK":
                outRecord = new Perk();
                break;

            case "BPTD":
                outRecord = new BodyPartData();
                break;

            case "ADDN":
                outRecord = new AddonNode();
                break;

            case "AVIF":
                outRecord = new ActorValueInformation();
                break;

            case "RADS":
                outRecord = new RadiationStage();
                break;

            case "CAMS":
                outRecord = new CameraShot();
                break;

            case "CPTH":
                outRecord = new CameraPath();
                break;

            case "VTYP":
                outRecord = new VoiceType();
                break;

            case "IPCT":
                outRecord = new Impact();
                break;

            case "IPDS":
                outRecord = new ImpactDataSet();
                break;

            case "ARMA":
                outRecord = new ArmorAddon();
                break;

            case "ECZN":
                outRecord = new EncounterZone();
                break;

            case "MESG":
                outRecord = new Message();
                break;

            case "RGDL":
                outRecord = new Ragdoll();
                break;

            case "DOBJ":
                outRecord = new DefaultObjectManager();
                break;

            case "LGTM":
                outRecord = new LightingTemplate();
                break;

            case "MUSC":
                outRecord = new MusicType();
                break;

            case "IMOD":
                outRecord = new ItemMod();
                break;

            case "REPU":
                outRecord = new Reputation();
                break;

            case "RCPE":
                outRecord = new Recipe();
                break;

            case "RCCT":
                outRecord = new RecipeCategory();
                break;

            case "CHIP":
                outRecord = new CasinoChip();
                break;

            case "CSNO":
                outRecord = new Casino();
                break;

            case "LSCT":
                outRecord = new LoadScreenType();
                break;

            case "MSET":
                outRecord = new MediaSet();
                break;

            case "ALOC":
                outRecord = new MediaLocationController();
                break;

            case "CHAL":
                outRecord = new Challenge();
                break;

            case "AMEF":
                outRecord = new AmmoEffect();
                break;

            case "CCRD":
                outRecord = new CaravanCard();
                break;

            case "CMNY":
                outRecord = new CaravanMoney();
                break;

            case "CDCK":
                outRecord = new CaravanDeck();
                break;

            case "DEHY":
                outRecord = new DehydrationStage();
                break;

            case "HUNG":
                outRecord = new HungerStage();
                break;

            case "SLPD":
                outRecord = new SleepDeprivationStage();
                break;

            case "CELL":
                outRecord = new Cell();
                break;

            case "WRLD":
                outRecord = new Worldspace();
                break;

            case "LAND":
                outRecord = new GenericRecord();
                break;

            case "NAVM":
                outRecord = new NavigationMesh();
                break;

            case "INFO":
                outRecord = new DialogResponse();
                break;

            case "REFR":
                outRecord = new Reference();
                break;

            case "ACHR":
                outRecord = new PlacedNPC();
                break;

            case "ACRE":
                outRecord = new PlacedCreature();
                break;

            case "PGRE":
                outRecord = new PlacedGrenade();
                break;

            case "PMIS":
                outRecord = new PlacedMissile();
                break;

            default:
                Console.WriteLine("Encountered unknown record: " + Tag);
                outRecord = new GenericRecord();
                break;
            }

            outRecord.Tag = Tag;

            return(outRecord);
        }
Beispiel #30
0
 public static void Remove(NonPlayerCharacter NPC)
 {
     lock (NPCs)
     {
         ushort MapID = NPC.Location.MapID;
         List<NonPlayerCharacter> npcs;
         if (NPCs.ContainsKey(MapID))
         {
             npcs = NPCs[MapID];
             npcs.Remove(NPC);
             NPCs[MapID] = npcs;
         }
     }
     // NPCs.ThreadSafeRemove(NPC.UID);
 }
    /// <summary>
    /// Handle movement,IFrames, user input
    /// </summary>
    void Update()
    {
        float horizontal = Input.GetAxis("Horizontal");
        float vertical   = Input.GetAxis("Vertical");

        Vector2 move = new Vector2(horizontal, vertical);

        if (!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f))
        {
            lookDirection.Set(move.x, move.y);
            lookDirection.Normalize();
            GetComponent <AudioSource>().UnPause();
        }
        else
        {
            GetComponent <AudioSource>().Pause();
        }

        animator.SetFloat("Look X", lookDirection.x);
        animator.SetFloat("Look Y", lookDirection.y);
        animator.SetFloat("Speed", move.magnitude);

        Vector2 position = rigidbody2d.position;

        moveSpeed = (Input.GetKey(KeyCode.LeftShift)) ? (speed * sprintSpeedMultiplier) : speed;

        position = position + move * moveSpeed * Time.deltaTime;

        rigidbody2d.MovePosition(position);

        if (isInvincible)
        {
            invincibleTimer -= Time.deltaTime;
            if (invincibleTimer < 0)
            {
                isInvincible = false;
            }
        }

        if (Input.GetKeyDown(KeyCode.C))
        {
            Launch();
            PlaySound(thrownClip);
        }

        if (Input.GetKeyDown(KeyCode.X))
        {
            RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC"));
            if (hit.collider != null)
            {
                NonPlayerCharacter character = hit.collider.GetComponent <NonPlayerCharacter>();
                if (character != null)
                {
                    if (oppController.opponentsLeft != 0)
                    {
                        //begin text
                        character.DisplayDialog(false);
                    }
                    else
                    {
                        //complete text
                        character.DisplayDialog(true);
                        PlaySound(questComplete);
                    }
                }
            }
        }
        if (Input.GetKeyDown(KeyCode.P))
        {
            Debug.Log(oppController.opponentsLeft);
        }
    }
Beispiel #32
0
 public bool Remove(NonPlayerCharacter NPC)
 {
     lock (NPCDictionary)
     {
         if (NPCDictionary.Remove(NPC.UID))
         {
             NonPlayerCharacter[] tmp = new NonPlayerCharacter[NPCDictionary.Count];
             NPCDictionary.Values.CopyTo(tmp, 0);
             ScreenNPCs = tmp;
             return true;
         }
     }
     return false;
 }
 public WorkHard(NonPlayerCharacter character)
 {
     this.character = character;
     character.Speed = 8;
 }
        public override void Update(GameTime gameTime)
        {
            world.Update(gameTime);
            player.Update(gameTime);
            player.Camera.LockToSprite(player.Sprite);

            if (InputHandler.KeyReleased(Keys.Space) ||
                InputHandler.ButtonReleased(Buttons.A, PlayerIndex.One))
            {
                foreach (ILayer layer in World.Levels[World.CurrentLevel].Map.Layers)
                {
                    if (layer is CharacterLayer)
                    {
                        foreach (Character c in ((CharacterLayer)layer).Characters.Values)
                        {
                            float distance = Vector2.Distance(
                                player.Sprite.Center,
                                c.Sprite.Center);

                            if (distance < Character.SpeakingRadius && c is NonPlayerCharacter)
                            {
                                NonPlayerCharacter npc = (NonPlayerCharacter)c;

                                if (npc.HasConversation)
                                {
                                    StateManager.PushState(GameRef.ConversationScreen);

                                    GameRef.ConversationScreen.SetConversation(
                                        player,
                                        npc,
                                        npc.CurrentConversation);

                                    GameRef.ConversationScreen.StartConversation();
                                }
                            }
                            else if (distance < Character.SpeakingRadius && c is Merchant)
                            {
                                StateManager.PushState(GameRef.ShopScreen);
                                GameRef.ShopScreen.SetMerchant(c as Merchant);
                            }
                        }
                    }
                }
            }

            MobLayer mobLayer = World.Levels[World.CurrentLevel].Map.Layers.Find(x => x is MobLayer) as MobLayer;

            if (playerAttacking)
            {
                foreach (var mob in mobLayer.Mobs.Values)
                {
                    if (playerSword.Intersects(mob.Sprite.Bounds))
                    {
                        if (player.Character.Entity.MainHand != null &&
                            player.Character.Entity.MainHand.Item is Weapon)
                        {
                            mob.Entity.ApplyDamage(player.Character.Entity.MainHand);
                            playerAttacking = false;

                            if (mob.Entity.Health.CurrentValue <= 0)
                            {
                                StateManager.PushState(GameRef.LootScreen);
                                GamePlayScreen.Player.Character.Entity.AddExperience(mob.XPValue);
                                GameRef.LootScreen.Gold = mob.GoldDrop;

                                foreach (var i in mob.Drops)
                                {
                                    GameRef.LootScreen.Items.Add(i);
                                }
                            }
                        }
                    }
                }
            }

            foreach (var mob in mobLayer.Mobs.Where(kv => kv.Value.Entity.Health.CurrentValue <= 0).ToList())
            {
                mobLayer.Mobs.Remove(mob.Key);
            }

            foreach (var mob in mobLayer.Mobs.Values)
            {
                float distance = Vector2.Distance(player.Sprite.Center, mob.Sprite.Center);

                if (distance < mob.Sprite.Width * 4)
                {
                    Vector2 motion = Vector2.Zero;

                    if (mob.Sprite.Position.X < player.Sprite.Position.X)
                    {
                        motion.X = 1;
                        mob.Sprite.CurrentAnimation = AnimationKey.Right;
                    }

                    if (mob.Sprite.Position.X > player.Sprite.Position.X)
                    {
                        motion.X = -1;
                        mob.Sprite.CurrentAnimation = AnimationKey.Left;
                    }

                    if (mob.Sprite.Position.Y < player.Sprite.Position.Y)
                    {
                        motion.Y = 1;
                        mob.Sprite.CurrentAnimation = AnimationKey.Down;
                    }

                    if (mob.Sprite.Position.Y > player.Sprite.Position.Y)
                    {
                        motion.Y = -1;
                        mob.Sprite.CurrentAnimation = AnimationKey.Up;
                    }

                    if (motion != Vector2.Zero)
                    {
                        motion.Normalize();
                    }

                    float speed = 200f;

                    motion *= speed * (float)gameTime.ElapsedGameTime.TotalSeconds;

                    mob.Sprite.Position   += motion;
                    mob.Sprite.IsAnimating = true;

                    if (mob.Sprite.Bounds.Intersects(player.Sprite.Bounds))
                    {
                        mob.Sprite.Position -= motion;
                    }
                }
                else
                {
                    mob.Sprite.IsAnimating = false;
                }
            }
            if (InputHandler.KeyReleased(Keys.I))
            {
                StateManager.PushState(GameRef.InventoryScreen);
            }

            if (InputHandler.KeyReleased(Keys.C))
            {
                StateManager.PushState(GameRef.StatsScreen);
                Visible = true;
            }

            if (Player.Character.Entity.Level < Mechanics.Experiences.Length)
            {
                if (Player.Character.Entity.Experience >= Mechanics.Experiences[Player.Character.Entity.Level])
                {
                    Player.Character.Entity.LevelUp();
                    StateManager.PushState(GameRef.LevelScreen);
                    Visible = true;
                }
            }

            if (InputHandler.CheckMousePress(MouseButton.Left) && playerTimer > 0.25 && !playerAttacking)
            {
                playerAttacking = true;
                playerTimer     = 0;

                if (player.Sprite.CurrentAnimation == AnimationKey.Up)
                {
                    attackDirection = 0;
                }
                else if (player.Sprite.CurrentAnimation == AnimationKey.Right)
                {
                    attackDirection = 1;
                }
                else if (player.Sprite.CurrentAnimation == AnimationKey.Down)
                {
                    attackDirection = 2;
                }
                else
                {
                    attackDirection = 3;
                }
            }

            if (playerTimer >= 0.25)
            {
                playerAttacking = false;
            }
            playerTimer += gameTime.ElapsedGameTime.TotalSeconds;

            base.Update(gameTime);
        }
    // Update is called once per frame
    void Update()
    {
        horizontal = Input.GetAxis("Horizontal");
        vertical   = Input.GetAxis("Vertical");

        Vector2 move = new Vector2(horizontal, vertical);

        if (!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f))
        {
            lookDirection.Set(move.x, move.y);
            lookDirection.Normalize();
        }
        animator.SetFloat("Look X", lookDirection.x);
        animator.SetFloat("Look Y", lookDirection.y);
        animator.SetFloat("Speed", move.magnitude);

        if (isInvincible)
        {
            invincibleTimer -= Time.deltaTime;
            if (invincibleTimer < 0)
            {
                isInvincible = false;
            }
        }
        if (Input.GetKeyDown(KeyCode.C))
        {
            Launch();
        }
        if (Input.GetKeyDown(KeyCode.X))
        {
            RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC"));
            if (hit.collider != null)
            {
                NonPlayerCharacter character = hit.collider.GetComponent <NonPlayerCharacter>();
                if (character != null)
                {
                    character.DisplayDialog();
                }
                if (scoreValue >= 4)
                {
                    SceneManager.LoadScene("Challenge3");
                    level++;
                }
            }
        }
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            Application.Quit();
        }
        if (scoreValue >= 4)
        {
            winloseText.text = "Talk to Jambi to visit stage two!";


            if (Input.GetKey(KeyCode.R))
            {
                SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
            }
        }
        if (currentHealth <= 0)
        {
            winloseText.text = "Game Over! Press R to Restart";
            if (Input.GetKey(KeyCode.R))
            {
                SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
                audioSource.clip = backgroundmusic;
                audioSource.Play();
                audioSource.loop = true;
            }
            speed = 0.0f;
        }

        if (level == 2)
        {
            if (scoreValue >= 4)
            {
                winloseText.text = "You win! Game by: Alan Zeng";
                speed            = 0.0f;
            }
        }
    }
Beispiel #36
0
    // Update is called once per frame
    void Update()
    {
        horizontal = Input.GetAxis("Horizontal");
        vertical   = Input.GetAxis("Vertical");

        Vector2 move = new Vector2(horizontal, vertical);

        if (!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f))
        {
            lookDirection.Set(move.x, move.y);
            lookDirection.Normalize();
        }

        animator.SetFloat("Look X", lookDirection.x);
        animator.SetFloat("Look Y", lookDirection.y);
        animator.SetFloat("Speed", move.magnitude);

        if (isInvincible)
        {
            invincibleTimer -= Time.deltaTime;
            if (invincibleTimer < 0)
            {
                isInvincible = false;
            }
        }

        if (Input.GetKeyDown(KeyCode.C))
        {
            if (cogcount > 0)
            {
                Launch();
            }
        }
        cogCountText.text = "Cogs: " + cogcount.ToString();

        if (Input.GetKeyDown(KeyCode.X))
        {
            RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC"));
            if (hit.collider != null)
            {
                NonPlayerCharacter character = hit.collider.GetComponent <NonPlayerCharacter>();
                if (character != null)
                {
                    character.DisplayDialog();
                    if (score == 4)
                    {
                        level = 1;
                        SceneManager.LoadScene("MainScene1");
                    }
                }
            }
        }

        if (level == 0)
        {
            if (score == 4)
            {
                winText.text = "Talk with Jambi to visit stage two!";
            }
        }


        if (level == 1)
        {
            if (score == 4)
            {
                gameWin          = true;
                winText.text     = "You Win! Game created by Matthew Reuter.";
                restartText.text = "Press R to restart or ESC to close the game";
                gameOver         = true;
            }
        }

        if (currentHealth == 0)
        {
            gameLose     = true;
            gameOver     = true;
            isInvincible = true;
        }

        if (gameOver == true)
        {
            backgroundmusic.SetActive(false);
        }

        if (gameLose == true)
        {
            winText.text     = "You Lose! Game created by Matthew Reuter.";
            restartText.text = "Press R to restart or ESC to close the game";
            speed            = 0;
            gameOver         = true;
        }

        if (gameWin == true)
        {
            winText.text     = "You Win! Game created by Matthew Reuter.";
            restartText.text = "Press R to restart or ESC to close the game";
            gameOver         = true;
        }

        if (Input.GetKey(KeyCode.R))
        {
            if (gameOver == true)
            {
                SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
            }
        }

        if (Input.GetKey("escape"))
        {
            Application.Quit();
        }
    }
 public Wander(NonPlayerCharacter character)
 {
     this.character = character;
     character.Speed = 2;
 }
Beispiel #38
0
    void Update()
    {
        // ============== MOVEMENT ======================
        float horizontal = Input.GetAxis("Horizontal");
        float vertical   = Input.GetAxis("Vertical");

        if (System.Enum.IsDefined(typeof(OverlandEnemyTrap.Levels), _scene.name) || _scene.name.Equals("DemonRealm"))
        {
            vertical = 0f;
        }

        Vector2 move = new Vector2(horizontal, vertical);

        if (!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f))
        {
            lookDirection.Set(move.x, move.y);
            lookDirection.Normalize();
        }

        currentInput = move;


        // ============== ANIMATION =======================

        animator.SetFloat("Look X", lookDirection.x);
        animator.SetFloat("Look Y", lookDirection.y);
        animator.SetFloat("Speed", move.magnitude);

        // ============== ATTACKS ======================

        if (Input.GetKeyDown(KeyCode.C))
        {
            LaunchProjectile();
        }

        if (Input.GetKeyDown(KeyCode.Z))
        {
            SwordAttack();
        }

        // ======== EXAMINE ==========
        if (Input.GetKeyDown(KeyCode.X))
        {
            RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 1.5f, 1 << LayerMask.NameToLayer("NPC"));
            if (hit.collider != null)
            {
                TreasureChest      chest     = hit.collider.GetComponent <TreasureChest>();
                NonPlayerCharacter character = hit.collider.GetComponent <NonPlayerCharacter>();
                if (character != null)
                {
                    if (!character.dialogBox.activeSelf)
                    {
                        character.DisplayDialog();
                    }
                    else
                    {
                        character.CloseDialog();
                    }
                }
                else if (chest != null && chest.status == TreasureChest.ChestState.CLOSED)
                {
                    Time.timeScale = 0f;
                    chest.DisplayDialog();
                    chest.status = TreasureChest.ChestState.OPENED;
                    ChestManager.chestManager.UpdateChest(chest.chestID, chest.status);
                }
            }
        }


        if (Input.GetKeyDown(KeyCode.Return))
        {
            RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.up * 0.2f, lookDirection, 1.5f, 1 << LayerMask.NameToLayer("NPC"));
            if (hit.collider != null)
            {
                TreasureChest chest = hit.collider.GetComponent <TreasureChest>();
                if (chest != null)
                {
                    if (chest.status == TreasureChest.ChestState.OPENED)
                    {
                        Time.timeScale = 1f;
                        chest.dialogBox.SetActive(false);
                        chest.GetTreasure();
                        chest.status = TreasureChest.ChestState.USED;
                        ChestManager.chestManager.UpdateChest(chest.chestID, chest.status);
                    }
                }
            }
        }
    }