Example #1
0
    private Blackhole GetBlackholeToSpawn()
    {
        Blackhole blackhole = PoolsManager.Instance.GetObjectFromPool <Blackhole>();

        blackhole.transform.position = new Vector2(999, 999);
        return(blackhole);
    }
Example #2
0
    public static void SaveIngredients(Blackhole blackhole)
    {
        BinaryFormatter formatter = new BinaryFormatter();
        //string path = Application.persistentDataPath + "/ingredients.bla";
        string     path   = "ingredients.bla";
        FileStream stream = new FileStream(path, FileMode.Create);

        IngredientsData data = new IngredientsData(blackhole);

        formatter.Serialize(stream, data);
        stream.Close();
    }
Example #3
0
        /// <summary>
        /// Creates a new instance of a debri entity.
        /// </summary>
        /// <param name="spawn">Spawn location.</param>
        public Debri(Vector2 spawn) : base(ECS.GetNextId())
        {
            Random random = new Random();

            // Components
            Components = new IComponent[]
            {
                new PositionComponent()
                {
                    Position        = spawn,
                    Momentum        = Blackhole.GetInitialMomentum(spawn),
                    AngularMomentum = random.Next(-40, 40),
                    Direction       = random.Next(0, 360),
                    CollisionMask   = new CollisionMaskCircle(
                        spawn, 32
                        )
                },
                new AnimationComponent()
                {
                    Sprite = "Objects/Resources/Debri"
                },
                new AffectedByBlackholeComponent()
                {
                    Entity = this
                },
                new WorldComponent()
                {
                    Entity = this
                },
                new CombatComponent()
                {
                    Health    = 1,
                    MaxHealth = 1,
                    Armour    = 0,
                    MaxArmour = 0,
                    Entity    = this
                },
                new ResourceComponent()
                {
                    Value = 50
                }
            };

            // Link as required
            ((AffectedByBlackholeComponent)Components[2]).Position = Position;
            ((WorldComponent)Components[3]).PositionComponent      = Position;

            // Register components
            RegisterComponents();
        }
Example #4
0
    void Awake()
    {
        _goForward = GetComponent <GoForward>();
        _auto      = GetComponent <Auto>();
        _blackhole = GetComponent <Blackhole>();
        _enemy     = GetComponent <Enemy>();
        _timer     = GetComponent <Timer>();
        _sploder   = GetComponent <Sploder>();

        Common.SetItem(transform.position.x, transform.position.y, this);

        if (IsKye)
        {
            GameController.Instance.StartPoint = transform.position;
        }
    }
Example #5
0
        public GameManager(GameController controller, int width, int height)
        {
            this.controller = controller;
            this.width      = width;
            this.height     = height;
            threshhold      = (float)Math.Atan((float)height / width);
            blackhole       = new Blackhole(controller, width, height);
            blackhole.Initialize(SpriteFactory.GetSprite("Blackhole"), new Vector2(width / 2, height / 2), 10);
            Sprite cover = SpriteFactory.GetSprite("BlackHoleCover");

            cover.Opacity = 0.8f;
            blackhole.Extra.Add(cover);
            player         = new Computer(controller, 100);
            player.Maximum = 200;
            player.Initialize(blackhole, SpriteFactory.GetSprite("Earth"), 0, 250f, 10, player_mas * SCALE, player_vel * SCALE);
            next_spawn = 0;
        }
Example #6
0
        /// <summary>
        /// Creates a Mothership entity.
        /// </summary>
        public Mothership(int x, int y, Team team) : base(ECS.GetNextId())
        {
            // Register components.
            Components = new IComponent[]
            {
                new PositionComponent()
                {
                    Position = new Vector2(x, y),
                    Momentum = Blackhole.GetInitialMomentum(
                        new Vector2(x, y)
                        ),
                    Direction       = 0,
                    AngularMomentum = 0,
                    CollisionMask   = new CollisionMaskCircle(
                        new Vector2(x, y), 128
                        )
                },
                new WorldComponent(),
                new AnimationComponent()
                {
                    Sprite = "Objects/Ships/Mothership"
                },
                new AffectedByBlackholeComponent()
                {
                    Entity = this
                },
                new TeamComponent()
                {
                    Team = team
                },
                new ResourceComponent()
                {
                    Value = 0
                }
            };

            // Link components
            World.Entity            = this;
            World.PositionComponent = Position;
            ((AffectedByBlackholeComponent)Components[3]).Position = Position;
            Team.Team.Mothership = this;

            // Register components
            RegisterComponents();
        }
Example #7
0
    public override void Spawn()
    {
        Blackhole spawnedBlackhole = GetBlackholeToSpawn();
        float     radius           = spawnedBlackhole.GetGravFieldRadius;

        for (int i = 0; i < maxTriesToSpawn; i++)
        {
            Vector3 spawnPosition = CalculateRandomPosition();
            if (IsAFreeSpot(spawnPosition, radius))
            {
                PositionBlackhole(spawnedBlackhole, spawnPosition);
                SoundManager.Instance.PlaySoundInPosition(transform.position, spawnSound, 0.5f);
                break;
            }
            else if (i == maxTriesToSpawn - 1)
            {
                ReturnUnabledToSpawnBlackhole(spawnedBlackhole);
            }
        }

        base.Spawn();
    }
Example #8
0
        /// <summary>
        /// Spawns all objects that should exist when the game starts.
        /// </summary>
        public static void SpawnWorld(Team teamA, Team teamB)
        {
            const int debriCount = 160;
            Random    random     = new Random();

            // BLACK HOLE OF DOOM
            Blackhole blackhole = new Blackhole(new Vector2(6000, 6000));

            // Spawn motherships
            Mothership mothershipA = new Mothership(6000, 1600, teamA);
            Mothership mothershipB = new Mothership(6000, 10400, teamB);

            // Fill the void with debri
            for (int i = 0; i < debriCount; i++)
            {
                float dir  = (float)(random.NextDouble() * Math.PI * 2);
                float len  = random.Next(2000, 5000);
                float xpos = 6000 + len * (float)Math.Cos(dir);
                float ypos = 6000 + len * (float)Math.Sin(dir);

                Debri debri = new Debri(new Vector2(xpos, ypos));
            }
        }
 public void OnEnable()
 {
     myTarget = (Blackhole)target;
 }
Example #10
0
        private void MoveBlackHole(Vector2 position)
        {
            if (Blackhole == null) {
                Blackhole = new Blackhole(World);
                GameplayScreen.DrawableObjects.Add(Blackhole);
            }

            Blackhole.Position = position;
        }
Example #11
0
 internal static object Thaw(Niecza.Serialization.ThawBuffer tb)
 {
     var n = new Blackhole();
     tb.Register(n);
     n.value = (P6any) tb.ObjRef();
     return n;
 }
Example #12
0
 void Start()
 {
     thetext = this.gameObject.GetComponent <Text>();
     BH      = GameObject.FindGameObjectWithTag("Blackhole").GetComponent <Blackhole>();
 }
    void OnTriggerEnter(Collider other)
    {
        if(other.GetComponent<Collider>().tag == Tags.Asteroid) {
            _hasCollision = true;
            _boostParticles.startSize = 0;
            StartCoroutine(EngineSoundOff());
            StartCoroutine(CollisionVelocity());
        }

        if(other.GetComponent<Collider>().tag == Tags.WormholeEnter) {
            _hasWormhole = true;
            _wormholeEnter = other.GetComponent<Wormhole>();
            _wormholeExit = other.transform.root.GetComponent<Wormhole>();
            _boostParticles.startSize = 0;
            StartCoroutine(WormholeEnter());
        }

        if(other.GetComponent<Collider>().tag == Tags.Blackhole) {
            _blackHole = other.GetComponent<Blackhole>();
            _boostParticles.Stop();
            StartCoroutine(BlackholeEnter());
        }

        if(other.GetComponent<Collider>().tag == Tags.Pulsar) {
            if(!_isRocketHasPulsarVelocity) {
                _isRocketHasPulsarVelocity = true;
                _blackHole = other.GetComponent<Blackhole>();
                GetComponent<Rigidbody>().AddForce( transform.forward * (10.5f + Vector3.Distance(transform.position, other.transform.position)), ForceMode.Impulse);
                StartCoroutine(DisablePulsarVelocity());
            }
        }
    }
Example #14
0
 private void ReturnUnabledToSpawnBlackhole(Blackhole _blackHoleToReturn)
 {
     PoolsManager.Instance.ReleaseObjectToPool <Blackhole>(_blackHoleToReturn);
     return;
 }
Example #15
0
 private void PositionBlackhole(Blackhole _blackHoleToPosition, Vector3 _spawnPosition)
 {
     _blackHoleToPosition.transform.position = _spawnPosition;
     return;
 }
Example #16
0
 private void Start()
 {
     blackHole = GameObject.FindGameObjectWithTag("Blackhole").GetComponent <Blackhole>();
 }
Example #17
0
        /// <summary>
        /// Creates a new player entity.
        /// </summary>
        public PlayerEntity(Team team) : base(ECS.GetNextId())
        {
            // Create components
            Components = new IComponent[]
            {
                new NetworkingClientComponent(this),
                new PositionComponent()
                {
                    Position        = new Vector2(),
                    Momentum        = new Vector2(),
                    AngularMomentum = 0,
                    Direction       = 0,
                    CollisionMask   = new CollisionMaskCircle(new Vector2(), 128),
                },
                new WorldComponent(),
                new AnimationComponent()
                {
                    Sprite = "Objects/Ships/GreenBeacon"
                },
                new EngineComponent()
                {
                    InputForce = new Vector2()
                },
                new ShipLimiterComponent()
                {
                    HandlingRank = 0,
                    SpeedRank    = 0
                },
                new TeamComponent()
                {
                    Team = team
                },
                new CombatComponent()
                {
                    Health    = 100,
                    MaxHealth = 100,
                    Armour    = 100,
                    MaxArmour = 100,
                    Entity    = this
                },
                new WeaponComponent()
                {
                    Cooldown        = 200,
                    CurrentCooldown = 0,
                    Direction       = 0f,
                    Trigger         = false,
                    Parent          = this
                },
                new ResourceComponent()
                {
                    Value = 0
                }
            };

            // Link components as required
            Client.Entity           = this;
            World.PositionComponent = Position;
            World.Entity            = this;
            Engine.Position         = Position;
            ShipLimiter.Position    = Position;
            ShipLimiter.Engine      = Engine;
            Weapon.Position         = Position;
            Weapon.Team             = Team;

            // Register to team
            Team.Team.RegisterPlayer(this);

            // Spawn according to team respawn
            Position.Position = Team.Team.Mothership.Position.Position
                                + new Vector2(100, 0);
            Position.Momentum =
                Blackhole.GetInitialMomentum(Position.Position);
            Position.Direction       = (new Random()).Next(0, 180);
            Position.AngularMomentum = (new Random()).Next(-20, 20);

            // Register components
            RegisterComponents();
        }
Example #18
0
 public IngredientsData(Blackhole blackhole)
 {
     ingredients = blackhole.ingredientCounter;
 }