private void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            swipe = true;
            swipeFirstPosition = Input.mousePosition.x;
            swipeCoroutine     = Swiping();
            StartCoroutine(swipeCoroutine);
        }
        if (Input.GetMouseButton(0) && swipe)
        {
            swipeFinished = false;
        }
        if (Input.GetMouseButtonUp(0))
        {
            swipe              = false;
            swipeFinished      = true;
            characterDirection = CharacterDirection.None;
            StopCoroutine(swipeCoroutine);
        }

        if (characterDirection == CharacterDirection.Left)
        {
            movement.TurnLeft();
        }
        else if (characterDirection == CharacterDirection.Right)
        {
            movement.TurnRight();
        }
    }
Exemplo n.º 2
0
 // work out the direction the character is facing
 // TODO: promote this into an abstract
 public void SetDirection(float inX, float inY)
 {
     if (inX == 0 && inY > 0)
     {
         currentCharacterDirection = CharacterDirection.N;
     }
     else if (inX > 0 && inY > 0)
     {
         currentCharacterDirection = CharacterDirection.NE;
     }
     else if (inX > 0 && inY == 0)
     {
         currentCharacterDirection = CharacterDirection.E;
     }
     else if (inX > 0 && inY < 0)
     {
         currentCharacterDirection = CharacterDirection.SE;
     }
     else if (inX == 0 && inY < 0)
     {
         currentCharacterDirection = CharacterDirection.S;
     }
     else if (inX < 0 && inY < 0)
     {
         currentCharacterDirection = CharacterDirection.SW;
     }
     else if (inX < 0 && inY == 0)
     {
         currentCharacterDirection = CharacterDirection.W;
     }
     else if (inX < 0 && inY > 0)
     {
         currentCharacterDirection = CharacterDirection.NW;
     }
 }
Exemplo n.º 3
0
    void GetDirection()
    {
        if (Input.GetAxis("Horizontal") > buffer)
        {
            theDirection = CharacterDirection.right;
            hitboxPivot.localEulerAngles = rotations [2];
        }
        if (Input.GetAxis("Horizontal") < -buffer)
        {
            theDirection = CharacterDirection.left;
            hitboxPivot.localEulerAngles = rotations [3];
        }
        if (Input.GetAxis("Vertical") < -buffer)
        {
            theDirection = CharacterDirection.down;
            hitboxPivot.localEulerAngles = rotations [1];
        }
        if (Input.GetAxis("Vertical") > buffer)

        {
            theDirection = CharacterDirection.up;
            hitboxPivot.localEulerAngles = rotations [0];
        }
        animator.SetFloat("direction", (float)theDirection);
    }
Exemplo n.º 4
0
    public Sprite GetSprite(CharacterDirection direction)
    {
        animationCount++;

        if (animationSpeed <= animationCount)
        {
            animationFrame += 1;
            animationCount  = 0;
        }

        if (animationTotalFrame <= animationFrame)
        {
            animationFrame = 0;
        }

        switch (direction)
        {
        case CharacterDirection.DOWN:  return(sprites[downHeadFrame + animationFrame]);

        case CharacterDirection.LEFT:  return(sprites[leftHeadFrame + animationFrame]);

        case CharacterDirection.UP:    return(sprites[upHeadFrame + animationFrame]);

        case CharacterDirection.RIGHT: return(sprites[rightHeadFrame + animationFrame]);
        }
        return(sprites[0]);
    }
Exemplo n.º 5
0
    public Position GetMaxReachPositon(Position currentPos, CharacterDirection direction, int range)
    {
        int      move = 0;
        Position next = currentPos;
        Position last = currentPos;

        while (move <= range)
        {
            next = Utils.GetPositonByDirction(next, direction);
            if (CanReach(next))
            {
                if (CharacterManager.Singleton.IsCharacterInPositon(next))
                {
                    return(last);
                }
                move++;
                last = next;
            }
            else
            {
                return(last);
            }
        }
        return(last);
    }
Exemplo n.º 6
0
    private void CalculateDirection()
    {
        float radian = Mathf.Atan2(speed.y, speed.x);

        if (radian < 0)
        {
            radian = radian + 2 * Mathf.PI;
        }
        float degree = Mathf.Floor(radian * Mathf.Rad2Deg);

        if (0 <= degree && degree < 45)
        {
            direction = CharacterDirection.RIGHT;
        }
        else if (45 <= degree && degree < 135)
        {
            direction = CharacterDirection.UP;
        }
        else if (135 <= degree && degree < 225)
        {
            direction = CharacterDirection.LEFT;
        }
        else if (225 <= degree && degree < 315)
        {
            direction = CharacterDirection.DOWN;
        }
        else
        {
            direction = CharacterDirection.RIGHT;
        }
    }
Exemplo n.º 7
0
        public void SetCharacter(Character c, int carSprite, CharacterDirection carSpriteDir, int view = 0, int loop = 0, int frame = 0)
        {
            this.DetachCharacter();
            int carl = 0;
            int carw = 0;

            if (carSpriteDir == eDirectionDown || carSpriteDir == eDirectionUp)
            {
                carl = Game.SpriteHeight[carSprite];
                carw = Game.SpriteWidth[carSprite];
            }
            else if (carSpriteDir == eDirectionLeft || carSpriteDir == eDirectionRight)
            {
                carl = Game.SpriteWidth[carSprite];
                carw = Game.SpriteHeight[carSprite];
            }
            else
            {
                AbortGame("Source car sprite direction cannot be diagonal, please provide sprite having one of the following directions: left, right, up or down.");
                return;
            }
            this.c               = c;
            this.carSprite       = carSprite;
            this.carSpriteAngle  = RotatedView.AngleForLoop(carSpriteDir);
            this.viewFrame       = Game.GetViewFrame(view, loop, frame);
            this.bodyLength      = IntToFloat(carl);
            this.bodyWidth       = IntToFloat(carw);
            this.collPointOff[0] = VectorF.create(carl / 2, -carw / 2);
            this.collPointOff[1] = VectorF.create(carl / 2, carw / 2);
            this.collPointOff[2] = VectorF.create(-carl / 2, carw / 2);
            this.collPointOff[3] = VectorF.create(-carl / 2, -carw / 2);
            this.SyncCharacter();
        }
Exemplo n.º 8
0
 private void Awake()
 {
     this.direction = this.GetComponent <CharacterDirection>();
     this.movement  = this.GetComponent <CharacterMovement>();
     this.attack    = this.GetComponent <CharacterAttack>();
     this.health    = this.GetComponent <CharacterHealth>();
 }
Exemplo n.º 9
0
 private void SetNormalDirections(float horizontalMove, float verticalMove)
 {
     if (horizontalMove > 0)
     {
         Direction = CharacterDirection.Right;
         m_Anim.SetInteger("Direction", (int)Direction);
     }
     else if (horizontalMove < 0)
     {
         Direction = CharacterDirection.Left;
         m_Anim.SetInteger("Direction", (int)Direction);
     }
     else if (verticalMove > 0)
     {
         Direction = CharacterDirection.Up;
         m_Anim.SetInteger("Direction", (int)Direction);
     }
     else if (verticalMove < 0)
     {
         Direction = CharacterDirection.Down;
         m_Anim.SetInteger("Direction", (int)Direction);
     }
     else
     {
         //Direction = CharacterDirection.None;
         //m_Anim.SetInteger("Direction", (int)Direction);
     }
 }
Exemplo n.º 10
0
        void Start()
        {
            // swap the model
            var seph = Instantiate(Assets.MainAssetBundle.LoadAsset <GameObject>("seph_obj"));

            direction = this.transform.root.GetComponentInChildren <CharacterDirection>();
            self      = this.transform.root.GetComponentInChildren <CharacterBody>();
            motor     = this.transform.root.GetComponentInChildren <CharacterMotor>();

            // set this stuffs
            foreach (var thisItem in direction.modelAnimator.GetComponentsInChildren <SkinnedMeshRenderer>())
            {
                thisItem.gameObject.SetActive(false);
            }
            foreach (var thisItem in direction.modelAnimator.GetComponentsInChildren <MeshRenderer>())
            {
                thisItem.gameObject.SetActive(false);
            }
            self.crosshairPrefab    = Resources.Load <GameObject>("prefabs/crosshair/simpledotcrosshair");
            seph.transform.position = direction.modelAnimator.transform.position;
            seph.transform.rotation = direction.modelAnimator.transform.rotation;
            seph.transform.SetParent(direction.modelAnimator.transform);
            direction.modelAnimator = seph.GetComponentInChildren <Animator>();

            // DISABLE ITEM DISPLAYING
            var model = self.GetComponentInChildren <CharacterModel>();

            if (model != null)
            {
                model.itemDisplayRuleSet = null;
            }
        }
Exemplo n.º 11
0
 void CalculateDir()
 {
     currentWaypoint = path[targetIndex];
     last_p          = -(((Vector2)this.realMe.position + rp) - currentWaypoint).normalized;
     if (Mathf.Abs(last_p.x) > Mathf.Abs(last_p.y * 0.67f))
     {
         if (last_p.x > 0)
         {
             dir = CharacterDirection.right;
         }
         else
         {
             dir = CharacterDirection.left;
         }
     }
     else
     {
         if (last_p.y > 0)
         {
             dir = CharacterDirection.back;
         }
         else
         {
             dir = CharacterDirection.front;
         }
     }
 }
Exemplo n.º 12
0
    private void CheckCharacterTransmissions(Character character, Vector2Int position)
    {
        if (!character || character.currentState != CharacterState.Infected)
        {
            return;
        }

        character.Transmit();

        if (character.currentState != CharacterState.Transmitting)
        {
            return;
        }

        for (int i = 0; i < directions.Length; i++)
        {
            Vector2Int         direction     = directions[i];
            CharacterDirection directionName = GetOppositeDirection(i);
            for (int j = 1; j <= character.transmissionRange; j++)
            {
                Vector2Int targetPosition = position + direction * j;

                TryTransmissionToPosition(targetPosition, directionName);
            }
        }
    }
Exemplo n.º 13
0
        private void Awake()
        {
            this.rb           = this.GetComponent <Rigidbody>();
            this.body         = this.GetComponent <CharacterBody>();
            this.motor        = this.GetComponent <CharacterMotor>();
            this.direction    = this.GetComponent <CharacterDirection>();
            this.modelLocator = this.GetComponent <ModelLocator>();

            if (this.direction)
            {
                this.direction.enabled = false;
            }

            if (this.modelLocator)
            {
                if (this.modelLocator.modelTransform)
                {
                    this.modelTransform   = modelLocator.modelTransform;
                    this.originalRotation = this.modelTransform.rotation;

                    this.modelLocator.enabled = false;
                }
            }

            if (this.motor)
            {
                this.gameObject.layer = LayerIndex.fakeActor.intVal;
                this.motor.Motor.RebuildCollidableLayers();
            }
        }
Exemplo n.º 14
0
    void Move(float x, float y, bool jump)
    {
        if (x > 0)
        {
            m_characterDirection = CharacterDirection.Right;
        }
        else if (x < 0)
        {
            m_characterDirection = CharacterDirection.Left;
        }

        if (Mathf.Abs(x) > 0)
        {
            Quaternion rot = transform.rotation;
            transform.rotation = Quaternion.Euler(rot.x, Mathf.Sign(x) == 1 ? 0 : 180, rot.z);
        }

        m_rigidbody2D.velocity = new Vector2(x * maxSpeed, m_rigidbody2D.velocity.y);

        m_animator.SetFloat("Horizontal", x);
        m_animator.SetFloat("Vertical", m_rigidbody2D.velocity.y);
        m_animator.SetBool("isGround", m_isGround);

        if (jump && m_isGround)
        {
            m_animator.SetTrigger("Jump");
            SendMessage("Jump", SendMessageOptions.DontRequireReceiver);
            m_rigidbody2D.AddForce(Vector2.up * jumpPower);
        }
    }
Exemplo n.º 15
0
    public void PlayAttackAnimation(Vector3 targetPosition)
    {
        Vector2            deltaVector = (Vector2)(targetPosition - this.transform.position);
        CharacterDirection direction   = DirectionHelper.GetDirectionFormVector(deltaVector);

        this.m_SpriteAnimator.Play(this.m_AnimationAttackDict[direction]);
    }
Exemplo n.º 16
0
    private void UpdateDirection()
    {
        if (NextTile == null)
        {
            //  default face to player
            _characterDirection = CharacterDirection.South;
        }
        else
        {
            if (NextTile == CurrentTile.GetNorthTile())
            {
                _characterDirection = CharacterDirection.North;
            }
            else if (NextTile == CurrentTile.GetSouthTile())
            {
                _characterDirection = CharacterDirection.South;
            }
            else if (NextTile == CurrentTile.GetWestTile())
            {
                _characterDirection = CharacterDirection.West;
            }
            else
            {
                _characterDirection = CharacterDirection.East;
            }
        }

        new CharacterUpdatedEvent {
            Character = this, Direction = _characterDirection
        }.Publish();
    }
Exemplo n.º 17
0
    private void Start()
    {
        switch (type)
        {
        case CharacterType.Hero:
            stat = (UnitStat)AssetDatabase.LoadAssetAtPath("Assets/Datas/Heroes/Hero_" + characterCode + ".asset", typeof(UnitStat));
            setSkills(stat.GetSkills());
            cooldown = new List <float> {
                0.0f, 0.0f, 0.0f, 0.0f
            };
            break;

        case CharacterType.Unit:
            stat = (UnitStat)AssetDatabase.LoadAssetAtPath("Assets/Datas/Units/Unit_" + characterCode + ".asset", typeof(UnitStat));
            break;

        case CharacterType.Building:
            stat = (UnitStat)AssetDatabase.LoadAssetAtPath("Assets/Datas/Buildings/Building_" + characterCode + ".asset", typeof(UnitStat));
            break;
        }
        setStats(stat.GetStats());
        setSprite(stat.GetSprite());
        anime = gameObject.GetComponent <Animator>();
        anime.runtimeAnimatorController = stat.GetAnime();
        nextMovePosition = transform.position;
        direction        = CharacterDirection.Right;
    }
Exemplo n.º 18
0
 public virtual void Initialize()
 {
     Name = Guid.NewGuid();
     ThisDisplayObject = null;
     Direction         = CharacterDirection.Bottom;
     IsVisible         = true;
 }
 // Token: 0x0600088F RID: 2191 RVA: 0x0002AF60 File Offset: 0x00029160
 public override void FixedUpdate()
 {
     base.FixedUpdate();
     if (NetworkServer.active && this.modelAnimator && this.modelAnimator.GetFloat("SwipeForward.hitBoxActive") > 0.1f)
     {
         if (!this.hasSlashed)
         {
             EffectManager.instance.SimpleMuzzleFlash(SwipeForward.swingEffectPrefab, base.gameObject, "SwingCenter", true);
             HealthComponent    healthComponent = base.characterBody.healthComponent;
             CharacterDirection component       = base.characterBody.GetComponent <CharacterDirection>();
             if (healthComponent)
             {
                 healthComponent.TakeDamageForce(SwipeForward.selfForceMagnitude * component.forward, true);
             }
             this.hasSlashed = true;
         }
         this.attack.forceVector = base.transform.forward * SwipeForward.forceMagnitude;
         this.attack.Fire(null);
     }
     if (base.fixedAge >= this.duration && base.isAuthority)
     {
         this.outer.SetNextStateToMain();
         return;
     }
 }
Exemplo n.º 20
0
        public static EffectGunFIreSub CreateObject(Vector3 current, Vector3 target, CharacterDirection dir)
        {
            //var obj = GameObject.Instantiate(ResourceInformation.Effect.transform.FindChild("GunFire").gameObject);
            //obj.transform.SetParent(ResourceInformation.Effect.transform, false);
            //EffectGunFIreSub d = obj.AddComponent<EffectGunFIreSub>();
            //obj.transform.localEulerAngles = CommonFunction.EulerAngles[dir];
            EffectGunFIreSub d = GetGameObject <EffectGunFIreSub>(false, "GunFireSub", ResourceInformation.Effect.transform);

            d.Parent.transform.localEulerAngles = CommonFunction.EulerAngles[dir];

            d.Direction = dir;

            //目標位置の取得
            d.TargetPoint = target;

            //現在位置の取得
            d.Parent.transform.localPosition = current;

            //発射位置を多少ずらすS
            float loc = (float)UnityEngine.Random.Range(-30, 30) / 100;

            d.Parent.transform.localPosition += new Vector3(loc, 0, 0);

            return(d);
        }
Exemplo n.º 21
0
        public override void OnEnter()
        {
            base.OnEnter();
            if (base.isAuthority)
            {
                //this.targetTracker = base.GetComponent<TargetTracker>();
                this.ownerPrefab = base.gameObject;
                CharacterBody   targetBody      = this.targetPrefab.GetComponent <CharacterBody>();
                CharacterBody   ownerBody       = this.ownerPrefab.GetComponent <CharacterBody>();
                GameObject      bodyPrefab      = BodyCatalog.FindBodyPrefab(targetBody);
                CharacterMaster characterMaster = MasterCatalog.allAiMasters.FirstOrDefault((CharacterMaster master) => master.bodyPrefab == bodyPrefab);
                this.masterSummon         = new MasterSummon();
                masterSummon.masterPrefab = characterMaster.gameObject;
                masterSummon.position     = ownerBody.footPosition;
                CharacterDirection component = ownerBody.GetComponent <CharacterDirection>();
                masterSummon.rotation           = (component ? Quaternion.Euler(0f, component.yaw, 0f) : ownerBody.transform.rotation);
                masterSummon.summonerBodyObject = (ownerBody ? ownerBody.gameObject : null);

                CharacterMaster characterMaster2 = masterSummon.Perform();

                GameObject       trackingTargetAsGO = this.targetTracker.GetTrackingTargetAsGO();
                RoR2.Console.Log log = new RoR2.Console.Log();
                if (trackingTargetAsGO != null)
                {
                    log.message = "REEE";
                    RoR2.Console.logs.Add(log);
                }
                else
                {
                    log.message = "YEET";
                    RoR2.Console.logs.Add(log);
                }
            }
        }
Exemplo n.º 22
0
    void AiNa()
    {
        if (cc.action == CharacterAnimation.Hurt)
        {
            return;
        }

        float dist = Vector2.Distance(Dist, Vector2.zero);

        if (dist > dist_w - dist2)
        {
            dist2 = dist_w * 0.33f;
        }
        else
        {
            if (Mathf.Abs(Dist.y) > Mathf.Abs(Dist.x))
            {
                if (Dist.y > 0)
                {
                    direction = CharacterDirection.back;
                }
                else
                {
                    direction = CharacterDirection.front;
                }
            }
            else
            {
                if (Dist.x > 0)
                {
                    direction = CharacterDirection.right;
                }
                else
                {
                    direction = CharacterDirection.left;
                }
            }
            switch (cc.weapon)
            {
            case weapon_type.spear:
            case weapon_type.spear + 1:
                next_action = CharacterAnimation.Thrust;
                break;

            case weapon_type.sword:
            case weapon_type.sword + 1:
                next_action = CharacterAnimation.Slash;
                break;

            case weapon_type.wand:
                next_action = CharacterAnimation.Slash;
                break;

            case weapon_type.bow:
                next_action = CharacterAnimation.Shoot;
                break;
            }
        }
    }
    public void ReplaceCharacterDirection(CharacterDirection newCharacterDirection)
    {
        var index     = GameComponentsLookup.CharacterDirection;
        var component = (CharacterDirectionComponent)CreateComponent(index, typeof(CharacterDirectionComponent));

        component.CharacterDirection = newCharacterDirection;
        ReplaceComponent(index, component);
    }
Exemplo n.º 24
0
 public virtual void SetThisDisplayObject(int x, int y)
 {
     ThisDisplayObject = ResourceInformation.GetInstance(InstanceName, true);
     //ThisDisplayObject = UnityEngine.Object.Instantiate(ResourceInformation.CommonImage.transform.FindChild(InstanceName).gameObject,
     //    ResourceInformation.DungeonDynamicObject.transform);
     Direction = Direction;
     SetPositionThrow(x, y);
 }
Exemplo n.º 25
0
        private void RW_BodyDirectionSetup()
        {
            CharacterDirection dir = this.RW_body.GetComponent <CharacterDirection>();

            dir.targetTransform = this.RW_body.GetComponent <ModelLocator>().modelBaseTransform;
            //dir.overrideAnimatorForwardTransform = body.transform;
            dir.driveFromRootRotation = false;
            dir.turnSpeed             = 300f;
        }
Exemplo n.º 26
0
        public Character CreateCharacter(Vector2Int pos, CharacterDirection dir)
        {
            var character = new Character();

            character.Initialize(m_Characters.Count, this, pos, dir);
            m_Characters.Add(character);
            m_AllColliders.Add(character);
            return(character);
        }
Exemplo n.º 27
0
 public void ChangeRoom <T>(int x = 0, int y = 0, CharacterDirection direction = CharacterDirection.CenterDown) where T : IRoomModule
 {
     path.Clear();
     X = x;
     Y = y;
     Face(direction);
     Room.RemoveCharacter(Module);
     campaigns.AsMonoGame().CurrentController.Rooms[typeof(T)].AddCharacter(this);
 }
    private void Awake()
    {
        game      = GameObject.FindGameObjectWithTag("GameManager").GetComponent <GameManager>();
        movement  = GetComponent <CharacterMovement>();
        character = GetComponent <CharacterBehaviours>();
        animation = GetComponent <CharacterAnimation>();

        characterDirection = CharacterDirection.None;
    }
Exemplo n.º 29
0
        void Start()
        {
            Debug.LogWarning("Tether handler start function run on " + gameObject);
            instance        = this;
            motor           = transform.root.GetComponentInChildren <CharacterMotor>();
            direction       = transform.root.GetComponentInChildren <CharacterDirection>();
            healthComponent = transform.root.GetComponentInChildren <HealthComponent>();

            GrappleTargets = new List <GrappleTarget>();
        }
Exemplo n.º 30
0
        public void SpawnDummyNPC(string pNPCID, Vector2 pPosition, string pFacing)
        {
            NPCData NPC = GetNPCDummy(pNPCID);

            print(NPC.NPCID);
            NPCData            newNPC = Instantiate <NPCData>(NPC, pPosition, transform.rotation);
            CharacterDirection facing = (CharacterDirection)System.Enum.Parse(typeof(CharacterDirection), pFacing);

            newNPC.GetComponent <AnimationController>().ChangeFacing(facing);
            SpawnedDummyNPCs.Add(newNPC);
        }
Exemplo n.º 31
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Выход из игры при нажатии клавиши Escape
            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
                this.Exit();

            // Если PacMan сталкивается с  привидением то игра закрывается

            if (playerPacMan.characterBackGroundRectangle.Intersects(ghostsRed.characterBackGroundRectangle) == true)
                this.Exit();

            if (playerPacMan.characterBackGroundRectangle.Intersects(ghostsYellow.characterBackGroundRectangle) == true)
                this.Exit();

            if (playerPacMan.characterBackGroundRectangle.Intersects(ghostsBlue.characterBackGroundRectangle) == true)
                this.Exit();

            if (playerPacMan.characterBackGroundRectangle.Intersects(ghostsPink.characterBackGroundRectangle) == true)
                this.Exit();

             /*
              //Управление с помощью джойстика XBox360

            if (GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.X > 0.5)
                playerDir = PlayerDirection.playerUpRight;
                playerPacMan.changeDirection(playerDir);

            if (GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.X < -0.5)
                playerDir = PlayerDirection.playerUpLeft;
                playerPacMan.changeDirection(playerDir);

            if (GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.Y > 0.5)
                 playerDir = PlayerDirection.playerUp;
                 playerPacMan.changeDirection(playerDir);

            if (GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.Y < -0.5)
                playerDir = PlayerDirection.playerUpDown;
                playerPacMan.changeDirection(playerDir);

            */

                if (Keyboard.GetState().IsKeyDown(Keys.Right))
                {
                   playerDir = CharacterDirection.characterUpRight;
                   playerPacMan.changeDirection(playerDir);

                }

                if (Keyboard.GetState().IsKeyDown(Keys.Left))
                {
                    playerDir = CharacterDirection.characterUpLeft;
                    playerPacMan.changeDirection(playerDir);
                }

                if (Keyboard.GetState().IsKeyDown(Keys.Up))
                {
                    playerDir = CharacterDirection.characterUp;
                    playerPacMan.changeDirection(playerDir);
                }

                if (Keyboard.GetState().IsKeyDown(Keys.Down))
                {
                   playerDir = CharacterDirection.characterUpDown;
                   playerPacMan.changeDirection(playerDir);
                }

               Character.UpdateCharacters( gameField);

            // If PacMan doesn't collide with the maze allow the PacMan to move.
            if ( true)
            {
                if (Keyboard.GetState().IsKeyDown(Keys.Left))
                {
                    playerDir = CharacterDirection.characterUpLeft;
                    playerPacMan.changeDirection(playerDir);

                }
                else if (Keyboard.GetState().IsKeyDown(Keys.Right))
                {
                    playerDir = CharacterDirection.characterUpRight;
                    playerPacMan.changeDirection(playerDir);

                }
                else if (Keyboard.GetState().IsKeyDown(Keys.Up))
                {
                    playerDir = CharacterDirection.characterUp;
                    playerPacMan.changeDirection(playerDir);

                }
                else if (Keyboard.GetState().IsKeyDown(Keys.Down))
                {
                    playerDir = CharacterDirection.characterUpDown;
                    playerPacMan.changeDirection(playerDir);

                }

            }

            // TODO: Add your update logic here

            base.Update(gameTime);
        }
        private ArrayList GetNextPossibleCoordinates(CharacterDirection Direction, Point CurrentCoordinate)
        {
            int x = CurrentCoordinate.X;
            int y = CurrentCoordinate.Y;

            ArrayList pts = new ArrayList();
            Point pntCheck;

            switch (Direction)
            {
                case CharacterDirection.Right:
                    // Can move Right?
                    pntCheck = new Point(CurrentCoordinate.X + 1, CurrentCoordinate.Y);
                    if (_board.CanMove(pntCheck)) pts.Add(pntCheck);

                    // Can move Up?
                    pntCheck = new Point(CurrentCoordinate.X, CurrentCoordinate.Y-1);
                    if (_board.CanMove(pntCheck)) pts.Add(pntCheck);

                    // Can move Down?
                    pntCheck = new Point(CurrentCoordinate.X, CurrentCoordinate.Y+1);
                    if (_board.CanMove(pntCheck)) pts.Add(pntCheck);

                    break;

                case CharacterDirection.Left:

                    // Can move Left?
                    pntCheck = new Point(CurrentCoordinate.X-1, CurrentCoordinate.Y);
                    if (_board.CanMove(pntCheck)) pts.Add(pntCheck);

                    // Can move Up?
                    pntCheck = new Point(CurrentCoordinate.X, CurrentCoordinate.Y-1);
                    if (_board.CanMove(pntCheck)) pts.Add(pntCheck);

                    // Can move Down?
                    pntCheck = new Point(CurrentCoordinate.X, CurrentCoordinate.Y+1);
                    if (_board.CanMove(pntCheck)) pts.Add(pntCheck);

                    break;

                case CharacterDirection.Down:

                    // Can move Right?
                    pntCheck = new Point(CurrentCoordinate.X + 1, CurrentCoordinate.Y);
                    if (_board.CanMove(pntCheck)) pts.Add(pntCheck);

                    // Can move Down?
                    pntCheck = new Point(CurrentCoordinate.X, CurrentCoordinate.Y+1);
                    if (_board.CanMove(pntCheck)) pts.Add(pntCheck);

                    // Can move Left?
                    pntCheck = new Point(CurrentCoordinate.X-1, CurrentCoordinate.Y);
                    if (_board.CanMove(pntCheck)) pts.Add(pntCheck);

                    break;

                case CharacterDirection.Up:

                    // Can move Right?
                    pntCheck = new Point(CurrentCoordinate.X+1, CurrentCoordinate.Y);
                    if (_board.CanMove(pntCheck)) pts.Add(pntCheck);

                    // Can move Left?
                    pntCheck = new Point(CurrentCoordinate.X-1, CurrentCoordinate.Y);
                    if (_board.CanMove(pntCheck)) pts.Add(pntCheck);

                    // Can move Up?
                    pntCheck = new Point(CurrentCoordinate.X, CurrentCoordinate.Y-1);
                    if (_board.CanMove(pntCheck)) pts.Add(pntCheck);

                    break;
            }
            return pts;
        }
        protected override sealed void MoveToEndPoint(CharacterDirection Direction, Point p)
        {
            Point TestPoint;

            while (_currentLocation != p)
            {

                TestPoint = GetNextCoordinate(Direction, _currentLocation);
                if (_board.CanMove(TestPoint))
                {
                    _currentLocation = TestPoint;

                    switch (_direction)
                    {
                        case CharacterDirection.Left:
                            if (_board.CanMove(_currentLocation, CharacterDirection.Up)) return;
                            if (_board.CanMove(_currentLocation, CharacterDirection.Down)) return;
                            break;

                        case CharacterDirection.Right:
                            if (_board.CanMove(_currentLocation, CharacterDirection.Up)) return;
                            if (_board.CanMove(_currentLocation, CharacterDirection.Down)) return;
                            break;

                        case CharacterDirection.Up:
                            if (_board.CanMove(_currentLocation, CharacterDirection.Left)) return;
                            if (_board.CanMove(_currentLocation, CharacterDirection.Right)) return;
                            break;

                        case CharacterDirection.Down:
                            if (_board.CanMove(_currentLocation, CharacterDirection.Left)) return;
                            if (_board.CanMove(_currentLocation, CharacterDirection.Right)) return;
                            break;
                    }
                }
                else
                {
                    break;
                }
            }
        }
        public virtual void Move()
        {
            _currentCharacterState = CharacterState.Stopped;

            // Tunnel
            if (_currentLocation.X == 448)
                _currentLocation.X = 0;
            else if (_currentLocation.X == 0)
                _currentLocation.X = 448;

            if (_attemptedDirection != CharacterDirection.None && _board.CanMove(GetNextCoordinate(_attemptedDirection, _currentLocation)))
            {
                // Test attempted direction
                MoveToEndPoint(_attemptedDirection, GetDestinationCoordinate(_attemptedDirection, _currentLocation));
                _direction = _attemptedDirection;
                _previousDirection = _attemptedDirection;
                _attemptedDirection = CharacterDirection.None;
                _currentCharacterState = CharacterState.Moving;
                return;
            }
            else
            {
                _direction = _previousDirection;
            }

            if (_board.CanMove(GetNextCoordinate(_direction, _currentLocation)))
            {
                // Test Actual Direction
                MoveToEndPoint(_direction, GetDestinationCoordinate(_direction, _currentLocation));
                _previousDirection = _direction;
                _currentCharacterState = CharacterState.Moving;
            }
        }
        public bool CanMove(Point p, CharacterDirection d)
        {
            switch (d)
            {
                case CharacterDirection.Left:
                    p.X-= 1;
                    break;

                case CharacterDirection.Right:
                    p.X+= 1;
                    break;

                case CharacterDirection.Up:
                    p.Y-= 1;
                    break;

                case CharacterDirection.Down:
                    p.Y+= 1;
                    break;
            }

            return _pathPoints.Contains(p);
        }
        protected Point GetNextCoordinate(CharacterDirection Direction, Point CurrentCoordinate)
        {
            int x = CurrentCoordinate.X;
            int y = CurrentCoordinate.Y;

            switch (Direction)
            {
                case CharacterDirection.Right:
                    x++;
                    break;
                case CharacterDirection.Left:
                    x--;
                    break;
                case CharacterDirection.Down:
                    y++;
                    break;
                case CharacterDirection.Up:
                    y--;
                    break;
            }
            return new Point(x, y);
        }
        protected Point GetDestinationCoordinate(CharacterDirection Direction, Point CurrentCoordinate)
        {
            int x = CurrentCoordinate.X;
            int y = CurrentCoordinate.Y;

            switch (Direction)
            {
                case CharacterDirection.Right:
                    x+= _moveInterval;
                    break;
                case CharacterDirection.Left:
                    x-= _moveInterval;
                    break;
                case CharacterDirection.Down:
                    y+= _moveInterval;
                    break;
                case CharacterDirection.Up:
                    y-= _moveInterval;
                    break;
            }
            return new Point(x, y);
        }
Exemplo n.º 38
0
 private bool FriendInWay(Character[] c, int ID, CharacterDirection face)
 {
     for (int i = 0; i < c.Length; i++)
     {
         if (i != ID)
         {
             if (c[i] != null)
             {
                 if (me.Team == c[i].Team)
                 {
                     if (me.Location.Y > c[i].Location.Y - 100f &&
                         me.Location.Y < c[i].Location.Y + 10f)
                     {
                         if (face == CharacterDirection.Right)
                         {
                             if (c[i].Location.X > me.Location.X &&
                                 c[i].Location.X < me.Location.X + 70f)
                                 return true;
                         }
                         else
                         {
                             if (c[i].Location.X < me.Location.X &&
                                 c[i].Location.X > me.Location.X - 70f)
                                 return true;
                         }
                     }
                 }
             }
         }
     }
     return false;
 }
        protected virtual void MoveToEndPoint(CharacterDirection Direction, Point p)
        {
            Point TestPoint;
            Point TestAttemptedPoint;

            int PointsToMove = _moveInterval;

            while (PointsToMove > 0)
            {
                if (_attemptedDirection != CharacterDirection.None)
                {
                    TestAttemptedPoint = GetNextCoordinate(_attemptedDirection, _currentLocation);
                    if (_board.CanMove(TestAttemptedPoint))
                    {
                        _currentLocation = TestAttemptedPoint;
                        _board.Pellets.RemovePellet(_currentLocation);
                        PointsToMove --;
                    }
                }

                TestPoint = GetNextCoordinate(Direction, _currentLocation);
                if (_board.CanMove(TestPoint))
                {
                    _currentLocation = TestPoint;
                    _board.Pellets.RemovePellet(_currentLocation);
                    PointsToMove --;
                }
                else
                {
                    break;
                }
            }
        }
Exemplo n.º 40
0
        //TODO Camera following // TODO Make the physics more like real maple -_- // TODO Ladders/Ropes
        public void Update(int gameTime)
        {
            if (!Constants.Game.CameraLimit)
                if (Mouse.GetState().RightButton == ButtonState.Pressed)
                    this.Position = new Vector2(Mouse.GetState().X + Camera.Position.X, Mouse.GetState().Y + Camera.Position.Y);

            if (Body != null && Body.ContainsKey(State))
                Body[State].Update(gameTime);
            if (Arm != null && Arm.ContainsKey(State))
                Arm[State].Frame = Body[State].Frame;
            if (Top != null)
            {
                Top.ani[State].Frame = Body[State].Frame;
                Top.armAni[State].Frame = Body[State].Frame;
            }

            LeftCollision = new Rectangle((int)this.Position.X - 1, (int)this.Position.Y + Bounds.Y + Bounds.Height - 7, 1, 6);
            RightCollision = new Rectangle((int)this.Position.X + 1, (int)this.Position.Y + Bounds.Y + Bounds.Height - 7, 1, 6);
            FeetCollision = new Rectangle((int)this.Position.X, (int)this.Position.Y + Bounds.Y + Bounds.Height - 7, 1, 8);

            Foothold = null;
            bool wallLeft = false;
            bool wallRight = false;
            foreach (MapleFoothold fh in MapEngine.CurrentMap.Footholds) // TODO: Slopes.
            {
                if (fh.Intersects(FeetCollision))
                {
                    Foothold = fh;
                    Layer = fh.Layer;
                }

                if (fh.Intersects(LeftCollision))
                    wallLeft = true;
                if (fh.Intersects(RightCollision))
                    wallRight = true;
            }
            bool touchingFoothold = (Foothold != null);

            if (touchingFoothold)
            {
                this.Position.Y = (Foothold.StartPos.Y - this.Bounds.Height) + -(int)Head.Origin.Y;
                FeetCollision.Y = (int)this.Position.Y + Bounds.Y + Bounds.Height - 7;
            }

            if (!touchingFoothold && Jump <= 0)
            {
                this.Position.Y += Constants.Physics.FallSpeed;
            }
            else if (Jump > 0 && Jump < Constants.Physics.JumpHeight)
            {
                Jump++; // TODO Jump velocity.... get rid of this quick fix XD
                this.Position.Y -= Constants.Physics.JumpSpeed;
            }
            else if (Jump >= Constants.Physics.JumpHeight)
            {
                jumpDelay = Constants.Physics.JumpDelay;
                Jump = 0;
            }

            if (this.Position.Y > MapEngine.CurrentMap.Bottom)
                    this.Position.Y = MapEngine.CurrentMap.Top;

            KeyboardState keyboard = Keyboard.GetState();

            this.State = CharacterState.Standing;

            if ((keyboard.IsKeyUp(Keys.LeftAlt) || keyboard.IsKeyUp(Keys.RightAlt)) && (oldState.IsKeyDown(Keys.LeftAlt) || oldState.IsKeyDown(Keys.RightAlt)))
                jumpDelay = 0;

            if (keyboard.IsKeyDown(Keys.Down) && touchingFoothold)
                this.State = CharacterState.Prone;

            if (this.State != CharacterState.Prone)
            {
                if (keyboard.IsKeyDown(Keys.Right) && this.Position.X < MapEngine.CurrentMap.Right && !wallRight)
                {
                    // TODO: Check edges
                    Position.X += Constants.Physics.WalkSpeed * ((Jump > 0 || !touchingFoothold) ? Constants.Physics.FallMovementPercent : 1);
                    this.State = CharacterState.Walking;
                    this.Direction = CharacterDirection.Right;
                }
                if (keyboard.IsKeyDown(Keys.Left) && this.Position.X > MapEngine.CurrentMap.Left && !wallLeft)
                {
                    Position.X -= Constants.Physics.WalkSpeed * ((Jump > 0 || !touchingFoothold) ? Constants.Physics.FallMovementPercent : 1);
                    this.State = CharacterState.Walking;
                    this.Direction = CharacterDirection.Left;
                }
                if (keyboard.IsKeyDown(Keys.Up))
                {
                    if (MapEngine.MapLoaded)
                        foreach (MaplePortal portal in MapEngine.CurrentMap.Portals)
                        {
                            if (portal.Bounds.Intersects(FeetCollision))
                            {
                                MapEngine.LoadMap(portal.toMapId, portal.SpawnName);
                                break;
                            }
                        }
                }
                if ((keyboard.IsKeyDown(Keys.LeftAlt) || keyboard.IsKeyDown(Keys.RightAlt)) && Jump <= 0 && touchingFoothold && jumpDelay <= 0)
                {
                    Jump = 1;
                    this.Position.Y -= 1;
                }
            }
            else if ((keyboard.IsKeyDown(Keys.LeftAlt) && oldState.IsKeyUp(Keys.LeftAlt)) || (keyboard.IsKeyDown(Keys.RightAlt) && oldState.IsKeyUp(Keys.RightAlt)))
                this.Position.Y += 10; // Place under foothold?

            if (jumpDelay > 0)
                jumpDelay -= gameTime;

            if (Jump > 0)
                State = CharacterState.Jump;
            oldState = keyboard;

            if (Constants.Game.CameraLimit)
            {
                if ((this.Position.X < Camera.Position.X + (Constants.Game.ScreenWidth / 3) && Direction == CharacterDirection.Left))
                    Camera.SetX((int)this.Position.X - (Constants.Game.ScreenWidth / 3));
                else if ((this.Position.X > Camera.Position.X + Constants.Game.ScreenWidth - (Constants.Game.ScreenWidth / 3) && Direction == CharacterDirection.Right))
                    Camera.SetX((int)this.Position.X - Constants.Game.ScreenWidth + (Constants.Game.ScreenWidth / 3));
                if ((this.Position.Y < Camera.Position.Y + (Constants.Game.ScreenHeight / 3)))
                    Camera.SetY((int)this.Position.Y - (Constants.Game.ScreenHeight / 3));
                if ((this.Position.Y > Camera.Position.Y + Constants.Game.ScreenHeight - (Constants.Game.ScreenHeight / 3)))
                    Camera.SetY((int)this.Position.Y - Constants.Game.ScreenHeight + (Constants.Game.ScreenHeight / 3));
            }
        }
Exemplo n.º 41
0
        public void DrawCharacter(SpriteBatch spriteBatch, CharacterDirection dir, Vector2 pos)
        {
            Vector2 AllOffset = Vector2.Zero;
            if (State == CharacterState.Prone)
            {
                AllOffset += new Vector2(-38, 26);
            }

            if (dir == CharacterDirection.Right)
                AllOffset.X = -AllOffset.X;

            if (dir == CharacterDirection.Left)
            {
                if (Body != null && Body.ContainsKey(State))
                    Body[State].Draw(spriteBatch, pos, AllOffset);
                if (Head != null)
                    Head.Draw(spriteBatch, pos, AllOffset);
                if (Face != null)
                    Face.Draw(spriteBatch, pos, AllOffset);
                if (Hair != null)
                    Hair[HairStates[(int)State]].Draw(spriteBatch, pos, AllOffset);

                // Draw Equip Body
                //if (Top != null)
                    //Top.DrawBody(spriteBatch, pos, Navel[States[(int)State] + Body[State].Frame.ToString()]); // wtf.. this doesn't work? todo this

                // Draw player arm (has to be in the middle of equip back and front
                if (Arm != null && Arm.ContainsKey(State))
                    Arm[State].Draw(spriteBatch, pos, AllOffset);

                // Draw Equip Arms
                //if (Top != null)
                    //Top.DrawArm(spriteBatch, pos, Navel[States[(int)State] + Body[State].Frame.ToString()]);
            }
            else
            {
                if (Body != null && Body.ContainsKey(State))
                {
                    MapleCanvas bodyCanvas = Body[State].Frames[Body[State].Frame].Canvas;
                    Vector2 BodyOffset = new Vector2(-bodyCanvas.Origin.X - bodyCanvas.Texture.Width, bodyCanvas.Origin.Y);
                    Body[State].Draw(spriteBatch, pos, (BodyOffset + AllOffset) - bodyCanvas.Origin, SpriteEffects.FlipHorizontally);
                }
                if (Head != null)
                {
                    Vector2 HeadOffset = new Vector2(-Head.Origin.X - Head.Texture.Width, Head.Origin.Y);
                    Head.Draw(spriteBatch, pos, (HeadOffset + AllOffset) - Head.Origin, SpriteEffects.FlipHorizontally);
                }
                if (Face != null)
                {
                    MapleCanvas FaceCanvas = Face.Frames[Face.Frame].Canvas;
                    Vector2 FaceOffset = new Vector2(-FaceCanvas.Origin.X - FaceCanvas.Texture.Width, FaceCanvas.Origin.Y);
                    Face.Draw(spriteBatch, pos, (FaceOffset + AllOffset) - FaceCanvas.Origin, SpriteEffects.FlipHorizontally);
                }
                if (Hair != null)
                {
                    MapleCanvas HairCanvas = Hair[HairStates[(int)State]].Frames[Hair[HairStates[(int)State]].Frame].Canvas;
                    Vector2 HairOffset = new Vector2(-HairCanvas.Origin.X - HairCanvas.Texture.Width, HairCanvas.Origin.Y);
                    Hair[HairStates[(int)State]].Draw(spriteBatch, pos, (HairOffset + AllOffset) - HairCanvas.Origin, SpriteEffects.FlipHorizontally);
                }
                if (Arm != null && Arm.ContainsKey(State))
                {
                    MapleCanvas armCanvas = Arm[State].Frames[Arm[State].Frame].Canvas;
                    Vector2 ArmOffset = new Vector2(-armCanvas.Origin.X - armCanvas.Texture.Width, armCanvas.Origin.Y);
                    Arm[State].Draw(spriteBatch, pos, (ArmOffset + AllOffset) - armCanvas.Origin, SpriteEffects.FlipHorizontally);
                }
            }
        }
Exemplo n.º 42
0
        /// <summary>
        /// Calcula a posição seguinte da personagem para efeitos de colisão
        /// Apenas existem duas possibilidades de movimento (frente, trás) já que os movimentos
        /// Esquerda/Direita são rotações
        /// </summary>
        /// <param name="direction">A direcção em que se está a movimentar a personagem</param>
        /// <returns>Vector3D que indica a próxima posição</returns>
        public Vector3D calculateNextPosition(CharacterDirection direction)
        {
            Vector3D nextPosition = new Vector3D();

            if (direction == CharacterDirection.Front)
            {
                nextPosition.Px = this.Position.Px + Math.Cos(this.Angle) * this.Velocity;
                nextPosition.Pz = this.Position.Pz + Math.Sin(-this.Angle) * this.Velocity;
            }
            else if (direction == CharacterDirection.Back)
            {
                nextPosition.Px = this.Position.Px - Math.Cos(this.Angle) * this.Velocity;
                nextPosition.Pz = this.Position.Pz - Math.Sin(-this.Angle) * this.Velocity;
            }

            return nextPosition;
        }
Exemplo n.º 43
0
        /// <summary>
        /// Updates the Character, checks for collision and handles input.
        /// This method has been verified!
        /// </summary>
        /// <param name="gameTime">The game time.</param>
        public void Update(Map map, ParticleManager particleManager, Character[] character)
        {
            if (Ai != null)
                Ai.Update(character, ID, map);

            PressedKey = PressedKeys.None;
            if (keyAttack)
            {
                PressedKey = PressedKeys.Attack;
                if (keyUp) PressedKey = PressedKeys.Lower;
                if (keyDown) PressedKey = PressedKeys.Upper;
            }
            if (keySecondary)
            {
                PressedKey = PressedKeys.Secondary;
                if (keyUp) PressedKey = PressedKeys.SecUp;
                if (keyDown) PressedKey = PressedKeys.SecDown;
            }
            if (PressedKey > PressedKeys.None)
            {
                if (GotoGoal[(int)PressedKey] > -1)
                {
                    SetFrame(GotoGoal[(int)PressedKey]);

                    if (keyLeft)
                        Face = CharacterDirection.Left;
                    if (keyRight)
                        Face = CharacterDirection.Right;

                    PressedKey = PressedKeys.None;

                    for (int i = 0; i < GotoGoal.Length; i++)
                        GotoGoal[i] = -1;

                    frame = 0f;
                }
            }

            if (StunFrame > 0f)
                StunFrame -= RuinExplorersMain.FrameTime;

            #region update dying
            if (DyingFrame > -1f)
            {
                DyingFrame += RuinExplorersMain.FrameTime;
            }
            #endregion

            #region Update Animation
            if (DyingFrame < 0)
            {
                Animation animation = characterDefinition.Animations[Animation];
                KeyFrame keyFrame = animation.KeyFrames[AnimationFrame];

                frame += RuinExplorersMain.FrameTime * 30.0f;

                if (frame > (float)keyFrame.Duration)
                {
                    int pframe = AnimationFrame;

                    script.DoScript(Animation, AnimationFrame);
                    CheckTrigger(particleManager);

                    frame -= (float)keyFrame.Duration;
                    if (AnimationFrame == pframe)
                        AnimationFrame++;

                    keyFrame = animation.KeyFrames[AnimationFrame];

                    if (AnimationFrame >=
                        animation.KeyFrames.Length)
                        AnimationFrame = 0;
                }

                if (keyFrame.FrameReference < 0)
                    AnimationFrame = 0;

                if (AnimationName == "jhit")
                {
                    if (Trajectory.Y > -100f)
                        SetAnim("jmid");
                }
            }

            #endregion

            #region Collision with other characters
            for (int i = 0; i < character.Length; i++)
            {
                if (i != ID)
                {
                    if (character[i] != null)
                    {
                        if (!Ethereal && !character[i].Ethereal)
                        {
                            if (Location.X > character[i].Location.X - 90f * character[i].Scale &&
                         Location.X < character[i].Location.X + 90f * character[i].Scale &&
                         Location.Y > character[i].Location.Y - 120f * character[i].Scale &&
                         Location.Y < character[i].Location.Y + 10f * character[i].Scale)
                            {
                                float dif = (float)Math.Abs(Location.X - character[i].Location.X);
                                dif = 180f * character[i].Scale - dif;
                                dif *= 2f;
                                if (Location.X < character[i].Location.X)
                                {
                                    CollisionMove = -dif;
                                    character[i].CollisionMove = dif;
                                }
                                else
                                {
                                    CollisionMove = dif;
                                    character[i].CollisionMove = -dif;
                                }
                            }
                        }
                    }
                }
            }

            if (CollisionMove > 0f)
            {
                CollisionMove -= 400f * RuinExplorersMain.FrameTime;
                if (CollisionMove < 0f)
                    CollisionMove = 0f;
            }
            if (CollisionMove < 0f)
            {
                CollisionMove += 400f * RuinExplorersMain.FrameTime;
                if (CollisionMove > 0f)
                    CollisionMove = 0f;
            }
            #endregion

            #region Update Location by Trajectory
            Vector2 previousLocation = new Vector2(Location.X, Location.Y);

            if (State == CharacterState.Ground || (State == CharacterState.Air && floating))
            {
                if (Trajectory.X > 0f)
                {
                    Trajectory.X -= RuinExplorersMain.Friction * RuinExplorersMain.FrameTime;
                    if (Trajectory.X < 0f)
                        Trajectory.X = 0f;
                }
                if (Trajectory.X < 0f)
                {
                    Trajectory.X += RuinExplorersMain.Friction * RuinExplorersMain.FrameTime;
                    if (Trajectory.X > 0f)
                        Trajectory.X = 0f;
                }
            }

            Location.X += Trajectory.X * RuinExplorersMain.FrameTime;
            Location.X += CollisionMove * RuinExplorersMain.FrameTime;

            if (State == CharacterState.Air)
            {
                Location.Y += Trajectory.Y * RuinExplorersMain.FrameTime;
            }
            #endregion

            #region Collision detection
            if (State == CharacterState.Air)
            {
                #region Air State
                if (floating)
                {
                    Trajectory.Y += RuinExplorersMain.FrameTime * RuinExplorersMain.Gravity * 0.5f;
                    if (Trajectory.Y > 100f) Trajectory.Y = 100f;
                    if (Trajectory.Y < -100f) Trajectory.Y = -100f;

                }
                else
                    Trajectory.Y += RuinExplorersMain.FrameTime * RuinExplorersMain.Gravity;

                CheckXCollision(map, previousLocation);

                #region Land on ledge
                if (Trajectory.Y > 0.0f)
                {
                    for (int i = 0; i < 16; i++)
                    {
                        if (map.Legdes[i].TotalNodes > 1)
                        {

                            int ts = map.GetLedgeSection(i, previousLocation.X);
                            int s = map.GetLedgeSection(i, Location.X);
                            float fY;
                            float tfY;
                            if (s > -1 && ts > -1)
                            {

                                tfY = map.GetLedgeYLocation(i, s, previousLocation.X);
                                fY = map.GetLedgeYLocation(i, s, Location.X);
                                if (previousLocation.Y <= tfY && Location.Y >= fY)
                                {
                                    if (Trajectory.Y > 0.0f)
                                    {

                                        Location.Y = fY;
                                        ledgeAttach = i;
                                        Land();
                                    }
                                }
                                else

                                    if (map.Legdes[i].isHardLedge == (int)LedgeFlags.Solid
                                        &&
                                        Location.Y >= fY)
                                    {
                                        Location.Y = fY;
                                        ledgeAttach = i;
                                        Land();
                                    }
                            }

                        }
                    }
                }
                #endregion

                #region Land on col
                if (State == CharacterState.Air)
                {
                    if (Trajectory.Y > 0f)
                    {
                        if (map.CheckCollision(new Vector2(Location.X, Location.Y + 15f)))
                        {
                            Location.Y = (float)((int)((Location.Y + 15f) / 64f) * 64);
                            Land();
                        }
                    }
                }
                #endregion

                #endregion
            }
            else if (State == CharacterState.Ground)
            {
                #region Grounded State

                if (ledgeAttach > -1)
                {
                    if (map.GetLedgeSection(ledgeAttach, Location.X) == -1)
                    {
                        FallOff();
                    }
                    else
                    {
                        Location.Y = map.GetLedgeYLocation(ledgeAttach,
                            map.GetLedgeSection(ledgeAttach, Location.X), Location.X);
                    }
                }
                else
                {
                    if (!map.CheckCollision(new Vector2(Location.X, Location.Y + 15f)))
                        FallOff();
                }

                CheckXCollision(map, previousLocation);

                #endregion
            }
            #endregion

            #region Key input
            if (AnimationName == "idle" || AnimationName == "run" ||
                (State == CharacterState.Ground && CanCancel))
            {
                if (AnimationName == "idle" || AnimationName == "run")
                {
                    if (keyLeft)
                    {
                        SetAnim("run");
                        Trajectory.X = -Speed;
                        Face = CharacterDirection.Left;
                    }
                    else if (keyRight)
                    {
                        SetAnim("run");
                        Trajectory.X = Speed;
                        Face = CharacterDirection.Right;
                    }
                    else
                    {
                        SetAnim("idle");
                    }
                }
                if (keyAttack)
                {
                    SetAnim("attack");
                }
                if (keySecondary)
                {
                    SetAnim("second");
                }
                if (keyJump)
                {
                    SetAnim("jump");
                }
                if (RightAnalog.X > 0.2f || RightAnalog.X < -0.2f)
                {
                    SetAnim("roll");
                    if (AnimationName == "roll")
                    {
                        if (RightAnalog.X > 0f)
                            Face = CharacterDirection.Right;
                        else
                            Face = CharacterDirection.Left;
                    }
                }
            }

            if (AnimationName == "fly" ||
                (State == CharacterState.Air && CanCancel))
            {
                if (keyLeft)
                {
                    Face = CharacterDirection.Left;
                    if (Trajectory.X > -Speed)
                        Trajectory.X -= 500f * RuinExplorersMain.FrameTime;
                }
                if (keyRight)
                {
                    Face = CharacterDirection.Right;
                    if (Trajectory.X < Speed)
                        Trajectory.X += 500f * RuinExplorersMain.FrameTime;
                }
                if (keySecondary)
                {
                    SetAnim("fsecond");
                }
                if (keyAttack)
                {
                    SetAnim("fattack");
                }
            }

            #endregion
        }
Exemplo n.º 44
0
        /// <summary>
        /// Sets a new animation.
        /// This method has been verified!
        /// </summary>
        /// <param name="newAnim">The new anim.</param>
        public void SetAnim(string newAnim)
        {
            if (AnimationName != newAnim)
            {
                for (int i = 0; i < characterDefinition.Animations.Length; i++)
                {
                    if (characterDefinition.Animations[i].Name == newAnim)
                    {
                        for (int t = 0; t < GotoGoal.Length; t++)
                            GotoGoal[t] = -1;

                        floating = false;
                        Animation = i;
                        AnimationFrame = 0;
                        frame = 0f;
                        AnimationName = newAnim;
                        CanCancel = false;
                        Ethereal = false;

                        if (keyLeft)
                            Face = CharacterDirection.Left;
                        if (keyRight)
                            Face = CharacterDirection.Right;

                    }

                }
            }
            //if (AnimationName == newAnim)
            //    return;
            //for (int i = 0; i < characterDefinition.Animations.Length; i++)
            //{
            //    if (characterDefinition.Animations[i].Name == newAnim)
            //    {
            //        Animation = i;
            //        AnimationFrame = 0;
            //        frame = 0;
            //        AnimationName = newAnim;
            //        Ethereal = false;
            //        break;
            //    }
            //}
        }
Exemplo n.º 45
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Character"/> class.
        /// This method has been verified!
        /// </summary>
        /// <param name="newLocation">The new location.</param>
        /// <param name="newCharDef">The new char def.</param>
        /// <param name="newID">The new ID.</param>
        /// <param name="newTeam">The new team.</param>
        public Character(Vector2 newLocation, CharacterDefinition newCharDef, int newID, int newTeam)
        {
            script = new Script(this);
            Ai = null;

            Location = newLocation;
            Trajectory = new Vector2();
            ID = newID;
            Team = newTeam;
            Face = CharacterDirection.Right;
            Scale = 0.5f;
            characterDefinition = newCharDef;

            NoLifty = false;

            InitScript();

            Ethereal = false;
            AnimationName = "";
            SetAnim("fly");

            State = CharacterState.Air;
        }
Exemplo n.º 46
0
 /// <summary>
 /// Makes a bullet with muzzle flash.
 /// </summary>
 /// <param name="location">The location to create the bullet from.</param>
 /// <param name="trajectory">bullet trajectory.</param>
 /// <param name="face">facing of the owner.</param>
 /// <param name="owner">The owner of the bullet.</param>
 public void MakeBullet(Vector2 location, Vector2 trajectory, CharacterDirection face, int owner)
 {
     switch (face)
     {
         case CharacterDirection.Left:
             AddParticle(new Bullet(location, new Vector2(-trajectory.X, trajectory.Y) + RandomGenerator.GetRandomVector2(-90.0f, 90f, -90f, 90f),
                 owner));
             MakeMuzzleFlash(location, new Vector2(-trajectory.X, trajectory.Y));
             break;
         case CharacterDirection.Right:
             AddParticle(new Bullet(location, trajectory + RandomGenerator.GetRandomVector2(-90.0f, 90f, -90f, 90f),
                 owner));
             MakeMuzzleFlash(location, trajectory);
             break;
         default:
             break;
     }
 }