Beispiel #1
0
 internal void update(Mothership enemyMothership = null, IEnumerable <Spaceship> enemySpaceships = null)
 {
     foreach (Spaceship spaceship in spaceships)
     {
         spaceship.update(enemyMothership, enemySpaceships, spaceships);
     }
 }
Beispiel #2
0
 internal void setTarget(Mothership mothership)
 {
     fadeSetDestinationEffect();
     physicsBody.BodyType = BodyType.Dynamic;
     destination          = null;
     targetNode           = mothership;
     setTargetEffect(new Vector2(position.X, mothership.position.Y), false);
 }
Beispiel #3
0
        bool PhysicsBody_OnCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
        {
            Shot shot = (Shot)fixtureA.Body.UserData;

            if (fixtureB.Body.UserData is Mothership)
            {
                Mothership mothership = (Mothership)fixtureB.Body.UserData;
                mothership?.getHitBy(shot);
                return(false);
            }

            if (fixtureB.Body.UserData is Spaceship)
            {
                Spaceship spaceship = (Spaceship)fixtureB.Body.UserData;
                spaceship?.getHitBy(shot);
                return(false);
            }

            return(false);
        }
Beispiel #4
0
        internal void loadJetEffect(SKNode gameWorld)
        {
            defaultEmitterNodeParticleBirthRate = speedAtribute * 20;

            emitterNode = new SKEmitterNode(int.MaxValue);
            emitterNode.setScaleToFit(8.0f, 8.0f);
            emitterNode.particleLifetime   = 1.0f;
            emitterNode.particleAlpha      = 1.0f;
            emitterNode.particleAlphaSpeed = -4.0f;
            emitterNode.particleScaleSpeed = -1.0f;

            emitterNode.color = Mothership.colorFor(team);

            emitterNode.blendState = BlendState.Additive;

            emitterNode.particlePositionRange = new Vector2(8.0f, 8.0f);


            gameWorld.addChild(emitterNode);
        }
Beispiel #5
0
        bool isMothershipInRange(Mothership mothership)
        {
            Vector2 point = new Vector2(position.X, mothership.position.Y);

            return(position.distanceTo(point) < weaponRange + Mothership.height / 2.0f);
        }
Beispiel #6
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
        }