Purpose: This controls each room and it's interactions.
Inheritance: MonoBehaviour
示例#1
0
        //-----------------------------------------------------------------------------
        // Mutators
        //-----------------------------------------------------------------------------

        // Break the tile, destroying it.
        public virtual void Break(bool spawnDrops)
        {
            // Spawn the break effect.
            if (breakAnimation != null)
            {
                Effect breakEffect = new Effect(breakAnimation, DepthLayer.EffectTileBreak, true);
                RoomControl.SpawnEntity(breakEffect, Center);
            }

            if (breakSound != null)
            {
                AudioSystem.PlaySound(breakSound);
            }

            // Spawn drops.
            if (spawnDrops)
            {
                SpawnDrop();
            }

            // Destroy the tile.
            if (properties.GetBoolean("disable_on_destroy", false))
            {
                Properties.Set("enabled", false);                 // TODO: this won't exactly work anymore.
            }
            RoomControl.RemoveTile(this);
        }
示例#2
0
        // Makes sure all rollers in the group can be pushed in the same direction.
        private bool CanPushRoller(int direction)
        {
            if (IsMoving)
            {
                return(false);
            }

            // Make sure were not pushing out of bounds.
            Point2I newLocation = Location + Directions.ToPoint(direction);

            if (!RoomControl.IsTileInBounds(newLocation))
            {
                return(false);
            }

            // Make sure there are no obstructions.
            int newLayer;

            if (IsMoveObstructed(direction, out newLayer))
            {
                return(false);
            }

            if ((IsVertical && Directions.IsVertical(direction)) || (!IsVertical && Directions.IsHorizontal(direction)))
            {
                return(nextRoller != null ? nextRoller.CanPushRoller(direction) : true);
            }
            return(false);
        }
示例#3
0
        //-----------------------------------------------------------------------------
        // Initialization
        //-----------------------------------------------------------------------------

        public void Initialize(RoomControl control)
        {
            this.roomControl = control;
            this.isAlive     = true;

            if (!isInitialized)
            {
                isInitialized = true;
                hasMoved      = false;
                velocity      = Vector2F.Zero;

                graphics.ImageVariant = roomControl.Room.Zone.ImageVariantID;

                // Begin a path if there is one.
                string   pathString = properties.GetString("path", "");
                TilePath p          = TilePath.Parse(pathString);
                BeginPath(p);

                // Set the solid state.
                isSolid = (SolidType != TileSolidType.NotSolid);

                // Setup default drop list.
                if (IsDigable && !IsSolid)
                {
                    dropList = RoomControl.GameControl.DropManager.GetDropList("dig");
                }
                else
                {
                    dropList = RoomControl.GameControl.DropManager.GetDropList("default");
                }

                // Call the virtual initialization method.
                OnInitialize();
            }
        }
示例#4
0
        // Move over a distance.
        protected bool Move(int direction, int distance, float movementSpeed)
        {
            if (isMoving)
            {
                return(false);
            }

            int newLayer;

            if (IsMoveObstructed(direction, out newLayer))
            {
                return(false);
            }

            this.movementSpeed       = movementSpeed;
            this.moveDistance        = distance;
            this.moveDirection       = Directions.ToPoint(direction);
            this.isMoving            = true;
            this.hasMoved            = true;
            this.currentMoveDistance = 0;

            // Move the tile one step forward.
            Point2I oldLocation = location;

            RoomControl.MoveTile(this, location + moveDirection, newLayer);
            offset = -Directions.ToVector(direction) * GameSettings.TILE_SIZE;

            // Fire the OnMove event.
            GameControl.ExecuteScript(properties.GetString("on_move", ""));

            return(true);
        }
示例#5
0
        public override void OnLand()
        {
            // Collide with monsters.
            foreach (Monster monster in Physics.GetEntitiesMeeting <Monster>(CollisionBoxType.Soft))
            {
                monster.TriggerInteraction(InteractionType.ThrownObject, this);
                if (IsDestroyed)
                {
                    return;
                }
            }

            // Collide with surface tiles.
            Point2I tileLoc = RoomControl.GetTileLocation(position);

            if (RoomControl.IsTileInBounds(tileLoc))
            {
                Tile tile = RoomControl.GetTopTile(tileLoc);
                if (tile != null)
                {
                    tile.OnHitByThrownObject(this);
                    if (IsDestroyed)
                    {
                        return;
                    }
                }
            }

            Break();
        }
示例#6
0
        //-----------------------------------------------------------------------------
        // Internal methods
        //-----------------------------------------------------------------------------

        private void Explode()
        {
            BombExplosion bombExplosion = new BombExplosion();

            RoomControl.SpawnEntity(bombExplosion, Center, zPosition);
            AudioSystem.PlaySound(GameData.SOUND_BOMB_EXPLODE);

            // Explode nearby top tiles.
            if (zPosition < 4)
            {
                Rectangle2F tileExplodeArea = Rectangle2F.Zero.Inflated(12, 12);
                tileExplodeArea.Point += Center;

                Rectangle2I area = RoomControl.GetTileAreaFromRect(tileExplodeArea);

                for (int x = area.Left; x < area.Right; x++)
                {
                    for (int y = area.Top; y < area.Bottom; y++)
                    {
                        Tile        tile     = RoomControl.GetTopTile(x, y);
                        Rectangle2F tileRect = new Rectangle2F(x * 16, y * 16, 16, 16);
                        if (tile != null && tileRect.Intersects(tileExplodeArea))
                        {
                            tile.OnBombExplode();
                        }
                    }
                }
            }

            DestroyAndTransform(bombExplosion);
        }
示例#7
0
 void Start()
 {
     rom    = GameObject.FindGameObjectWithTag("Board").GetComponent <RoomControl>();
     spawn  = new int[50];
     img    = Resources.LoadAll <Sprite>("Graphics/Tiles/Room" + rom.andar);
     en     = rom.monsters;
     player = GameObject.FindGameObjectWithTag("Player");
     Load();
     Modificate();
     oppened = false;
     if (type == 1)
     {
         // Spawn();
         oppened = true;
         player.transform.position = transform.position;
     }
     if (type == 2)
     {
         // End();
     }
     if (type == 3)
     {
         //Monster();
     }
     if (type == 4)
     {
         //Boss();
     }
 }
示例#8
0
        //-----------------------------------------------------------------------------
        // Reward Methods
        //-----------------------------------------------------------------------------

        public void SpawnReward()
        {
            if (!IsLooted)
            {
                string rewardName = Properties.GetString("reward", "rupees_1");
                Reward reward     = RoomControl.GameControl.RewardManager.GetReward(rewardName);

                CollectibleReward collectible = new CollectibleReward(reward);
                collectible.Collected += delegate() {
                    Properties.Set("looted", true);
                };

                // Spawn the reward collectible.
                RoomControl.SpawnEntity(collectible);
                collectible.SetPositionByCenter(Center);

                if (Properties.GetBoolean("spawn_from_ceiling", false))
                {
                    collectible.ZPosition                = Center.Y + 8;
                    collectible.Physics.HasGravity       = true;
                    collectible.Physics.CollideWithWorld = RoomControl.IsSideScrolling;
                }
                else
                {
                    collectible.Physics.CollideWithWorld       = false;
                    collectible.Physics.HasGravity             = false;
                    collectible.Physics.IsDestroyedInHoles     = false;
                    collectible.Physics.IsDestroyedOutsideRoom = false;
                }
            }
        }
示例#9
0
        //-----------------------------------------------------------------------------
        // Constructor
        //-----------------------------------------------------------------------------

        public RoomGraphics(RoomControl roomControl)
        {
            this.roomControl = roomControl;
            this.layerHeads  = new DrawingInstruction[(int)DepthLayer.Count];
            this.layerTails  = new DrawingInstruction[(int)DepthLayer.Count];
            this.layerCounts = new int[(int)DepthLayer.Count];
        }
示例#10
0
        //-----------------------------------------------------------------------------
        // Methods
        //-----------------------------------------------------------------------------

        public void SpawnTile()
        {
            Tile tileObj = Tile.CreateTile(tile);

            RoomControl.RemoveTile(this);
            RoomControl.PlaceTile(tileObj, Location, Layer);
        }
示例#11
0
 public static void Show(RoomControl control, GameModel model)
 {
     UIManager.instance.ShowPanel(Name);
     instance.curControl  = control;
     instance.selectModel = model;
     instance.Init();
 }
示例#12
0
    public void OnClickRoomSelect(Dropdown down)
    {
        curControl = (RoomControl)down.value;
        switch (curControl)
        {
        case RoomControl.创建房间:
            objRoomName.SetActive(true);
            objRoomID.SetActive(false);
            objRoomType.SetActive(true);
            //OnClickRoomName(downName);
            inputName.text = DataController.instance.myInfo.Register.name + "的房间";
            break;

        case RoomControl.加入房间:
            objRoomName.SetActive(false);
            objRoomID.SetActive(true);
            objRoomType.SetActive(true);
            OnClickRoomID(downID);
            break;

        case RoomControl.修改房间:
            objRoomName.SetActive(true);
            objRoomID.SetActive(false);
            inputName.text = DataController.instance.MyRoomInfo.RoomName;
            //OnClickRoomName(downName);
            break;
        }
    }
示例#13
0
        //-----------------------------------------------------------------------------
        // Overridden methods
        //-----------------------------------------------------------------------------

        public override bool OnPush(int direction, float movementSpeed)
        {
            Dungeon dungeon = RoomControl.Dungeon;

            // Check if we have a small key to use.
            if (dungeon.NumSmallKeys > 0)
            {
                dungeon.NumSmallKeys--;

                AudioSystem.PlaySound(GameData.SOUND_CHEST_OPEN);
                AudioSystem.PlaySound(GameData.SOUND_GET_ITEM);

                // Spawn the key and poof effects.
                RoomControl.SpawnEntity(new EffectUsedItem(GameData.SPR_REWARD_SMALL_KEY), Center);
                RoomControl.SpawnEntity(new Effect(GameData.ANIM_EFFECT_BLOCK_POOF, DepthLayer.EffectSomariaBlockPoof), Center);

                // Destroy the tile forever.
                Properties.Set("enabled", false);
                RoomControl.RemoveTile(this);

                return(true);
            }
            else
            {
                GameControl.DisplayMessage("You need a <red>key<red> for this block!");
            }

            return(false);
        }
示例#14
0
        //-----------------------------------------------------------------------------
        // Overridden methods
        //-----------------------------------------------------------------------------

        public override void OnInitialize()
        {
            startPosition = (IsVertical ? Location.Y : Location.X);
            returnTimer   = 0;
            TileRoller roller = this;

            do
            {
                firstRoller = roller;
                // Don't look any further, this is automatically the first roller.
                if (roller.Properties.GetBoolean("first_roller"))
                {
                    break;
                }
                roller = RoomControl.GetTopTile(roller.Location + Directions.ToPoint(IsVertical ? Directions.Left : Directions.Up)) as TileRoller;
            } while (roller != null);

            nextRoller = RoomControl.GetTopTile(Location + Directions.ToPoint(IsVertical ? Directions.Right : Directions.Down)) as TileRoller;
            // Don't include the next roller if it's the start of a new group.
            if (nextRoller != null && nextRoller.Properties.GetBoolean("first_roller"))
            {
                nextRoller = null;
            }

            pushed    = false;
            pushTimer = 0;

            Graphics.PlayAnimation(TileData.SpriteList[1].Animation);
            Graphics.AnimationPlayer.SkipToEnd();
        }
示例#15
0
        // Custom collision function for colliding with room edges.
        public void CheckRoomTransitions()
        {
            if (!AllowRoomTransition || IsOnHazardTile() || IsInAir)
            {
                return;
            }

            // Check for room edge collisions.
            int transitionDirection = -1;

            foreach (CollisionInfo info in Physics.GetCollisions())
            {
                if (info.Type == CollisionType.RoomEdge && CanRoomTransition(info.Direction))
                {
                    transitionDirection = info.Direction;
                    break;
                }
            }
            // Request a transition on the room edge.
            if (transitionDirection >= 0)
            {
                physics.Velocity = Vector2F.Zero;
                RoomControl.RequestRoomTransition(transitionDirection);
            }
        }
示例#16
0
        //-----------------------------------------------------------------------------
        // Overridden methods
        //-----------------------------------------------------------------------------

        public override bool OnPush(int direction, float movementSpeed)
        {
            Dungeon dungeon = RoomControl.Dungeon;

            if (dungeon.HasBossKey)
            {
                Open();

                AudioSystem.PlaySound(GameData.SOUND_CHEST_OPEN);
                AudioSystem.PlaySound(GameData.SOUND_GET_ITEM);

                // Spawn the key effect.
                EffectUsedItem effect = new EffectUsedItem(GameData.SPR_REWARD_BOSS_KEY);
                RoomControl.SpawnEntity(effect, Center);

                // Disable this tile forever.
                Properties.Set("enabled", false);

                // Unlock doors connected to this one in the adjacent room.
                TileDataInstance connectedDoor = GetConnectedDoor();
                if (connectedDoor != null)
                {
                    connectedDoor.ModifiedProperties.Set("enabled", false);
                }
                return(true);
            }
            else
            {
                GameControl.DisplayMessage("This keyhole is different!");
            }

            return(false);
        }
        //-----------------------------------------------------------------------------
        // Internal methods
        //-----------------------------------------------------------------------------

        // Return true if a somaria block would break when spawned at the given tile location.
        private bool CanBlockSpawnAtLocation(Point2I location)
        {
            if (!RoomControl.IsSideScrolling && IsInAir)
            {
                return(false);
            }

            // TODO: check if there is a solid block below when side-scrolling.

            if (!RoomControl.IsTileInBounds(location))
            {
                return(false);
            }

            foreach (Tile t in RoomControl.TileManager.GetTilesAtPosition(Center))
            {
                if (!t.IsSurface || !t.IsCoverableByBlock || t.IsHoleWaterOrLava)
                {
                    return(false);
                }
            }

            /*
             * Tile checkTile = RoomControl.GetTopTile(location);
             * if (checkTile == null)
             *      return true;
             * return (checkTile.Layer != RoomControl.Room.TopLayer &&
             *              checkTile.IsCoverableByBlock && !checkTile.IsHoleWaterOrLava);*/
            return(true);
        }
示例#18
0
 public override void OnCollideTile(Tile tile, bool isInitialCollision)
 {
     // Create cling effect.
     RoomControl.SpawnEntity(new EffectCling(), position, zPosition);
     AudioSystem.PlaySound(GameData.SOUND_EFFECT_CLING);
     BeginReturn();
 }
示例#19
0
        public void DestroyBridge(bool instantaneous = false, bool rememberState = false)
        {
            if (bridgeDirection >= 0 && (state == TileBridgeState.Created || state == TileBridgeState.Creating))
            {
                if (state == TileBridgeState.Creating)
                {
                    pieceLocation -= Directions.ToPoint(bridgeDirection);
                    if (pieceLocation == Location)
                    {
                        return;
                    }
                }
                else
                {
                    // Find the second to last tile in the bridge.
                    pieceLocation = new Point2I(-1, -1);
                    TileBridge pieceTile = GetConnectedTile(bridgeDirection);

                    while (pieceTile != null)
                    {
                        TileBridge nextTile = pieceTile.GetConnectedTile(bridgeDirection);
                        if (nextTile == null)
                        {
                            break;
                        }
                        pieceLocation = pieceTile.Location;
                        pieceTile     = nextTile;
                    }
                }

                if (pieceLocation.X > 0 && pieceLocation.Y > 0)
                {
                    state = TileBridgeState.Destroying;
                    timer = 0;
                }
            }

            if (instantaneous)
            {
                while (state == TileBridgeState.Destroying)
                {
                    TileBridge pieceTile = GetConnectedTile(pieceLocation);
                    if (pieceTile != null)
                    {
                        RoomControl.RemoveTile(pieceTile);
                    }
                    pieceLocation -= Directions.ToPoint(bridgeDirection);
                    if (pieceLocation == Location)
                    {
                        state = TileBridgeState.Destroyed;
                        break;
                    }
                }
            }

            if (state == TileBridgeState.Destroyed || state == TileBridgeState.Destroying)
            {
                Properties.Set("built", false);
            }
        }
示例#20
0
        //-----------------------------------------------------------------------------
        // Lever Methods
        //-----------------------------------------------------------------------------

        public override void OnToggle(bool switchState)
        {
            // Sync color switch across dungeon.
            if (syncWithDungeon && RoomControl.Dungeon != null)
            {
                Dungeon dungeon = RoomControl.Dungeon;
                dungeon.ColorSwitchColor = color;

                // Raise/lower color barriers if there are any.
                if (RoomControl.GetTilesOfType <TileColorBarrier>().Any())
                {
                    GameControl.PushRoomState(new RoomStateColorBarrier(color));
                }

                // Sync other color switches in the same room.
                foreach (TileColorSwitch tile in RoomControl.GetTilesOfType <TileColorSwitch>())
                {
                    if (tile != this && tile.SyncWithDungeon)
                    {
                        tile.SetSwitchState(SwitchState);
                    }
                }
            }

            AudioSystem.PlaySound(GameData.SOUND_SWITCH);
        }
示例#21
0
    // does there exist a room in the location given?
    private RoomControl get(Vector2 pos)
    {
        RoomControl output = null;

        roomsDict.TryGetValue(pos, out output);
        return(output);
    }
示例#22
0
    // Set up the bidirectional relationship between to rooms that will later ensure the doors are linked
    public void SetAdj(RoomControl room, Vector2 dir, RoomControl adjRoom)
    {
        room.SetAdj(dir, adjRoom);
        adjRoom.SetAdj(dir * -1, room);

        GameObject.Instantiate(trash, (room.transform.position + adjRoom.transform.position) / 2, Quaternion.identity);
    }
示例#23
0
        public override void Update()
        {
            AudioSystem.LoopSoundWhileActive(GameData.SOUND_BOOMERANG_LOOP);

            // Check for boomerangable tiles.
            if (itemBoomerang.Level == Item.Level2)
            {
                Point2I tileLoc = RoomControl.GetTileLocation(position);
                if (tileLoc != tileLocation && RoomControl.IsTileInBounds(tileLoc))
                {
                    Tile tile = RoomControl.GetTopTile(tileLoc);
                    if (tile != null)
                    {
                        tile.OnBoomerang();
                    }
                }
                tileLocation = tileLoc;
            }

            // Pickup collectibles.
            foreach (Collectible collectible in Physics.GetEntitiesMeeting <Collectible>(CollisionBoxType.Soft))
            {
                if (collectible.IsPickupable && collectible.IsCollectibleWithItems)
                {
                    collectibles.Add(collectible);
                    collectible.Destroy();
                    BeginReturn();
                }
            }

            base.Update();
        }
示例#24
0
 private void AssignSystemToRoomAndInit(ShipSystem system, RoomControl room)
 {
     system.Initialize();
     room.InitializeSystem(system);
     system.enabled = true;
     room.enabled   = true;
 }
示例#25
0
        protected override void Initialize()
        {
            base.Initialize();

            bool isDead = properties.GetBoolean("dead", false);

            Monster monster = null;

            // Construct the monster object.
            if (!isDead)
            {
                string monsterTypeStr = Properties.GetString("monster_type", "");
                monster = ConstructObject <Monster>(monsterTypeStr);
                if (monster == null)
                {
                    Console.WriteLine("Error trying to spawn monster of type " + monsterTypeStr);
                }
            }

            // Spawn the monster entity.
            if (monster != null)
            {
                Vector2F center = position + new Vector2F(8, 8);
                monster.SetPositionByCenter(center);
                monster.Properties = properties;
                RoomControl.SpawnEntity(monster);
            }
        }
示例#26
0
    // Set up the bidirectional relationship between to rooms that will later ensure the doors are linked
    public void SetAdj(RoomControl room, Vector2 dir, RoomControl adjRoom)
    {
        room.SetAdj(dir, adjRoom);
        adjRoom.SetAdj(dir * -1, room);

        GameObject.Instantiate(trash, (room.transform.position + adjRoom.transform.position) / 2, Quaternion.identity);
    }
示例#27
0
 public Projectile ShootProjectile(Projectile projectile, Vector2F velocity, Vector2F positionOffset, int zPositionOffset)
 {
     projectile.Owner            = this;
     projectile.Direction        = direction;
     projectile.Physics.Velocity = velocity;
     RoomControl.SpawnEntity(projectile, Center + positionOffset, zPosition + zPositionOffset);
     return(projectile);
 }
示例#28
0
 public Projectile ShootFromAngle(Projectile projectile, int angle, float speed, Vector2F positionOffset, int zPositionOffset = 0)
 {
     projectile.Owner            = this;
     projectile.Angle            = angle;
     projectile.Physics.Velocity = Angles.ToVector(angle, true) * speed;
     RoomControl.SpawnEntity(projectile, Center + positionOffset, zPosition + zPositionOffset);
     return(projectile);
 }
示例#29
0
        public override void Intercept()
        {
            // Create cling effect.
            Effect effect = new EffectCling(true);

            RoomControl.SpawnEntity(effect, position, zPosition);
            DestroyAndTransform(effect);
        }
示例#30
0
 public Projectile ShootFromDirection(Projectile projectile, int direction, float speed, Vector2F positionOffset, int zPositionOffset = 0)
 {
     projectile.Owner            = this;
     projectile.Direction        = direction;
     projectile.Physics.Velocity = Directions.ToVector(direction) * speed;
     RoomControl.SpawnEntity(projectile, Center + positionOffset, zPosition + zPositionOffset);
     return(projectile);
 }
示例#31
0
 /// 快速加入房间
 private void onJoinRoom()
 {
     if (rooms.Count > 0)
     {
         RoomControl rc = rooms[Random.Range(0, rooms.Count)];
         rc.AddPlayer(PlayerManager.Instance.PlayerSelf);
     }
 }
示例#32
0
 // Does this room have an adjacent place for a room that is not occupied by a room already?
 private bool IsNextToEmpty(RoomControl room)
 {
     for (int index = 0; index < 4; index++) {
         if (IsEmpty(room.Index + RoomControl.vectors[index])) {
             return true;
         }
     }
     return false;
 }
示例#33
0
	public NeuralNetwork(RoomControl rc, FrogMove fm) {//Inputs are fed to the hidden layer which are in turn fed into the visible layer
		hiddenLayer = new Neuron[hiddenSize];
		this.rc = rc;
		this.fm = fm;
		for (int i = 0; i < hiddenSize; i++) {
			hiddenLayer [i] = new Neuron(this, numInputs, 1);
		}
		topLayer = new Neuron[numOutputs];
		topLayer [0] = new Neuron(this, hiddenSize, 1);
		topLayer [1] = new Neuron(this, hiddenSize, 1);
		topLayer [2] = new Neuron(this, hiddenSize, 0);
		topLayer [3] = new Neuron(this, hiddenSize, 2);
	}
示例#34
0
	public NeuralNetwork(RoomControl rc, FrogMove fm, Neuron[] neurons) {//We already have the whole neuron array (called in generations after the 1st)
		hiddenLayer = new Neuron[hiddenSize];
		this.rc = rc;
		this.fm = fm;
		int i = 0;
		for (; i < hiddenSize; i++) {
			hiddenLayer [i] = neurons [i];
			hiddenLayer [i].SetParent(this);
		}
		topLayer = new Neuron[numOutputs];
		for (int x=0; x<numOutputs; x++) {
			topLayer [x] = neurons [i + x];
			topLayer [x].SetParent(this);
		}
	}
示例#35
0
    // returns: 0-3  signalling a direction which can give an empty room
    //          -1   if no such direction exists
    private Vector2 RandomEmpty(RoomControl room)
    {
        if (!IsNextToEmpty(room)) {
            throw new System.InvalidOperationException("Can not give empty room if not next to empty");
        }

        Vector2 vect;
        int d = 0;
        do {
            vect = RoomControl.vectors[UnityEngine.Random.Range(0, 4)];
            if (d > 1000) {
                throw new System.Exception("Infinite loop occuring.");
            }
            d++;
        } while (!IsEmpty(room.Index+vect));
        return vect;
    }
示例#36
0
	public void Setup(RoomControl rc, float roomSize, NeuralNetwork nn) {
		this.rc = rc;
		this.roomSize = roomSize;
		this.nn = nn;
	}
示例#37
0
    // Link the relevant door from this room to the other given room
    public void SetAdj(Vector2 dir, RoomControl adjRoom)
    {
        adjRoomsDict[dir] = adjRoom;

        GameObject thisDoor = transform.Find("Doors/" + directions[dir]).gameObject;
        GameObject adjDoor = adjRoomsDict[dir].transform.Find("Doors/" + directions[dir*-1]).gameObject;

        thisDoor.GetComponent<DoorControl>().goalDoor = adjDoor; // link the goal
        transform.Find("Door Blockers/" + directions[dir]).gameObject.SetActive(false); // disable the blocker
    }
示例#38
0
 public AddToGroupWindow(RoomControl room)
 {
     InitializeComponent();
     _currentRoom = room;
     _chatService = new ChatServiceClient();
 }
示例#39
0
 // Returns: 0-3  signalling a direction which can give an empty room
 private Vector2 RandomNotEmpty(RoomControl room)
 {
     Vector2 vect;
     int d = 0;
     do {
         vect = RoomControl.vectors[UnityEngine.Random.Range(0, 4)];
         if (d > 1000)
         {
             throw new System.Exception("Infinite loop occurring.");
         }
         d++;
     } while (IsEmpty(room.Index + vect));
     return vect;
 }
示例#40
0
文件: Configs.cs 项目: JvJ/CotWM
    /// <summary>
    /// Overlay the specified roomControl, room and config onto the room control.
    /// </summary>
    /// <param name='roomControl'>
    /// Room control.
    /// </param>
    /// <param name='room'>
    /// Room.
    /// </param>
    /// <param name='config'>
    /// Config.
    /// </param>
    public void Overlay(RoomControl roomControl, Room room, Config config)
    {
        if (config.Width != room.Width || config.Height != room.Height){
            throw new ConfigFormatException("Room and config dimensions do not match!");
        }

        for( int x = 0; x < room.Width; x++){
            for(int y = 0; y < room.Height; y++){

                // Only add the overlay if it's not already occupied by the room
                switch(room[x,y].Type){
                case TileType.BLANK:

                    var currentConf = config[x,y];
                    var currentPre = this[currentConf];

                    if (currentPre != null){

                        // Instantiate whatever the prefab is!
                        var o = GameObject.Instantiate(currentPre) as GameObject;

                        o.transform.position = CubeGen.Singleton.PositionFromIdx(roomControl.Position, new coords(x,y));

                        switch (currentConf){
                        case ObjectType.SNOW:
                            o.transform.localScale = new Vector3( CubeGen.Singleton.cubeSize, CubeGen.Singleton.cubeSize, CubeGen.Singleton.cubeSize);
                            var mRend = o.GetComponent(typeof(MeshRenderer)) as MeshRenderer;
                            mRend.material.color = new Color(1f,1f,1f);
                            o.tag = "SNOW";
                            o.layer = LayerMask.NameToLayer("Terrain");
                            roomControl.AddTerrain(o);
                            break;
                        case ObjectType.PLAYER_START:
                            roomControl.PlayerStart = o;
                            break;
                        case ObjectType.XLGRHTHBTRG:
                            var xc = o.GetComponent(typeof(XlGrhthbtrgControl)) as XlGrhthbtrgControl;
                            xc.player = player;
                            xc.currentState = EntityState.STILL;
                            xc.target = player.transform.Find("Armature/Hip");
                            o.layer = LayerMask.NameToLayer("Enemy");
                            roomControl.AddEnemy(xc);
                            break;
                        case ObjectType.WYRM:
                            numWyrms++;
                            var wc = o.GetComponent(typeof(WyrmControl)) as WyrmControl;
                            wc.player = player;
                            wc.currentState = EntityState.STILL;
                            o.layer = LayerMask.NameToLayer("Wyrm");
                            roomControl.AddEnemy(wc);
                            break;
                        case ObjectType.SHOGGOTH:
                            var sc = o.GetComponent(typeof(ShoggothControl)) as ShoggothControl;
                            sc.player = player;
                            sc.currentState = EntityState.STILL;
                            o.layer = LayerMask.NameToLayer("Enemy");
                            roomControl.AddEnemy(sc);
                            break;
                        }
                    }
                    break;
                default:
                    break;
                }
            }
        }
    }
示例#41
0
 private void CreateRoom(UserDto reiceivedUser)
 {
     var isChatting = ChattingUsersId.Exists(u => u == reiceivedUser.Id);
     if (!isChatting)
     {
         Application.Current.Dispatcher.Invoke((Action)delegate
         {
             var room = new RoomControl(_currentUser, reiceivedUser);
             roomArea.Children.Add(room);
             ChattingUsersId.Add(reiceivedUser.Id);
         });
     }
 }