示例#1
0
 private void Awake()
 {
     wallSprite = GetComponent <WallSprite>();
     bm         = FindObjectOfType <BuildingManager>();
     am         = FindObjectOfType <AudioManager>();
     ////////////////////////////////////
     GameEvents.OnGameStart.AddListener(StartGame);
 }
    new void OnCollisionEnter2D(Collision2D collision2D)
    {
        Moveable moveable   = collision2D.collider.GetComponent <Moveable> ();
        bool     isMoveable = (moveable != null);

        WallSprite wall   = collision2D.collider.GetComponent <WallSprite> ();
        bool       isWall = (wall != null);

        if (isWall)
        {
            Destroy(gameObject);
        }
        else if (isMoveable)
        {
            moveable.health = moveable.health - 1;
            health          = health - 1;
        }

        base.OnCollisionEnter2D(collision2D);
    }
示例#3
0
        public override void Build(int length, int width, Vector2 position, Player player)
        {
            _doors   = new List <DoorSprite>();
            _sprites = new Sprite[length, width];

            _roomLength   = length;
            _roomWidth    = width;
            _roomPosition = position;
            _player       = player;
            _enemySprites = new List <Enemy>();
            _otherSprites = new List <Sprite>();

            Vector2 tempPosition = position;
            float   currentX     = position.X;
            float   currentY     = position.Y;
            int     xAdjust      = 64;
            int     yAdjust      = 128;



            for (int i = 0; i < length; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    if (i == 0)
                    {
                        if (j == 0)
                        {
                            _sprites[i, j] = new WallSprite(new Vector2(currentX, currentY), ("TOP", "LEFT", "CORNER"));
                            currentX      += xAdjust;
                        }
                        else if (j == width - 1)
                        {
                            _sprites[i, j] = new WallSprite(new Vector2(currentX, currentY), ("TOP", "RIGHT", "CORNER"));
                            currentX       = position.X;
                            currentY      += yAdjust;
                        }
                        else
                        {
                            _sprites[i, j] = new WallSprite(new Vector2(currentX, currentY), ("TOP", "CENTER", "WALL"));
                            currentX      += xAdjust;
                        }
                    }
                    else if (i == length - 1)
                    {
                        if (j == 0)
                        {
                            _sprites[i, j] = new WallSprite(new Vector2(currentX, currentY), ("BOTTOM", "LEFT", "CORNER"));
                            currentX      += xAdjust;
                        }
                        else if (j == width - 1)
                        {
                            _sprites[i, j] = new WallSprite(new Vector2(currentX, currentY), ("BOTTOM", "RIGHT", "CORNER"));
                        }
                        else
                        {
                            _sprites[i, j] = new WallSprite(new Vector2(currentX, currentY), ("BOTTOM", "CENTER", "WALL"));
                            currentX      += xAdjust;
                        }
                    }
                    else
                    {
                        if (j == 0)
                        {
                            _sprites[i, j] = new WallSprite(new Vector2(currentX, currentY), ("NORMAL", "LEFT", "WALL"));
                            currentX      += xAdjust;
                        }
                        else if (j == width - 1)
                        {
                            _sprites[i, j] = new WallSprite(new Vector2(currentX, currentY), ("NORMAL", "RIGHT", "WALL"));
                            currentX       = position.X;
                            currentY      += 64;
                        }
                        else
                        {
                            _sprites[i, j] = new FloorSprite(new Vector2(currentX, currentY));
                            currentX      += xAdjust;
                        }
                    }
                }
            }
        }