Example #1
0
    void OnTriggerEnter2D(Collider2D other)
    {
        if (gamecon.gamestate == global::Gemecon.Gamestate.play)
        {
            if (other.gameObject.tag == "Enemybullet" ||
                other.gameObject.tag == "enemy" ||
                other.gameObject.tag == "boss")
            {
                if (gamecon.gamestate != Gemecon.Gamestate.clear)
                {
                    Instantiate(P_explo, transform.position, Quaternion.identity);
                    se.source.PlayOneShot(se.explo);
                    gamecon.gamestate = global::Gemecon.Gamestate.gekiha;
                    Destroy(gameObject);
                }
            }
        }

        switch (other.gameObject.tag)
        {
        case "Item_W": Destroy(other.gameObject);
            playerstate = Playerstate.Wide;
            break;

        case "Item_L":
            Destroy(other.gameObject);
            playerstate = Playerstate.laser;
            break;

        default: break;
        }
    }
Example #2
0
 public void SetState(Playerstate newstate)
 {
     foreach (PlayerFSMState fsm in states.Values)
     {
         fsm.enabled = false;
     }
     states[newstate].enabled = true;
 }
Example #3
0
 // Use this for initialization
 void Start()
 {
     gamecon     = GameObject.FindWithTag("Respawn").GetComponent <Gemecon>();
     mutekibool  = false;
     renderer    = GetComponent <SpriteRenderer>();
     animator    = GetComponent <Animator>();
     Rigid2D     = GetComponent <Rigidbody2D>();
     playerstate = Playerstate.Normal;
     se          = GameObject.FindWithTag("se").GetComponent <sescript>();
     speed       = syokispeed;
 }
Example #4
0
        public Player()
        {
            //default constructor
            health = 1;
            Image = ImageBank.defaultImage;

            Location = new Rectangle(50, 250, 57, 87);
            //Location.Width = Image.Width;
            //Location.Height = Image.Height;
            bullet = new Projectile(0,0,false);
            bullet.Active = false;
            //map = m;
            state = Playerstate.standing;
            previous = state;

            //    bullet = new Projectile(2, 2, false);
        }
Example #5
0
    void Update() {
        horizontalInput = Input.GetAxisRaw("Horizontal");

        animator.SetFloat("Speed", Mathf.Abs(horizontalInput));

        if(Input.GetKeyUp(KeyCode.Space)) {
            jumpButtonReleased = true;
        }
        if(Input.GetKeyDown(KeyCode.Space) && jumpButtonReleased && onGround) {
            jump = true;
            jumpButtonReleased = false;
        }

        if(ps == Playerstate.Jumparound && randomJumpTimer < 0) {
            randomJumpTimer = Random.Range(.3f, 1f);
            jump = true;
        }

        if(powerupTimer < 0) {
            ps = Playerstate.Normal;
        }
        powerupTimer -= Time.deltaTime;
        randomJumpTimer -= Time.deltaTime;
    }
Example #6
0
 public void EatShroom(Playerstate state) {
     ps = state;
     powerupTimer = powerupTime;
 }
Example #7
0
        //overload of update method
        public override void Update()
        {
            if (previous != state) {
               // ResetAnimation();
            }
             //   base.Update();

            if (state == Playerstate.standing || state == Playerstate.defending || state == Playerstate.attacking) { //if player is standing still, deccelarate
                if (xSpeed > 0) { xSpeed-=acceleration; }
                else if (xSpeed < 0) { xSpeed += acceleration; }
                else { xSpeed = 0; } //Bugfix: if caught in small space between acc and -acc, set speed to 0 to avoid sliding
            }

            Map.scroll.X -= xSpeed;
            Map.scroll.Y -= ySpeed;

            if (shotFired) { //if shot fired
                shootTimer++; //wait [shootCooldown] many frames to renenable shooting
                if (shootTimer >= shootCooldown) {
                    shootTimer = 0;
                    shotFired = false;
                }
            }

            //update player's image based on current state
            if (state == Playerstate.jumping) {
                Animate(ImageBank.playerJump);
            } else if (state == Playerstate.walking) { //most animations have variants depending on cheat state
                animationSpeed = 7;
                if (cheat == Cheatstate.attack) {
                    Animate(ImageBank.playerWalkShoot);
                }
                else if (cheat == Cheatstate.defend) {
                    Animate(ImageBank.playerWalkDefend);
                }
                else {
                    Animate(ImageBank.playerWalk);
                }
            } else if (state == Playerstate.standing) {
                animationSpeed = 25;
                if (cheat == Cheatstate.attack) {
                    Animate(ImageBank.playerStandShoot);
                }
                else if (cheat == Cheatstate.defend) {
                    Animate(ImageBank.playerStandDefend);
                }
                else {
                    Animate(ImageBank.playerStand);
                }
            }
            /*else if (attacking) {
                animationSpeed = 1;
                Animate(ImageBank.playerAttack);
            }*/
            else if (state == Playerstate.defending) {
                animationSpeed = 1;
                Animate(ImageBank.playerDefend);
            }///*
            else if (state == Playerstate.attacking) {
                animationSpeed = 1;
                Animate(ImageBank.playerAttack);
            }
            if (animationEnd) {
                attacking = false;
            }//*/

            //after updating image, reset state (unless it's jumping state, which must be changed externally)
            if (state != Playerstate.jumping && idle) {
                state = Playerstate.standing;
            }

            if (state != previous)
            {
                animationTimer = 25;
            }

            //increment shieldTimer when shield is broken
            if (shieldTimer < shieldCooldown && shieldBroken) {
                shieldTimer++;
            }
            else if (shieldTimer == shieldCooldown) { //when shieldTimer passes cooldown, repair shield
                shieldBroken = false;
            }

            previous = state;

            base.Update();

            //apply gravity
            ySpeed += Movable.gravity;
            //ySpeed = 1;

            idle = true;

            if (countDown >= 0) {
                countDown--;
            } if (countDown == 0) {
                col = Color.White;
            }

            //collidingWithPlatform = false;
        }
Example #8
0
 //player has collided with enemy or bullet
 public void TakeHit()
 {
     if (state != Playerstate.defending) {
         base.TakeDamage(1);
     }
     else { //if player is defending, he will not take damage
         state = Playerstate.shieldBreaking;
         shieldBroken = true;
         shieldTimer = 0;
     }
     //Reset();
 }
Example #9
0
        private void Dead()
        {
            if (lives > 0)
            {
                Lives(-1);
                X(25);
                Y(Game.HEIGHT / 2 - bodyTexture.Height / 2);
            }

            state = Playerstate.Alive;
        }
Example #10
0
 public void SetPlayerState(Playerstate p_state)
 {
     m_prevPlayerState   = m_playerState;
     m_playerState       = p_state;
     playerStateModified = true;
 }
Example #11
0
    void Update()
    {
        if (Ismoving == true)
        {
            state = Playerstate.running_and_gunning; //todat ik een beteren run animation heb is dit de run animation
        }
        else if (Ismoving == false)
        {
            state = Playerstate.idle;
        }

        #region Movement

        //float moveHorizontal = Input.GetAxisRaw("Horizontal");
        //float moveVertical = Input.GetAxisRaw("Vertical");

        //movement = new Vector3(moveHorizontal, moveVertical, 0f);

        //movement = movement * speed * Time.deltaTime;

        //transform.position += movement;



        #endregion

        if (follow_mouse_bullet != null)
        {
            follow_mouse_bullet_position = follow_mouse_bullet.transform.position;
        }

        #region BulletSwitch

        if (Input.GetKeyDown(KeyCode.E))
        {
            BulletSwitch += 1;

            if (BulletSwitch != 1)
            {
                follow_mouse_bullet.SetActive(false);
            }
        }

        //dit zorgt er voor dat de bullet switch niet -1 kan zijn
        if (BulletSwitch < 0)
        {
            BulletSwitch = 0;
        }

        //door de code boven en onder kan de bullet switch dus alleen 0 en 1 zijn en als ik meer nodig heb dan moet ik
        //de code van onder aanpassen door er een bij te doen

        //dit zorgt er voor dat de bullet switch weer terug gaat naar het begin
        if (BulletSwitch > 1)
        {
            BulletSwitch = 0;
        }

        //Debug.Log("Bullet Switch = " + BulletSwitch);

        #endregion



        if (Input.GetMouseButton(0))
        {
            if (BulletSwitch == 0)
            {
                if (Ismoving == true)
                {
                    ShootNormalBullets();
                    state = Playerstate.running_and_gunning;
                    MuzzleFlashAnimation.SetActive(true);
                }
                else if (Ismoving == false)
                {
                    ShootNormalBullets();
                    state = Playerstate.standing_and_gunning;
                    MuzzleFlashAnimation.SetActive(true);
                }
            }
        }

        if (Input.GetMouseButtonUp(0))
        {
            if (BulletSwitch == 1)
            {
                ShootFollowMouseBullets();
            }
        }

        //nadat de player heeft geschoten zet ik hier de muzzleflash uit
        //en voor de zekerheid zet ik de players animatie op idle
        if (Input.GetMouseButtonUp(0))
        {
            state = Playerstate.idle;
            MuzzleFlashAnimation.SetActive(false);
        }

        if (Input.GetMouseButtonDown(1))
        {
            Teleport();
        }

        if (Input.GetMouseButton(2))
        {
            CreateBarricade();
        }

        animator.SetInteger("State", (int)state);
    }
Example #12
0
 public void State(int newState)
 {
     if (newState == 1)
         state = Playerstate.Alive;
     if (newState == 2)
         state = Playerstate.Dead;
 }
Example #13
0
 //player touches ground and can jump again
 public override void Landing()
 {
     base.Landing();
     if (state == Playerstate.jumping) {
         state = Playerstate.standing;
     }
     hasJumped = false;
 }
Example #14
0
 //method controls walking, does not have a bool value as I assume it can't be disabled
 private void Walk(bool facingLeft)
 {
     if (!collidingWithWall)
     {
         idle = false;
         if (state != Playerstate.jumping)
         { //unless player is airborn, set state to walking
             state = Playerstate.walking;
         }
         faceLeft = facingLeft;
         if (xSpeed < runSpeed && !faceLeft)
         { //increase horizantal speed until runspeed is reached
             xSpeed++;
         }
         if (xSpeed > -runSpeed && faceLeft)
         { //if facing left, must actually decrease speed to negative limit
             xSpeed--;
         }
     }
 }
Example #15
0
        private void Jump()
        {
            //player leaps into the air
            if (!hasJumped && state != Playerstate.defending) { //cant jump while defending, or while has previously jumped
               // if(previous == Playerstate.standing){
                hasJumped = true;
                idle = false;
                state = Playerstate.jumping;

                ySpeed = -jumpSpeed; //jumpspeed is actually negative because Y axis is wierd
            }
        }
Example #16
0
        private void Defend()
        {
            //player produces a shield, which can block one attack
            if (canDefend && !shieldBroken) {
                idle = false;
                state = Playerstate.defending;

            }
        }
Example #17
0
 //Method stubs for things player can do
 //these methods are marked private, public key-pressed methods below should be called from game
 //player shoots a bullet
 private void Attack()
 {
     if (canAttack) {
         state = Playerstate.attacking;
         idle = false;
         //idle = false;
         Shoot();
     }
 }