Esempio n. 1
0
    public void breakObject(bool isPressed)
    {
        if (currentState == characterState.switching)
        {
            isPressed = false;
        }
        //Make it such that pressing the button makes the interactions capsule coll. enabled for a bit
        //but then is disabled regardless if the button is held down

        if (isPressed && !smash)
        {
            //Vector3 currPosition = gameObject.transform.position;
            //Collider[] touched = Physics.OverlapCapsule(currPosition, new Vector3(currPosition.x, currPosition.y, currPosition.z + 1.0f), 0.5f);
            anim.ResetTrigger("isBreakingObj");
            anim.SetTrigger("isBreakingObj");
            currentState = characterState.smashing;
            // add a Time.deltaTime
            //    foreach (Collider collider in touched) //Checks everything it collided with to see if any objects it detected are breakable
            //    {
            //        if (collider.gameObject.GetComponent<InteractableObject>())
            //        {
            //            if (collider.gameObject.GetComponent<InteractableObject>().isBreakable)
            //            {
            //                //TODO Play character and object animations for breaking
            //                Destroy(collider.gameObject);
            //            }
            //        }
            //    }
            //}
        }
        smash = isPressed;
    }
Esempio n. 2
0
        public void Attacking()
        {
            if (Keyboard.GetState().IsKeyDown(Keys.Space))
            {
                if (shootInterval > 1.0f)
                {
                    firing = true;
                    if (state != characterState.shooting)
                    {
                        state = characterState.shooting;
                        PlayerState();
                    }
                    shootInterval = 0;
                    FireBullet();
                    bulletsFired++;
                    isReadyToFire = false;
                }
            }
            if (shootInterval > 1.0f)
            {
                isReadyToFire = true;
            }


            if (state == characterState.shooting)
            {
                if (currentAnimator.Progress > 0.9)
                {
                    state  = characterState.idle;
                    firing = false;
                    PlayerState();
                }
            }
        }
 void MoveTo(Vector3 targetPos)
 {
     curState = characterState.moveStart;
     StartCoroutine(CharacterMove(map.MapToWorld(targetPos, characterOffset)));
     Destroy(moveSquareHolder);
     Destroy(attackSquareHolder);
 }
Esempio n. 4
0
        public void ChangeState(characterState state)
        {
            if (!stunBool /* && !dead*/)
            {
                if (state != currentState)
                {
                    currentState = state;

                    currentAnimation.ChangeFrames(animations[state]);

                    for (int i = 0; i < currentAnimation.frameCount; i++)
                    {
                        currentAnimation.ChangeOrigin(animations[state][i].Origin /*, i*/);
                        //currentAnimation.ChangeFrameRate(animations[state][i].Length);
                    }

                    //currentAnimation.ChangeOrigin(animations[state][0].Origin);

                    currentAnimation.ChangeFrameRate(animations[state][0].Length);

                    currentAnimation.currentFrame = 0;

                    currentAnimation.ResetLoop();
                }
            }
        }
Esempio n. 5
0
 public void PlayerSpotted(int playerPosition)
 {
     if (facingRight)
     {
         distance = playerPosition - (int)animator.Position.X;
         if (distance < spottingDistance && !(distance < 0))
         {
             if (state != characterState.Shooting)
             {
                 prevState         = state;
                 prevFacingRight   = facingRight;
                 state             = characterState.Shooting;
                 animator.Progress = 1;
                 firing            = true;
             }
         }
         else if (state == characterState.Shooting)
         {
             if (((int)animator.Position.X - playerPosition) < spottingDistance)
             {
                 facingRight = !facingRight;
             }
             else
             {
                 facingRight = prevFacingRight;
                 state       = prevState;
                 firing      = false;
             }
         }
     }
     else if (!facingRight)
     {
         distance = (int)animator.Position.X - playerPosition;
         if (distance < spottingDistance && !(distance < 0))
         {
             if (state != characterState.Shooting)
             {
                 prevState         = state;
                 prevFacingRight   = facingRight;
                 state             = characterState.Shooting;
                 animator.Progress = 1;
                 firing            = true;
             }
         }
         else if (state == characterState.Shooting)
         {
             if ((playerPosition - (int)animator.Position.X) < spottingDistance)
             {
                 facingRight = !facingRight;
             }
             else
             {
                 facingRight = prevFacingRight;
                 state       = prevState;
                 firing      = false;
             }
         }
     }
 }
Esempio n. 6
0
    /*
     * Main game loop function. This function is called for every monobehaviour every frame
     * We use it to run the functions that happen constantly like cone of vision
     * and checking if we're in base
     *
     */
    void Update()
    {
        if (!Gunshot.isPlaying)
        {
            Gunshot.enabled = false;
        }

        checkZone();
        if (MyTeam == team.blue)
        {
            if (myZone == zone.BlueBase)
            {
                loadoutFlag = true;
            }
            else
            {
                loadoutFlag = false;
            }
        }
        if (MyTeam == team.red)
        {
            if (myZone == zone.RedBase)
            {
                loadoutFlag = true;
            }
            else
            {
                loadoutFlag = false;
            }
        }
        if (health > 0)
        {
            if (!turnLock)
            {
                TurnChar();
            }
            visible.Clear();
            visibleEnemyLocations.Clear();
            GetVisibleObjects(visible);
            Fire(priority);
            AnimDoneMoving(1.0f);
        }
        else if (currentState != characterState.RESPAWNING)
        {
            currentState = characterState.RESPAWNING;
            refreshRespawnTimer();
            IDied.Invoke();
            prefabObject.SetActive(false);
        }
        else if (respawnTImer == 0)
        {
            currentState    = characterState.ALIVE;
            moveDestination = transform.position;
            health          = 100;
            prefabObject.transform.position = transform.position;
            IGotHit.Invoke(MyTeam, playerNumber, health);
            prefabObject.SetActive(true);
        }
    }
Esempio n. 7
0
 public void playattackAnimation()
 {
     if (state != Mover.characterState.Swimming)
     {
         state = Mover.characterState.Attack;
         Animation();
     }
 }
Esempio n. 8
0
    private void HandleMovement()
    {
        Vector3 localScale = gameObject.transform.localScale;

        if (up)
        {
            if (charState == characterState.onTheGround && canJump)
            {
                characterRigidBody.velocity = new Vector2(characterRigidBody.velocity.x, 0);
                characterRigidBody.AddForce(new Vector2(0, velocity.getJumpVelocity()), ForceMode2D.Impulse);
                charState         = characterState.jumping;
                jumpedInThisFrame = true;
                secondJump        = false;
                up = false;
            }
            else
            if (!secondJump)
            {
                characterRigidBody.velocity = new Vector2(characterRigidBody.velocity.x, 0);
                characterRigidBody.AddForce(new Vector2(0, velocity.getJumpVelocity()), ForceMode2D.Impulse);
                charState = characterState.jumping;
                Instantiate(secondJumpParticleSystem, gameObject.transform.position, Quaternion.Euler(0, 0, 0));
                secondJump = true;
                up         = false;
            }
        }
        if (left)
        {
            if (characterRigidBody.velocity.x > -walkVelocityPerSecond)
            {
                characterRigidBody.AddForce(new Vector2(-xForce, 0), ForceMode2D.Impulse);
            }
            if (charFacing == characterFacing.right)
            {
                charFacing = characterFacing.left;
                ChangeScaleFacing(localScale);
            }
        }
        else
        if (right)
        {
            if (characterRigidBody.velocity.x < walkVelocityPerSecond)
            {
                characterRigidBody.AddForce(new Vector2(xForce, 0), ForceMode2D.Impulse);
            }
            if (charFacing == characterFacing.left)
            {
                charFacing = characterFacing.right;
                ChangeScaleFacing(localScale);
            }
        }
        else
        if (characterRigidBody.velocity.x > 0 || characterRigidBody.velocity.x < 0)
        {
            characterRigidBody.AddForce(new Vector2(-characterRigidBody.velocity.x, 0), ForceMode2D.Impulse);
        }
    }
Esempio n. 9
0
    public void walk(Vector2 movementDirection)
    {
        if (animateMovement == true)
        {
            if (movementDirection.x < -0.1)
            {
                facing = FacingDirection.left;
            }
            else if (movementDirection.x > 0.1)
            {
                facing = FacingDirection.right;
            }


            if (movementDirection.y < -0.1)
            {
                facing = FacingDirection.down;
            }
            else if (movementDirection.y > 0.1)
            {
                facing = FacingDirection.up;
            }


            if (movementDirection.magnitude > 1)
            {
                movementDirection.Normalize();
            }

            if (lastFacingDirction != facing)
            {
                setFaceDirect();
            }

            if (state == characterState.Attack)
            {
                return;
            }

            if (isInWater)
            {
                state = characterState.Swimming;
            }
            else if (Vector2.Distance(movementDirection, Vector2.zero) > 0.15)
            {
                state = characterState.Walking;
            }
            else
            {
                state = characterState.Idle;
            }

            Animation();
        }
        direction            = movementDirection;
        rigidbody2D.velocity = direction * activeMoveSpeed;
    }
 void Start()
 {
     //select = GameObject.FindGameObjectWithTag("selectSquare").GetComponent<SelectController>();
     //use vector 2
     moveSquareList   = new List <Vector3>();
     attackSpuareList = new List <Vector3>();
     curState         = characterState.turnStart;
     //unecessary
     GetComponent <Renderer>().sortingOrder = -(int)transform.position.y;
 }
Esempio n. 11
0
 public PlayerComponent(Game game) : base(game)
 {
     state       = characterState.idle;
     facingRight = true;
     running     = true;
     hasJumped   = false;
     firing      = false;
     hacking     = false;
     movement    = new Vector2();
     gravity     = new Vector2();
 }
 //make it faster...little bit.
 IEnumerator CharacterMove(Vector3 targetPos)
 {
     while (transform.position != targetPos)
     {
         transform.position = Vector3.MoveTowards(transform.position, targetPos, moveSpeed * Time.deltaTime);
         GetComponent <Renderer>().sortingOrder = -(int)transform.position.y;
         yield return(null);
     }
     curState = characterState.moveEnd;
     //CharController.movManager.UpdateGrid(newposition,CharController.mov)
     print("Pop Menu!");
 }
Esempio n. 13
0
        public void Input(GameTime gameTime)
        {
            kPrevState    = kState;
            kState        = Keyboard.GetState();
            previousState = currentState;


            if (kState.IsKeyDown(Keys.W))
            {
                Jump(gameTime);
                currentState = characterState.jumping;
            }
            else if (kState.IsKeyDown(Keys.A))
            {
                acceleration.X -= .005f;

                if (velocity.X <= -3)
                {
                    velocity.X   = -3;
                    currentState = characterState.running;
                }
                else
                {
                    velocity.X  += acceleration.X;
                    currentState = characterState.walking;
                }
            }
            else if (kState.IsKeyDown(Keys.D))
            {
                acceleration.X += .005f;
                if (velocity.X >= 3)
                {
                    velocity.X   = 3;
                    currentState = characterState.running;
                }
                else
                {
                    velocity.X  += acceleration.X;
                    currentState = characterState.walking;
                }
            }
            else
            {
                //currentState = characterState.standing;
                acceleration.X = 0;
                velocity.X     = 0;
            }
        }
Esempio n. 14
0
    // --------------------------------------------------------------------------------------

    // Damage Distribution

    public void Death()
    {
        state = characterState.Dead;

        if (hasAnimator)
        {
            anim.SetTrigger(deathHash);
        }

        agent.enabled = false;

        foreach (Collider c in colliders)
        {
            c.enabled = false;
        }
    }
Esempio n. 15
0
    public bool switchPlayers()
    {
        if (currentState != characterState.free || isBoostJumping || isBoostRunning)  // If the character isn't in the default state,
        // it probably won't be allowed to switch
        {
            return(false);
        }
        currentState = characterState.switching; // Record that the character is switching
        anim.ResetTrigger("isSwitching");
        anim.SetTrigger("isSwitching");
        bool p1OrNah = anim.GetBool("isP1Moving");

        anim.SetBool("isP1Moving", !p1OrNah);

        MovingPlayer = MovingPlayer == 1 ? 2 : 1;

        return(true);
    }
Esempio n. 16
0
 protected virtual void setActive()
 {
     if (hasAttacked == true)
     {
         return;
     }
     if (activeCharacter != null)
     {
         activeCharacter.transform.SendMessage("setIdle");
         // activeCharacter.setIdle();
     }
     status = characterState.active;
     rend.material.color = Color.blue;
     activeCharacter     = gameObject;
     if (hasMoved == false)
     {
         Grids.grid.SendMessage("detectReachableTile");
     }
 }
Esempio n. 17
0
    public void reset()
    {
        //transform.position = RespawnPoint;
        velocity = Vector3.zero;
        if (lastCkpt)
        {
            transform.position = lastCkpt.transform.position;
            transform.rotation = lastCkpt.transform.rotation;
            //transform.position = Vector3.up; //Kyle's original
            cam.transform.rotation = lastCkpt.transform.rotation * Quaternion.AngleAxis(30f, Vector3.right);
            //cam.transform.rotation = Quaternion.AngleAxis(30f, Vector3.right);
            cam.transform.position = transform.position - cam.transform.forward * camSettings.distance;
            goalCamRotNoY          = lastCkpt.transform.rotation;
        }
        else
        {
            transform.position = Vector3.up;
            transform.rotation = Quaternion.identity;
            //transform.position = Vector3.up; //Kyle's original
            cam.transform.rotation = Quaternion.AngleAxis(30f, Vector3.right);
            //cam.transform.rotation = Quaternion.AngleAxis(30f, Vector3.right);
            cam.transform.position = transform.position - cam.transform.forward * camSettings.distance;
            goalCamRotNoY          = Quaternion.identity;
        }
        camRotY = 30f;

        StopAllCoroutines();
        boostWindow = true;
        cooldownBar.gameObject.SetActive(false);

        maybeBoostJumping1 = false;
        maybeBoostJumping2 = false;
        isBoostJumping     = false;
        jetPackParticles.Stop();

        maybeBoostRunning1 = false;
        maybeBoostRunning2 = false;
        isBoostRunning     = false;
        runThrusterParticles.Stop();

        currentState = characterState.free;
    }
Esempio n. 18
0
 // Update is called once per frame
 void FixedUpdate()
 {
     CheckGroundPoints();
     SteppingOnEnemies();
     if (characterRigidBody.velocity.y < 0 && !triggered && charState != characterState.onTheGround)
     {
         charState = characterState.falling;
     }
     if (charState != characterState.onTheGround)
     {
         walkVelocityPerSecond = velocity.getMaxWalkVelocityPerSecond();
     }
     else
     {
         hitTargets.Clear();
         secondJump = false;
     }
     HandleMovement();
     ResetPhysicsValues();
 }
Esempio n. 19
0
 public void Defending(GameTime gameTime)
 {
     defendingTime += (float)gameTime.ElapsedGameTime.TotalSeconds;
     if (defendingTime > 20)
     {
         defendingTime = 0;
     }
     if ((Keyboard.GetState().IsKeyDown(Keys.E)) && !firing)
     {
         if (state != characterState.shielding)
         {
             defendingTime = 0;
             state         = characterState.shielding;
             PlayerState();
         }
     }
     if (defendingTime > 2 && state == characterState.shielding)
     {
         state = characterState.idle;
         PlayerState();
     }
 }
Esempio n. 20
0
 public Enemy(Game game, String animationPath, int positionX, int positionY, int correctionX, int correctionY) : base(game)
 {
     this.animationPath = "Enemies/" + animationPath;
     this.positionX     = positionX;
     this.positionY     = positionY;
     this.correctionX   = correctionX;
     this.correctionY   = correctionY;
     reached            = false;
     facingRight        = false;
     prevFacingRight    = facingRight;
     firing             = false;
     gravity            = new Vector2(0);
     time             = 0;
     destination      = 0;
     maxBullets       = 5;
     bulletsFired     = 0;
     prevBullet       = bulletsFired;
     spottingDistance = 400;
     shootInterval    = 0;
     state            = characterState.Idle;
     prevState        = state;
 }
 void setState()
 {
     print("characterState:" + curState);
     if (select.curState == SelectController.state.confirm)
     {
         if (curState == characterState.turnStart && InSelect())
         {
             print("selected");
             SelectCharacter();
             prePos   = transform.position;
             curState = characterState.selected;
         }
         else if (curState == characterState.selected && InMoveRange())
         {
             print("move to" + map.WorldToMap(select.transform.position, squareOffset));
             MoveTo(map.WorldToMap(select.transform.position, squareOffset));
         }
         else if (curState == characterState.moveEnd)
         {
             print("show PopMenu!");
         }
     }
     else if (select.curState == SelectController.state.cancel)
     {
         if (curState == characterState.selected)
         {
             DestroyMoveSquare();
             DestroyAttactSquare();
             curState = characterState.moveStart;
         }
         if (curState == characterState.moveEnd)
         {
             transform.position = prePos;
             SelectCharacter();
             curState = characterState.selected;
         }
     }
 }
Esempio n. 22
0
    public void walk(float angle, bool useRigidBody, bool flipX) //flipX Is used for fleeing
    {
        if (angle <= 45 || angle >= 315)
        {
            facing = FacingDirection.left;
            if (flipX)
            {
                facing = FacingDirection.right;
            }
        }
        else if (angle > 45 && angle <= 135)
        {
            facing = FacingDirection.up;
        }
        else if (angle > 135 && angle <= 225)
        {
            facing = FacingDirection.right;
            if (flipX)
            {
                facing = FacingDirection.left;
            }
        }
        else
        {
            facing = FacingDirection.down;
        }

        setFaceDirect();

        state = characterState.Walking;

        direction = UtilityHelper.GetVectorFromAngle(angle);
        if (useRigidBody)
        {
            rigidbody2D.velocity = direction * activeMoveSpeed;
        }
        Animation();
    }
Esempio n. 23
0
        private static void setCrosshairState()
        {
            crosshairStatePrev = crosshairState;

            if ((characterAiming || characterEquippedBow) && !isFirstPerson)
            {
                crosshairState = characterState.bowequipped;
            }
            else
            {
                crosshairState = characterState.standing;
            }

            if (crosshairState != crosshairStatePrev)
            {
                timePos = 0;
                crosshairStateChanged = true;
                crosshairStatePrev    = crosshairState;
            }
            else
            {
                crosshairStateChanged = false;
            }
        }
Esempio n. 24
0
        public void Physics(List <GameObject> objectList)
        {
            acceleration.Y = -0.28f;

            velocity.X += acceleration.X;
            velocity.Y += acceleration.Y;

            if (velocity.Y < -6.0f)
            {
                velocity.Y = -6.0f;
            }

            foreach (GameObject gObject in objectList)
            {
                if (gObject == this)
                {
                    continue;
                }
                if (gObject is FreezeShot)
                {
                    continue;
                }
                if (!gObject.Active)
                {
                    continue;
                }


                if (velocity.X > 0)
                {
                    if (gObject is Platform)
                    {
                        if (position.X + position.Width > gObject.Position.X + gObject.Position.Width - 10)
                        {
                            position.X = gObject.Position.X + 10;
                        }
                    }
                    else
                    {
                        if (right.Intersects(gObject.Position))
                        {
                            velocity.X = 0;
                        }
                    }
                }
                else if (velocity.X < 0)
                {
                    if (gObject is Platform)
                    {
                        if (position.X < gObject.Position.X + 10)
                        {
                            position.X = gObject.Position.X + gObject.Position.Width - position.Width - 10;
                        }
                    }
                    else
                    {
                        if (left.Intersects(gObject.Position))
                        {
                            velocity.X = 0;
                        }
                    }
                }

                if (velocity.Y < 0)
                {
                    if (inAir)
                    {
                        currentState = characterState.falling;
                    }
                    if (gObject is Platform)
                    {
                        if (position.Y + position.Height >= gObject.Position.Y + gObject.Position.Height - 15)
                        {
                            velocity.Y = 0;
                            velocity.Y = 0;
                            inAir      = false;
                            isJumping  = false;
                        }
                    }
                    else
                    {
                        if (bottom.Intersects(gObject.Position))
                        {
                            velocity.Y = 0;
                            inAir      = false;
                            isJumping  = false;
                        }
                    }
                }
                else if (velocity.Y > 0)
                {
                    if (gObject is Platform)
                    {
                        if (position.Y <= gObject.Position.Y)
                        {
                            velocity.X = 0;
                        }
                    }
                    else
                    {
                        if (top.Intersects(gObject.Position) && !gObject.PassableFromBelow)
                        {
                            velocity.Y = 0;
                        }
                    }
                }

                currentState = characterState.standing;
            }
        }
Esempio n. 25
0
        public void UpdateMovement(GameTime time)
        {
            currentAnimator.Position += movement * speed * (float)time.ElapsedGameTime.TotalSeconds;

            shootInterval  += (float)time.ElapsedGameTime.TotalSeconds;
            actionInterval += (float)time.ElapsedGameTime.TotalSeconds;
            if (shootInterval > 10)
            {
                shootInterval = 2;
            }
            movement = new Vector2();

            if (Keyboard.GetState().IsKeyDown(Keys.Q))
            {
                running = !running;
            }

            if (GetKeyboardState(Keys.D) && running == false && !GetKeyboardState(Keys.A))
            {
                facingRight = true;
                if (state != characterState.walking)
                {
                    state = characterState.walking;
                    PlayerState();
                }
                movement = new Vector2(1, 0);
            }

            if (GetKeyboardState(Keys.D) && running == true && !GetKeyboardState(Keys.A))
            {
                facingRight = true;
                if (state != characterState.running)
                {
                    state = characterState.running;
                    PlayerState();
                }
                movement = new Vector2(2, 0);
            }

            if (GetKeyboardState(Keys.A) && running == true && !GetKeyboardState(Keys.D))
            {
                facingRight = false;
                if (state != characterState.running)
                {
                    state = characterState.running;
                    PlayerState();
                }
                movement = new Vector2(-2, 0);
            }

            if (GetKeyboardState(Keys.A) && running == false && !GetKeyboardState(Keys.D))
            {
                facingRight = false;
                if (state != characterState.walking)
                {
                    state = characterState.walking;
                    PlayerState();
                }
                movement = new Vector2(-1, 0);
            }
            if (GetKeyboardState(Keys.F))
            {
                if (actionInterval >= 0.5)
                {
                    foreach (Door door in GameLevel.CurrentGameLevel.Doors)
                    {
                        numberOfKeys = door.DoorAction(currentAnimator.Position, numberOfKeys);
                    }
                    actionInterval = 0;
                }
            }
            if (GetKeyboardState(Keys.H))
            {
                if (actionInterval >= 0.5)
                {
                    foreach (Door door in GameLevel.CurrentGameLevel.Doors)
                    {
                        if (door.HackingDoor(currentAnimator.Position))
                        {
                            door.hackingConsole.LoadPanel();
                            hacking = true;
                        }
                    }
                    if (GameLevel.CurrentGameLevel.controlPanel.HackingPanel(currentAnimator.Position))
                    {
                        hacking = true;
                    }
                    actionInterval = 0;
                }
            }
            if (GetKeyboardState(Keys.W) && IsOnFirmGround())
            {
                hasJumped = true;
            }
            else
            {
                if (((!GetKeyboardState(Keys.A) && !GetKeyboardState(Keys.D)) || (GetKeyboardState(Keys.A) && GetKeyboardState(Keys.D))) && state != characterState.shooting && state != characterState.shielding)
                {
                    if (state != characterState.idle)
                    {
                        state = characterState.idle;
                        PlayerState();
                    }
                }
            }
        }
Esempio n. 26
0
    // Fixed update from PlayerScript
    public virtual void UpdatePhysics()
    {
        currentCharacterState = characterState.Idle;

        physVel = Vector2.zero;

        // move left
        if(xCurrentInputState == inputState.Walk)
        {
            physVel.x = walkVel * xAcceleration;
            currentCharacterState = characterState.Walk;
        } else if(xCurrentInputState == inputState.Run){
            currentCharacterState = characterState.Run;
            physVel.x = runVel * xAcceleration;
        }

        if(detectFall())
        {
            grounded = false;
            currentCharacterState = characterState.Jump;
            _rigidbody.AddForce(-Vector3.up * fallVel);
        }
        else {
            grounded = true;
            jumps = 0;
        }

        //wall jump
        if (!grounded && detectWallSlide ()) {
            jumps = 0;
        }

        // jump (after raycasting to avoid unfortunate jump reset even before actually jumping)
        if(yCurrentInputState == inputState.Jump)
        {
            if(jumps < maxJumps)
            {
                GlobalHandlers.soundManager.PlayJump();
                jumps ++;
                if(jumps == 1)
                {
                    _rigidbody.velocity = new Vector2(physVel.x, jumpVel);
                }
                else {// Keeping it for later, no more double jump for now
                    _rigidbody.velocity = new Vector2(physVel.x, jump2Vel);
                }
            }
        }

        // actually move the player
        _rigidbody.velocity = new Vector2(physVel.x, _rigidbody.velocity.y);

        // inputstate reset once the command has been executed
        xCurrentInputState = inputState.None;
        yCurrentInputState = inputState.None;
    }
Esempio n. 27
0
    // Detect if the player is sliding against a wall. We also update the character state accordingly
    bool detectWallSlide()
    {
        Debug.DrawRay (new Vector2 (_transform.position.x + 0.32f, _transform.position.y - 0.26f), Vector2.right, Color.green);
        Debug.DrawRay (new Vector2(_transform.position.x+0.32f,_transform.position.y+0.26f), Vector2.right, Color.green);
        Debug.DrawRay (new Vector2(_transform.position.x-0.32f,_transform.position.y+0.26f), -Vector2.right, Color.green);
        Debug.DrawRay (new Vector2(_transform.position.x-0.32f,_transform.position.y-0.26f), -Vector2.right, Color.green);

        // Split it in 2. Need to know if we're against left or right wall.
        if (Physics2D.Raycast (new Vector2 (_transform.position.x + 0.32f, _transform.position.y - 0.26f), Vector2.right, .03f, groundMask)
                        || Physics2D.Raycast (new Vector2 (_transform.position.x + 0.32f, _transform.position.y + 0.26f), Vector2.right, .03f, groundMask)) {
            currentCharacterState = characterState.SlideWall;
            currentCharacterDirection = characterDirection.Left;
            return true;
        } else if(Physics2D.Raycast (new Vector2 (_transform.position.x - 0.32f, _transform.position.y + 0.26f), -Vector2.right, .03f, groundMask)
            || Physics2D.Raycast (new Vector2 (_transform.position.x - 0.32f, _transform.position.y - 0.26f), -Vector2.right, .03f, groundMask)) {
            currentCharacterState = characterState.SlideWall;
            currentCharacterDirection = characterDirection.Right;
            return true;
        } else {
            return false;
        }
    }
Esempio n. 28
0
 public void WasHit()
 {
     animator.Progress = 1;
     state             = characterState.Dead;
 }
Esempio n. 29
0
        // Warunki zmiany stanów
        public void EnemyAI(GameTime gameTime)
        {
            switch (state)
            {
            case characterState.Idle:
                time += (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (time > 5)
                {
                    state       = characterState.Walking;
                    destination = (int)animator.Position.X;
                    facingRight = !facingRight;
                    reached     = false;
                    time        = 0;
                    if (facingRight == true)
                    {
                        animator.Play("walking");
                    }
                    else
                    {
                        animator.Play("walking_reverse");
                    }
                }
                break;

            case characterState.Walking:
                /*
                 * if(facingRight == false)
                 * {
                 *
                 *  if(destination > animator.Position.X)
                 * // if((distance - 200) < destination)
                 *  {
                 *      reached = true;
                 *      distance = 0;
                 *      state = characterState.Idle;
                 *  }else if (destination > animator.Position.X)
                 * // else if((distance+200) > destination)
                 *  {
                 *      distance = 0;
                 *      reached = true;
                 *      state = characterState.Idle;
                 *  }
                 * }
                 */
                if (facingRight == false)
                {
                    if (destination - 200 > animator.Position.X)
                    {
                        reached = true;
                        state   = characterState.Idle;
                        animator.Play("idle_reverse");
                    }
                }
                else if (facingRight == true)
                {
                    if (destination + 200 < animator.Position.X)
                    {
                        reached = true;
                        state   = characterState.Idle;
                        animator.Play("idle");
                    }
                }
                break;

            case characterState.Dead:
                if (animator.Progress > 0.9)
                {
                    if (facingRight)
                    {
                        animator.Play("dead");
                    }
                    else
                    {
                        animator.Play("dead_reverse");
                    }
                }

                //  }
                break;

            case characterState.Shooting:
                if (animator.Progress > 0.9)
                {
                    if (facingRight)
                    {
                        animator.Play("shooting");
                    }
                    else
                    {
                        animator.Play("shooting_reverse");
                    }
                }
                break;
            }
        }
Esempio n. 30
0
 protected virtual void setIdle()
 {
     status = characterState.idle;
     rend.material.color = Color.white;
 }
Esempio n. 31
0
    private void CheckGroundPoints()
    {
        onMovingPlatform = false;
        //this is a fix for the moving platform moving downwards because character looses connection with it
        foreach (Collider2D collider in Physics2D.OverlapBoxAll(groundPoints[1].position, new Vector2(0, 0.15f), LayerMask.GetMask("Platforms")))
        {
            if (collider.gameObject.CompareTag("MovingPlatform") && !triggered && characterRigidBody.velocity.y <= 0 &&
                groundPoints[1].position.y > collider.bounds.max.y)
            {
                onMovingPlatform = true;
                float dx = collider.gameObject.GetComponentInParent <PathFollower>().dx;
                float dy = collider.gameObject.GetComponentInParent <PathFollower>().dy;
                transform.Translate(new Vector2(dx, dy));

                charState             = characterState.onTheGround;
                walkVelocityPerSecond = velocity.getMaxWalkVelocityPerSecond();
                canJump   = true;
                triggered = true;
            }
        }

        foreach (Transform point in groundPoints)
        {
            foreach (Collider2D collider in Physics2D.OverlapPointAll(point.position, LayerMask.GetMask(groundLayers)))
            {
                if (collider.gameObject.CompareTag("Ground") && !collider.isTrigger)
                {
                    float angle = collider.gameObject.transform.rotation.eulerAngles.z;
                    if (angle > 180)
                    {
                        angle = 360 - angle;
                    }
                    //if (angle <= maxJumpAngle)
                    canJump   = true;
                    charState = characterState.onTheGround;
                    if (angle != 0 && transform.position.y >= lastFrameCharacterY)
                    {
                        walkVelocityPerSecond = velocity.getMaxWalkVelocityPerSecond() * (90 - angle) / 90;
                    }
                    else
                    {
                        walkVelocityPerSecond = velocity.getMaxWalkVelocityPerSecond();
                    }
                    triggered = true;
                }
                if (characterRigidBody.velocity.y <= 0)
                {
                    if (collider.gameObject.CompareTag("Platform") && !collider.isTrigger && point.position.y > collider.bounds.max.y - deviationYToCountForProperOnPlatform)
                    {
                        float angle = collider.gameObject.transform.rotation.eulerAngles.z;
                        if (angle > 180)
                        {
                            angle = 360 - angle;
                        }
                        //if (angle <= maxJumpAngle)
                        canJump   = true;
                        charState = characterState.onTheGround;
                        if (angle != 0 && transform.position.y >= lastFrameCharacterY)
                        {
                            walkVelocityPerSecond = velocity.getMaxWalkVelocityPerSecond() * (90 - angle) / 90;
                        }
                        else
                        {
                            walkVelocityPerSecond = velocity.getMaxWalkVelocityPerSecond();
                        }
                        triggered = true;
                    }
                }
                if (collider.gameObject.CompareTag("Barrel"))
                {
                    charState             = characterState.onTheGround;
                    walkVelocityPerSecond = velocity.getMaxWalkVelocityPerSecond();
                    canJump   = true;
                    triggered = true;
                }
                if (collider.gameObject.CompareTag("MovingPlatform") && !triggered && characterRigidBody.velocity.y <= 0 &&
                    !onMovingPlatform && point.position.y > collider.bounds.max.y - deviationYToCountForProperOnPlatform)
                {
                    onMovingPlatform = true;
                    float dx = collider.gameObject.GetComponentInParent <PathFollower>().dx;
                    float dy = collider.gameObject.GetComponentInParent <PathFollower>().dy;
                    transform.Translate(new Vector2(dx, dy));

                    charState             = characterState.onTheGround;
                    walkVelocityPerSecond = velocity.getMaxWalkVelocityPerSecond();
                    canJump   = true;
                    triggered = true;
                }
            }
        }
    }
Esempio n. 32
0
        public void Input(GameTime gameTime)
        {
            kPrevState = kState;
            kState = Keyboard.GetState();
            previousState = currentState;

            if(kState.IsKeyDown(Keys.W))
            {
                Jump(gameTime);
                currentState = characterState.jumping;

            }
            else if (kState.IsKeyDown(Keys.A))
            {
                acceleration.X -= .005f;

                if (velocity.X <= -3)
                {
                    velocity.X = -3;
                    currentState = characterState.running;
                }
                else
                {
                    velocity.X += acceleration.X;
                    currentState = characterState.walking;
                }

            }
            else if (kState.IsKeyDown(Keys.D))
            {
                acceleration.X += .005f;
                if (velocity.X >= 3)
                {
                    velocity.X = 3;
                    currentState = characterState.running;
                }
                else
                {
                    velocity.X += acceleration.X;
                    currentState = characterState.walking;
                }

            }
            else
            {
                //currentState = characterState.standing;
                acceleration.X = 0;
                velocity.X = 0;

            }
        }
Esempio n. 33
0
        public void Physics(List<GameObject> objectList)
        {
            acceleration.Y = -0.28f;

            velocity.X += acceleration.X;
            velocity.Y += acceleration.Y;

            if (velocity.Y < -6.0f)
            {
                velocity.Y = -6.0f;
            }

            foreach (GameObject gObject in objectList)
            {
                if (gObject == this)
                    continue;
                if (gObject is FreezeShot)
                    continue;
                if (!gObject.Active)
                    continue;

                if (velocity.X > 0)
                {
                    if (gObject is Platform)
                    {
                        if (position.X + position.Width > gObject.Position.X + gObject.Position.Width - 10)
                        {
                            position.X = gObject.Position.X + 10;
                        }

                    }
                    else
                    {
                        if (right.Intersects(gObject.Position))
                        {
                            velocity.X = 0;
                        }
                    }

                }
                else if (velocity.X < 0)
                {
                    if (gObject is Platform)
                    {
                        if (position.X < gObject.Position.X + 10)
                            position.X = gObject.Position.X + gObject.Position.Width - position.Width - 10;

                    }
                    else
                    {
                        if (left.Intersects(gObject.Position))
                        {
                            velocity.X = 0;
                        }
                    }
                }

                if (velocity.Y < 0)
                {
                    if (inAir)
                    {
                        currentState = characterState.falling;
                    }
                    if (gObject is Platform)
                    {
                        if (position.Y + position.Height >= gObject.Position.Y + gObject.Position.Height - 15)
                        {
                            velocity.Y = 0;
                            velocity.Y = 0;
                            inAir = false;
                            isJumping = false;
                        }

                    }
                    else
                    {
                        if (bottom.Intersects(gObject.Position))
                        {
                            velocity.Y = 0;
                            inAir = false;
                            isJumping = false;

                        }
                    }
                }
                else if (velocity.Y > 0)
                {
                    if (gObject is Platform)
                    {
                        if (position.Y <= gObject.Position.Y)
                            velocity.X = 0;

                    }
                    else
                    {
                        if (top.Intersects(gObject.Position) && !gObject.PassableFromBelow)
                        {
                            velocity.Y = 0;

                        }
                    }
                }

                currentState = characterState.standing;

            }
        }
Esempio n. 34
0
 //called by animation attack after sequence
 public void FinishedAttackSequence()
 {
     state = characterState.Idle;
 }