示例#1
0
        private void die(Spaceship shooter)
        {
            emitterNodeParticleBirthRate = 0;

            if (shooter != null)
            {
                shooter.kills += 1;
                shooter.healthBar.labelLevel.color = GameColors.controlYellow;
                getHitBySpaceships.Remove(shooter);
            }

            foreach (var spaceship in getHitBySpaceships)
            {
                spaceship.assists += 1;
            }

            getHitBySpaceships.Clear();

            health = 0;

            retreat();
            resetToStartingPosition();

            isHidden = true;

            deaths    += 1;
            deathTime  = SKScene.currentTime;
            lastSecond = SKScene.currentTime;

            if (canRespawn)
            {
                labelRespawn.text = $"{deaths * (rarity.GetHashCode() + 1)}";
            }

            fadeSetDestinationEffect();
        }
示例#2
0
 static void setSelected(Spaceship spaceship)
 {
     selectedSpaceship = spaceship;
     spaceship?.showWeaponRangeShapeNode();
 }
示例#3
0
        internal void update(Mothership enemyMothership = null, IEnumerable <Spaceship> enemySpaceships = null, List <Spaceship> allySpaceships = null)
        {
            emitterNodeParticleBirthRate = 0;

            if (health > 0)
            {
                if (destination != null)
                {
                    if (position.distanceTo(destination.Value) <= radius)
                    {
                        if (destination.Value == startingPosition)
                        {
                            resetToStartingPosition();
                        }
                        destination = null;
                        fadeSetDestinationEffect();
                    }
                    else
                    {
                        rotateTo(destination.Value);
                        applyForce();
                    }
                }
                else
                {
                    if (physicsBody != null)
                    {
                        if (physicsBody.BodyType != BodyType.Dynamic)
                        {
                            if ((position - startingPosition).LengthSquared() < 4.0f)
                            {
                                heal();
                            }
                            if (physicsBody.BodyType == BodyType.Dynamic)
                            {
                                rotateTo(new Vector2(position.X, 0));
                                applyForce();
                            }
                        }
                        else
                        {
                            if (targetNode != null)
                            {
                                if (targetNode is Spaceship)
                                {
                                    Spaceship targetSpaceship = (Spaceship)targetNode;
                                    if (targetSpaceship.health <= 0)
                                    {
                                        targetNode = null;
                                    }
                                    else
                                    {
                                        if ((targetSpaceship.position - targetSpaceship.startingPosition).LengthSquared() < 4)
                                        {
                                            targetNode = null;
                                        }
                                        else
                                        {
                                            rotateTo(targetSpaceship.position);

                                            if (position.distanceTo(targetSpaceship.position) > weaponRange + radius)
                                            {
                                                applyForce();
                                            }
                                            else
                                            {
                                                tryToShoot();
                                            }
                                        }
                                    }
                                }

                                if (targetNode is Mothership)
                                {
                                    Mothership targetMothership = (Mothership)targetNode;
                                    if (targetMothership.health <= 0)
                                    {
                                        targetNode = null;
                                    }
                                    else
                                    {
                                        var point = new Vector2(position.X, targetMothership.position.Y);
                                        rotateTo(point);

                                        if (position.distanceTo(point) > weaponRange + Mothership.height / 2.0f)
                                        {
                                            applyForce();
                                        }
                                        else
                                        {
                                            tryToShoot();
                                        }
                                    }
                                }
                            }
                            else
                            {
                                Spaceship someTargetNode = nearestSpaceshipInRange(enemySpaceships);
                                if (someTargetNode != null)
                                {
                                    setTarget(someTargetNode);
                                }
                                else
                                {
                                    if (enemyMothership != null)
                                    {
                                        if (isMothershipInRange(enemyMothership))
                                        {
                                            setTarget(enemyMothership);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                if (canRespawn)
                {
                    if (SKScene.currentTime - lastSecond > 1.0)
                    {
                        lastSecond = SKScene.currentTime;

                        if (SKScene.currentTime - deathTime > (deaths * (rarity.GetHashCode() + 1)))
                        {
                            respawn();
                        }
                        else
                        {
                            if (labelRespawn != null)
                            {
                                int text = (deaths * (rarity.GetHashCode() + 1)) - (int)(SKScene.currentTime - deathTime);
                                labelRespawn.text = $"{text}";
                            }
                        }
                    }
                }
            }

            updateWeaponRangeShapeNode();
            updateHealthBarPosition();

            updateJetEffect(); //TODO: move to didSimulatePhysics
        }