Пример #1
0
    public Interactible instantiateInteractible(Interactible interactible, Vector3 position)
    {
        int x = (int)position.x;
        int y = (int)position.y;
        int z = (int)position.z;

        if (interactible is Item)
        {
            //Interactible is of the item class
            Item          curItem          = (Item)interactible;
            GameObject    itemObject       = Instantiate(dungeonEntityPrefab, new Vector3(x, y + 0.5f, (z) - 1), Quaternion.Euler(0, 0, 0));
            DungeonEntity newDungeonEntity = itemObject.GetComponent <DungeonEntity>();
            curItem.gameObjectScript = newDungeonEntity;
            curItem.initGameObject();


            return(curItem);
        }
        else
        {
            //Interactible is just an interactible (lever or door, etc)

            return(null);
        }
    }
    public static void Explode(DungeonEntity source, float explosionDamage, float explosionForce,
                               Vector2 explosionPosition, float explosionRadius)
    {
        Collider2D[] hits = Physics2D.OverlapCircleAll(explosionPosition, explosionRadius);
        foreach (Collider2D hit in hits)
        {
            if (hit.gameObject == source.gameObject)
            {
                continue;
            }

            /* Get all MonoBehaviour components of the hit. */
            var scripts = hit.GetComponents <MonoBehaviour>();
            /* Select all scripts that implement IExplodable. */
            IExplodable[] interfaceScripts = (
                from a in scripts where a.GetType().GetInterfaces().Any(
                    k => k == typeof(IExplodable)) select(IExplodable) a).ToArray();

            foreach (IExplodable explodable in interfaceScripts)
            {
                explodable.BlowUp(source, explosionDamage);
            }

            Rigidbody2D rigidbody;
            if ((rigidbody = hit.GetComponent <Rigidbody2D>()) != null)
            {
                rigidbody.AddExplosionForce(explosionForce, explosionPosition, explosionRadius);
            }
        }
    }
Пример #3
0
 // Use this for initialization
 void Start()
 {
     solved = false;
     entity = transform.GetComponent<DungeonEntity>();
     entity.liftable = false;
     GameState.mState.triggers.Add(this);
 }
    public virtual void Init(DungeonUnity dungeonUnity, DungeonEntity entity)
    {
        this.dungeonUnity = dungeonUnity;
        this.entity       = entity;

        trans.position = dungeonUnity.GetWorldPosition(entity.Position);
        trans.rotation = dungeonUnity.GetWorldRotation(entity.Rotation);
    }
Пример #5
0
 public LiftExec(DungeonCharacter dc, DungeonEntity b, Tile t)
 {
     dchar = dc;
     target = dc.entity.tile;
     bottom = b;
     origin = t;
     lifted = t.entities.ToArray();
     origCount = origin.entities.IndexOf(bottom);
 }
Пример #6
0
    public DungeonEntityUnity GetEntityUnity(DungeonEntity entity)
    {
        if (entities.ContainsKey(entity.Id))
        {
            return(entities[entity.Id]);
        }

        return(null);
    }
Пример #7
0
    public void AddEntity(DungeonEntity entity, int x, int y, DungeonRotation rotation)
    {
        if (!CheckValidPosition(x, y))
        {
            throw new ArgumentException("Invalid entity position");
        }

        entities.Add(entity);

        entity.OnAddedToDungeon(this, new DungeonVector2(x, y), rotation, nextEntityId++);
    }
Пример #8
0
    public void UpdateVisibility()
    {
        visibilityAlgorithm.Reset(this);
        for (int i = 0; i < GetEntitiesCount(); i++)
        {
            DungeonEntity entity = GetEntity(i);

            if (entity.Type == DungeonEntityType.Avatar)
            {
                visibilityAlgorithm.SetVisible(this, entity.Position.x, entity.Position.y, 999);
            }
        }
    }
Пример #9
0
    public DungeonEntity AddEntity(DungeonEntityType entityType, int x, int y, DungeonRotation rotation)
    {
        DungeonEntity entity = DungeonEntityFactory.CreateEntity(entityType);

        if (entity == null)
        {
            throw new ArgumentException("Unknown entity type " + entityType);
        }

        AddEntity(entity, x, y, rotation);

        return(entity);
    }
Пример #10
0
    void OnBeaten()
    {
        player.OnRoomBeaten();
        foreach (DungeonObject dungeonObject in contents.objects)
        {
            dungeonObject.OnRoomBeaten();
        }
        foreach (DungeonTile dungeonTile in contents.tiles)
        {
            if (dungeonTile != null)
            {
                dungeonTile.OnRoomBeaten();
            }
        }

        if (Random.Range(0f, 1f) <= rewardChance)
        {
            int x, y;
            x = gridWidth / 2;
            y = gridHeight / 2;

            while (contents.GetTile(x, y) != null)
            {
                Directions rand = (Directions)Random.Range(0, 5);
                if ((x += (int)rand.ToVector().x) >= gridWidth || x < 0)
                {
                    x -= (int)rand.ToVector().x;
                }
                if ((y += (int)rand.ToVector().y) >= gridHeight || y < 0)
                {
                    y -= (int)rand.ToVector().y;
                }
            }

            DungeonEntity rewardPrefab = rewards[Random.Range(0, rewards.Length)];
            DungeonEntity reward       = Instantiate <DungeonEntity>(rewardPrefab, transform);
            Vector2       pos          = new Vector2(x - gridWidth / 2, y - gridHeight / 2);
            reward.transform.position = transform.TransformPoint(pos);

            reward.room = this;

            contents.objectAddQueue.Enqueue(reward);
        }
    }
Пример #11
0
    private void AddEntity(DungeonEntity entity)
    {
        DungeonEntityUnity entityUnity = entityFactory.CreateEntity(entity);

        if (entityUnity != null)
        {
            entityUnity.trans.parent = entitiesContainer;

            entities.Add(entity.Id, entityUnity);

            entityUnity.Init(this, entity);

            if (entity.Type == DungeonEntityType.Avatar)
            {
                avatar = (DungeonEntityAvatarUnity)entityUnity;
            }
        }
        else
        {
            Debug.LogWarning("No unity entity created for entity type: " + entity.Type);
        }
    }
Пример #12
0
    public void RemoveEntity(DungeonEntity entity)
    {
        entity.OnRemovedFromDungeon();

        entities.Remove(entity);
    }
    public override void Init(DungeonUnity dungeonUnity, DungeonEntity entity)
    {
        base.Init(dungeonUnity, entity);

        avatar = (DungeonEntityAvatar)entity;
    }
 public DungeonEventEntityRotated(DungeonEntity entity, DungeonRotation from, DungeonRotation to) : base(DungeonEventType.EntityRotated)
 {
     this.entity = entity;
     this.from   = from;
     this.to     = to;
 }
Пример #15
0
    public DungeonEntityUnity CreateEntity(DungeonEntity entity)
    {
        GameObject prefab = GetPrefab(entity.Type);

        return(((GameObject)GameObject.Instantiate(prefab)).GetComponent <DungeonEntityUnity>());
    }
Пример #16
0
 /*
 public boolean IsEmpty() {
     return (entities.Count == 0);
 }
 */
 public void MoveStackTo(DungeonEntity bottom, Tile target, bool inc)
 {
     int bi = bottom.tileIndex;
     if (!inc) {
         bi++;
     }
     var stack = entities.GetRange(bi, entities.Count - bi);
     foreach (DungeonEntity e in stack) {
         if (e) {
             e.MoveTo(target);
         }
     }
 }
Пример #17
0
 public DungeonEventEntityMoved(DungeonEntity entity, DungeonVector2 from, DungeonVector2 to) : base(DungeonEventType.EntityMoved)
 {
     this.entity = entity;
     this.from   = from;
     this.to     = to;
 }
Пример #18
0
 static public DungeonEvent CreateEntityMoved(DungeonEntity entity, DungeonVector2 from, DungeonVector2 to)
 {
     return(new DungeonEventEntityMoved(entity, from, to));
 }
Пример #19
0
 static public DungeonEvent CreateEntityRotated(DungeonEntity entity, DungeonRotation from, DungeonRotation to)
 {
     return(new DungeonEventEntityRotated(entity, from, to));
 }
Пример #20
0
    public void Initialize(Character c, ALIGNMENT a, MapState ms)
    {
        character = c;
        mState = ms;
        alignment = a;
        actions = new List<Executable>();
        health = c.maxHealth;
        mana = c.maxMana;
        entity = transform.GetComponent<DungeonEntity>();
        states = new List<CharacterState>();

        GameObject healthBarObj = UnityEngine.Object.Instantiate(Resources.Load("healthbar"), transform.position, Quaternion.identity) as GameObject;
        healthBarObj.transform.parent = transform;
        healthBar = healthBarObj.transform.GetComponent<HealthBar>();
        healthBar.dchar = this;
        healthBar.mState = mState;
    }
Пример #21
0
    public void Initialize(DungeonEntity e, SpriteData sd, LinkedSpriteManager ls)
    {
        entity = e;
        spriteData = sd;
        lsManager = ls;
        Texture texture = lsManager.material.mainTexture;
        Vector2 textDim = new Vector2(texture.width, texture.height);
        uvDim = new Vector2(spriteData.spriteDim.x / textDim.x, spriteData.spriteDim.y / textDim.y);
        Vector2 uvCoord = Vector2.zero;
        uvCoord.x = uvDim.x * 7;
        uvCoord.y = 1 - (spriteData.spriteDim.y * (spriteData.spriteIndex + 1) / textDim.y);
        sprite = lsManager.AddSprite(gameObject, spriteData.dim.x, spriteData.dim.y, uvCoord, uvDim, Vector3.up * 0.5f, true);
        visible = true;

        transform.localPosition = Vector3.up * sd.dim.y/2;

        Vector2 pos;

        UVAnimation walking_s = new UVAnimation();
        pos = new Vector2(0, uvCoord.y);
        walking_s.BuildUVAnim(pos, uvDim, 3, 1, 3, 10);
        walking_s.name = "walking_s";
        walking_s.loopCycles = -1;

        UVAnimation walking_nw = new UVAnimation();
        pos = new Vector2(uvDim.x * 3, uvCoord.y);
        walking_nw.BuildUVAnim(pos, uvDim, 3, 1, 3, 10);
        walking_nw.name = "walking_nw";
        walking_nw.loopCycles = -1;

        UVAnimation walking_sw = new UVAnimation();
        pos = new Vector2(uvDim.x * 3, uvCoord.y);
        walking_sw.BuildUVAnim(pos, uvDim, 3, 1, 3, 10);
        walking_sw.name = "walking_sw";
        walking_sw.loopCycles = -1;

        UVAnimation walking_ne = new UVAnimation();
        pos = new Vector2(uvDim.x * 6, uvCoord.y);
        walking_ne.BuildUVAnim(pos, uvDim, 3, 1, 3, 10);
        walking_ne.name = "walking_ne";
        walking_ne.loopCycles = -1;

        UVAnimation walking_se = new UVAnimation();
        pos = new Vector2(uvDim.x * 6, uvCoord.y);
        walking_se.BuildUVAnim(pos, uvDim, 3, 1, 3, 10);
        walking_se.name = "walking_se";
        walking_se.loopCycles = -1;

        UVAnimation walking_n = new UVAnimation();
        pos = new Vector2(uvDim.x * 9, uvCoord.y);
        walking_n.BuildUVAnim(pos, uvDim, 3, 1, 3, 10);
        walking_n.name = "walking_n";
        walking_n.loopCycles = -1;

        sprite.AddAnimation(walking_n);
        sprite.AddAnimation(walking_ne);
        sprite.AddAnimation(walking_nw);
        sprite.AddAnimation(walking_s);
        sprite.AddAnimation(walking_se);
        sprite.AddAnimation(walking_sw);
    }