상속: NetworkBehaviour
예제 #1
0
 /// <summary>
 /// Constructeur de base 
 /// </summary>
 /// <param name="pParent">Le Ship qui tirera </param>
 /// <param name="pTtl">millisecondes où le laser restera en vie</param>
 public Weapon(MovingObject pParent, int pTtl = 500)
 {
     _ttl = pTtl;
     _icon = SpriteManager.IconLaser;
     _parent = pParent;
     _timeSinceShot = DateTime.Now.Ticks / 1000;
     _multiplicateurVitesse = 1;
 }
 public AdjustableTileCamera(ref TileMap map, MovingObject montior, int width, int height, int startRow = 0, int startCol = 0)
     : base(map, montior, width, height, startRow, startCol)
 {
     TopOfCamera = LeftSideOfCamera = 0;
     BottomOfCamera = height;
     RightSideOfCamera = width;
     firstUpdate = true;
     controller = this;
 }
예제 #3
0
        public bool IsAboveLevelObject(MovingObject a)
        {
            if(a.PrevPosition.Y + a.IntersectRectangle.Height <= Position.Y)
            {
                return true;
            }

            return false;
        }
예제 #4
0
	/*
	//y%2==0,intend_grids
	int[,] intend_move0= new int[6,2]
	{
		{0,-1},
		{-1,0},
		{0,1},
		{1,1},
		{1,0},
		{1,-1}
	};

	//y%2==1,intend_grids
	int[,] intend_move1= new int[6,2]
	{
		{0,-1},
		{1,0},
		{0,1},
		{-1,1},
		{-1,0},
		{-1,-1}
	};*/

	
	void Awake ()
	{
		if (instance == null)
			instance = this;
		else if (instance != this)
			Destroy (gameObject);
        quick_tap = false;
		//DontDestroyOnLoad (gameObject);
	}
예제 #5
0
 public void fill(GameObject obj)
 {
     if (obj.tag.Equals("Enemy") || obj.tag.Equals("Player"))
     {
         character = obj.GetComponent<MovingObject>();
         Debug.Log("added " + character.tag);
     }
     else if (obj.tag.Equals("StaticObject"))
         staticObjects.Add(obj.GetComponent<StaticObject>());
     //else other.Add(obj);
 }
예제 #6
0
    void SpawnObject()
    {
        lastSpawnTime = Time.time;
        spawnInterval *= 0.99f;//Speed up spawning

        DirectionEnum direction = spawnDirection; //-1 or 1

        Transform newObj = (Transform)Instantiate(objectPrefab, transform.position, transform.rotation);
        MovingObject movObj = new MovingObject(direction, newObj);
        GameManager.SP.AddTarget( movObj );
    }
예제 #7
0
        public DefenseBase(MovingObject pParent)
            : base(pParent)
        {
            _color = Color.White;
            _lifes = 5;
            _color = new Color(0,255,0);
            _lstCoul = new List<Color>() { Color.White, Color.Aqua, Color.Blue, Color.Purple, Color.Red };

            _parent = pParent;
            _sprite = SpriteManager.Shield1;
            _origine = new Vector2(_sprite.Width, _sprite.Height) / 2;// *SpriteManager.scaleRateShield / 2;
        }
예제 #8
0
    public void AddControlled(MovingObject obj)
    {
        this.controlledObject = obj;

        this.Add(obj);

        if (GetCollidedObject(this.controlledObject) != null)
        {
            this.isGameOver = true;

            this.OnGameOver(this, new EventArgs());
        }
    }
예제 #9
0
        public override void Loop(MovingObject pShip)
        {
            if (Methods.Random.Next(32) == 0)
            {
                InputStates.Clear();

                if (Methods.Random.Next() > 0)
                    InputStates.Left = true;
                else
                    InputStates.Right = true;

                InputStates.Up = true;
            }
        }
 public void CollideAction(GameObject obj, MovingObject sender)
 {
     if (obj is WallBlock || obj is Enemy)
     {
         sender.Speed.XPosition *= -1;
     }
     else
     {
         sender.Lifes--;
         if (sender.Lifes == 0)
         {
             sender.isAlive = false;
         }
     }
 }
예제 #11
0
    // ==============================
    // Public Functions
    // ==============================
    // Specify the animation when the skill is executed
    public override void PlaySkillAnimation(MovingObject sourceObject, List<MovingObject> affectedObjects, Action callback)
    {
        _callback = callback;

        enemiesHit = 0;
        enemiesTotal = affectedObjects.Count;

        // Create a projectile affect targeted at all affected objects
        var startPos = sourceObject.transform.position;
        foreach (var affectedObject in affectedObjects)
        {
            var animationObject = Instantiate(SkillAnimation, startPos, Quaternion.identity) as GameObject;
            animationObject.GetComponent<ProjectileEffect>().MoveTowards(affectedObject, AnimationCallback);
        }
    }
예제 #12
0
        public override void Loop(MovingObject pShip)
        {
            InputStates.Clear();

            if ((TargetShip.Position - pShip.Position).Length > 16) // chase the player ship if it gets too far
            {
                Targets.Clear();
                Targets.Add(TargetShip.Position);
            }
            else if (Targets.Count == 0) // face the same way as the player ship once you reach it
            {
                InputStates.Left = Methods.AngleDifference(pShip.Angle, TargetShip.Angle) < -15;
                InputStates.Right = Methods.AngleDifference(pShip.Angle, TargetShip.Angle) > 15;
            }

            InputStates.Add(MoveToNextTarget(pShip));
            InputStates.DetectPresses();
        }
예제 #13
0
 public override void Loop(MovingObject pShip)
 {
     // no input.
 }
예제 #14
0
    // Sets obj to be queued on tile (x, y), so that no other objects can move to (x, y)
    // Also makes the obj's previous tile free to me moved on
    public void SetObjectOnTileQueued(int x, int y, MovingObject obj)
    {
        // Friendly objects can make multiple movements, so we have to null the previous tile
        if (obj is FriendlyObject)
        {
            var friendlyObj = (FriendlyObject)obj;
            GetHexTile(friendlyObj.ShadowX, friendlyObj.ShadowY).ObjectOnTileQueued = null;
        }

        GetHexTile(obj.X, obj.Y).ObjectOnTile = null;
        GetHexTile(x, y).ObjectOnTileQueued = obj;
    }
예제 #15
0
 void Start()
 {
     movingObject = GetComponent<MovingObject>();
 }
 public override void onAwake()
 {
     plateforme = GetComponent <MovingObject>();
 }
예제 #17
0
 //Call this to add the passed in Enemy to the List of Enemy objects.
 public void removeEnemyfromList(MovingObject script)
 {
     //Add Enemy to List enemies.
     enemies.Remove(script);
 }
예제 #18
0
        /// <summary>
        /// Calculates the position after the collsion of two object
        /// </summary>
        /// <param name="a">The first object in the collision</param>
        /// <param name="b">The second object in the collsion</param>
        internal void calcCollPos(MovingObject a, MovingObject b)
        {
            if (a == null || b == null)
            {
                return;
            }

            Vector apos;
            Vector bpos;

            {
                Vector mid = a.Position + b.Position;
                mid /= 2.0f;

                Vector mid2a = a.Position - mid;
                Vector mid2b = b.Position - mid;

                /* pfr 10/25/01
                 * This was a really nasty bug. This used to be the condition
                 * if ( a->pos == b->pos )
                 * If a->pos and b->pos are approximately equal (but
                 * not ==, then a->pos - mid and b->pos - mid can both be 0.
                 * This means that in the else clause below, we call PVector::r(v)
                 * on two zero vectors, which makes them both (v,0).
                 * Then, the while statement below is an infinite loop */
                if (a.Position == b.Position ||
                    ((a.Position - mid).Radius < Defines.Epsilon &&
                     (b.Position - mid).Radius < Defines.Epsilon)
                    )
                {
                    // if the two objects are directly on top on one and other
                    // then they will be separated at a random angle
                    float a_ang = (float)Utilities.CustomRandom.NextDouble(-Math.PI, Math.PI);
                    float b_ang = (float)Utilities.Normalize_angle(a_ang + Math.PI);
                    mid2a = Vector.fromPolar((a.Size + b.Size) / 2.0f + Defines.Epsilon, a_ang);
                    mid2b = Vector.fromPolar((a.Size + b.Size) / 2.0f + Defines.Epsilon, b_ang);
                }
                else
                {
                    mid2a.normalize((a.Size + b.Size) / 2.0f + Defines.Epsilon);
                    mid2b.normalize((a.Size + b.Size) / 2.0f + Defines.Epsilon);
                }

                apos = mid + mid2a;
                bpos = mid + mid2b;

                // 0.01% is added to the movement, as sometimes structural noise
                // means that even though mid2a and mid2b should be
                // a->size + b->size apart, they are ever so slightly
                // less.
                int count = 0;
                while (apos.distance(bpos) < a.Size + b.Size &&
                       count < 10)
                {
                    mid2a.normalize((float)(mid2a.Radius * 1.0001));
                    mid2b.normalize((float)(mid2b.Radius * 1.0001));
                    apos = mid + mid2a;
                    bpos = mid + mid2b;
                    ++count;
                }
            }


            /*    cout << "apos = " << a->pos << std::endl; */
            /*    cout << "anewpos = " << (mid + mid2a ) << std::endl; */

            /*    cout << "bpos = " << b->pos << std::endl; */
            /*    cout << "bnewpos = " << (mid + mid2b ) << std::endl; */

            /*    cout << "old distance = " << a->pos.distance ( b->pos ) << std::endl; */
            /*    cout << "new distance = " << apos.distance ( bpos ) << std::endl; */

            a.collide(apos);
            b.collide(bpos);
        }
예제 #19
0
 public NoShield(MovingObject pParent, Boolean pWeapon = false)
 {
     _parent       = pParent;
     _weapon       = pWeapon;
     _wallsTouched = new List <Wall>();
 }
 private GameObject GetCollidedObject(MovingObject obj)
 {
     return(GetCollidedObject(obj, obj.Direction));
 }
예제 #21
0
 public void OnFinalWaypoint(MovingObject obj, WaypointNode node)
 {
     Debug.Log("Объект " + obj.gameObject.name + " достиг конечной точки " + node.gameObject.name);
 }
예제 #22
0
 public MovingDirect(MovingObject pParent) : base(pParent)
 {
     _accelFactor = 0.5f;
 }
예제 #23
0
 protected BaseAbility(MovingObject owner)
 {
     Owner = owner;
 }
예제 #24
0
    private bool TestForGround() // returns false if we skip the test for whetever reason
    {
        if (stuckBetweenSlopes)
        {
            stuckBetweenSlopes = false;
            return(false);
        }
        if (isMovingUp)
        {
            isGrounded = false;
            return(false);
        }
        //check to see if we're climbing stairs; if so, stay on ground
        if (isGrounded)
        {
            if (StairClimbSweep(ref lastMoveVector, true).Length > 0)
            {
                onStairsFallDelayTimer = onStairsDelayBeforeFalling;
                return(false);
            }
            else
            {
                onStairsFallDelayTimer -= Time.fixedDeltaTime;
                if (onStairsFallDelayTimer > 0)
                {
                    return(false);
                }
            }
        }

        float   riseAmount    = 0;
        Vector3 capsuleCenter = transform.position;
        float   pointDist     = capsuleHeight / 2 - capsuleRadius;

        RaycastHit[] raycasthits;
        raycasthits = Physics.CapsuleCastAll(capsuleCenter - pointDist * Vector3.down, capsuleCenter - pointDist * Vector3.up, capsuleRadius,
                                             Vector3.down, capsuleRadius + GROUND_CHECK_DISTANCE + skinWidth, geometryCollisionLayers); //first capsule cast, checking for ground. Casts an extra radius and ignores results within the lower hemisphere, in order to imitate a cylinder
        isGrounded = false;
        Collider groundCollider = null;
        bool     hitGround      = false; // did we hit something that's within our "cylinder" the bottom of which is GROUND_CHECK_DISTANCE lower than the bottom of the collision capsule

        foreach (RaycastHit hit in raycasthits)
        {
            if (hit.point.y > capsuleCenter.y - capsuleHeight / 2 - GROUND_CHECK_DISTANCE - skinWidth) //calculating the distance if we were casting a cylinder instead of a capsule
            {
                riseAmount = hit.point.y - (capsuleCenter.y - capsuleHeight / 2 - skinWidth);          //calculating the distance if we were casting a cylinder instead of a capsule
                riseAmount = Mathf.Max(riseAmount, 0);
                hitGround  = true;
                if (IsGround(hit.normal))
                {
                    isGrounded     = true;
                    groundCollider = hit.collider;
                    break;
                }
            }
        }
        if (hitGround && !isGrounded)
        {
            RaycastHit groundHitinfo;
            if (PhysHelper.FakeCylinderCast(FAKE_CAPSULE_CAST_BOXES, capsuleHeight - capsuleRadius * 2, capsuleRadius, capsuleCenter, Vector3.down, out groundHitinfo,
                                            capsuleRadius + skinWidth, geometryCollisionLayers, false)) // fake cylinder cast, checking for steep slopes and prevent us from thinking we're on ground if the slope is too steep
            {
                if (IsGround(groundHitinfo.normal))
                {
                    isGrounded = true;
                }
            }
        }
        bool groundParentFound = false;

        if (isGrounded)
        {
            float      amtToMoveUp = Mathf.Min(platformRisingSpeed * Time.fixedDeltaTime, riseAmount);
            RaycastHit hitinfo;
            bool       hitUp = Physics.CapsuleCast(capsuleCenter - pointDist * Vector3.down, capsuleCenter - pointDist * Vector3.up, capsuleRadius,
                                                   Vector3.up, out hitinfo, amtToMoveUp + skinWidth, geometryCollisionLayers); // cast to check if we can rise
            if (!hitUp)
            {
                AttemptSetPosition(transform.position + Vector3.up * amtToMoveUp);
            }
            else if (hitinfo.distance > skinWidth)
            {
                AttemptSetPosition(transform.position + Vector3.up * (hitinfo.distance - skinWidth));
            }
            if (groundCollider && groundCollider.gameObject.layer == MovingGeometryLayer)
            {
                MovingObject groundMovingObject = groundCollider.GetComponent <MovingObject>();
                if (groundMovingObject)
                {
                    SetGroundParent(groundMovingObject);
                    groundParentFound = true;
                }
            }
        }
        if (!groundParentFound)
        {
            ClearGroundParent();
        }
        return(true);
    }
예제 #25
0
 public void AddTarget(MovingObject newObj)
 {
     spawnedObjects++;
     objectsList.Add(newObj);
 }
예제 #26
0
파일: Character.cs 프로젝트: Aye1/Cities
 // Start is called before the first frame update
 void Start()
 {
     _moving = GetComponent <MovingObject>();
     _moving.OnObjectReached += OnObjectReached;
 }
예제 #27
0
 public void MonitorRectangle(MovingObject monitor)
 {
     monitorObject = monitor;
 }
예제 #28
0
 public HeadbuttAbility(MovingObject owner) : base(owner)
 {
 }
예제 #29
0
        // Move the desired displacement, limited by hitting an
        // obstacle.  Then, if we're not already at the terrain level,
        // "fall" until we are either at the terrain level, or hit an
        // obstacle
        public static Vector3 MoveMobNode(MobNode mobNode, Vector3 requestedDisplacement, Client client)
        {
//             Logger.Log(0, "MoveMobNode oid {0} requestedDisplacement {1}", mobNode.Oid, requestedDisplacement);
//             log.DebugFormat("MoveMobNode: mobNode oid {0}, name {1}, followTerrain {2}, position {3}, disp {4}",
//                             mobNode.Oid, mobNode.Name, mobNode.FollowTerrain, mobNode.Position, requestedDisplacement);
            Vector3      start    = mobNode.Position;
            MovingObject mo       = mobNode.Collider;
            bool         collided = false;
            // Zero the y coordinate of displacement, because it seems
            // that it can be arbitrarily large
            Vector3 desiredDisplacement = requestedDisplacement;

            if (mobNode.FollowTerrain)
            {
                desiredDisplacement.y = 0;
            }
            if (desiredDisplacement.LengthSquared <= float.Epsilon)
            {
                return(start);
            }
            if (MO.DoLog)
            {
                MO.Log("MoveMobNode called with mobNode {0} at {1}, disp of {2}",
                       mobNode.Oid, start, requestedDisplacement);
            }
            if (collisionManager == null)
            {
                log.Info("MoveMobNode: returning because collisionManager isn't initialized");
                return(start + desiredDisplacement);
            }
            if (mo == null || mo.parts.Count == 0)
            {
                if (MO.DoLog)
                {
                    MO.Log("MoveMobNode returning because no collision volume for node");
                }
                return(start + requestedDisplacement);
            }
            if (mobNode is Player && NowColliding(mo, "Testing player collision on entry"))
            {
                if (client.MillisecondsStuckBeforeGotoStuck != 0)
                {
                    if (!playerStuck)
                    {
                        stuckGotoTime = DateTime.Now.AddMilliseconds(client.MillisecondsStuckBeforeGotoStuck);
                        playerStuck   = true;
                    }
                    else if (DateTime.Now >= stuckGotoTime)
                    {
                        // We issue the goto command to move us out of the
                        // collision volume
                        client.Write("Executing /stuck command because player has been in a collision volume for " + client.MillisecondsStuckBeforeGotoStuck + " milliseconds");
                        client.NetworkHelper.SendTargettedCommand(client.Player.Oid, "/stuck");
                        playerStuck = false;
                        return(start);
                    }
                }
            }
            else
            {
                playerStuck = false;
            }
            // If we haven't completed setup to this extent, just give up
            CollisionParms parms = new CollisionParms();
            Vector3        pos   = FindMobNodeDisplacement(mobNode, parms, desiredDisplacement, out collided);
//             log.DebugFormat("MoveMobNode: mobNode oid {0}, name {1}, mob node position {2}, displacement {3}",
//                 mobNode.Oid, mobNode.Name, pos, requestedDisplacement);
            float h = worldManager.GetHeightAt(pos);

            // If we're already below ground level, just set our
            // level to ground level.  This will have to be modified
            // if we deal with caves
            if (pos.y - h < 0)
            {
//                 log.DebugFormat("MoveMobNode: mobNode oid {0}, name {1} below terrain level", mobNode.Oid, mobNode.Name);
                mo.AddDisplacement(new Vector3(0f, h - pos.y, 0f));
                pos.y = h;
                if (MO.DoLog && (pos.y - h) < -.001 * Client.OneMeter)
                {
                    MO.Log(string.Format(" MobNode at {0} is below ground height {1}!",
                                         pos, h));
                }
            } // else {
            if (mobNode.FollowTerrain)
            {
//                  NowColliding(mo, " Before falling loop");
                // Fall toward the terrain or an obstacle, whichever comes
                // first
                float step = mo.StepSize(new Vector3(0, h, 0));
                while (true)
                {
                    if (Math.Abs(pos.y - h) < CollisionAPI.VerticalTerrainThreshold * Client.OneMeter)
                    {
                        mo.AddDisplacement(new Vector3(0f, h - pos.y, 0f));
                        pos.y = h;
                        break;
                    }
                    else
                    {
                        float   dy           = -Math.Min(pos.y - h, step);
                        Vector3 displacement = new Vector3(0, dy, 0);
                        Vector3 cd           = displacement;
                        if (MO.DoLog)
                        {
                            MO.Log(" Testing for collision falling {0}", dy);
                            TraceMOBottom(mo, " Before falling");
                        }
                        if (collisionManager.TestCollision(mo, ref displacement, parms))
                        {
                            if (MO.DoLog)
                            {
                                TraceMOBottom(mo, " After TestCollision after falling");
                                NowColliding(mo, " After TestCollision after falling");
                                MO.Log(" Collision when object {0} falls from {1} to {2}",
                                       parms.part.handle, pos, pos + cd);
                                TraceObstacle(parms.obstacle);
                                MO.Log(" Adding dy {0} - displacement.y {1} to pos {2}",
                                       dy, displacement.y, pos);
                            }
                            pos.y += dy - displacement.y;
                            break;
                        }
                        if (MO.DoLog)
                        {
                            MO.Log(" Didn't collide falling; dy {0}, pos {1}",
                                   dy, pos);
                        }
                        pos.y += dy;
                    }
                }
            }
            else
            {
                if (MO.DoLog)
                {
                    MO.Log(" Not falling because mobNode {0} doesn't have FollowTerrain",
                           mobNode.Oid);
                }
            }
//          }

            if (MO.DoLog)
            {
                NowColliding(mo, " Leaving MoveMobNode");
                MO.Log("MoveMobNode returning pos {0}", pos);
                MO.Log("");
            }
            if (collided)
            {
                log.DebugFormat("MoveMobNode collided: mobNode oid {0}, name {1}, orig pos {2}, displacement {3}, new pos {4}",
                                mobNode.Oid, mobNode.Name, start, requestedDisplacement, pos);
            }
            else
            {
                log.DebugFormat("MoveMobNode didn't collide: mobNode oid {0}, name {1}, orig pos {2}, displacement {3}, new pos {4}",
                                mobNode.Oid, mobNode.Name, start, requestedDisplacement, pos);
            }
            return(pos);
        }
예제 #30
0
 /// <summary>
 /// Constructeur de base
 /// </summary>
 /// <param name="pParent"></param>
 /// <param name="pTtl"></param>
 public ShotGun(MovingObject pParent, int pTtl = 400)
     : base(pParent, pTtl)
 {
     TIME_TO_SHOOT = 2500;
     _icon         = SpriteManager.IconShotGun;
 }
예제 #31
0
 public void AddTarget(MovingObject newObj)
 {
     spawnedObjects++;
     objectsList.Add(newObj);
 }
예제 #32
0
    protected override void Update()
    {
        mainCamera.transform.position = new Vector3(
            gameObject.transform.position.x,
            gameObject.transform.position.y + cameraYOffset,
            gameObject.transform.position.z - 10);

        base.Update();

        if (isKeyRepeat)
        {
            return;
        }
        //プレイヤーの順番じゃない時Updateは実行しない
        if (!GameManager.instance.playersTurn)
        {
            return;
        }
        if (isMovingPre || isAttackingAnimation)
        {
            return;
        }
        if (GameManager.instance.MainWindow.State == MenuWindow.WindowState.Active ||
            GameManager.instance.MainWindow.State == MenuWindow.WindowState.WaitChildren)
        {
            isKeyRepeatReserve = true;
            return;
        }

        if (isKeyRepeatReserve)
        {
            isKeyRepeatReserve = false;
            StartCoroutine(KeyRepert(0.2f));
            return;
        }

        int  x        = 0;
        int  y        = 0;
        bool isAttack = false;

        SetCommand(TurnCommand.Undef);

        // メニュー呼び出し

        if (Input.GetKeyDown("x"))
        {
            MenuWindow.player = this;
            GameManager.instance.MainWindow.gameObject.SetActive(true);
            GameManager.instance.MainWindow.State = MenuWindow.WindowState.Active;
            return;
        }

        if (Input.GetKeyDown("s"))
        {
            MenuWindow.player = GameManager.instance.GetNPCList()[0];
            GameManager.instance.MainWindow.gameObject.SetActive(true);
            GameManager.instance.MainWindow.State = MenuWindow.WindowState.Active;
            return;
        }

        if (MenuWindow.Command == MenuWindow.WindowTurnCommand.UseItem)
        {
            MenuWindow.Command = MenuWindow.WindowTurnCommand.Undef;
            SetCommand(TurnCommand.UseItem);
        }
        if (MenuWindow.Command == MenuWindow.WindowTurnCommand.ThrowItem)
        {
            SetAttackLine(GetDirection() * 5);
            AnimationType      = AttackAnimationType.Throw;
            MenuWindow.Command = MenuWindow.WindowTurnCommand.Undef;
            SetCommand(TurnCommand.ThrowItem);
        }
        if (MenuWindow.Command == MenuWindow.WindowTurnCommand.PutItem)
        {
            MenuWindow.Command = MenuWindow.WindowTurnCommand.Undef;
            SetCommand(TurnCommand.PutItem);
        }
        if (MenuWindow.Command == MenuWindow.WindowTurnCommand.MoveMap)
        {
            MenuWindow.Command = MenuWindow.WindowTurnCommand.Undef;
            SetCommand(TurnCommand.MoveMap);
        }

        if (GetCommand() == TurnCommand.Undef)
        {
            // 右・左
            x = (int)Input.GetAxisRaw("Horizontal");

            // 上・下
            y = (int)Input.GetAxisRaw("Vertical");

            if (x == 0 && y == 0)
            {
                if (Input.GetKey(KeyCode.Keypad7))
                {
                    x = -1;
                    y = 1;
                }
                if (Input.GetKey(KeyCode.Keypad4))
                {
                    x = -1;
                }
                if (Input.GetKey(KeyCode.Keypad1))
                {
                    x = -1;
                    y = -1;
                }
                if (Input.GetKey(KeyCode.Keypad2))
                {
                    y = -1;
                }
                if (Input.GetKey(KeyCode.Keypad3))
                {
                    x = 1;
                    y = -1;
                }
                if (Input.GetKey(KeyCode.Keypad6))
                {
                    x = 1;
                }
                if (Input.GetKey(KeyCode.Keypad9))
                {
                    x = 1;
                    y = 1;
                }
                if (Input.GetKey(KeyCode.Keypad8))
                {
                    y = 1;
                }
            }

            //上下左右どれかに移動する時
            if (((x != 0 || y != 0) && !Input.GetKey("v")) || (x != 0 && y != 0 && Input.GetKey("v")))
            {
                SetDirection(new Vector2(x, y));
                if (Input.GetKey("c"))
                {
                    //振り向きのみ
                }
                else if (AttemptMove <Wall>(x, y))
                {
                    SetCommand(TurnCommand.Move);
                }
                else if (Input.GetKey(KeyCode.LeftShift))
                {
                    MovingObject obj = GameManager.instance.ExitstMovingObject(logicalPos + GetDirection());
                    if (obj != null)
                    {
                        NPC npc = obj.gameObject.GetComponent <NPC>();
                        if (npc != null)
                        {
                            destPos        += GetDirection();
                            npc.SwapDestPos = logicalPos;
                            SetCommand(TurnCommand.Move);
                            npc.swapFlag = true;
                        }
                    }
                }
            }
            playerAnimator.SetInteger("Direction", GetDirectionNumber());
        }

        if (GetCommand() == TurnCommand.Undef)
        {
            isAttack = Input.GetKey("z");
            if (isAttack)
            {
                SetAttackLine(GetDirection());
                AnimationType = AttackAnimationType.Normal;
                SetCommand(TurnCommand.Attack);
            }
        }

        /*
         * if (GetCommand() == TurnCommand.Undef)
         * {
         *  isAttack = Input.GetKey("f");
         *  if (isAttack)
         *  {
         *
         *      SetAttackLine(GetDirection() * 5);
         *      SetCommand(TurnCommand.CastMagic);
         *  }
         * }*/

        //プレイヤーの順番終了
        if (GetCommand() != TurnCommand.Undef)
        {
            GameManager.instance.playersTurn = false;
        }
    }
예제 #33
0
 // Specify what objects are affected by the skill
 public override List<MovingObject> GetAffectedObjects(MovingObject sourceObject)
 {
     return CombatBoardManager.Instance.GetObjectsInRange(sourceObject.X, sourceObject.Y, Range);
 }
예제 #34
0
 private void HandleLabelChanged(MovingObject obj)
 {
     label.Text = $"Life: {gamer.Lifes}  Money: {gamer.Money}";
 }
예제 #35
0
 // Specify how the skill affects the targets
 public override void SkillEffect(MovingObject sourceObject, List<MovingObject> affectedObjects)
 {
     Debug.Log(string.Format("All enemies withing {0} range took {1} damage!", Range, DamageAmount));
 }
예제 #36
0
 // Use this for initialization
 void Awake()
 {
     movingObject = GetComponent <MovingObject>();
 }
예제 #37
0
 // If there is a queued object on the tile, make it ACTUALLY on the tile
 public void SetObjectOnTile(int x, int y, MovingObject obj)
 {
     var tile = GetHexTile(x, y);
     if (tile.ObjectOnTileQueued != null)
     {
         tile.ObjectOnTile = tile.ObjectOnTileQueued;
         tile.ObjectOnTileQueued = null;
     }
 }
예제 #38
0
    // Update is called once per frame
    void Update()
    {
        if (Controllable)
        {
            movements.attacks = Attacks.NoSpell;

            RaycastHit ObjectInfront;
            float      DistanceFromEnemy = (transform.position - Target.transform.position).magnitude;

            Collider[] DangerSurrounding = Physics.OverlapSphere(transform.position, 30, 0b10000000000000000);
            Collider[] IncomingObj       = Physics.OverlapSphere(transform.position, 30, 0b1001100000000000);
            Collider[] DetectPowerUps    = Physics.OverlapSphere(transform.position, 50, 0b1000000000000000000);

            MagicShield MS = GetComponentInChildren <MagicShield>();

            if (movements.control == Control.Forward && Physics.SphereCast(new Ray(transform.position, transform.forward), 6, out ObjectInfront, 2, ~512))
            {
                movements.rotate = GoAround(ObjectInfront.transform.gameObject);
            }
            else if (DetectPowerUps.Length > 0)
            {
                Transform PowerUpTrans = DetectPowerUps[0].transform;
                Vector2   PowerUpDir   = (new Vector2(PowerUpTrans.position.x - transform.position.x, PowerUpTrans.position.z - transform.position.z)).normalized;
                movements.rotate = Alignment(PowerUpDir, this.gameObject);
                if (movements.rotate == Rotation.NoRotate)
                {
                    movements.control = Control.Forward;
                }
                else
                {
                    movements.control = Control.Still;
                }
            }
            else if (DangerSurrounding.Length > 0 || Charstats.CurrentMana < EquippedSpell.Cost || Charstats.CurrentHealth < 150)
            {
                Debug.Log(Charstats.CurrentMana + " : " + EquippedSpell.Cost);
                if (DistanceFromEnemy < 15)
                {
                    movements.rotate = RunAwayFromEnemy(Target.transform);
                }
                else if (DistanceFromEnemy >= 15)
                {
                    movements.rotate = CircleAroundEnemy(Target.transform);
                }

                foreach (Collider Danger in DangerSurrounding)
                {
                    movements.rotate = RunAwayFromEnemy(Danger.gameObject.transform);
                }

                movements.control = Control.Forward;
            }
            else if (IncomingObj.Length > 0)
            {
                foreach (Collider IncObj in IncomingObj)
                {
                    MovingObject spellObj    = IncObj.GetComponent <MovingObject>();
                    HomingObj    homingSpell = IncObj.GetComponent <HomingObj>();
                    if (spellObj != null && spellObj.CasterName == this.gameObject.name)
                    {
                        continue;
                    }
                    if (homingSpell != null && homingSpell.Caster == this.gameObject.name)
                    {
                        continue;
                    }
                    switch (IncObj.gameObject.layer)
                    {
                    case 11:
                        if (DefensiveSpells[1].currentCoolDown < DefensiveSpells[1].Cooldown && movements.IsDoneAnimatingAttack())
                        {
                            defensives.defense = AvoidMissiles(IncObj.gameObject);
                        }
                        else if (MS == null || (MS != null && MS.gameObject.layer != 14))
                        {
                            EquippedSpell = DefensiveSpells[1];
                            CastSpell();
                        }
                        break;

                    case 12:
                        if (DefensiveSpells[0].currentCoolDown < DefensiveSpells[0].Cooldown && movements.IsDoneAnimatingAttack())
                        {
                            defensives.defense = AvoidMissiles(IncObj.gameObject);
                        }
                        else if (MS == null || (MS != null && MS.gameObject.layer != 13))
                        {
                            EquippedSpell = DefensiveSpells[0];
                            CastSpell();
                        }
                        break;

                    case 15:
                        if (movements.IsDoneAnimatingAttack())
                        {
                            defensives.defense = AvoidMissiles(IncObj.gameObject);
                        }
                        break;
                    }
                }
            }
            else if (animator.GetCurrentAnimatorClipInfo(3).Length == 0)
            {
                Vector2 EnemyDir = (new Vector2(Target.transform.position.x - transform.position.x, Target.transform.position.z - transform.position.z)).normalized;
                movements.rotate = Alignment(EnemyDir, Aim);
                GameObject Obstacle = null;

                if (DistanceFromEnemy < 15 && Spells[2].currentCoolDown >= Spells[2].Cooldown)
                {
                    EquippedSpell = Spells[2];
                    CastSpell();
                }
                else if (movements.rotate == Rotation.NoRotate)
                {
                    Vector2    EnemyFacingVec   = (new Vector2(Target.transform.forward.x, Target.transform.forward.z)).normalized;
                    float      EnemyFacingAngle = Mathf.Acos(Vector2.Dot(EnemyDir, EnemyFacingVec));
                    Vector3    RayDir           = (new Vector3(Target.transform.position.x - Aim.transform.position.x, 0, Target.transform.position.z - Aim.transform.position.z)).normalized;
                    RaycastHit Rayhit;

                    Debug.DrawRay(Aim.transform.position, RayDir * 40f);

                    if (Physics.Raycast(new Ray(Aim.transform.position + Aim.transform.right / 2, RayDir), out Rayhit, 40f, 0b100000000000000000))
                    {
                        Obstacle = Rayhit.transform.gameObject;
                    }
                    else if (EnemyFacingAngle < Mathf.PI * .4f)
                    {
                        if (Spells[4].currentCoolDown >= Spells[4].Cooldown)
                        {
                            EquippedSpell = Spells[4];
                            EquippedSpell.CastAtPosition = Target.transform.position;
                            CastSpell();
                        }
                        else
                        {
                            EquippedSpell = Spells[3];
                            CastSpell();
                        }
                    }
                    else
                    {
                        EquippedSpell = Spells[1];
                        CastSpell();
                    }
                }

                if (Obstacle != null)
                {
                    movements.control = AvoidObstacle(Obstacle);
                }
                else if (DistanceFromEnemy < 30)
                {
                    movements.control = Control.Backward;
                }
                else if (DistanceFromEnemy > 40)
                {
                    movements.control = Control.Forward;
                }
                else
                {
                    movements.control = Control.Still;
                }
            }
        }
        else
        {
            movements.control  = Control.Still;
            movements.rotate   = Rotation.NoRotate;
            movements.attacks  = Attacks.NoSpell;
            defensives.defense = Defensive.NotDefensive;
        }

        foreach (AbstractSpell AS in Spells)
        {
            AS.UpdateCoolDown();
        }
        foreach (AbstractSpell AS in DefensiveSpells)
        {
            if (AS.GlobalCoolDown)
            {
                foreach (AbstractSpell DS in DefensiveSpells)
                {
                    DS.currentCoolDown = 0;
                }
                AS.GlobalCoolDown = false;
                break;
            }
            AS.UpdateCoolDown();
        }
    }
예제 #39
0
        // We only call this if both the collisionManager and the collider exist
        private static Vector3 FindMobNodeDisplacement(MobNode mobNode, CollisionParms parms, Vector3 desiredDisplacement, out bool collided)
        {
            Vector3      start        = mobNode.Position;
            Vector3      pos          = start + desiredDisplacement;
            Vector3      displacement = desiredDisplacement;
            MovingObject mo           = mobNode.Collider;
            Vector3      moStart      = mo.parts[0].shape.center;

            if (MO.DoLog)
            {
                MO.Log(" moStart = {0}, start = {1}", moStart, start);
                MO.Log(" pos = {0}, displacement = {1}", pos, displacement);
                TraceMOBottom(mo, " On entry to FindMobNodeDisplacement");
            }
            collided = false;
            if (collisionManager.TestCollision(mo, ref displacement, parms))
            {
                collided = true;
                if (MO.DoLog)
                {
                    MO.Log(" Collision when moving object {0} from {1} to {2}",
                           parms.part.handle, start, pos);
                    NowColliding(mo, " After first TestCollision in FindMobNodeDisplacement");
                    TraceObstacle(parms.obstacle);
                    MO.Log(" Before collision moved {0}", desiredDisplacement - displacement);
                }
                // Decide if the normals are such that we want
                // to slide along the obstacle
                Vector3 remainingDisplacement = displacement;
                Vector3 norm1 = parms.normObstacle.ToNormalized();
                if (DecideToSlide(mo, start + displacement, parms, ref remainingDisplacement))
                {
                    if (MO.DoLog)
                    {
                        MO.Log(" After DecideToSlide, remainingDisplacement {0}", remainingDisplacement);
                    }
                    // We have to test the displacement
                    if (collisionManager.TestCollision(mo, ref remainingDisplacement, parms))
                    {
                        if (MO.DoLog)
                        {
                            NowColliding(mo, " After first try TestCollision");
                            MO.Log(" Slid into obstacle on the first try; remainingDisplacement = {0}",
                                   remainingDisplacement);
                            TraceObstacle(parms.obstacle);
                        }
                        if (remainingDisplacement.LengthSquared > 0)
                        {
                            Vector3 norm2 = parms.normObstacle.ToNormalized();
                            // Find the cross product of the of norm1 and
                            // norm2, and dot with displacement.  If
                            // negative, reverse.
                            Vector3 newDir = norm1.Cross(norm2);
                            float   len    = newDir.Dot(remainingDisplacement);
                            if (len < 0)
                            {
                                newDir = -newDir;
                                len    = -len;
                            }
                            Vector3 slidingDisplacement         = len * newDir;
                            Vector3 originalSlidingDisplacement = slidingDisplacement;
                            if (MO.DoLog)
                            {
                                MO.Log(" norm1 = {0}, norm2 = {1}, len = {2}",
                                       norm1, norm2, len);
                                MO.Log(" Cross product slidingDisplacement is {0}", slidingDisplacement);
                            }
                            if (collisionManager.TestCollision(mo, ref slidingDisplacement, parms))
                            {
                                if (MO.DoLog)
                                {
                                    NowColliding(mo, " After second try TestCollision");
                                    MO.Log(" Slid into obstacle on the second try; slidingDisplacement = {0}",
                                           slidingDisplacement);
                                }
                            }
                            else
                            if (MO.DoLog)
                            {
                                MO.Log(" Didn't slide into obstacle on the second try");
                            }
                            remainingDisplacement -= (originalSlidingDisplacement - slidingDisplacement);
                        }
                    }
                }
                else
                {
                    remainingDisplacement = displacement;
                }
                if (MO.DoLog)
                {
                    MO.Log(" Before checking hop, remainingDisplacement is {0}", remainingDisplacement);
                }
                if (remainingDisplacement.Length > 30f)
                {
                    // Try to hop over the obstacle
                    Vector3 c = remainingDisplacement;
                    mo.AddDisplacement(new Vector3(0f, CollisionAPI.HopOverThreshold * Client.OneMeter, 0f));
                    if (MO.DoLog)
                    {
                        TraceMOBottom(mo, " Before trying to hop");
                        MO.Log(" remainingDisplacement {0}", remainingDisplacement);
                    }
                    if (collisionManager.TestCollision(mo, ref remainingDisplacement, parms))
                    {
                        if (MO.DoLog)
                        {
                            MO.Log(" Even after hopping up {0} meters, can't get over obstacle; disp {1}",
                                   CollisionAPI.HopOverThreshold, remainingDisplacement);
                        }
                        c   = c - remainingDisplacement;
                        c.y = 0;
                        c  += new Vector3(0f, CollisionAPI.HopOverThreshold * Client.OneMeter, 0f);
                        if (MO.DoLog)
                        {
                            MO.Log(" After failed hop, subtracting {0}", c);
                        }
                        mo.AddDisplacement(-c);
                    }
                    else if (MO.DoLog)
                    {
                        MO.Log(" Hopping up {0} meters got us over obstacle; disp {1}",
                               CollisionAPI.HopOverThreshold, remainingDisplacement);
                        TraceMOBottom(mo, " After hopping");
                    }
                    NowColliding(mo, " After hopping");
                }
            }
            Vector3 moPos = mo.parts[0].shape.center;

            pos = start + moPos - moStart;
            if (MO.DoLog)
            {
                MO.Log(" mo location = {0}, moPos - moStart {1}", moPos, moPos - moStart);
                NowColliding(mo, " Leaving FindMobNodeDisplacement");
                MO.Log(" pos = {0}", pos);
            }
            return(pos);
        }
예제 #40
0
 public override bool SetMovingObject(MovingObject movingObject)
 {
     return(false);
 }
예제 #41
0
        // Create object in room upon user click
        private void MakeSpaceObject(string texName, Image tex, DrawPoint mp)
        {
            texName = texName.Replace(".png", "");

            string[] lastname_ary= (string[])texName.Split('\\');
            string lastname = lastname_ary[lastname_ary.Length-1];

            string texStripName = texName.Replace(lastname,"strips\\"+lastname) + "_strip";

            //int numberOfFrames = SpaceObject.GetNumberOfFrames(texName);

            Vector2 screenposition = Conversion.DrawPointToVector2(mp);
            Vector2 gameposition = new Vector2(screenposition.X / CASSWorld.SCALE, screenposition.Y / CASSWorld.SCALE);

            if (rb_AnimationObjects.Checked)
            {
                AnimationObject ao;
                // TODO : i'm not a fan of these ifs, since the only thing that's changing are those last two numbers
                //        having to do with the animation. is there a way they could be passed in, or even better,
                //        derived from the strip image?
                if (lastname == "fan")
                    ao = new AnimationObject(world.World, texStripName, texName, tex.Width, tex.Height, 20, 7);
                else if (lastname == "broken_platform")
                    ao = new AnimationObject(world.World, texStripName, texName, tex.Width, tex.Height, 20, 8);
                else if (lastname == "light" || lastname == "fire")
                {
                    ao = new AnimationObject(world.World, texStripName, texName, tex.Width, tex.Height, 20, 8,false, false);
                    //ao.RemoveFromWorld();
                    //world.World.DestroyBody(ao.Body);
                }
                else if (lastname == "rollingpin")
                {
                    ao = new AnimationObject(world.World, texStripName, texName, tex.Width, tex.Height, 20, 8, true, true);
                }
                else
                {
                    ao = new AnimationObject(world.World, texStripName, texName, tex.Width, tex.Height, 20, 8);
                }
                ao.Position = gameposition;
                world.AddObject(ao);
            }
            else if (rb_BoxObjects.Checked)
            {
                BoxObject bo;
                bo = new BoxObject(world.World, texName, 0, .5f, 0, 1, false);
                bo.Position = gameposition;
                world.AddObject(bo);
            }
            else if (rb_CircleObjects.Checked)
            {
                CircleObject co;
                co = new CircleObject(world.World, texName, 1, .5f, 0, 1);
                co.Position = gameposition;
                world.AddObject(co);
            }
            else if (rb_WinDoorObject.Checked)
            {
                WinDoorObject so;
                // HACK - hard-coded for the win-door
                so = new WinDoorObject(world.World, texStripName, texName, tex.Width, tex.Height, 20, 5);
                so.Position = gameposition;
                world.AddObject(so);
            }
            else if (rb_PistonObject.Checked)
            {
                PistonObject po;
                Console.WriteLine("{0}", gameposition);
                po = new PistonObject(world.World, .5f, .5f, 12f, 13f, 9.7f, 12.6f, .01f, .1f, gameposition);
                po.Position = gameposition;
                world.AddObject(po);
            }
            else if(rb_SeeSawObject.Checked)
            {
                SeeSawObject ss;
                ss = new SeeSawObject(world.World, texName, 1.5f, gameposition);
                ss.Position = gameposition;
                world.AddObject(ss);

            }
            else if (rb_SwitchObject.Checked)
            {
                SwitchObject ss1;
             //       ss1 = new SwitchObject(world.World, "Art\\Objects\\SwitchObjects\\button_strip","Art\\Objects\\SwitchObjects\\button", 181, 84, 20, 2);
                //brokenMovingPlatform1 = new SwitchObject(World, "broken_strip", "broken_moving_platform", 89, 32, 20, 8);
             //       ss1.Position = gameposition;
              //  world.AddObject(ss1);

                if (lastname == "button")
                {
                    ss1 = new SwitchObject(world.World, "Art\\Objects\\SwitchObjects\\button_strip", "Art\\Objects\\SwitchObjects\\button", 181, 84, 20, 2);

                    ss1.Position = gameposition;
                    world.AddObject(ss1);
                }
                else if (lastname == "death")
                {

                    DeathPlatform ss2;
                    ss2 = new DeathPlatform(world.World, "Art\\Objects\\SwitchObjects\\button_death_strip", "Art\\Objects\\SwitchObjects\\death", 181, 84, 20, 2);

                    //brokenMovingPlatform1 = new SwitchObject(World, "broken_strip", "broken_moving_platform", 89, 32, 20, 8);
                    ss2.Position = gameposition;
                    world.AddObject(ss2);
                }
                else
                {
                    FailButtonObject ss2;
                    ss2 = new FailButtonObject(world.World, "Art\\Objects\\SwitchObjects\\button_strip", "Art\\Objects\\SwitchObjects\\fail_button", 181, 84, 20, 2);

                    //brokenMovingPlatform1 = new SwitchObject(World, "broken_strip", "broken_moving_platform", 89, 32, 20, 8);
                    ss2.Position = gameposition;
                    world.AddObject(ss2);
                }

            }
            else if (rb_HoleObject.Checked)
            {
                HoleObject ss;
                ss = new HoleObject(world.World, "Art\\Objects\\HoleObjects\\hole_strip", "Art\\Objects\\HoleObjects\\hole");
                //hole1 = new HoleObject(World, "Art\\Objects\\HoleObjects\\hole_strip", "Art\\Objects\\HoleObjects\\hole");
                ss.Position = gameposition;
                world.AddObject(ss);

            }
            else if (rb_MovingPlatform.Checked)
            {
                MovingObject ss;
              //  ss = new MovingObject(world.World, "Art\\Objects\\MovingPlatformObjects\\moving_platform", 1000, 0.5f, 0, 1, false, null, new Vector2(0, -11500), 4.5f, 14.2f);
               // movPlatform1 = new MovingObject(World, "moving platform", 1000f, .5f, 0, 1, false, brokenMovingPlatform1, new Vector2(0, -11500), 4.5f, 14.2f);
               // ss.Position = gameposition;
              //  world.AddObject(ss);

                if (lastname == "moving_platform")
                    ss = new MovingObject(world.World, "Art\\Objects\\MovingPlatformObjects\\moving_platform", 0, 0.5f, 0, 1, false, null, new Vector2(0, -11500), 4.5f, 14.2f);
                else if (lastname == "gate")
                {
                    SwitchObject ssfine;
                    ssfine = new SwitchObject(world.World, "Art\\Objects\\SwitchObjects\\button_strip", "Art\\Objects\\SwitchObjects\\button", 181, 84, 20, 2);
                    ss = new MovingObject(world.World, "Art\\Objects\\MovingPlatformObjects\\gate", 0, 0.5f, 0, 1, false, ssfine, new Vector2(0, -11500), 4.5f, 14.2f);
                    //brokenMovingPlatform1 = new SwitchObject(World, "broken_strip", "broken_moving_platform", 89, 32, 20, 8);
                    ssfine.Position = gameposition;
                    world.AddObject(ssfine);
                }
                else
                {

                    SwitchObject ss1;
                    ss1 = new SwitchObject(world.World, "Art\\Objects\\SwitchObjects\\button_strip", "Art\\Objects\\SwitchObjects\\button", 181, 84, 20, 2);
                    ss = new MovingObject(world.World, "Art\\Objects\\MovingPlatformObjects\\switchmoving_platform", 0, 0.5f, 0, 1, false, ss1, new Vector2(0, -11500), 4.5f, 14.2f);
                    //brokenMovingPlatform1 = new SwitchObject(World, "broken_strip", "broken_moving_platform", 89, 32, 20, 8);
                    ss1.Position = gameposition;
                    world.AddObject(ss1);
                }

                ss.Position = gameposition;
                world.AddObject(ss);

            }
            else if (rb_HorizontalMovingPlatform.Checked)
            {
                HorizontalMovingObject ss;
              //  ss = new HorizontalMovingObject(world.World, "Art\\Objects\\HorizontalMovingPlatformObjects\\moving_platform", 0, 0.5f, 0, 1, false, null, new Vector2(0, -11500), 4.5f, 14.2f);
               // movPlatform2 = new HorizontalMovingObject(World, "Art\\Objects\\HorizontalMovingPlatformObjects\\moving_platform", 0f, 0.5f, 0, 1, false, null, new Vector2(0, -11500), 32f, 38f);

                if (lastname == "moving_platform")
                    ss = new HorizontalMovingObject(world.World, "Art\\Objects\\HorizontalMovingPlatformObjects\\moving_platform", 0, 0.5f, 0, 1, false, null, new Vector2(0, -11500), 4.5f, 14.2f);
                else
                {

                    SwitchObject ss1;
                    ss1 = new SwitchObject(world.World, "Art\\Objects\\SwitchObjects\\button_strip", "Art\\Objects\\SwitchObjects\\button", 181, 84, 20, 2);
                    ss = new HorizontalMovingObject(world.World, "Art\\Objects\\HorizontalMovingPlatformObjects\\switchmoving_platform", 0, 0.5f, 0, 1, false, ss1, new Vector2(0, -11500), 4.5f, 14.2f);
                    //brokenMovingPlatform1 = new SwitchObject(World, "broken_strip", "broken_moving_platform", 89, 32, 20, 8);
                    ss1.Position = gameposition;
                    world.AddObject(ss1);
                }

                ss.Position = gameposition;
                world.AddObject(ss);

            }
            else if (rb_PaintedObjects.Checked)
            {
                switch (lastname)
                {
                    case "block_long":
                        InstasteelObject io;
                        io = new InstasteelObject(world.World, texName, 580, 1, .5f, 0, 1, false);
                        io.Position = gameposition;
                        world.AddObject(io);
                        break;
                    case "disk_long":
                        InstasteelCircleObject ico;
                        ico = new InstasteelCircleObject(world.World, texName, 480, 1, .5f, 0, 1);
                        ico.Position = gameposition;
                        world.AddObject(ico);
                        break;
                    case "line_long":
                        InstasteelObject ilo;
                        ilo = new InstasteelObject(world.World, texName, 190, 1, .5f, 0, 1, false);
                        ilo.Position = gameposition;
                        world.AddObject(ilo);
                        break;
                    default:
                        break;
                }
            }
                /*
            else if (rb_PaintedObjects.Checked)
            {
                PaintedObject po;
                List<Vector2> blobs = new List<Vector2>();
                float radius;
                float sidelength;
                Vector2 centeroff;
                switch (lastname)
                {
                    case "line_short":
                        float linelength_short = (30f/60f) * 1.2f;
                        blobs.Add(gameposition + new Vector2(linelength_short/2f, 0f));
                        blobs.Add(gameposition + new Vector2(-linelength_short/2f, 0f));
                        centeroff = new Vector2(0,0);
                        break;
                    case "line":
                        float linelength = 1.2f;
                        blobs.Add(gameposition + new Vector2(linelength/2, 0f));
                        blobs.Add(gameposition + new Vector2(-linelength/2f, 0f));
                        centeroff = new Vector2(0,0);
                        break;
                    case "line_long":
                        float linelength_long = (200f/60f) * 1.2f;
                        blobs.Add(gameposition + new Vector2(linelength_long/2f, 0f));
                        blobs.Add(gameposition + new Vector2(-linelength_long/2f, 0f));
                        centeroff = new Vector2(0,0);
                        break;
                    case "disk_short":
                        radius =  (30f/60f) *0.6f;
                        blobs = paintedCircle(radius, gameposition); // radius of 0.6f
                        centeroff = -1 * new Vector2(radius, radius);
                        centeroff = new Vector2(0,0);
                        break;
                    case "disk_small":
                        radius =  (40f/60f) *0.6f;
                        blobs = paintedCircle(radius, gameposition); // radius of 0.6f
                        centeroff = -1 * new Vector2(radius, radius);
                        centeroff = new Vector2(0,0);
                        break;
                    case "disk":
                        radius =  0.6f;
                        blobs = paintedCircle(radius, gameposition); // radius of 0.6f
                        centeroff = -1 * new Vector2(radius, radius);
                        centeroff = new Vector2(0,0);
                        break;
                    case "disk_long":
                        radius =  (150f/60f) * 0.6f;
                        blobs = paintedCircle(radius, gameposition); // radius of 0.6f
                        centeroff = -1 * new Vector2(radius, radius);
                        centeroff = new Vector2(0,0);
                        break;
                    case "block_short":
                        sidelength =  (30f/60f) *0.6f;
                        blobs = paintedSquare((30f/60f) * 1.2f, gameposition); // sidelength of 1.2f
                        centeroff = -1 * new Vector2(sidelength, sidelength);
                        break;
                    case "block_small":
                        sidelength =  (40f/60f) *0.6f;
                        blobs = paintedSquare((40f/60f) * 1.2f, gameposition); // sidelength of 1.2f
                        centeroff = -1 * new Vector2(sidelength, sidelength);
                        break;
                    case "block":
                        sidelength =  0.6f;
                        blobs = paintedSquare(1.2f, gameposition); // sidelength of 1.2f
                        centeroff = -1 * new Vector2(sidelength, sidelength);
                        break;
                    case "block_long":
                        sidelength =  (150f/60f) * 0.6f;
                        blobs = paintedSquare((150f/60f) * 1.2f, gameposition); // sidelength of 1.2f
                        centeroff = -1 * new Vector2(sidelength, sidelength);
                        break;
                    default:
                        blobs.Add(gameposition + new Vector2(0.6f, 0f));
                        blobs.Add(gameposition + new Vector2(-0.6f, 0f));
                        centeroff = new Vector2(0,0);
                        break;
                }
                po = new PaintedObject(world.World, "paint", "paintedsegment", blobs);
                po.TextureFilename = "Art\\Objects\\PaintedObjects\\" + lastname;
                po.Position = gameposition + centeroff;
                world.AddObject(po);
            }
            */
            else if (rb_BackgroundObjects.Checked)
            {
                BackgroundObject bo;
                bo = new BackgroundObject(world.World, world, texName,gameposition);
                bo.Position = gameposition;
                world.AddObject(bo);

            }

                /*
            else if (rb_Player.Checked)
            {
                mp.X -= (int)((texture.Width * Constants.PLAYER_SCALE) / 2);
                mp.Y -= (int)((texture.Height * Constants.PLAYER_SCALE) / 2);

                world.player = new Player(
                    Conversion.DrawPointToVector2(mp),
                    currdir + "\\" + texName + ".tri"
                    );

                world.CurrentRoom = currentlySelectedRoom;
                world.player.TextureName = texName;
            }
            */
        }
예제 #42
0
 void Start()
 {
     movingObject       = FindObjectOfType <MovingObject>();
     startAngle         = this.transform.eulerAngles.x;
     transform.position = new Vector3(2.29f, 15.15f, -23.84f);
 }
예제 #43
0
        public TileCamera(TileMap gameMap, MovingObject montior,  int width, int height, int startRow = 0, int startCol = 0)
        {
            scrollLock = ScrollLock.unlocked;
            this.map = gameMap;
            controller = this;
            Width = width;
            Height = height;

            minRowToStartDraw = 0;
            minColToStartDraw = 0;

            StartRow = (startRow < 0) ? 0 : startRow;
            StartCol = (startCol < 0) ? 0 : startCol;

            maxCol = (gameMap.Width - Width) / gameMap[0, 0].Width;
            maxCol = (maxCol < 0) ? 0 : maxCol;

            maxRow = (gameMap.Height - Height) / gameMap[0, 0].Height;
            maxRow = (maxRow < 0) ? 0 : maxRow;

            currentMaxCol = maxCol;
            currentMinCol = minColToStartDraw;

            currentMaxRow = maxRow;
            currentMinRow = minRowToStartDraw;

            horizontalScrollPoint = new Vector2(0, width);
            verticalScrollPoint = new Vector2(0, height);

            maxRowsToDraw = GetMaxRows(gameMap as ITileMap);
            maxColToDraw = GetMaxCols(gameMap as ITileMap);
            MonitorRectangle(montior);
            tk = new TimeKeeper();
            timer = new ObjectTimer("mili", 400, true);
            _vScrolling = _hscrolling = false;
        }
예제 #44
0
 public MovingDirect(MovingObject pParent)
     : base(pParent)
 {
     _accelFactor = 0.5f;
 }
예제 #45
0
 public FollowController(MovingObject pTargetShip)
 {
     TargetShip = pTargetShip;
 }
예제 #46
0
 public MovingBase(MovingObject pParent)
 {
     _parent = pParent;
 }
예제 #47
0
 void Start()
 {
     if (isEnemy)
     {
         parent = transform.GetComponent<Enemy>();
     }
     else
     {
         parent = transform.GetComponent<Player>();
     }
 }
예제 #48
0
    IEnumerator CalculatePearson()
    {
        while (!_shouldStop)
        {
            _pearsonIsRunning = true;

            TimeSpan calcStart = new TimeSpan();
            calcStart = PupilGazeTracker.Instance._globalTime;

            List <MovingObject> _tempObjects = new List <MovingObject>();

            // work with copies to (hopefully) improve performance
            _cloningInProgress = true;
            foreach (MovingObject mo in sceneObjects)
            {
                _tempObjects.Add((MovingObject)mo.Clone());                                       //
            }
            MovingObject _tempGaze = (MovingObject)gazeTrajectory.Clone();
            _cloningInProgress = false;

            List <double> _tempXPgaze = new List <double>(_tempGaze.getXPoints());
            List <double> _tempYPgaze = new List <double>(_tempGaze.getYPoints());

            List <float> results = new List <float>();

            foreach (MovingObject mo in _tempObjects)
            {
                // temporary list for not having to generate a new one at every loop
                List <double> _tempXPObj = new List <double>(mo.getXPoints());
                List <double> _tempYPObj = new List <double>(mo.getYPoints());

                // surround calculation with try/catch block or else coroutine will end if something is divided by zero
                try
                {
                    double coeffX = Pearson.calculatePearson(_tempXPgaze, _tempXPObj);
                    double coeffY = Pearson.calculatePearson(_tempYPgaze, _tempYPObj);

                    // in cases where an object only moves along one axis, replace NaN with 0
                    if (double.IsNaN(coeffX))
                    {
                        coeffX = 0;
                    }
                    if (double.IsNaN(coeffY))
                    {
                        coeffY = 0;
                    }

                    // add result to the original list
                    results.Add((float)sceneObjects.Find(x => x.Equals(mo)).addSample(calcStart, (coeffX + coeffY) / 2, corrWindow));

                    correlationWriter.WriteLine(mo.name + ";" + calcStart.TotalSeconds + ";" + coeffX + ";" + coeffY + ";" + w + ";" + corrWindow + ";" + corrFrequency + ";" + Coefficient + ";" + Gaze);
                }
                catch (Exception e)
                {
                    Debug.LogError("Out of bounds:" + e.StackTrace);
                }
            }

            //activate only one item at a time
            for (int i = 0; i < results.Count; i++)
            {
                // activate the object with the highest correlation value only if it's above pearsonThreshold
                if (results[i].CompareTo(results.Max()) == 0 && results[i] > threshold / 2)
                {
                    _tempObjects[i].activate(true); //doesn't matter if original or clone list is used as both refer to the same GameObject
                }
                else
                {
                    _tempObjects[i].activate(false);
                }
            }

            calcDur = PupilGazeTracker.Instance._globalTime - calcStart;

            yield return(new WaitForSeconds(corrFrequency - (float)calcDur.TotalSeconds)); // calculation should take place every x seconds
        }
    }
예제 #49
0
 public void deleteChar()
 {
     Debug.Log("deleted "+character.tag);
     character = null;
 }
예제 #50
0
    // Update is called once per frame
    void Update()
    {
        if (start_game && !game_over)
        {
            updateTime();
            if (!object_exists)
            {
                int rand = UnityEngine.Random.Range(0, NUMBER_OF_ITEMS);
                switch (rand)
                {
                case 0:
                    moving = new MovingFence(movingItems[0]);
                    break;

                case 1:
                    moving = new MovingWallE(movingItems[1]);
                    break;

                case 2:
                    moving = new MovingElephant(movingItems[2]);
                    break;

                default:
                    moving = new MovingFence(movingItems[0]);
                    break;
                }
                object_exists = true;
            }

            moving.CurrentObject.transform.Translate(Vector3.back * Time.deltaTime * moving.Speed, Space.World);

            if (object_exists && moving.offBounds())
            {
                moving.CurrentObject.transform.parent = null;
                Destroy(moving.CurrentObject);
                object_exists = false;
            }
        }

        if (object_exists)
        {
            if (moving.CurrentObject.transform.position.z <= LeftHand_BallManager.points[0].z)           //// need right hand too ////////////////
            {
                if (LeftHand_BallManager.ball.Ball_Object.GetComponent <Rigidbody>())
                {
                    Destroy(LeftHand_BallManager.ball.Ball_Object);
                }
                gameOver();
            }
        }

        if (tut_timer)
        {
            int curr_timer = (int)(3 - (Mathf.Floor(Time.realtimeSinceStartup - current_time_tut)));
            if (current_tut_num == 4)
            {
                timer_text_count.GetComponent <TextMesh>().text = "Good Job! tutorial is finished.";
            }
            else
            {
                timer_text_count.GetComponent <TextMesh>().text = "Well done! Next tutorial in : " + curr_timer;
            }
            if (current_time_tut + 3f < Time.realtimeSinceStartup)
            {
                timer_text_count.GetComponent <TextMesh>().text = "";
            }
            if (current_time_tut + 4f < Time.realtimeSinceStartup)
            {
                tut_timer = false;
                startTutorial(current_tut_num);
            }
        }
    }
예제 #51
0
 //Call this to add the passed in Enemy to the List of Enemy objects.
 public void AddEnemyToList(MovingObject script)
 {
     //Add Enemy to List enemies.
     enemies.Add(script);
 }
예제 #52
0
        // Decide, based on the normal to the collision object, if the
        // moving object can slide across the obstacle, and if it can,
        // return the updated displacement.  This displacement may in fact
        // run into _another_ obstacle, however, so the call must again
        // run the collision test.
        private static bool DecideToSlide(MovingObject mo, Vector3 mobNodePosition,
                                          CollisionParms parms, ref Vector3 displacement)
        {
            Vector3 normDisplacement = displacement.ToNormalized();
            Vector3 normObstacle     = parms.normObstacle.ToNormalized();

            if (MO.DoLog)
            {
                MO.Log(" DecideToSlide: normObstacle {0}, normDisplacement {1}",
                       normObstacle.ToString(), normDisplacement.ToString());
                MO.Log(" DecideToSlide: displacement {0}", displacement);
            }
            // First we find the angle between the normal and the
            // direction of travel, and reject the displacement if
            // it's too small
            float slideAngle = (NormalizeAngle((float)Math.Acos((double)normDisplacement.Dot(normObstacle))) -
                                .5f * (float)Math.PI);

            if (Math.Abs(slideAngle) > CollisionAPI.MinSlideAngle)
            {
                if (MO.DoLog)
                {
                    MO.Log(" After collision, displacement {0}, won't slide because slideAngle {1} > minSlideAngle {2}",
                           displacement.ToString(), slideAngle, CollisionAPI.MinSlideAngle);
                }
                displacement = Vector3.Zero;
                return(false);
            }
            // Then we find the angle with the y axis, and reject the
            // displacement if it's too steep
            float verticalAngle = NormalizeAngle((float)Math.Acos((double)normDisplacement[1]));

            if (Math.Abs(verticalAngle) > CollisionAPI.MaxVerticalAngle)
            {
                if (MO.DoLog)
                {
                    MO.Log(" After collision, displacement {0}, won't slide because verticalAngle {1} <= maxVerticalAngle {2}",
                           displacement.ToString(), verticalAngle, CollisionAPI.MaxVerticalAngle);
                }
                displacement = Vector3.Zero;
                return(false);
            }
            // Else, we can slide, so return a displacement that
            // points in the direction we're sliding, and has length
            // equal to a constant times the displacement length

            // Rotate displacement so that it's 90 degress from the
            // obstacle normal
            Vector3    cross           = normObstacle.Cross(normDisplacement);
            Quaternion q               = Quaternion.FromAngleAxis(.5f * (float)Math.PI, cross);
            Matrix4    transform       = q.ToRotationMatrix();
            Vector3    transformedNorm = transform * normObstacle.ToNormalized();
            float      len             = displacement.Length;

            displacement = transformedNorm * len;
//          Vector3 alignedPart = normObstacle * (normObstacle.Dot(displacement));
//          displacement -= alignedPart;

            Vector3 p = mobNodePosition + displacement;
            float   h = worldManager.GetHeightAt(p);

            // If sliding would put us below ground, limit the displacement
            if (h > p.y)
            {
                if (MO.DoLog)
                {
                    MO.Log(" Sliding up because terrain height is {0} is higher than projected mobNode height {1}",
                           h, p.y);
                }
                displacement.y += h - p.y;
            }
            if (MO.DoLog)
            {
                MO.Log(" Exiting DecideToSlide, sliding displacement {0}, slideAngle {1},  verticalAngle {2}",
                       displacement.ToString(), slideAngle, verticalAngle);
                MO.Log(" Exiting DecideToSlide, cross product {0}, quaternion {1}, transformedNorm {2}",
                       cross, q, transformedNorm);
//              MO.Log(" Exiting DecideToSlide, alignedPart {0}", alignedPart);
            }
            return(true);
        }
예제 #53
0
 private void HandleTankCreated(MovingObject obj)
 {
     AddChild(obj);
     tanks.Add(obj);
 }
예제 #54
0
 public AstShield(MovingObject pParent)
     : base(pParent)
 {
 }
 private GameObject GetCollidedObject(MovingObject obj)
 {
     return GetCollidedObject(obj, obj.Direction);
 }
예제 #56
0
 private void HandleExplosion(MovingObject obj)
 {
     AddChild(new CCParticleExplosion(obj.Position));
 }
예제 #57
0
 public NoShield(MovingObject pParent, Boolean pWeapon = false)
 {
     _parent = pParent;
     _weapon = pWeapon;
     _wallsTouched = new List< Wall>();
 }
예제 #58
0
    void Update()
    {
        if (Input.touches.Length > 0 && !LevelManager.solved && !LevelManager.paused && !MovingObject.getIsMoving())
        {
            Touch        touch           = Input.GetTouch(0);
            Vector3      screenPoint     = new Vector3(touch.position.x, touch.position.y, -Camera.main.transform.position.z);
            Vector3      touchPosWorld   = Camera.main.ScreenToWorldPoint(screenPoint);
            Vector2      touchPosWorld2D = new Vector2(touchPosWorld.x, touchPosWorld.y);
            RaycastHit2D hitInformation  = Physics2D.Raycast(touchPosWorld2D, Camera.main.transform.forward);

            // Selected object has not been set (could add highlighter here)
            if (selectedObj == null && hitInformation.collider != null)
            {
                selectedObj = hitInformation.transform.gameObject;
                // Held Swipe Effect
                // selectedObj.transform.localScale = LevelUtility.calculateShipTouchScaleSize();
            }

            // Detect swipe direction
            if (touch.phase == TouchPhase.Began)
            {
                startPos = touch.position;
            }
            if (touch.phase == TouchPhase.Ended)
            {
                endPos = touch.position;
            }

            // Held Swipe Effect
            Vector2 heldSwipe = new Vector3(touch.position.x - startPos.x, touch.position.y - startPos.y);
            if (selectedObj != null && heldSwipe.magnitude >= minSwipeLength)
            {
                Swipe direction = getSwipeDirection(heldSwipe);
                MovingObject.setSwipeDirection(direction);
                MovingObject.setPosition(selectedObj.transform.position);
                MovingObject.setObject(selectedObj);
            }

            if (startPos == new Vector2(0, 0) || endPos == new Vector2(0, 0))
            {
                return;
            }

            // Make sure it was a legit swipe and on a movable game object
            Vector2 currentSwipe = new Vector3(endPos.x - startPos.x, endPos.y - startPos.y);
            startPos = new Vector2(0, 0);
            endPos   = new Vector2(0, 0);

            if (selectedObj != null && currentSwipe.magnitude >= minSwipeLength)
            {
                // Held Swipe Effect
                // selectedObj.transform.localScale = new Vector3(0.8f, 0.8f, 1);

                Swipe direction = getSwipeDirection(currentSwipe);

                // If invalid swipe, return
                if (!(direction == Swipe.Up || direction == Swipe.Down || direction == Swipe.Left || direction == Swipe.Right))
                {
                    return;
                }

                // If the player has moved, hints should be disabled
                if (GameManager.gameType == "levels")
                {
                    disableHints();
                }

                MovingObject.setObject(selectedObj);
                MovingObject.setSwipeDirection(direction);

                Vector3 currentPos = MovingObject.getObject().transform.position;
                Vector3 newPos     = calculateNewPosition(currentPos, direction);

                // Only increase counter if new location
                if (currentPos != newPos)
                {
                    Move move = new Move(MovingObject.getObject(), direction, currentPos, newPos);
                    LevelManager.moves.Add(move);
                }

                MovingObject.setPosition(newPos);
                MovingObject.setIsMoving(true);
                selectedObj = null;
            }

            // Held Swipe Effect
            // else if (selectedObj != null && currentSwipe.magnitude <= minSwipeLength) {
            //   selectedObj.transform.localScale = new Vector3(0.8f, 0.8f, 1);
            //   selectedObj = null;
            // }
        }
    }