예제 #1
0
    public void TryToTeleport(Movable _movable)
    {
        if (isXWarp)
        {
            // Teleport if exit map
            if (Mathf.Sign(transform.position.x - _movable.transform.position.x) == Mathf.Sign(transform.position.x - teleportTransform.position.x))
            {
                return;
            }

            _movable.transform.position = new Vector3(teleportTransform.position.x, isXAndYChanged ? teleportTransform.position.y : _movable.transform.position.y, _movable.transform.position.z);
            _movable.Flip();
        }
        else
        {
            // Teleport if exit map
            if (Mathf.Sign(transform.position.y - _movable.transform.position.y) == Mathf.Sign(transform.position.y - teleportTransform.position.y))
            {
                return;
            }

            _movable.transform.position = new Vector3(_movable.transform.position.x, teleportTransform.transform.position.y, _movable.transform.position.z);
        }

        GameManager.PlayClipAtPoint(GameManager.I?.WarpSound, _movable.transform.position);
    }
        /// <summary>
        /// Attempts to set movement of an entity.
        /// </summary>
        /// <param name="entity">Entity to set movement on.</param>
        /// <param name="relativePosition">Vector of direction and distance.</param>
        /// <param name="locomotion">Method of movement by terrain type</param>
        /// <returns>Returns true if movement set successfully.</returns>
        internal bool SetMovement(Entity entity, Vector2 destinationVector)
        {
            float       distance       = destinationVector.magnitude;
            Vector2     direction      = destinationVector.normalized;
            Coordinates endCoordinates = entity.Coordinates.AtVector(destinationVector);

            // If obstacles in the way, ignore move
            if (physicsManager)
            {
                if (physicsManager.GetTargetRay(entity, direction, distance))
                {
                    return(false);
                }
            }

            // If we can place the entity at new coordinates set movements
            if (Place((EntityMember)entity, endCoordinates))
            {
                Attributes attributes = entity.GetComponent <Attributes>();
                Movable    movable    = entity.GetComponent <Movable>();

                if (movable & attributes & worldManager)
                {
                    float speed = worldManager.GetSpeed(endCoordinates, attributes, TerrainTileEntity.TerrainType.Land); // Default to using land locomotion
                    movementManager.Set(movable, destinationVector, speed);
                    return(true);
                }
            }
            return(false);
        }
예제 #3
0
 // Method, which will move Movable implementing class by dx and dy
 public void moveBy(Movable serviced, int dx, int dy)
 {
     // this is the place to offer the functionality
     dx += serviced.getPosition().xPosition;
     dy += serviced.getPosition().yPosition;
     serviced.setPosition(new Position(dx, dy));
 }
예제 #4
0
 private void Awake()
 {
     _playerState = GetComponent <PlayerState>();
     _movable     = GetComponent <Movable>();
     _attackLogic = GetComponent <AttackLogic>();
     _probability = new Probability();
 }
예제 #5
0
    public void UpdateShields(Movable movable)
    {
        if (movable.Cell.Index != Index)
        {
            return;
        }

        if (typeof(Enemy).IsCompatibleWith(movable.GetType()))
        {
            ShieldsCount--;
            // Destroy Monster
            Inventory.RemoveToken(movable);
            Destroy(movable.gameObject);
            EventManager.TriggerEnemyDestroyed((Enemy)movable);
        }
        else if (typeof(Farmer).IsCompatibleWith(movable.GetType()))
        {
            ShieldsCount++;
            // Destroy Farmer
            Inventory.RemoveToken(movable);
            Destroy(movable.gameObject);
            EventManager.TriggerFarmerDestroyed((Farmer)movable);
        }

        if (ShieldsCount < 1)
        {
            EventManager.TriggerGameOver();
        }
        EventManager.TriggerShieldsUpdate(ShieldsCount);
    }
예제 #6
0
        public void TryToChange(FruitWithDir data)
        {
            if (gameState == GameState.Wait)
            {
                return;
            }
            Movable mainFruit  = data.Fruit.GetComponent <Movable>();
            Movable otherFruit = mainFruit.GetNeighborMovable(data.Dir, _allObjects);

            if (CanChange(mainFruit, data.Dir))
            {
                gameState = GameState.Wait;
                ChangeFruits(mainFruit, otherFruit);
                EventHolder.startAnimation.Invoke(moveSpeed);
                List <Combine> matchesList = finder.GetCombinedObjects(_allObjects);
                AudioManager.Instance.SwipeSound();
                if (matchesList.Count == 0)
                {
                    StartCoroutine(RevertGems(mainFruit, otherFruit));
                }
                else
                {
                    taskManager.MadeMove();
                    shredder.MakeDamage(matchesList);
                    StartCoroutine(shredder.FruitsDestroy(_allObjects, moveSpeed + 0.1f));
                }
            }
        }
예제 #7
0
파일: Witch.cs 프로젝트: penspanic/Mawang
 bool IsInSkillRange(Movable target)
 {
     if (Mathf.Abs(this.transform.position.x - target.transform.position.x) < skillRange * BattleManager.tileSize)
         return true;
     else
         return false;
 }
예제 #8
0
    void setAIContext(UserMoveController player)
    {
        for (int y = 0; y < height; y++)
        {
            for (int x = 0; x < width; x++)
            {
                GameObject obj = tileCreator.getObj(x, y);
                if (obj != null)
                {
                    Movable movable = obj.GetComponentInChildren <Movable>();
                    if (movable != null)
                    {
                        movable.graphBuilder = this;
                    }

                    AIMoveController ai = obj.GetComponentInChildren <AIMoveController>();
                    if (ai != null)
                    {
                        ai.player   = player;
                        ai.graphMap = graphMap;
                    }
                }
            }
        }
    }
예제 #9
0
        void Start()
        {
            // Start with turn 0
            _history.Clear();
            _history.Push(new Turn(0));

            // All entities MUST BE INITIALIZED AT SOME TURN
            // Turn0 by default
            var foundEntities = GameObject.FindObjectsOfType <Entity>();

            _playerEntity  = GameObject.FindGameObjectWithTag("Player").GetComponent <Entity>();
            _playerMovable = _playerEntity.GetComponent <Movable>();

            foreach (var entity in foundEntities)
            {
                var newId = GetNewEntityId();
                entity.Initialize(this, newId);
                _entities.Add(newId, entity);
            }

            SwitchState(GameState.WaitingForPlayerCommand);
            _sceneName = SceneManager.GetActiveScene().name;
            Common.SetActiveLevel(this);

            //fixed rollback for test
            PlayerStats.Instance.SetFixedRollBack();
        }
예제 #10
0
        public void MoveToward(Vector2 position, float velocity)
        {
            Movable locomotion = Locomotion;

            Vector2 directionVector = new Vector2();

            if (position.y < locomotion.GlobalPosition.y)
            {
                directionVector.y = -1f;
            }
            else if (position.y > locomotion.GlobalPosition.y)
            {
                directionVector.y = 1f;
            }

            if (position.x < locomotion.GlobalPosition.x)
            {
                directionVector.x = -1f;
            }
            else if (position.x > locomotion.GlobalPosition.x)
            {
                directionVector.x = 1f;
            }

            locomotion.velocity = directionVector.Normalized() * velocity;
        }
예제 #11
0
        public void PaintDebug(DebugDrawer drawer)
        {
            if (Settings.Data.debugMode)
            {
                Movable locomotion = Locomotion;

                drawer.DrawCircle(drawer.Position, Controller.searchRadius, new Color(1.0f, 0.0f, 0.0f, 0.2f));
                //drawer.DrawLine(drawer.Position, debugHitLocation.RelativeTo(locomotion.GlobalPosition), new Color(0.0f, 1.0f, 0.0f), 2f, true);
                if (target != null)
                {
                    const float size = 24f;
                    drawer.DrawRect(new Rect2(target.Location.RelativeTo(locomotion.GlobalPosition) - new Vector2(size / 2f, size / 2f), size, size), new Color(0.0f, 1.0f, 0.0f), false);
                }

                if (state == ChaseAIState.Wandering)
                {
                    drawer.DrawLine(drawer.Position, target.Location.RelativeTo(locomotion.GlobalPosition), new Color(0.0f, 0.0f, 1.0f), 2f, true);
                    drawer.DrawCircle(target.Location.RelativeTo(locomotion.GlobalPosition), 8f, new Color(0.0f, 0.0f, 1.0f));
                }
                else if (state == ChaseAIState.Chasing)
                {
                    drawer.DrawLine(drawer.Position, target.Location.RelativeTo(locomotion.GlobalPosition), new Color(1.0f, 0.0f, 0.0f), 2f, true);
                    drawer.DrawCircle(target.Location.RelativeTo(locomotion.GlobalPosition), 8f, new Color(1.0f, 0.0f, 0.0f));
                }
            }
        }
예제 #12
0
    // Either the character controller moved into something, or something moved into the supercollider spheres.
    private void HandleCollision(GameObject obj, Vector3 hitNormal, Vector3 hitPos)
    {
        if (ignoreCollisions)
        {
            //Debug.Log ("Ignoring collsion because we're ignorin."+Time.time);
            return;
        }
        if (ignoreFootCollisions && (transform.position.y - distToGround + stepSize) >= hitPos.y + 0.01f)
        {
            //Debug.Log ("Ignoring collsion because its feet."+hitPos.y + " " + (transform.position.y - distToGround + stepSize));
            return;
        }
        if ((layerMask & (1 << obj.layer)) == 0)
        {
            //Debug.Log ("Ignoring collsion of object with " + obj.layer);
            return;
        }
        if (Vector3.Angle(hitNormal, Vector3.up) < controller.slopeLimit)
        {
            //Debug.Log ("Ignoring collsion because it's valid ground."+Time.time);
            return;
        }
        float mag = velocity.magnitude;

        velocity = ClipVelocity(velocity, hitNormal);
        Movable check = obj.GetComponent <Movable> ();

        if (check != null)
        {
            Vector3 vel = check.velocity;
            float   d   = Vector3.Dot(vel, hitNormal);  // How similar is our velocity to our hitnormal (perp = 0, backwards = -1, same = 1)
            if (d > 0.01f)                              // If the velocity should be applied
            {
                velocity += hitNormal * d * overbounce; // We apply it with some overbounce, to keep us from getting stuck.
            }
        }
        float     change     = Mathf.Abs(mag - velocity.magnitude);
        Rigidbody rigidcheck = obj.GetComponent <Rigidbody> ();

        if (rigidcheck != null)
        {
            Vector3 vel = rigidcheck.GetPointVelocity(hitPos);
            float   d   = Vector3.Dot(vel, hitNormal);
            if (d > 0.01f)
            {
                velocity += hitNormal * d * overbounce;
            }
            rigidcheck.AddForceAtPosition(-hitNormal * change * mass, hitPos);
        }
        if (change > fallSoundThreshold)
        {
            float fvol = Mathf.Min(change / (maxSafeFallSpeed - fallSoundThreshold), 1f);
            PlayerRoughLandingEffects(fvol, hitPos, hitNormal);
        }
        if (change > fallPunchThreshold)
        {
            float shakeIntensity = Mathf.Min((change - fallPunchThreshold) / (maxSafeFallSpeed - fallPunchThreshold), 1f);
            gameObject.SendMessage("ShakeImpact", -hitNormal * shakeIntensity);
        }
    }
예제 #13
0
 public Tile(Vector2 pos, Texture2D texture, Movable movable, Rectangle rect)
 {
     this.pos = pos;
     this.texture = texture;
     this.movable = movable;
     this.rect = rect;
 }
예제 #14
0
        private bool TryAnimateHint(Movable curMovable, Movable otherMovable, Vector2Int dir, GameObject[,] allObjects, bool findBigMatch, bool onlyCheck)
        {
            int maxMatch;

            if (findBigMatch)
            {
                maxMatch = 3;
            }
            else
            {
                maxMatch = 0;
            }

            List <Combine> combineList = GetPotentialMatchs(curMovable, otherMovable, allObjects, maxMatch);

            if (combineList != null)
            {
                if (onlyCheck)
                {
                    return(true);
                }

                if (combineList.Contains(curMovable.GetComponent <Combine>()))
                {
                    if (dir == Vector2Int.up)
                    {
                        curMovable.GetComponent <Animeted>().HintUp();
                    }
                    else
                    {
                        curMovable.GetComponent <Animeted>().HintRight();
                    }
                }
                else
                {
                    if (dir == Vector2Int.up)
                    {
                        otherMovable.GetComponent <Animeted>().HintDown();
                    }
                    else
                    {
                        otherMovable.GetComponent <Animeted>().HintLeft();
                    }
                }

                foreach (Combine combine in combineList)
                {
                    if (combine.gameObject == curMovable.gameObject)
                    {
                        continue;
                    }
                    combine.GetComponent <Animeted>().HintScale();
                }


                return(true);
            }
            return(false);
        }
예제 #15
0
 public virtual void Init()
 {
     _movable = GetComponent <Movable>();
     if (_movable == null)
     {
         _movable = gameObject.AddComponent <Movable>();
     }
 }
예제 #16
0
    private void Awake()
    {
        battleMgr = GameObject.FindObjectOfType<BattleManager>();
        parent = transform.parent.GetComponent<Movable>();

        damage = parent.GetAttackDamage();
        isMoveRight = parent.isOurForce ? true : false;
    }
예제 #17
0
 // Use this for initialization
 void Start()
 {
     movable = GetComponent <Movable>();
     if (movable == null)
     {
         Debug.LogError("Movable Controller not found");
     }
 }
예제 #18
0
    public Movable SpawnOurForce(Movable obj, int line, Vector2 pos)
    {
        Movable newObj = Instantiate(obj, ourForceLinePos[line - 1], new Quaternion()) as Movable;
        orderMgr.UpdateOrder(line);
        newObj.transform.position = pos;

        return newObj;
    }
예제 #19
0
 public void TrySpawnOurForce(Movable obj, int line)
 {
     if (goldMgr.playerGold - obj.GetUnitCost() >= 0)
     {
         goldMgr.playerGold -= obj.GetUnitCost();
         SpawnOurForce(obj, line);
     }
 }
예제 #20
0
 public override char Print()
 {
     if (Movable != null)
     {
         return(Movable.Print());
     }
     return('~');
 }
예제 #21
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (Id != 0)
            {
                hash ^= Id.GetHashCode();
            }
            if (relativePosition_ != null)
            {
                hash ^= RelativePosition.GetHashCode();
            }
            if (relativeVelocity_ != null)
            {
                hash ^= RelativeVelocity.GetHashCode();
            }
            if (Rcs != 0D)
            {
                hash ^= Rcs.GetHashCode();
            }
            if (Movable != false)
            {
                hash ^= Movable.GetHashCode();
            }
            if (Width != 0D)
            {
                hash ^= Width.GetHashCode();
            }
            if (Length != 0D)
            {
                hash ^= Length.GetHashCode();
            }
            if (Height != 0D)
            {
                hash ^= Height.GetHashCode();
            }
            if (Theta != 0D)
            {
                hash ^= Theta.GetHashCode();
            }
            if (absolutePosition_ != null)
            {
                hash ^= AbsolutePosition.GetHashCode();
            }
            if (absoluteVelocity_ != null)
            {
                hash ^= AbsoluteVelocity.GetHashCode();
            }
            if (Count != 0)
            {
                hash ^= Count.GetHashCode();
            }
            if (MovingFramesCount != 0)
            {
                hash ^= MovingFramesCount.GetHashCode();
            }
            return(hash);
        }
예제 #22
0
 public bool TryPlaceObject(Movable obj)
 {
     if (currentObject != null)
     {
         return(false);
     }
     SetObject(obj);
     return(true);
 }
예제 #23
0
 private void UnsetObject(ARInteractable oldInteractable, ARInteractable newInteractable)
 {
     print(newInteractable);
     print(oldInteractable);
     if (newInteractable != null && newInteractable != oldInteractable)
     {
         this.currentObject = null;
     }
 }
예제 #24
0
 private void Awake()
 {
     // init components
     _movable = GetComponent <Movable>();
     // try get this, null if player
     _enemyController = GetComponent <EnemyController>();
     // Set animation speed for attacks based on attack time
     animator.SetFloat(AttackSpeed, 1 / (float)attackTime);
 }
예제 #25
0
 public bool TryTake()
 {
     if (currentObject == null)
     {
         return(false);
     }
     currentObject = null;
     return(true);
 }
예제 #26
0
 private void Awake()
 {
     if (!spriteRenderer)
     {
         spriteRenderer = GetComponent <SpriteRenderer>();
     }
     animator = GetComponent <Animator>();
     movable  = GetComponent <Movable>();
 }
예제 #27
0
 private void HandleTick(int tick, int partialTick, float tickDuration, bool everyone)
 {
     if (everyone && Level.Instance.HasAgent(AgentID))
     {
         Movable m = Level.Instance.GetMovableById(AgentID);
         HandleWalkStatus(m);
         Emit(heading);
     }
 }
예제 #28
0
    private void OnTriggerEnter(Collider other)
    {
        Movable movable = other.GetComponent <Movable>();

        if (movable != null)
        {
            movable.PullInComptoir(transform, comptoir);
        }
    }
예제 #29
0
        public override bool AcceptMove(Movable movable)
        {
            if (movable.GetType() == typeof(Movables.Baricade))
            {
                return(false);
            }

            return(base.AcceptMove(movable));
        }
예제 #30
0
        public void ChangeMotion <TBoard>(Movable <TBoard> movable) where TBoard : Board <TBoard>
        {
            Velocity velocity = movable.Velocity;

            IsActive = false;
            // can't do this because we don't have something called friction to resist fixed velocity motion
            // movable.Velocity = new Velocity(velocity.FinenessX + MoveFinenessX, velocity.FinenessY);
            movable.Velocity = new Velocity(MoveFinenessX, velocity.FinenessY);
        }
예제 #31
0
    void MoveComplete(Movable movable)
    {
        if (movable != this.movable)
        {
            return;
        }

        if (stops.Count == 0)
        {
            Dispose();
        }
        else
        {
            Cell stop = stops[0];
            stops.RemoveAt(0);
            Cell start = movable.Cell;

            int startIndex = path.Cells.IndexOf(start);
            if (startIndex != -1)
            {
                foreach (Farmer f in start.Inventory.Farmers)
                {
                    foreach (Pair <Farmer, Cell> farmer in farmers)
                    {
                        if (farmer.First == f)
                        {
                            int stopInd = -1;
                            if (farmer.Second != null)
                            {
                                stopInd = path.Cells.IndexOf(farmer.Second);
                            }

                            if (stopInd == -1)
                            {
                                stopInd = path.Cells.Count - 1;
                            }

                            List <Cell> subpathFarmer = path.Cells.GetRange(startIndex, stopInd - startIndex + 1);
                            f.Move(subpathFarmer);
                            break;
                        }
                    }
                }

                int stopIndex = path.Cells.IndexOf(stop, startIndex + 1);
                if (stopIndex != -1)
                {
                    List <Cell> subpathHero = path.Cells.GetRange(startIndex, stopIndex - startIndex + 1);
                    movable.Move(subpathHero, totalFreeMoves);
                }
                else
                {
                    Dispose();
                }
            }
        }
    }
예제 #32
0
 public static bool CanReach(this Movable seeker, TargetInfo targetInfo)
 {
     if (seeker.Navigator is Navigation2D navigator)
     {
         object simplePath = navigator.GetSimplePath(seeker.GlobalPosition, targetInfo) != null;
         return(simplePath != null);
     }
     return(false);
 }
예제 #33
0
 void Start()
 {
     movable = GetComponentInParent <Movable>();
     my_body = GetComponent <ColoredBody>();
     if (my_body == null)
     {
         Debug.LogError("Bullet objects must have a ColoredBody component!");
     }
 }
예제 #34
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        Movable movable = other.gameObject.GetComponent <Movable>();

        if (movable)
        {
            GetInto(movable);
        }
    }
예제 #35
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        GUILayout.Space(8f);

        if (!EditorApplication.isPlaying &&
            GUILayout.Button("Apply to changed", GUILayout.Height(25f)))
        {
            MovableText movableText = target as MovableText;

            int       messageLength = movableText.Message.Length;
            Transform movTransform  = movableText.transform;

            #region Summary

            /*=================================================================================
             * If amount of unstableChar is more than messageLength, removal unstableChar at the last.
             * 만약 불안정문자의 수가 메시지의 길이보다 많다면, 제일 뒤에있는 불안정문자를 제거한다.
             *=================================================================================*/
            #endregion
            while (messageLength < movTransform.childCount)
            {
                Undo.DestroyObjectImmediate(movTransform.GetChild(movTransform.childCount - 1).gameObject);
            }
            #region Summary

            /*=================================================================================
             * Rearrange unstableChar based on length of changed message and change the each unstableChar by changed message.
             * 변경된 메시지에따라 불안정문자를 재배치하고, 각 불안정문자들이 나타내는 글자를 변경한다.
             *=================================================================================*/
            #endregion
            for (int i = 0; i < messageLength; i++)
            {
                if (i >= movTransform.childCount)
                {
                    Movable.CreateMovableChar(i, movableText.Message[i], movableText.GetTextInfo)
                    .transform.parent = movTransform;
                }

                Undo.RecordObject(movTransform.GetChild(i), movableText.Message);

                if (movableText.transform.GetChild(i).TryGetComponent(out MovableObject movable))
                {
                    movable.Setting(movableText.GetTextInfo);
                }
                movTransform.GetChild(i).SetLetterSpace(messageLength, movableText.LetterSpace, i);

                if (movTransform.GetChild(i).TryGetComponent(out Text text))
                {
                    Undo.RecordObject(text, "Apply to changed text");

                    text.text = movableText.Message[i].ToString();
                }
            }
        }
    }
예제 #36
0
    public void Init()
    {
        target = transform.parent.GetComponent<Movable>();
        if (target.forDecoration)
        {
            Destroy(this.gameObject);
            return;
        }
        hpRed = transform.FindChild("Red").gameObject;
        hpBack = transform.FindChild("Hp Back").gameObject;

        hpBack.GetComponent<SpriteRenderer>().color = target.isOurForce ? ourForceBackColor : enemyBackColor;
        SetHpBar();
    }
예제 #37
0
    public void OnTouch()
    {
        spawnObj = selectTab.GetUnit();

        if (spawnObj != null)
        {
            switch (gameObject.name)
            {
                case "Spawn Line1":
                    spawnMgr.TrySpawnOurForce(spawnObj, 1);
                    break;

                case "Spawn Line2":
                    spawnMgr.TrySpawnOurForce(spawnObj, 2);
                    break;

                case "Spawn Line3":
                    spawnMgr.TrySpawnOurForce(spawnObj, 3);
                    break;
            }
        }
        selectTab.ResetButton();
    }
예제 #38
0
    IEnumerator WaitAndRevival(Movable target, int line, Vector3 pos)
    {
        yield return new WaitForSeconds(1f);

        spawnMgr.SpawnOurForce(target, line, pos);
    }
예제 #39
0
		public TerrainQuadTreeNode( Terrain terrain, TerrainQuadTreeNode parent, ushort xOff, ushort yOff, ushort size,
		                            ushort lod, ushort depth, ushort quadrant )
			: base()
		{
			this.mTerrain = terrain;
			this.mParent = parent;
			this.mOffsetX = xOff;
			this.mOffsetY = yOff;
			this.mBoundaryX = (ushort)( xOff + size );
			this.mBoundaryY = (ushort)( yOff + size );
			this.mSize = size;
			this.mBaseLod = lod;
			this.mDepth = depth;
			this.mQuadrant = quadrant;
			this.mBoundingRadius = 0;
			this.mCurrentLod = -1;
			this.mMaterialLodIndex = 0;
			this.mLodTransition = 0;
			this.mChildWithMaxHeightDelta = null;
			this.mSelfOrChildRendered = false;
			this.mNodeWithVertexData = null;
			this.mAABB = new AxisAlignedBox();
			if ( this.mTerrain.MaxBatchSize < size )
			{
				var childSize = (ushort)( ( ( size - 1 )*0.5f ) + 1 );
				var childOff = (ushort)( childSize - 1 );
				var childLod = (ushort)( lod - 1 ); // LOD levels decrease down the tree (higher detail)
				var childDepth = (ushort)( depth + 1 );
				// create children
				this.mChildren[ 0 ] = new TerrainQuadTreeNode( this.mTerrain, this, xOff, yOff, childSize, childLod, childDepth, 0 );
				this.mChildren[ 1 ] = new TerrainQuadTreeNode( this.mTerrain, this, (ushort)( xOff + childOff ), yOff, childSize,
				                                               childLod,
				                                               childDepth, 1 );
				this.mChildren[ 2 ] = new TerrainQuadTreeNode( this.mTerrain, this, xOff, (ushort)( yOff + childOff ), childSize,
				                                               childLod,
				                                               childDepth, 2 );
				this.mChildren[ 3 ] = new TerrainQuadTreeNode( this.mTerrain, this, (ushort)( xOff + childOff ),
				                                               (ushort)( yOff + childOff ),
				                                               childSize, childLod, childDepth, 3 );

				var ll = new LodLevel();
				// non-leaf nodes always render with minBatchSize vertices
				ll.BatchSize = this.mTerrain.MinBatchSize;
				ll.MaxHeightDelta = 0;
				ll.CalcMaxHeightDelta = 0;
				this.mLodLevels.Add( ll );
			}
			else
			{
				//no children
				Array.Clear( this.mChildren, 0, this.mChildren.Length );
				// this is a leaf node and may have internal LODs of its own
				var ownLod = this.mTerrain.NumLodLevelsPerLeaf;

				Debug.Assert( lod == ( ownLod - 1 ), "The lod passed in should reflect the number of lods in a leaf" );
				// leaf nodes always have a base LOD of 0, because they're always handling
				// the highest level of detail
				this.mBaseLod = 0;
				var sz = this.mTerrain.MaxBatchSize;

				while ( ownLod-- != 0 )
				{
					var ll = new LodLevel();
					ll.BatchSize = sz;
					ll.MaxHeightDelta = 0;
					ll.CalcMaxHeightDelta = 0;
					this.mLodLevels.Add( ll );
					if ( ownLod != 0 )
					{
						sz = (ushort)( ( ( sz - 1 )*0.5 ) + 1 );
					}
				}
				Debug.Assert( sz == this.mTerrain.MinBatchSize );
			}

			// local centre calculation
			// because of pow2 +1 there is always a middle point
			var midoffset = (ushort)( ( size - 1 )/2 );
			var midpointX = (ushort)( this.mOffsetX + midoffset );
			var midpointY = (ushort)( this.mOffsetY + midoffset );

			//derive the local centry, but give it a height if 0
			//TODO: - what if we actually centred this at the terrain height at this point?
			//would this be better?
			this.mTerrain.GetPoint( midpointX, midpointY, 0, ref this.mLocalCentre );
			this.mMovable = new Movable( this );
			this.mRend = new Rend( this );
		}
예제 #40
0
 void Start()
 {
     movable = GetComponent<Movable>();
     health = GetComponent<Damageable>();
 }
 public void AddMovable(Movable m)
 {
     updateList.Add(m);
 }
 public void Remove(Movable m)
 {
     if(updateList.Contains(m))
         updateList.Remove(m);
 }
예제 #43
0
		protected override void dispose( bool disposeManagedResources )
		{
			if ( !IsDisposed )
			{
				if ( disposeManagedResources )
				{
					if ( this.mMovable != null )
					{
						if ( !this.mMovable.IsDisposed )
						{
							this.mMovable.Dispose();
						}

						this.mMovable = null;
					}

					if ( this.mRend != null )
					{
						this.mRend = null;
					}

					if ( this.mLocalNode != null )
					{
						this.mTerrain.RootSceneNode.RemoveAndDestroyChild( this.mLocalNode.Name );
						this.mLocalNode = null;
					}

					for ( int i = 0; i < this.mChildren.Length; i++ )
					{
						if ( this.mChildren[ i ] != null )
						{
							this.mChildren[ i ].Dispose();
						}
					}

					DestroyCpuVertexData();
					DestroyGpuVertexData();
					DestroyGpuIndexData();

					if ( this.mLodLevels != null )
					{
						this.mLodLevels.Clear();
						this.mLodLevels = null;
					}

					this.mVertexDataRecord = null;
				}
			}

			base.dispose( disposeManagedResources );
		}
예제 #44
0
 public void SpawnOurForce(Movable obj, int line)
 {
     Instantiate(obj, ourForceLinePos[line - 1], new Quaternion());
     orderMgr.UpdateOrder(line);
 }
예제 #45
0
 void Start()
 {
     movable = GetComponent<Movable>();
     animator = GetComponent<Animator>();
 }
예제 #46
0
 public int[] ShortestDepotPath(int[] startInd, Movable mover)
 {
     int[] shortestInd = null;
     float shortestLen = Mathf.Infinity;
     foreach (int[] stopInd in depots) {
         float len = mover.TravelDistance (stopInd);
         if (len < shortestLen && mover.CanReach (stopInd)) {
             shortestInd = stopInd;
             shortestLen = len;
         }
     }
     return shortestInd;
 }
예제 #47
0
 // Use this for initialization
 void Start()
 {
     player = GetComponent<Movable>();
     TurnRight();
 }