Пример #1
0
 private void Awake()
 {
     agent           = this.GetComponent <NavMeshAgent>();
     playerCharacter = this.GetComponent <CharacterController>();
     playerDir       = this.GetComponent <PlayerDir>();
     agent.enabled   = false;
 }
Пример #2
0
 void Start()
 {
     attack     = GetComponent <PlayerAttack>();
     dir        = GetComponent <PlayerDir>();
     controller = GetComponent <CharacterController>();
     playerInfo = GetComponent <PlayerInfo>();
 }
Пример #3
0
 void Awake()
 {
     ps  = this.GetComponent <PlayerStatus> ();
     pm  = this.GetComponent <PlayerMove> ();
     dir = this.GetComponent <PlayerDir>();
     pa  = this.GetComponent <PlayerAnimationS> ();
 }
Пример #4
0
 void Start()
 {
     playerState         = ControlWalkState.Idle;
     characterController = GetComponent <CharacterController>();
     playerDir           = GetComponent <PlayerDir>();
     playerAttack        = GetComponent <PlayerAttack>();
 }
Пример #5
0
        public Bullet fire(int x, int y, PlayerDir dir, bulletOwner owner, bulletType type)
        {
            Bullet bullet = new Bullet();

            bullet.x = x;
            bullet.y = y;

            int vel    = 0;
            int width  = 0;
            int height = 0;

            switch (type)
            {
            case bulletType.SMALL:     //adjust properties here
                vel    = 8;
                width  = 9;
                height = 9;
                break;

            case bulletType.SWORD:     // no bullets if a sword is the weapon
                vel    = 0;
                width  = 36;
                height = 36;
                break;
            }

            switch (dir) // determine direction the character is looking, so we know what trail to fire the bullets in
            {
            case PlayerDir.UP:
                bullet.vel_x = 0;
                bullet.vel_y = -vel;
                break;

            case PlayerDir.DOWN:
                bullet.vel_y = vel;
                bullet.vel_x = 0;
                break;

            case PlayerDir.LEFT:
                bullet.vel_x = -vel;
                bullet.vel_y = 0;
                break;

            case PlayerDir.RIGHT:
                bullet.vel_x = vel;
                bullet.vel_y = 0;
                break;
            }

            bullet.owner   = owner;
            bullet.type    = type;
            bullet.width   = width;
            bullet.height  = height;
            bullet.col_tok = game_state.coll_engine.register_object(bullet, ColType.BULLET);
            //set some final bullet properties

            bullets.Add(bullet); // add the bullet to the list to be displayed later

            return(bullet);
        }
Пример #6
0
        public Player(Vector2 p)
        {
            this.tile       = texture = Game1.content.Load <Texture2D>("Sprites/kenney_32x32");
            this.Position   = p;
            this.LayerDepth = 1f;
            this.playerDir  = PlayerDir.right;
            killed          = false;

            sn_kill_player = Game1.content.Load <SoundEffect>("Sounds/cute_low_impact_01");
            sn_jump        = Game1.content.Load <SoundEffect>("Sounds/Jump");

            // Setup physics
            rigidbody = BodyFactory.CreateCircle(Game1.world, ConvertUnits.ToSimUnits(playerRect.Width / 2), 1f, ConvertUnits.ToSimUnits(this.Position));
            //Set rigidbody behaivior here
            rigidbody.BodyType            = BodyType.Dynamic;
            rigidbody.SleepingAllowed     = false;
            rigidbody.UserData            = (string)"Player";
            rigidbody.FixedRotation       = true;
            rigidbody.Restitution         = 0f;            // No bounciness
            rigidbody.Friction            = 1f;
            rigidbody.CollisionCategories = Category.Cat2; // cat2 player
            rigidbody.CollidesWith        = Category.All;

            rigidbody.OnCollision += Rigidbody_OnCollision; // Tack collision
        }
Пример #7
0
        public Player(Vector2 p)
        {
            this.tile = texture = Game1.content.Load<Texture2D>("Sprites/kenney_32x32");
            this.Position = p;
            this.LayerDepth = 1f;
            this.playerDir = PlayerDir.right;
            killed = false;

            sn_kill_player = Game1.content.Load<SoundEffect>("Sounds/cute_low_impact_01");
            sn_jump = Game1.content.Load<SoundEffect>("Sounds/Jump");

            // Setup physics
            rigidbody = BodyFactory.CreateCircle(Game1.world, ConvertUnits.ToSimUnits(playerRect.Width / 2), 1f, ConvertUnits.ToSimUnits(this.Position));
            //Set rigidbody behaivior here
            rigidbody.BodyType = BodyType.Dynamic;
            rigidbody.SleepingAllowed = false;
            rigidbody.UserData = (string)"Player";
            rigidbody.FixedRotation = true;
            rigidbody.Restitution = 0f; // No bounciness
            rigidbody.Friction = 1f;
            rigidbody.CollisionCategories = Category.Cat2; // cat2 player
            rigidbody.CollidesWith = Category.All;

            rigidbody.OnCollision += Rigidbody_OnCollision; // Tack collision
        }
Пример #8
0
    // Use this for initialization
    void Start()
    {
        dir = this.GetComponent<PlayerDir>();
        controller = this.GetComponent<CharacterController>();

        dir.targetPosition = this.transform.position;
    }
Пример #9
0
        void fire(Enemy monster)
        {
            int       player_x  = game_state.local_player.getX();
            int       player_y  = game_state.local_player.getY();
            int       monster_x = monster.getX();
            int       monster_y = monster.getY();
            int       fire_x    = 0;
            int       fire_y    = 0;
            int       min       = 0;
            int       max       = 0;
            PlayerDir dir       = PlayerDir.UP;
            Random    random    = new Random();
            bool      fire      = false;

            if (player_x < monster_x + monster.getWidth() && player_x > monster_x - monster.getWidth())
            {
                fire   = true;
                min    = monster.getX();
                max    = monster.getX() + monster.getWidth();
                fire_x = random.Next(min, max);
                if (monster_y - player_y >= 0)
                {
                    dir    = PlayerDir.UP;
                    fire_y = monster.getY() + 5;
                }
                else
                {
                    dir    = PlayerDir.DOWN;
                    fire_y = monster.getY() + monster.getHeight();
                }
            }
            else if (player_y < monster_y + monster.getHeight() && player_y > monster_y - monster.getHeight())
            {
                fire   = true;
                min    = monster.getY();
                max    = monster.getY() + monster.getHeight();
                fire_y = random.Next(min, max);
                if (monster_x - player_x >= 0)
                {
                    dir    = PlayerDir.LEFT;
                    fire_x = monster.getX() - 5;
                }
                else
                {
                    dir    = PlayerDir.RIGHT;
                    fire_x = monster.getX() + monster.getWidth();
                }
            }
            if (fire)
            {
                game_state.bullet_engine.fire(fire_x, fire_y, dir, bulletOwner.ENEMY, bulletType.SMALL);
                fire = false;
            }
            else
            {
                this.advance(monster);
            }
            //Place holder till bullet system works
        }
Пример #10
0
        public Bullet fire(int x, int y, PlayerDir dir, bulletOwner owner, bulletType type)
        {
            Bullet bullet = new Bullet();

            bullet.x = x;
            bullet.y = y;

            int vel    = 0;
            int width  = 0;
            int height = 0;

            switch (type)
            {
            case bulletType.SMALL:
                vel    = 8;
                width  = 9;
                height = 9;
                break;

            case bulletType.SWORD:
                vel    = 0;
                width  = 36;
                height = 36;
                break;
            }

            switch (dir)
            {
            case PlayerDir.UP:
                bullet.vel_x = 0;
                bullet.vel_y = -vel;
                break;

            case PlayerDir.DOWN:
                bullet.vel_y = vel;
                bullet.vel_x = 0;
                break;

            case PlayerDir.LEFT:
                bullet.vel_x = -vel;
                bullet.vel_y = 0;
                break;

            case PlayerDir.RIGHT:
                bullet.vel_x = vel;
                bullet.vel_y = 0;
                break;
            }

            bullet.owner   = owner;
            bullet.type    = type;
            bullet.width   = width;
            bullet.height  = height;
            bullet.col_tok = game_state.coll_engine.register_object(bullet, ColType.BULLET);

            bullets.Add(bullet);

            return(bullet);
        }
Пример #11
0
  //  private NavMeshAgent agent;

	// Use this for initialization
	void Start () {
	
		dir = this.GetComponent<PlayerDir> ();
		controller = this.GetComponent<CharacterController> ();
        attack = this.transform.parent.GetComponent<DBaseFightRole>();
       // agent = this.GetComponent<NavMeshAgent>();

	}
Пример #12
0
    void Start()
    {
        dir = this.GetComponent <PlayerDir> ();

        controller = this.GetComponent <CharacterController> ();

        attack = this.GetComponent <PlayerAttack> ();
    }
Пример #13
0
    //애니메이션 컨트롤 함수
    void AnimationControl()
    {
        SpriteObj.transform.eulerAngles = new Vector3(0, Camera.main.transform.eulerAngles.y, 0);
        if (tempX > 0)
        {
            SpriteObj.transform.localScale = new Vector3(-spriteLocalScale, spriteLocalScale, spriteLocalScale);
        }
        if (tempX < 0)
        {
            SpriteObj.transform.localScale = new Vector3(spriteLocalScale, spriteLocalScale, spriteLocalScale);
        }
        if (tempZ > 0)
        {
            b_isBack  = true;
            playerDir = PlayerDir.Back;
        }
        if (tempZ < 0)
        {
            b_isBack  = false;
            playerDir = PlayerDir.Front;
        }
        if (tempZ == 0)
        {
            playerDir = PlayerDir.Side;
        }


        if (b_Air)
        {
            if (rigid.velocity.y > 0)
            {
                anim.Play("Jump_Up");
            }
            else
            {
                anim.Play("Jump_Down");
            }
        }
        else
        {
            if (rigid.velocity.x != 0 || rigid.velocity.z != 0)
            {
                anim.Play("Run");
            }
            else
            {
                //string temp = "Front";
                //if (b_isBack)
                //{
                //    temp = "Back";
                //}

                anim.Play("Idle");
            }
        }
    }
Пример #14
0
 // Use this for initialization
 void Start()
 {
     rigid            = GetComponent <Rigidbody>();
     SpriteObj        = transform.Find("Sprite");
     anim             = SpriteObj.GetComponent <Animator>();
     col              = GetComponent <CapsuleCollider>();
     playerDir        = PlayerDir.Back;
     spriteLocalScale = SpriteObj.localScale.x;
     cur_Health       = f_Health;
 }
Пример #15
0
    void Start()
    {
        DOTween.SetTweensCapacity(600, 600);

        gameStates    = GameStates.Start;
        playerDir     = PlayerDir.Straight;
        playerSpecial = playerObj.GetComponent <PlayerSpecial>();
        playerRb      = playerObj.GetComponent <Rigidbody>();
        camHolder.GetComponent <CameraFollow>().enabled = true;
        UIManager.Instance.distanceChecker.gameObject.SetActive(true);
    }
Пример #16
0
    /// <summary>
    /// Swing an axe and break the block over a certain period of time
    /// </summary>
    private IEnumerator BreakBlock()
    {
        _breakingBlock = true;
        yield return(new WaitForSeconds(.1f));

        //face the block
        if (target != null)
        {
            Debug.Log("Player " + playerID + " is about to break a block");

            float xDiff = transform.position.x - target.position.x;
            float yDiff = transform.position.y - target.position.y;

            if (xDiff < -.5f)
            {
                _direction = PlayerDir.Right;
            }
            if (xDiff > .5f)
            {
                _direction = PlayerDir.Left;
            }
            if (yDiff < -.5f)
            {
                _direction = PlayerDir.Up;
            }
            if (yDiff > .5f)
            {
                _direction = PlayerDir.Down;
            }
            int health = 0;
            if (target.gameObject.GetComponent <BreakableRock>() != null)
            {
                health = target.gameObject.GetComponent <BreakableRock>().health;
            }

            while (health > 0)
            {
                Debug.Log("um hello!!!!!");
                AxeDown();

                yield return(new WaitForSeconds(.5f));

                AxeUp();

                yield return(new WaitForSeconds(.5f));

                health--;
            }
        }
        DetermineNewTarget();
        _state         = AIState.TravelPath;
        _breakingBlock = false;
        _stuckNumber   = 0;
    }
Пример #17
0
        public Bullet fire(int x, int y, PlayerDir dir, bulletOwner owner, bulletType type)
        {
            Bullet bullet = new Bullet();
            bullet.x = x;
            bullet.y = y;

            int vel = 0;
            int width = 0;
            int height = 0;
            switch (type)
            {
                case bulletType.SMALL: //adjust properties here
                    vel = 8;
                    width = 9;
                    height = 9;
                    break;
                case bulletType.SWORD: // no bullets if a sword is the weapon
                    vel = 0;
                    width = 36;
                    height = 36;
                    break;
            }

            switch (dir) // determine direction the character is looking, so we know what trail to fire the bullets in
            {
                case PlayerDir.UP:
                    bullet.vel_x = 0;
                    bullet.vel_y = -vel;
                    break;
                case PlayerDir.DOWN:
                    bullet.vel_y = vel;
                    bullet.vel_x = 0;
                    break;
                case PlayerDir.LEFT:
                    bullet.vel_x = -vel;
                    bullet.vel_y = 0;
                    break;
                case PlayerDir.RIGHT:
                    bullet.vel_x = vel;
                    bullet.vel_y = 0;
                    break;
            }

            bullet.owner = owner;
            bullet.type = type;
            bullet.width = width;
            bullet.height = height;
            bullet.col_tok = game_state.coll_engine.register_object(bullet, ColType.BULLET);
            //set some final bullet properties

            bullets.Add(bullet); // add the bullet to the list to be displayed later

            return bullet;
        }
Пример #18
0
        public Bullet fire(int x, int y, PlayerDir dir, bulletOwner owner, bulletType type)
        {
            Bullet bullet = new Bullet();
            bullet.x = x;
            bullet.y = y;

            int vel = 0;
            int width = 0;
            int height = 0;
            switch (type)
            {
                case bulletType.SMALL:
                    vel = 8;
                    width = 9;
                    height = 9;
                    break;
                case bulletType.SWORD:
                    vel = 0;
                    width = 36;
                    height = 36;
                    break;
            }

            switch (dir)
            {
                case PlayerDir.UP:
                    bullet.vel_x = 0;
                    bullet.vel_y = -vel;
                    break;
                case PlayerDir.DOWN:
                    bullet.vel_y = vel;
                    bullet.vel_x = 0;
                    break;
                case PlayerDir.LEFT:
                    bullet.vel_x = -vel;
                    bullet.vel_y = 0;
                    break;
                case PlayerDir.RIGHT:
                    bullet.vel_x = vel;
                    bullet.vel_y = 0;
                    break;
            }

            bullet.owner = owner;
            bullet.type = type;
            bullet.width = width;
            bullet.height = height;
            bullet.col_tok = game_state.coll_engine.register_object(bullet, ColType.BULLET);

            bullets.Add(bullet);

            return bullet;
        }
Пример #19
0
        /**
         * Update the rotation of player before moving
         */
        IEnumerator RotatePlayer()
        {
            float nextRotation = 0.0f;

            // if we have to go to another direction
            if (nextPlayerDir != currentPlayerDir)
            {
                switch (nextPlayerDir)
                {
                case PlayerDir.Up:
                    nextRotation = 90;
                    break;

                case PlayerDir.Down:
                    nextRotation = -90;
                    break;

                case PlayerDir.Right:
                    nextRotation = 180;
                    break;

                case PlayerDir.Left:
                    nextRotation = 0;
                    break;
                }

                currentPlayerDir = nextPlayerDir;

                float   currentTime     = 0.0f;
                Vector3 currentRotation = transform.GetChild(0).localEulerAngles;

                //float deltaAngle = Mathf.DeltaAngle(m_CurrentYaw, m_TargetYaw);
                //deltaAngle = Mathf.Abs(deltaAngle);

                while (currentTime <= rotationTime)
                {
                    //display.transform.localPosition = Vector3.Lerp(originalPosition, destinationPosition, currentTime/timeHover);

                    currentRotation.y = Mathf.Lerp(currentRotation.y, nextRotation, Time.deltaTime * 15f);

                    transform.GetChild(0).localEulerAngles = currentRotation;

                    //print(currentRotation.y);

                    currentTime += Time.deltaTime;
                    yield return(null);
                }
            }

            playerCanMove = true;  //on autorise le player à bouger
        }
Пример #20
0
    void OnPlayerDirChange(NetworkMessage netMsg)
    {
        NetDir    dirUpdate = netMsg.ReadMessage <NetDir>();
        PlayerDir playerDir = new PlayerDir();

        playerDir.id    = netMsg.conn.connectionId;
        playerDir.vect3 = dirUpdate.value;
        playerDir.b     = dirUpdate.b;
        sendToAllExcept(netMsg.conn.connectionId, 912, playerDir);

        /*foreach(User u in ConnectedUsers.FindAll(x => x.id != netMsg.conn.connectionId)){
         *              NetworkServer.SendToClient(u.id,912,playerDir);
         *      }*/
        ConnectedUsers.Find(x => x.id == netMsg.conn.connectionId).direction = dirUpdate.value;
    }
Пример #21
0
	void Awake(){
		_instance = this;
		movexu = this.GetComponent<playerMove> ();
		psxu = this.GetComponent<PlayerStatus> ();
		hudtextFollow= transform.Find ("HUDTextXu").gameObject;
		//主角控制器
		controller = this.GetComponent<CharacterController> ();
		dir = this.GetComponent<PlayerDir> ();

		normal = body.renderer.material.color;
		foreach (GameObject go in effectxu) {
			skillIeffectDict.Add(go.name,go);		
		}

	}
Пример #22
0
    // Update is called once per frame
    void Update()
    {
        if (!canMove)
        {
            return;
        }

        if (Input.GetKey(KeyCode.Z))
        {
            run = 2;
        }
        else
        {
            run = 1;
        }

        Vector2 movement_vector = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));

        if (movement_vector != Vector2.zero)
        {
            anim.SetBool("isWalking", true);
            anim.SetFloat("input_x", movement_vector.x);
            anim.SetFloat("input_y", movement_vector.y);

            if (movement_vector == upVector)
            {
                currentDirection = PlayerDir.up;
            }
            else if (movement_vector == downVector)
            {
                currentDirection = PlayerDir.down;
            }
            else if (movement_vector == rightVector)
            {
                currentDirection = PlayerDir.right;
            }
            else if (movement_vector == leftVector)
            {
                currentDirection = PlayerDir.left;
            }
        }
        else
        {
            anim.SetBool("isWalking", false);
        }

        rbody.MovePosition(rbody.position + movement_vector * Time.deltaTime * run);
    }
Пример #23
0
    // Update is called once per frame
    private void Update()
    {
        float x = 0;
        float y = 0;

        if (canMove)
        {
            if (Input.GetKey(left) && !_axeDown)
            {
                x         -= _speed;
                _direction = PlayerDir.left;
            }

            else if (Input.GetKey(right) && !_axeDown)
            {
                x         += _speed;
                _direction = PlayerDir.right;
            }

            else if (Input.GetKey(up) && !_axeDown)
            {
                y         += _speed;
                _direction = PlayerDir.up;
            }

            else if (Input.GetKey(down) && !_axeDown)
            {
                y         -= _speed;
                _direction = PlayerDir.down;
            }

            if (Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.KeypadEnter))
            {
                AxeDown();
            }
            if (Input.GetMouseButtonUp(0) || Input.GetKeyUp(KeyCode.KeypadEnter))
            {
                AxeUp();
            }
        }



        transform.position += new Vector3(x, y, 0);
        GameData.Instance.playerLocalLocations[playerID] = transform.localPosition;
    }
Пример #24
0
        int attack, defense, speed, health, max_health; //Bonuses from items
        // player has an attack, speed, and health or hp stat
        // a small weapon inventory, size is to be decided
        // or a system of active/secondary weapons can be used

        /// <summary>
        /// Constructor for a Player object
        /// </summary>
        /// <param name="xLoc">Input the initial x coordinate of the player</param>
        /// <param name="yLoc">Input the initial y coordinate of the player</param>
        public Player(int xLoc, int yLoc, int pWidth, int pHeight)
        {
            last_x = x = xLoc;
            last_y = y = yLoc;
            width  = pWidth;
            height = pHeight;                 // set player position

            max_health   = health = 100;      // give the user 100 "units" of health
            speed        = 3;                 // move at 3 pixels/frame
            attack       = defense = 0;       // no additional boosts by default
            activeWeapon = weaponType.NONE;   // user starts with no weapons by default
            dir          = PlayerDir.UP;      // facing up by default
            moving       = false;             // users not moving by default
            col_tok      = null;
            inventory    = new List <Item>(); // has no inventory by default
            hurt         = false;             // user has not been hurt yet
        }
Пример #25
0
        /// <summary>
        /// Constructor for a Player object
        /// </summary>
        /// <param name="xLoc">Input the initial x coordinate of the player</param>
        /// <param name="yLoc">Input the initial y coordinate of the player</param>
        // player has an attack, speed, and health or hp stat
        // a small weapon inventory, size is to be decided
        // or a system of active/secondary weapons can be used
        public Player(int xLoc, int yLoc, int pWidth, int pHeight)
        {
            last_x = x = xLoc;
            last_y = y = yLoc;
            width  = pWidth;
            height = pHeight;

            max_health   = health = 100;
            speed        = 3;
            attack       = defense = 0;
            activeWeapon = weaponType.NONE;
            //secondaryWeapon = null;
            dir       = PlayerDir.UP;
            moving    = false;
            col_tok   = null;
            inventory = new List <Item>();
            hurt      = false;
        }
Пример #26
0
 public void movePlayer(PlayerDir dir)
 {
     if (dir == PlayerDir.LEFT)
     {
         if (tile_id % grid.width > 0)
         {
             StartCoroutine(PlayerMovement(grid.tiles[tile_id - 1].anchoredPosition));
             tile_id--;
         }
     }
     else if (dir == PlayerDir.RIGHT)
     {
         if (tile_id % grid.width < grid.width - 1)
         {
             StartCoroutine(PlayerMovement(grid.tiles[tile_id + 1].anchoredPosition));
             tile_id++;
         }
     }
 }
Пример #27
0
        public Enemy(int xLoc, int yLoc, int eWidth, int eHeight, enemyType t)
        {
            last_x = x = xLoc;
            last_y = y = yLoc;
            width = eWidth;
            height = eHeight;

            last_dir = dir = PlayerDir.UP;
            cur_target = null;
            col_tok = null;
            //creates the lowest level of enemy
            if (t == enemyType.GRUNT)
            {
                eType = t;
                attack = 2;
                speed = 2;
                max_health = health = 10;
            }
            //creates the second level of enemy
            else if (t == enemyType.BEETLE)
            {
                eType = t;
                attack = 5;
                speed = 2;
                max_health = health = 10;
            }
            //creates toughest level of enemy
            else if (t == enemyType.BERSERKER)
            {
                eType = t;
                attack = 5;
                speed = 3;
                max_health = health = 15;
            }
            else if (t == enemyType.TROOPER)
            {
                eType = t;
                attack = 5;
                speed = 2;
                max_health = health = 20;

            }
        }
Пример #28
0
        public Enemy(int xLoc, int yLoc, int eWidth, int eHeight, enemyType t)
        {
            last_x = x = xLoc;
            last_y = y = yLoc;
            width  = eWidth;
            height = eHeight;

            last_dir   = dir = PlayerDir.UP;
            cur_target = null;
            col_tok    = null;
            //creates the lowest level of enemy
            if (t == enemyType.GRUNT)
            {
                eType      = t;
                attack     = 2;
                speed      = 2;
                max_health = health = 10;
            }
            //creates the second level of enemy
            else if (t == enemyType.BEETLE)
            {
                eType      = t;
                attack     = 5;
                speed      = 2;
                max_health = health = 10;
            }
            //creates toughest level of enemy
            else if (t == enemyType.BERSERKER)
            {
                eType      = t;
                attack     = 5;
                speed      = 3;
                max_health = health = 15;
            }
            else if (t == enemyType.TROOPER)
            {
                eType      = t;
                attack     = 5;
                speed      = 2;
                max_health = health = 20;
            }
        }
Пример #29
0
    private void EnumBehaviour()
    {
        if (Input.mousePosition.x < Camera.main.WorldToScreenPoint(transform.position).x)
        {
            playerDir = PlayerDir.Left;
        }
        else
        {
            playerDir = PlayerDir.Right;
        }

        if (Input.GetAxis("Controller Axis") == -1)
        {
            playerDir = PlayerDir.Left;
        }
        else if (Input.GetAxis("Controller Axis") == 1)
        {
            playerDir = PlayerDir.Right;
        }
    }
Пример #30
0
    private Vector3 skillReleasePos;    //AOE技能释放位置

    void Awake()
    {
        player       = GameObject.FindGameObjectWithTag(Tags.Player);
        playerDir    = player.GetComponent <PlayerDir>();
        playerMove   = player.GetComponent <PlayerMove>();
        playerStatus = player.GetComponent <PlayerStatus>();
        animator     = GetComponent <Animator>();

        foreach (Transform temp in player.transform)
        {
            Renderer render = temp.GetComponent <MeshRenderer>();
            if (null != render)
            {
                pRenderList.Add(render);
                normalColorList.Add(render.material.color);
            }
        }
//        foreach (var skillEffectPrefab in skillEffectList)
//        {
//            skillEffectDictionary.Add(skillEffectPrefab.name, skillEffectPrefab);
//        }
    }
Пример #31
0
        private void Input(GameTime gameTime)
        {
            if (Keyboard.GetState().IsKeyDown(Keys.Left))
            {
                //  rigidbody.LinearVelocity = new Vector2(-moveSpeed, rigidbody.LinearVelocity.Y);
                rigidbody.Position = new Vector2(rigidbody.Position.X - moveSpeed * Time.DeltaTime, rigidbody.Position.Y);
                playerDir          = PlayerDir.left;

                if (isGrounded)
                {
                    Frames();
                }
            }

            if (Keyboard.GetState().IsKeyDown(Keys.Right))
            {
                //  rigidbody.LinearVelocity = new Vector2(moveSpeed, rigidbody.LinearVelocity.Y);
                rigidbody.Position = new Vector2(rigidbody.Position.X + moveSpeed * Time.DeltaTime, rigidbody.Position.Y);
                playerDir          = PlayerDir.right;

                if (isGrounded)
                {
                    Frames();
                }
            }

            if (Keyboard.GetState().IsKeyDown(Keys.Space) && !buttonDown)
            {
                GameDebug.Log("JUMP!!!!");
                jumpCount += 1;
                Jump(gameTime);
                buttonDown = true;
            }
            else if (Keyboard.GetState().IsKeyUp(Keys.Space) && buttonDown)
            {
                GameDebug.Log("DO NOT JUMP!!!!!");
                buttonDown = false;
            }
        }
Пример #32
0
        /**
         * Update the list of the tiles the player has to go through and then activate move mechanic
         * The parameter targetNodePos is the target node position
         */
        public void CalculatePlayerPath(Vector3Int targetNodePos)
        {
            nbNodesToMove = BuffManager.Instance.ApplyModifiedMove(_cardEffectDatas[0].nbMoves); //Update le nombre de rooms à parcourir, qui changera en fct du nb sur la carte et si un fast shoes a été joué

            GameManager.Instance.DownPanelBlock(true);                                           //Block le down panel pour que le joueur ne puisse pas jouer de carte pendant le mouvement


            //Get player tile pos
            Vector3Int playerTilePos = GetTilePosOfPlayer();

            //Get target tile pos from the target node
            Vector3Int targetTilePos = new Vector3Int(targetNodePos.x + 1, playerTilePos.y, targetNodePos.z + 1);

            playerPath = new List <Spot>();

            tileIndex = 0;

            if (playerPath != null && playerPath.Count > 0) //reset le roadpath
            {
                playerPath.Clear();
            }


            //création du path, prenant en compte la position des tiles, le point de départ, le point d'arrivée, et la longueur en tiles du path
            //playerPath est une liste de spots = une liste de positions de tiles
            playerPath = MapManager.Instance.astar.CreatePath(MapManager.Instance.grid, new Vector2Int(playerTilePos.x, playerTilePos.z), new Vector2Int(targetTilePos.x, targetTilePos.z), 5);

            enemyOnPath = false;

            if (playerPath == null)
            {
                return;
            }

            // S'il y a un enemy au bout du chemin, on retire la tile où il se situe
            if (null != EnemyMgr.Instance.GetEnemyByPosition(new Vector3Int(playerPath[0].X, 0, playerPath[0].Y)))
            {
                EnemyMgr.Instance.GetEnemyByPosition(new Vector3Int(playerPath[0].X, 0, playerPath[0].Y)).enemyData.inPlayersNode = true;
                enemyOnPath = true;
                firstInRoom = false;

                supposedPos = new Vector3Int(playerPath[0].X, 0, playerPath[0].Y);    //La position supposée est celle de l'ennemi sur le path
                playerPath.Remove(playerPath[0]);
            }

            //Si on ETAIT le premier arrivé dans la room, alors un ennemi présent dans la room doit se recentrer au milieu de la room
            if (firstInRoom)
            {
                EnemyMgr.Instance.RecenterEnemiesAfterPlayerMove();
            }


            playerPath.Reverse(); //on inverse la liste pour la parcourir de la tile la plus proche à la plus éloignée
            playerPath.RemoveAt(0);

            //Si on n'a pas d'ennemi sur le chemin, on est le premier arrivé dans la room
            if (!enemyOnPath)
            {
                supposedPos = new Vector3Int(playerPath[playerPath.Count - 1].X, 0, playerPath[playerPath.Count - 1].Y); //position supposée = dernière tile du path

                firstInRoom = true;
                foreach (EnemyScript enemy in EnemyMgr.Instance.GetEnemiesOnPlayersNode())
                {
                    enemy.enemyData.inPlayersNode = false;
                }
            }

            // Player is moving LEFT
            if (playerPath[0].X > playerPath[1].X)
            {
                nextPlayerDir = PlayerDir.Left;
            }
            // Player is moving RIGHT
            else if (playerPath[0].X < playerPath[1].X)
            {
                nextPlayerDir = PlayerDir.Right;
            }
            // Player is moving DOWN
            else if (playerPath[0].Y > playerPath[1].Y)
            {
                nextPlayerDir = PlayerDir.Down;
            }
            // Player is moving UP
            else if (playerPath[0].Y < playerPath[1].Y)
            {
                nextPlayerDir = PlayerDir.Up;
            }

            StartCoroutine(RotatePlayer());

            tileIndex = 0;

            nbMoveIterationCounter++;   //On ajoute un move au compteur


            //SFX player move
            MusicManager.Instance.PlayPlayerMove();
        }
Пример #33
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>
        public void Update(GameTime gameTime) // is the user dead? if so handle it
        {
            if (game_state.local_player.getHealth() <= 0)
            {
                die();
                return;
            }

            PlayerDir pot_dir = game_state.local_player.getDirection();
            int       pot_x   = game_state.local_player.getX();
            int       pot_y   = game_state.local_player.getY();

            double new_width = ((double)health_bar_width) * (double)((double)game_state.local_player.getHealth() / (double)game_state.local_player.getMaxHealth());

            health_bar_rec.Width = (int)new_width;

            TouchCollection touchCollection = TouchPanel.GetState();

            foreach (TouchLocation tl in touchCollection)
            // for each place the screen has been touched at the point of "getState"
            {
                //if the screen is pressed on an arrow, move sprite accordingly
                if (tl.State == TouchLocationState.Pressed || tl.State == TouchLocationState.Moved)
                {
                    if ((tl.Position.X >= 60) && (tl.Position.X <= 110) && (tl.Position.Y >= 330) && (tl.Position.Y <= 380)) // up arrow
                    {
                        pot_y  -= game_state.local_player.getSpeed();
                        pot_dir = PlayerDir.UP;
                        // -1 = up direction (axis goes down incresingly)
                    }

                    if ((tl.Position.X >= 60) && (tl.Position.X <= 110) && (tl.Position.Y >= 420) && (tl.Position.Y <= 470)) // down arrow
                    {
                        pot_y  += game_state.local_player.getSpeed();
                        pot_dir = PlayerDir.DOWN;
                    }

                    if ((tl.Position.X >= 15) && (tl.Position.X <= 65) && (tl.Position.Y >= 375) && (tl.Position.Y <= 425)) // left arrow
                    {
                        pot_x  -= game_state.local_player.getSpeed();
                        pot_dir = PlayerDir.LEFT;
                    }

                    if ((tl.Position.X >= 100) && (tl.Position.X <= 150) && (tl.Position.Y >= 375) && (tl.Position.Y <= 425)) // right arrow
                    {
                        pot_x  += game_state.local_player.getSpeed();
                        pot_dir = PlayerDir.RIGHT;
                    }


                    //Collision and updating
                    if (game_state.coll_engine.check_map_col(pot_x, pot_y, game_state.local_player.getWidth(), game_state.local_player.getHeight()) == false)
                    {
                        if (game_state.obj_mang.checkForGateAt(pot_x, pot_y, game_state.local_player.getWidth(), game_state.local_player.getHeight()) && !game_state.local_player.hasKey())
                        {
                            //there is a gate and the player does not have a key
                        }
                        else //no gate or the player has the key
                        {
                            game_state.local_player.setX(pot_x);
                            game_state.local_player.setY(pot_y);


                            Item item = game_state.obj_mang.getItemAt(pot_x, pot_y, game_state.local_player.getWidth(), game_state.local_player.getHeight());
                            if (item != null)
                            {
                                game_state.fx_engine.RequestSound(soundType.ITEM_PICKUP);
                                game_state.local_player.addItem(item); // item collected, set weapon type to respective type of item collected

                                if (game_state.local_player.getWeapon() == weaponType.NONE)
                                {
                                    if (item.getType() == itemType.SWORD)
                                    {
                                        game_state.local_player.setWeapon(weaponType.SWORD);
                                    }
                                    if (item.getType() == itemType.LASER)
                                    {
                                        game_state.local_player.setWeapon(weaponType.LASER);
                                    }
                                }
                            }

                            if (!game_state.local_player.moving) // player is still
                            {
                                game_state.local_player.setDirection(pot_dir);
                                game_state.local_player.moving = true;
                                character_sprite[(int)game_state.local_player.getWeapon()].StartAnimating((int)pot_dir * 3, ((int)pot_dir * 3) + 2);
                            }
                        }
                    }
                }
                else if (tl.State == TouchLocationState.Released)
                {
                    if (tl.Position.X >= backpackpos.X && tl.Position.X <= backpackpos.X + backpack.Width && tl.Position.Y >= backpackpos.Y && tl.Position.Y <= backpackpos.Y + backpack.Height)
                    {
                        // has user elected to bring up inventory?
                        backpackmenu.backpack_touched = true;
                        //^^ yes
                    }
                    if (backpackmenu.backpack_touched == false)               // if they havent
                    {
                        if ((tl.Position.X >= 700) && (tl.Position.Y >= 385)) // and the Fire button is tapped
                        {
                            game_state.fx_engine.RequestRumble(200);
                            if (game_state.local_player.getWeapon() == weaponType.LASER) //if the proper weapon is selected and able to shoot bullets while the fire button is tapped

                            {
                                game_state.bullet_engine.fire(game_state.local_player.getX() + (int)character_sprite[(int)game_state.local_player.getWeapon()].size.X / 2,
                                                              game_state.local_player.getY() + (int)character_sprite[(int)game_state.local_player.getWeapon()].size.Y / 2,
                                                              game_state.local_player.getDirection(),
                                                              bulletOwner.PLAYER,
                                                              bulletType.SMALL);
                                game_state.fx_engine.RequestSound(soundType.SHOOT); // shoot a bullet
                            }
                            else if (game_state.local_player.getWeapon() == weaponType.SWORD)
                            // else swing the sword, dont shoot bullets
                            {
                                sword_swing = true;
                                game_state.fx_engine.RequestSound(soundType.SWORD);
                                int bullet_x = 0;
                                int bullet_y = 0;
                                switch (game_state.local_player.getDirection())
                                {
                                case PlayerDir.DOWN:
                                    bullet_x = game_state.local_player.getX() - 2;
                                    bullet_y = game_state.local_player.getY() + game_state.local_player.getHeight();
                                    break;

                                case PlayerDir.UP:
                                    bullet_x = game_state.local_player.getX() - 2;
                                    bullet_y = game_state.local_player.getY() - game_state.local_player.getHeight();
                                    break;

                                case PlayerDir.LEFT:
                                    bullet_x = game_state.local_player.getX() - (game_state.local_player.getWidth());
                                    bullet_y = game_state.local_player.getY();
                                    break;

                                case PlayerDir.RIGHT:
                                    bullet_x = game_state.local_player.getX() + game_state.local_player.getWidth();
                                    bullet_y = game_state.local_player.getY();
                                    break;
                                }

                                sword_bullet = game_state.bullet_engine.fire(bullet_x, bullet_y, game_state.local_player.getDirection(), bulletOwner.PLAYER, bulletType.SWORD);
                            }
                        }
                    }
                    else // bring up the inventory and display the items properly and in an orderly fashion
                    {
                        Vector2 formatpos = new Vector2(315, 170);
                        int     tileSize  = game_state.tile_engine.getTileSize();

                        Item toRemove = null;
                        foreach (Item i in game_state.local_player.getInventory())
                        {
                            Rectangle dest = new Rectangle((int)formatpos.X, (int)formatpos.Y, 300, 40);
                            if (dest.Contains((int)tl.Position.X, (int)tl.Position.Y))
                            {
                                //menu item Clicked and ready to be used in game
                                switch (i.getType())
                                {
                                case itemType.LASER: game_state.local_player.setWeapon(weaponType.LASER); break;

                                case itemType.SWORD: game_state.local_player.setWeapon(weaponType.SWORD); break;

                                case itemType.ATT_BOOST: toRemove = i; att_boost_delay = 10000; game_state.local_player.setAttackBonus(5); break;

                                case itemType.DEF_BOOST: toRemove = i; def_boost_delay = 10000; game_state.local_player.setDefenseBonus(5); break;

                                case itemType.KEY:
                                default: break;
                                }
                                backpackmenu.backpack_touched = false;  // exit from inventory now
                            }
                            formatpos.Y += 50;
                        }
                        if (toRemove != null)
                        {
                            game_state.local_player.removeItem(toRemove);
                        }

                        if (backpackExit.Contains((int)tl.Position.X, (int)tl.Position.Y)) // coordinates of the "exit" button in inventory
                        {
                            backpackmenu.backpack_touched = false;                         //user has exited, return to main game screen
                        }
                    }

                    character_sprite[(int)game_state.local_player.getWeapon()].StopAnimating();
                    game_state.local_player.moving = false;
                }
            }

            if (sword_swing) // swing sword
            {
                sword_delay += gameTime.ElapsedGameTime.Milliseconds;
                if (sword_delay > 200)
                {
                    sword_delay = 0;
                    sword_swing = false;
                    game_state.bullet_engine.RemoveBullet(sword_bullet);
                }
            }

            if (game_state.local_player.getAttackBonus() > 0) //add attack bonuses
            {
                att_boost_delay -= gameTime.ElapsedGameTime.Milliseconds;
                if (att_boost_delay <= 0)
                {
                    game_state.local_player.setAttackBonus(0);
                }
            }

            if (game_state.local_player.getDefenseBonus() > 0) // add defensive bonuses
            {
                def_boost_delay -= gameTime.ElapsedGameTime.Milliseconds;
                if (def_boost_delay <= 0)
                {
                    game_state.local_player.setDefenseBonus(0);
                }
            }

            List <ColToken> cols = game_state.local_player.col_tok.GetCollisions();

            for (int j = 0; j < cols.Count(); ++j)
            {
                ColToken coll = cols.ElementAt(j);
                if (coll.GetLocalType() != ColType.MAP)
                {
                    if (!game_state.local_player.hurt)
                    {
                        int damage = 0;
                        if (coll.GetLocalType() == ColType.BULLET)
                        {
                            Bullet bul = (Bullet)coll.GetParent();
                            if (bul.owner == bulletOwner.PLAYER)
                            {
                                continue;
                            }
                        }
                        else if (coll.GetLocalType() == ColType.MONSTER)
                        {
                            Enemy enem = (Enemy)coll.GetParent();
                            damage = enem.getAttack();
                        }
                        //Player gets hurt!

                        game_state.local_player.setHealth(game_state.local_player.getHealth() + game_state.local_player.getDefenseBonus() - damage);
                        game_state.local_player.hurt = true;
                        game_state.fx_engine.RequestSound(soundType.PLAYER_HURT);
                        //Get hurt by a little
                        hurt_time = 500;
                    }
                }
            }
            game_state.local_player.col_tok.ResetCollisions();
            game_state.local_player.col_tok.update(game_state.local_player.getX(), game_state.local_player.getY());

            if (game_state.local_player.hurt)
            {
                hurt_time -= gameTime.ElapsedGameTime.Milliseconds; // dont repeatedly get hurt, only get hurt once per attack by an enemy
                if (hurt_time <= 0)
                {
                    game_state.local_player.hurt = false; // time to get hurt has run out
                }
            }
            currTime -= gameTime.ElapsedGameTime; // start timer on actual game


            if (currTime.TotalSeconds <= 0) // time per level has run out
            {
                return;
            }

            game_state.monster_engine.Update(gameTime.ElapsedGameTime.Milliseconds);
            game_state.bullet_engine.Update();

            game_state.coll_engine.Update();

            game_state.fx_engine.Update(gameTime.ElapsedGameTime.Milliseconds);
            if (testAtExit(game_state.local_player.getX(), (game_state.local_player.getY() + game_state.local_player.getHeight() - 1)) || testAtExit(game_state.local_player.getX() + game_state.local_player.getWidth(), (game_state.local_player.getY() + game_state.local_player.getHeight())))
            {
                int tempn = game_state.tile_engine.getCurrentLevel() + 1;
                LoadLevel(tempn);
            }
        }
Пример #34
0
 public void setDirection(PlayerDir _dir)
 {
     last_dir = dir;
     dir      = _dir;
 }
Пример #35
0
 public void setDirection(PlayerDir _dir)
 {
     dir = _dir;
 }
Пример #36
0
    void rotate()
    {
        if (Input.GetMouseButtonDown(0))
        {
            mouseClick = Input.mousePosition;
        }

        if (Input.GetMouseButtonUp(0))
        {
            mouseGap = Input.mousePosition - mouseClick;
        }


        float gapX = mouseGap.x;
        float gapY = mouseGap.y;

        switch (currentDir)
        {
        case PlayerDir.up:
            if (gapX > 200)
            {
                transform.Rotate(new Vector3(0, 0, 90));
                currentDir = PlayerDir.right;
                mouseGap   = Vector3.zero;
            }
            else if (gapX < -200)
            {
                transform.Rotate(new Vector3(0, 0, -90));
                currentDir = PlayerDir.left;
                mouseGap   = Vector3.zero;
            }
            break;

        case PlayerDir.right:
            if (gapY > 200)
            {
                transform.Rotate(new Vector3(0, 0, -90));
                currentDir = PlayerDir.up;
                mouseGap   = Vector3.zero;
            }
            else if (gapY < -200)
            {
                transform.Rotate(new Vector3(0, 0, 90));
                currentDir = PlayerDir.down;
                mouseGap   = Vector3.zero;
            }
            break;

        case PlayerDir.down:
            if (gapX > 200)
            {
                transform.Rotate(new Vector3(0, 0, -90));
                currentDir = PlayerDir.right;
                mouseGap   = Vector3.zero;
            }
            else if (gapX < -200)
            {
                transform.Rotate(new Vector3(0, 0, 90));
                currentDir = PlayerDir.left;
                mouseGap   = Vector3.zero;
            }
            break;

        case PlayerDir.left:
            if (gapY > 200)
            {
                transform.Rotate(new Vector3(0, 0, 90));
                currentDir = PlayerDir.up;
                mouseGap   = Vector3.zero;
            }
            else if (gapY < -200)
            {
                transform.Rotate(new Vector3(0, 0, -90));
                currentDir = PlayerDir.down;
                mouseGap   = Vector3.zero;
            }
            break;
        }
    }
Пример #37
0
 private void OnEnable()
 {
     currentDir = PlayerDir.up;
 }
Пример #38
0
        /// <summary>
        /// Constructor for a Player object
        /// </summary>
        /// <param name="xLoc">Input the initial x coordinate of the player</param>
        /// <param name="yLoc">Input the initial y coordinate of the player</param>
        // player has an attack, speed, and health or hp stat
        // a small weapon inventory, size is to be decided
        // or a system of active/secondary weapons can be used
        public Player(int xLoc, int yLoc, int pWidth, int pHeight)
        {
            last_x = x = xLoc;
            last_y = y = yLoc;
            width = pWidth;
            height = pHeight;

            max_health = health = 100;
            speed = 3;
            attack = defense = 0;
            activeWeapon = weaponType.NONE;
            //secondaryWeapon = null;
            dir = PlayerDir.UP;
            moving = false;
            col_tok = null;
            inventory = new List<Item>();
            hurt = false;
        }
Пример #39
0
 public void setDirection(PlayerDir _dir)
 {
     dir = _dir;
 }
Пример #40
0
        private void Input(GameTime gameTime)
        {
            if (Keyboard.GetState().IsKeyDown(Keys.Left))
            {
              //  rigidbody.LinearVelocity = new Vector2(-moveSpeed, rigidbody.LinearVelocity.Y);
              rigidbody.Position = new Vector2(rigidbody.Position.X -moveSpeed * Time.DeltaTime, rigidbody.Position.Y);
                playerDir = PlayerDir.left;

                if (isGrounded)
                    Frames();
            }

            if (Keyboard.GetState().IsKeyDown(Keys.Right))
            {
                //  rigidbody.LinearVelocity = new Vector2(moveSpeed, rigidbody.LinearVelocity.Y);
                rigidbody.Position = new Vector2(rigidbody.Position.X + moveSpeed * Time.DeltaTime, rigidbody.Position.Y);
                playerDir = PlayerDir.right;

                if (isGrounded)
                    Frames();
            }

            if (Keyboard.GetState().IsKeyDown(Keys.Space) && !buttonDown)
            {
                GameDebug.Log("JUMP!!!!");
                jumpCount += 1;
                Jump(gameTime);
                buttonDown = true;
            }
            else if (Keyboard.GetState().IsKeyUp(Keys.Space) && buttonDown)
            {
                GameDebug.Log("DO NOT JUMP!!!!!");
                buttonDown = false;
            }
        }
Пример #41
0
 public void setDirection(PlayerDir _dir)
 {
     last_dir = dir;
     dir = _dir;
 }
Пример #42
0
        int y; // y position

        #endregion Fields

        #region Constructors

        // player has an attack, speed, and health or hp stat
        // a small weapon inventory, size is to be decided
        // or a system of active/secondary weapons can be used
        /// <summary>
        /// Constructor for a Player object
        /// </summary>
        /// <param name="xLoc">Input the initial x coordinate of the player</param>
        /// <param name="yLoc">Input the initial y coordinate of the player</param>
        public Player(int xLoc, int yLoc, int pWidth, int pHeight)
        {
            last_x = x = xLoc;
            last_y = y = yLoc;
            width = pWidth;
            height = pHeight; // set player position

            max_health = health = 100; // give the user 100 "units" of health
            speed = 3; // move at 3 pixels/frame
            attack = defense = 0; // no additional boosts by default
            activeWeapon = weaponType.NONE; // user starts with no weapons by default
            dir = PlayerDir.UP; // facing up by default
            moving = false; // users not moving by default
            col_tok = null;
            inventory = new List<Item>(); // has no inventory by default
            hurt = false; // user has not been hurt yet
        }
Пример #43
0
 public void setDirection(PlayerDir _dir)
 {
     dir = _dir; //update direction the character is facing
 }