Exemple #1
0
 void Start()
 {
     lastShotTime = Time.time;
     currentState = SpitterState.Idle;
     prevState    = currentState;
     destination  = transform.rotation;
     angleRange   = 120f;
 }
Exemple #2
0
        public MutantAcidSpitter(LevelState parentWorld, float initial_x, float initial_y)
        {
            position       = new Vector2(initial_x, initial_y);
            velocity_speed = 2.0f;
            velocity       = new Vector2(velocity_speed, 0);
            dimensions     = new Vector2(48.0f, 48.0f);

            enemy_damage                    = 4;
            enemy_life                      = 5;
            windup_timer                    = 0.0f;
            spitter_count                   = 0;
            change_direction_time           = 0.0f;
            change_direction_time_threshold = 1000.0f;
            angle          = 0.0f;
            range_distance = 500.0f;

            prob_item_drop    = 0.3;
            number_drop_items = 4;

            state            = SpitterState.Search;
            this.parentWorld = parentWorld;
            direction_facing = GlobalGameConstants.Direction.Right;
            enemy_type       = EnemyType.Alien;
            entity_found     = null;
            acid_pool        = AnimationLib.getFrameAnimationSet("acidPool");

            for (int i = 0; i < size_of_spit_array; i++)
            {
                projectile[i]        = new SpitProjectile(new Vector2(0, 0), 0);
                projectile[i].active = false;
            }

            death = false;

            directionAnims = new AnimationLib.SpineAnimationSet[4];
            directionAnims[(int)GlobalGameConstants.Direction.Up]   = AnimationLib.loadNewAnimationSet("acidSpitterUp");
            directionAnims[(int)GlobalGameConstants.Direction.Down] = AnimationLib.loadNewAnimationSet("acidSpitterDown");
            directionAnims[(int)GlobalGameConstants.Direction.Left] = AnimationLib.loadNewAnimationSet("acidSpitterRight");
            directionAnims[(int)GlobalGameConstants.Direction.Left].Skeleton.FlipX = true;
            directionAnims[(int)GlobalGameConstants.Direction.Right] = AnimationLib.loadNewAnimationSet("acidSpitterRight");

            for (int i = 0; i < 4; i++)
            {
                directionAnims[i].Animation = directionAnims[i].Skeleton.Data.FindAnimation("run");
            }
        }
Exemple #3
0
    // Update is called once per frame
    private void Update()
    {
        switch (currentState)
        {
        case SpitterState.Idle:
            Idle();
            break;

        case SpitterState.Spitting:
            if (Time.time - lastShotTime > shotCooldown)
            {
                LookAt2D(transform, player.transform);
                spit();
                lastShotTime = Time.time;
            }
            break;
        }

        // If the player is in range and in the line of sight, start spitting
        if (Vector2.Distance(player.transform.position, transform.position) < spitterRange)
        {
            LookAt2D(transform, player.transform);
            RaycastHit2D hit = Physics2D.Raycast(transform.position, transform.right, 1000, ~LayerMask.NameToLayer("Default"));
            prevState    = currentState;
            currentState = hit.transform.name == "Player" ? SpitterState.Spitting : SpitterState.Idle;
        }
        // Otherwise remain idle
        else
        {
            prevState    = currentState;
            currentState = SpitterState.Idle;
        }
        if (prevState != currentState)
        {
            Sprite sprite = currentState == SpitterState.Idle ? idle : spitting;
            gameObject.ChangeSprite(sprite);
        }
    }
Exemple #4
0
        public override void update(GameTime currentTime)
        {
            change_direction_time += currentTime.ElapsedGameTime.Milliseconds;
            animation_time        += currentTime.ElapsedGameTime.Milliseconds;

            if (state == SpitterState.Search && sound_alert && entity_found == null && !death)
            {
                alert_timer    = 0.0f;
                animation_time = 0.0f;
                state          = SpitterState.Alert;
            }

            if (!death && enemy_life <= 0)
            {
                state = SpitterState.Death;
                death = true;
                directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation(deathAnims[Game1.rand.Next() % 3]);
                animation_time = 0.0f;
                parentWorld.pushCoin(this);
            }

            switch (state)
            {
            case SpitterState.Search:
                directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("run");

                if (death == false)
                {
                    if (enemy_found == false)
                    {
                        foreach (Entity en in parentWorld.EntityList)
                        {
                            if (en == this)
                            {
                                continue;
                            }
                            else if (en.Enemy_Type != enemy_type && en.Enemy_Type != EnemyType.NoType && en.Death == false && en.Death == false)
                            {
                                component.update(this, en, currentTime, parentWorld);
                                if (enemy_found)
                                {
                                    entity_found = en;
                                    break;
                                }
                            }
                        }
                    }
                    if (enemy_found)
                    {
                        state          = SpitterState.WindUp;
                        velocity       = Vector2.Zero;
                        animation_time = 0.0f;
                    }
                }
                break;

            case SpitterState.Alert:
                directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("idle");

                if (sound_alert && entity_found == null)
                {
                    //if false then sound didn't hit a wall
                    if (!parentWorld.Map.soundInSight(this, sound_position))
                    {
                        directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("run");
                        alert_timer += currentTime.ElapsedGameTime.Milliseconds;
                        for (int i = 0; i < parentWorld.EntityList.Count; i++)
                        {
                            if (parentWorld.EntityList[i].Enemy_Type != enemy_type && parentWorld.EntityList[i].Enemy_Type != EnemyType.NoType && parentWorld.EntityList[i].Death == false)
                            {
                                distance = Vector2.Distance(CenterPoint, parentWorld.EntityList[i].CenterPoint);
                                if (distance <= range_distance)
                                {
                                    enemy_found    = true;
                                    entity_found   = parentWorld.EntityList[i];
                                    state          = SpitterState.WindUp;
                                    animation_time = 0.0f;
                                    sound_alert    = false;
                                    alert_timer    = 0.0f;
                                    windup_timer   = 0.0f;
                                    animation_time = 0.0f;
                                    velocity       = Vector2.Zero;
                                    break;
                                }
                            }
                        }

                        if (alert_timer > 3000 || ((int)CenterPoint.X == (int)sound_position.X && (int)CenterPoint.Y == (int)sound_position.Y))
                        {
                            entity_found   = null;
                            enemy_found    = false;
                            sound_alert    = false;
                            state          = SpitterState.Search;
                            velocity       = Vector2.Zero;
                            animation_time = 0.0f;
                            windup_timer   = 0.0f;
                            animation_time = 0.0f;
                        }
                    }
                    else
                    {
                        entity_found   = null;
                        enemy_found    = false;
                        sound_alert    = false;
                        state          = SpitterState.Search;
                        velocity       = Vector2.Zero;
                        animation_time = 0.0f;
                        windup_timer   = 0.0f;
                        animation_time = 0.0f;
                    }
                }
                else if (entity_found != null)
                {
                    sound_alert = false;
                    distance    = Vector2.Distance(CenterPoint, entity_found.CenterPoint);
                    if (parentWorld.Map.enemyWithinRange(entity_found, this, range_distance) && distance < range_distance && entity_found.Death == false)
                    {
                        state          = SpitterState.WindUp;
                        animation_time = 0.0f;
                        windup_timer   = 0.0f;
                    }
                    else
                    {
                        entity_found   = null;
                        enemy_found    = false;
                        state          = SpitterState.Search;
                        velocity       = Vector2.Zero;
                        animation_time = 0.0f;
                        windup_timer   = 0.0f;
                        animation_time = 0.0f;
                    }
                }
                break;

            case SpitterState.WindUp:
                windup_timer += currentTime.ElapsedGameTime.Milliseconds;
                directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("windUp");
                if (windup_timer > max_windup_timer)
                {
                    state          = SpitterState.Fire;
                    spitter_timer  = 0.0f;
                    windup_timer   = 0.0f;
                    animation_time = 0.0f;
                }

                switch (direction_facing)
                {
                case GlobalGameConstants.Direction.Right:
                    if (angle < -1 * Math.PI / 3.27)
                    {
                        direction_facing = GlobalGameConstants.Direction.Up;
                        current_skeleton = walk_up;
                    }
                    else if (angle > Math.PI / 3.27)
                    {
                        direction_facing = GlobalGameConstants.Direction.Down;
                        current_skeleton = walk_down;
                    }
                    break;

                case GlobalGameConstants.Direction.Left:
                    if (angle < Math.PI / 1.44 && angle > Math.PI / 1.5)
                    {
                        direction_facing = GlobalGameConstants.Direction.Down;
                        current_skeleton = walk_down;
                    }
                    else if (angle > -1 * Math.PI / 1.44 && angle < -1 * Math.PI / 1.5)
                    {
                        direction_facing = GlobalGameConstants.Direction.Up;
                        current_skeleton = walk_up;
                    }
                    break;

                case GlobalGameConstants.Direction.Up:
                    if (angle < -1 * Math.PI / 1.24)
                    {
                        direction_facing = GlobalGameConstants.Direction.Left;
                        current_skeleton = walk_right;
                    }
                    else if (angle > -1 * Math.PI / 5.14)
                    {
                        direction_facing = GlobalGameConstants.Direction.Right;
                        current_skeleton = walk_right;
                    }
                    break;

                default:
                    if (angle < Math.PI / 5.14)
                    {
                        direction_facing = GlobalGameConstants.Direction.Right;
                        current_skeleton = walk_right;
                    }
                    else if (angle > Math.PI / 1.24)
                    {
                        direction_facing = GlobalGameConstants.Direction.Left;
                        current_skeleton = walk_right;
                    }
                    break;
                }

                break;

            case SpitterState.Fire:
                angle = (float)(Math.Atan2(entity_found.CenterPoint.Y - CenterPoint.Y, entity_found.CenterPoint.X - CenterPoint.X));
                directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("attack");
                spitter_timer += currentTime.ElapsedGameTime.Milliseconds;

                if (!spit_fired)
                {
                    for (int i = 0; i < size_of_spit_array; i++)
                    {
                        if (!projectile[i].active)
                        {
                            AudioLib.playSoundEffect("acidSpit");
                            projectile[i] = new SpitProjectile(new Vector2(directionAnims[(int)direction_facing].Skeleton.FindBone("head").WorldX, directionAnims[(int)direction_facing].Skeleton.FindBone("head").WorldY), angle);
                            spit_fired    = true;
                            break;
                        }
                    }
                }

                if (spitter_timer > 500)
                {
                    if (entity_found.Death)
                    {
                        entity_found = null;
                        enemy_found  = false;
                    }
                    spit_fired    = false;
                    state         = SpitterState.Alert;
                    spitter_timer = 0.0f;
                }
                break;

            case SpitterState.KnockBack:
                disable_movement_time += currentTime.ElapsedGameTime.Milliseconds;
                directionAnims[(int)direction_facing].Animation = directionAnims[(int)direction_facing].Skeleton.Data.FindAnimation("hurt");

                if (disable_movement_time > 300)
                {
                    state = SpitterState.Search;
                    disable_movement_time = 0.0f;
                }
                break;

            case SpitterState.Death:
                velocity = Vector2.Zero;
                break;

            default:
                break;
            }

            for (int i = 0; i < size_of_spit_array; i++)
            {
                if (projectile[i].active)
                {
                    projectile[i].update(parentWorld, currentTime, this);
                }
            }

            Vector2 pos      = new Vector2(position.X, position.Y);
            Vector2 nextStep = new Vector2(position.X + velocity.X, position.Y + velocity.Y);
            Vector2 finalPos = parentWorld.Map.reloactePosition(pos, nextStep, dimensions);

            position.X = finalPos.X;
            position.Y = finalPos.Y;

            directionAnims[(int)direction_facing].Animation.Apply(directionAnims[(int)direction_facing].Skeleton, animation_time / 1000f, state == SpitterState.Search ? true : false);
        }
Exemple #5
0
        public override void knockBack(Vector2 direction, float magnitude, int damage, Entity attacker)
        {
            if (death == false)
            {
                if (disable_movement_time == 0.0)
                {
                    AudioLib.playSoundEffect("fleshyKnockBack");
                    state = SpitterState.KnockBack;
                    if (Math.Abs(direction.X) > (Math.Abs(direction.Y)))
                    {
                        if (direction.X < 0)
                        {
                            velocity = new Vector2(-2.0f * magnitude, direction.Y / 100 * magnitude);
                        }
                        else
                        {
                            velocity = new Vector2(2.0f * magnitude, direction.Y / 100 * magnitude);
                        }
                    }
                    else
                    {
                        if (direction.Y < 0)
                        {
                            velocity = new Vector2(direction.X / 100f * magnitude, -2.0f * magnitude);
                        }
                        else
                        {
                            velocity = new Vector2((direction.X / 100f) * magnitude, 2.0f * magnitude);
                        }
                    }
                    enemy_life = enemy_life - damage;
                }

                if (attacker == null)
                {
                    return;
                }
                else if (attacker.Enemy_Type != enemy_type && attacker.Enemy_Type != EnemyType.NoType)
                {
                    enemy_found  = true;
                    entity_found = attacker;

                    switch (attacker.Direction_Facing)
                    {
                    case GlobalGameConstants.Direction.Right:
                        direction_facing = GlobalGameConstants.Direction.Left;
                        break;

                    case GlobalGameConstants.Direction.Left:
                        direction_facing = GlobalGameConstants.Direction.Right;
                        break;

                    case GlobalGameConstants.Direction.Up:
                        direction_facing = GlobalGameConstants.Direction.Down;
                        break;

                    default:
                        direction_facing = GlobalGameConstants.Direction.Up;
                        break;
                    }
                }
            }
            parentWorld.Particles.pushBloodParticle(CenterPoint);
            parentWorld.Particles.pushBloodParticle(CenterPoint);
            parentWorld.Particles.pushBloodParticle(CenterPoint);
        }