Пример #1
0
        /// <summary>
        ///
        /// </summary>
        public override void interact()
        {
            if (state == State.closed)
            {
                state = State.open;
                openChest.setEnabled(true);
                closedChest.setEnabled(false);

                //This is testing spawining an item when the player first opens a chest
                if (untouched == true)
                {
                    Sword sword = new Sword(Core.graphicsDevice);
                    sword.transform.position = new Vector2(this.transform.position.X, this.transform.position.Y - 4);
                    scene.addEntity(sword);

                    //Add the sword to the list of items in the MasterScene
                    MasterScene mScene = scene as MasterScene;
                    mScene.items.Add(sword);

                    untouched = false;
                }
            }
            else if (state == State.open)
            {
                state = State.closed;
                openChest.setEnabled(false);
                closedChest.setEnabled(true);
            }
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        public override void update()
        {
            base.update();

            if (swordSprite.isPlaybackDone() && atkTimer <= 0)
            {
                currentAction = Actions.idle;
                swordSprite.play(Animations.held);
            }


            if (atkTimer > 0)
            {
                MasterScene   mScene     = scene as MasterScene;
                List <Entity> allEnemies = mScene.entities.entitiesOfType <Enemy>();
                for (int i = 0; i < allEnemies.Count; i++)
                {
                    if (state == States.equipped && type == Types.weapon &&                              //The item has to be equipped and a weapon
                        !alreadyAtkd.Contains(allEnemies[i]) &&                                          //Will not attack an enemy that has already been attacked during this attack sequence
                        allEnemies[i].getCollider <BoxCollider>() != null &&                             //Check to see if the enemies collider is null
                        currentAction == Item.Actions.attack &&                                          //The items current action has to be attack
                        getCollider <BoxCollider>().overlaps(allEnemies[i].getCollider <BoxCollider>())) //Finally check to see if the weapons collider overlaps the enemies
                    {
                        alreadyAtkd.Add(allEnemies[i]);                                                  //Add this enemy to the alreadyAtkd list so it is not hurt duing this sequence again
                        //View the enemy as a type of Enemy not just Entity
                        Enemy enm = allEnemies[i] as Enemy;
                        enm.rmvHealth(dmg);
                    }
                }
                atkTimer--;
            }
        }
Пример #3
0
    void Start() // This is like the main() function. This will be executed first
    {
        _heatScript = Object.FindObjectOfType <MasterScene>();

        _heatScript.initHeatMap(spawnLocations.Length);
        _heatScript.resetHeat();
        _heatScript.updateHeatUI();

        SpawnAgent();
        //SetupScene();
    }
    private static void SelectMasterScene()
    {
        string masterScene = EditorUtility.OpenFilePanel("Select Master Scene", Application.dataPath, "unity");

        if (!string.IsNullOrEmpty(masterScene))
        {
            MasterScene      = masterScene;
            MasterScene      = MasterScene.Substring(MasterScene.IndexOf("Assets"));
            LoadMasterOnPlay = true;
        }
    }
Пример #5
0
        /// <summary>
        /// This is meant to be added to a player
        /// It handles determing if a player interacts with an item
        /// Also handles what happens when they player interacts with it
        /// </summary>
        public void update()
        {
            //Check every item currently in the scene and look for an interaction
            MasterScene mScene = entity.scene as MasterScene;

            for (int i = 0; i < mScene.items.Count; i++)
            {
                //Don't bother with it if it is already equipped by a player
                if ((mScene.items[i].state == Item.States.dropped) && (entity.getCollider <BoxCollider>().overlaps(mScene.items[i].getCollider <BoxCollider>()) && (mScene.items[i].spawnTime <= 0)))
                {
                    mScene.items[i].state = Item.States.equipped;
                    Player p = entity as Player;
                    p.weapon = mScene.items[i];
                    mScene.items[i].onEquipped();
                    break;
                }
            }
        }
Пример #6
0
        /// <summary>
        /// Does all the stuff needed when essentially spawning in
        /// </summary>
        public override void onAddedToScene()
        {
            base.onAddedToScene();

            state = States.dropped;

            MasterScene mScene = this.scene as MasterScene;

            swordSprite.setRenderLayer(-9);
            addComponent(swordSprite);

            Rectangle sourceRectangle;
            Texture2D cropTexture;

            Color[] data;

            #region Set Idle Animation
            //Set idle animation sprite from spritesheet
            Texture2D spriteSheet     = this.scene.content.Load <Texture2D>("Sprites/DefaultSwordSpinningSpriteSheet");
            int       subSpriteWidth  = 11;
            int       subSpriteHeight = 24;
            //Goes through 4 times because there are 4 walking animation frames
            //Gets the sub sprite images out of the spritesheet
            for (int i = 0; i < 4; i++)
            {
                sourceRectangle = new Rectangle((i * subSpriteWidth), 0, subSpriteWidth, subSpriteHeight);
                cropTexture     = new Texture2D(graphics, sourceRectangle.Width, sourceRectangle.Height);
                data            = new Color[sourceRectangle.Width * sourceRectangle.Height];
                spriteSheet.GetData(0, sourceRectangle, data, 0, data.Length);
                cropTexture.SetData(data);
                idleAnimation.addFrame(new Subtexture(cropTexture));
            }
            swordSprite.addAnimation(Animations.idle, idleAnimation);
            #endregion

            //Then play the idle animation because it just spawned in
            swordSprite.play(Animations.idle);


            Texture2D swingSpriteSheet = this.scene.content.Load <Texture2D>("Sprites/DefaultSwordSpriteSheet");
            subSpriteWidth  = 22;
            subSpriteHeight = 24;
            #region Set Held Animation
            //Add the sprite animation for the sword being held
            sourceRectangle = new Rectangle(0, 0, subSpriteWidth, subSpriteHeight);
            cropTexture     = new Texture2D(graphics, sourceRectangle.Width, sourceRectangle.Height);
            data            = new Color[sourceRectangle.Width * sourceRectangle.Height];
            swingSpriteSheet.GetData(0, sourceRectangle, data, 0, data.Length);
            cropTexture.SetData(data);
            //Subtexture heldSprite = new Subtexture(this.scene.content.Load<Texture2D>("Sprites/DefaultSword"));
            swordSprite.addAnimation(Animations.held, new SpriteAnimation().addFrame(new Subtexture(cropTexture)));
            #endregion

            #region Set Swing animation
            //Add the swinging animation
            //Goes through 4 times because there are 4 walking animation frames
            //Gets the sub sprite images out of the spritesheet for the swinging
            for (int i = 0; i < 4; i++)
            {
                sourceRectangle = new Rectangle((i * subSpriteWidth), 0, subSpriteWidth, subSpriteHeight);
                cropTexture     = new Texture2D(graphics, sourceRectangle.Width, sourceRectangle.Height);
                data            = new Color[sourceRectangle.Width * sourceRectangle.Height];
                swingSpriteSheet.GetData(0, sourceRectangle, data, 0, data.Length);
                cropTexture.SetData(data);
                swingAnimation.addFrame(new Subtexture(cropTexture));
            }
            swingAnimation.setLoop(false);
            swingAnimation.setFps(20);
            swordSprite.addAnimation(Animations.swing, swingAnimation);
            #endregion

            #region Add the controller so the object can move with physics
            //Add the controller and mover and add collision layers to the mover
            TiledMapMover mapMover = new TiledMapMover(mScene.tileMap.getLayer <TiledTileLayer>("CollidableLayer1")); //Add the first collision layer
            for (int i = 1; i < mScene.numOfCollisionLayers; i++)
            {
                int    num       = i + 1;
                string layerName = "CollidableLayer" + num.ToString();
                mapMover.addCollisionLayer(mScene.tileMap.getLayer <TiledTileLayer>(layerName));
            }
            addComponent(mapMover);

            //Add controller
            controller = new ObjectMapController(1500);
            addComponent(controller);
            #endregion
            addCollider(new BoxCollider(-swordSprite.width / 2, -swordSprite.height / 2, swordSprite.width, swordSprite.height));

            //Do little bounce when spawning in
            controller.bounce(20);

            spawnTime = 25;
        }
Пример #7
0
 public void SetScene(MasterScene masterScene)
 {
     theScene = masterScene;
 }
Пример #8
0
 public void SetScene(MasterScene s)
 {
     theScene = s;
 }