Inheritance: MonoBehaviour
Esempio n. 1
0
    void Start()
    {
        if (playerPrefab == null)
        {
            Debug.LogError("Scene Manager: No player prefab set in inspector");
        }

        playerCam = FindObjectOfType <PlayerCamera>();
        if (playerCam == null)
        {
            Debug.LogError("Scene Manager: No PlayerCam exists in the scene");
        }

        GameObject[] spawnPoints = GameObject.FindGameObjectsWithTag("Respawn");
        foreach (GameObject spawnPoint in spawnPoints)
        {
            spawnPoint.SetActive(false);
        }

        // Gravity
        gravityBodies.AddRange(FindObjectsOfType <Rigidbody>());
        gravityWells.AddRange(FindObjectsOfType <GravityWell>());
        currentWell = FindClosestWell();
        ChangeGravityWell(currentWell);

        // Player Spawn
        SpawnPlayer(playerSpawn, Vector3.zero);
        PlayerCamera.instance.MoveCamToPlayer();
    }
Esempio n. 2
0
    protected override void CreateLevel()
    {
        MusicPlay("sounds/level1Loop");

        levelSize = new Vector2(80, 60); //set the level size

        CreateObject("SpaceDustPF", gameBounds.center, 0);

        for (int i = 0; i < 4; i++)
        {
            Blob current = (Blob)CreateObject("BlobPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        for (int i = 0; i < 1; i++)
        {
            GravityWell current = (GravityWell)CreateObject("GravityWellPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        for (int i = 0; i < 2; i++)
        {
            RotatingLazerSentry current = (RotatingLazerSentry)CreateObject("RotatingLazerSentryPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        for (int i = 0; i < 3; i++)
        {
            LazerEmitter current = (LazerEmitter)CreateObject("LazerEmitterPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        RapidShots rapid = (RapidShots)CreateObject("RapidShotsPF");
    }
    void Update()
    {
        // Update mouse direction
        mouseDir = (Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position).normalized;

        // Fire rocket on click
        if (Input.GetButton("Shoot") && canFireRocket && !PauseMenu.Singleton.IsPaused)
        {
            // Start rocket cooldown
            StartCoroutine(RocketCooldown());

            // Spawn rocket
            Rocket rocket = PhotonNetwork.Instantiate("Rocket", transform.position, Quaternion.FromToRotation(Vector2.right, mouseDir), 0).GetComponent <Rocket>();
            rocket.IsLocal   = true;
            rocket.Direction = mouseDir;

            // Apply recoil force to player
            playerBody.AddForce(recoilStrength * -mouseDir, ForceMode2D.Impulse);

            // Invoke onShoot event
            onShoot.Invoke();
        }
        else if (Input.GetButton("Alt Fire") && canFireGravityWell && !PauseMenu.Singleton.IsPaused)
        {
            StartCoroutine(GravityWellCooldown());

            GravityWell gravityWell = PhotonNetwork.Instantiate("GravityWell", transform.position, Quaternion.identity, 0).GetComponent <GravityWell>();
            gravityWell.IsLocal   = true;
            gravityWell.Direction = mouseDir;

            onShoot.Invoke();
            HUD.Singleton.StartGravityWellCooldown(gravityWellCooldown);
        }
    }
Esempio n. 4
0
    public static Dictionary <string, GravityWell> GetSystemMap(string path)
    {
        var sytemMap = new Dictionary <string, GravityWell>();
        var input    = File.ReadAllLines(path);
        var id       = 0;

        foreach (var w in input)
        {
            var         bodyId   = w.Split(')')[1];
            var         parentId = w.Split(')')[0];
            GravityWell gravityWell;
            if (sytemMap.ContainsKey(bodyId))
            {
                gravityWell = sytemMap[bodyId];
            }
            else
            {
                var well = new GravityWell
                {
                    BodyId       = bodyId,
                    ParentBodyId = parentId,
                    Id           = id++
                };
                sytemMap.Add(bodyId, well);
            }
        }

        return(sytemMap);
    }
Esempio n. 5
0
    protected override void CreateLevel()
    {
        MusicPlay("sounds/level1Loop");

        levelSize = new Vector2(80, 60); //set the level size

        CreateObject("SpaceDustPF", gameBounds.center, 0);

        IngameInterface.DisplayMessage("Survive the attack of the Space Blobs!", 3);

        for (int i = 0; i < 4; i++)
        {
            Blob current = (Blob)CreateObject("BlobPF", GetRandomPosition(), GetRandomAngle(), GetRandomVelocity(10));
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        for (int i = 0; i < 1; i++)
        {
            GravityWell current = (GravityWell)CreateObject("GravityWellPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        for (int i = 0; i < 2; i++)
        {
            SlowTurner current = (SlowTurner)CreateObject("SlowTurnerPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        for (int i = 0; i < 2; i++)
        {
            RandomTurner current = (RandomTurner)CreateObject("RandomTurnerPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        for (int i = 0; i < 2; i++)
        {
            SputteringDebris current = (SputteringDebris)CreateObject("SputteringDebrisPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        for (int i = 0; i < 2; i++)
        {
            RotatingLazerSentry current = (RotatingLazerSentry)CreateObject("RotatingLazerSentryPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        for (int i = 0; i < 1; i++)
        {
            LazerEmitter current = (LazerEmitter)CreateObject("LazerEmitterPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        for (int i = 0; i < 2; i++)
        {
            IndestructableDebris current = (IndestructableDebris)CreateObject("IndestructableDebrisPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        LazerBeam beam = (LazerBeam)CreateObject("LazerBeamPF");
    }
Esempio n. 6
0
 //If this Item is dropped, destroy its GravityWell if it currrently has one
 protected override void DropItem()
 {
     if (well != null)
     {
         well.DestroyThis();
         well = null;
     }
 }
Esempio n. 7
0
 void Start()
 {
     vectorField = GetComponent <VectorField>();
     state       = GetComponent <GameState>();
     camera      = Camera.main;
     mgr         = World.Active.EntityManager;
     ent         = mgr.CreateEntity(typeof(Translation), typeof(GravityWell));
     gw          = new GravityWell(range, vectorField.spacing, false, strength);
     mgr.SetComponentData(ent, gw);
     marker.gameObject.SetActive(false);
     fp    = GameObjectConversionUtility.ConvertGameObjectHierarchy(factoryPrefab, mgr.World);
     audio = FindObjectOfType <AudioManager>();
 }
Esempio n. 8
0
 void ChangeGravityWell(GravityWell /*Gabe*/ newWell)
 {
     Debug.Log("SceneManager: Gravity well changed");
     foreach (GravityWell well in gravityWells)
     {
         if (well != newWell)
         {
             well.enabled = false;
         }
         else
         {
             well.enabled = true;
             currentWell  = well;
         }
     }
 }
Esempio n. 9
0
 /// <summary>
 /// Function calls
 /// PlayerBroadcast()
 /// </summary>
 void Start()
 {
     gameObject.name = "Player";
     CheckPlayerBounds();
     currentHealth  = maxHealth;
     livesRemaining = maxLives;
     SetPlayerControls();
     well = FindObjectOfType <GravityWell>();
     foreach (SpringJoint2D s in gameObject.GetComponents <SpringJoint2D>())
     {
         s.connectedBody = well.GetComponent <Rigidbody2D>();
     }
     well.transform.position = new Vector3(spawnPosition.x - 2, spawnPosition.y, spawnPosition.z);
     transform.position      = spawnPosition;
     _fsm.Transition(_fsm.state, PLAYERSTATES.dead);
 }
Esempio n. 10
0
    GravityWell FindClosestWell()
    {
        float       minimumDistanceSqr = float.MaxValue;
        GravityWell closestWell        = null;

        foreach (GravityWell well in gravityWells)
        {
            float distanceSqr = (playerCam.transform.position - well.transform.position).sqrMagnitude;
            if (distanceSqr < minimumDistanceSqr)
            {
                minimumDistanceSqr = distanceSqr;
                closestWell        = well;
            }
        }

        return(closestWell);
    }
    public void Release(GravityWell well)
    {
        if (well == null)
        {
            return;
        }
        if (activeWell != well)
        {
            return;
        }

        // This would be a race condition if concurrent grabbing becomes allowed
        if (isBeingPulled)
        {
            activeWell    = null;
            isBeingPulled = false;
            OnStopPulling?.Invoke(well.transform);
        }
    }
Esempio n. 12
0
    protected override void HoldingItem(bool use, bool startUse, bool endUse, bool doubleUse)
    {
        //When the holder first presses this Item's key, create a GravityWell
        //behind the holder if there isn't one, if there is one move it behind the holder.
        if (startUse)
        {
            Vector2 direction = holder.velocity.normalized;
            direction.x *= -1;
            if (well == null)
            {
                well         = (GravityWell)level.CreateObject("GravityWellPF", holder.position + offset.Rotate(direction.GetAngle()));
                well.damage  = wellDamage;
                well.gravity = startGravity;
            }
            else
            {
                well.position = holder.position + offset.Rotate(direction.GetAngle());
            }
        }
        //When the holder holds down this Item's key, increase the GravityWell's size.
        else if (use && well != null)
        {
            well.gravity *= 1f + gravityIncreaseSpeed;

            if (well.gravity > maxGravity)
            {
                well.gravity = maxGravity;
            }
        }

        //When the holder double presses this Item's key, destroy the GravityWell if one exists.
        if (doubleUse && well != null)
        {
            well.DestroyThis();
            well = null;
        }

        if (well != null)
        {
            level.score += USE_POINTS;
        }
    }
    public void Grab(GravityWell well)
    {
        if (well == null)
        {
            return;
        }

        if (activeWell != null)
        {
            return;
        }

        // This would be a race condition if concurrent grabbing becomes allowed
        if (!isBeingPulled)
        {
            activeWell = well;
            OnStartPulling?.Invoke(well.transform);
            isBeingPulled = true;
        }
    }
Esempio n. 14
0
    /// <summary>
    /// Function calls
    /// PlayerBroadcast()
    /// </summary>
    void Start()
    {
        int round = (int)ScreenBorders.m_topLeft.x + 2;

        startPosition.x = (float)round;
        gameObject.name = "Player";              //Changes the name of the object to Player
        CheckPlayerBounds();                     //Checks to see if the player in within the game play area
        currentHealth  = maxHealth;              //Sets the current health equal to the maximumHealth
        livesRemaining = maxLives;               //Sets the lives remaining equal the the max lives
        SetPlayerControls();                     //Sets the controls the user uses to control the player
        well = FindObjectOfType <GravityWell>(); //Searchs for an object of type GravityWell and sets the return value equal to the well
        foreach (SpringJoint2D s in gameObject.GetComponents <SpringJoint2D>())
        {
            s.connectedBody = well.GetComponent <Rigidbody2D>();                                      //Sets the connected body of the springs attached to the player equal to the well's rigidbody
        }
        well.transform.position = new Vector3(spawnPosition.x - 2, spawnPosition.y, spawnPosition.z); //Sets the wells position to just behind the player
        transform.position      = spawnPosition;                                                      //Sets the player's position to be just out side the play area
        _fsm.Transition(_fsm.state, PLAYERSTATES.dead);                                               //Transitions the player to the dead state so it will start its spawning movement
        DylanGamePlay.UpdatePlayer(currentHealth, livesRemaining);
    }
Esempio n. 15
0
    /// <summary>
    /// Defines all actions that can happen depending the state the game is in
    /// </summary>
    static void StateProperties()
    {
        ExitGamePlay = false;
        switch (_fsm.state)
        {
        case GAMESTATE.init:
            _fsm.Transition(_fsm.state, GAMESTATE.mainMenu);
            break;

        case GAMESTATE.mainMenu:
            Time.timeScale = 1;
            if (player != null)
            {
                Destroy(player.gameObject);
            }
            if (gravityWell != null)
            {
                Destroy(gravityWell.gameObject);
            }
            break;

        case GAMESTATE.gamePlay:
            Time.timeScale = 1;
            player         = Instantiate(Resources.Load(PlayerName, typeof(Player))) as Player;
            gravityWell    = Instantiate(Resources.Load(GravityWellName, typeof(GravityWell))) as GravityWell;
            break;

        case GAMESTATE.pauseMenu:
            break;

        case GAMESTATE.gameOver:
            ExitGamePlay = true;
            //Destroy(player.gameObject);
            //Destroy(gravityWell.gameObject);
            //GUIMenuManager.GameOver();
            break;

        case GAMESTATE.exit:
            break;
        }
    }
Esempio n. 16
0
    protected override void CreateLevel()
    {
        MusicPlay("sounds/level1Loop");

        levelSize = new Vector2(80, 60); //set the level size

        CreateObject("SpaceDustPF", gameBounds.center, 0);

        for (int i = 0; i < 2; i++)
        {
            GravityWell current = (GravityWell)CreateObject("GravityWellPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        for (int i = 0; i < 4; i++)
        {
            RandomTurner current = (RandomTurner)CreateObject("RandomTurnerPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        for (int i = 0; i < 2; i++)
        {
            RubberyDebris current = (RubberyDebris)CreateObject("RubberyDebrisPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        for (int i = 0; i < 4; i++)
        {
            SputteringDebris current = (SputteringDebris)CreateObject("SputteringDebrisPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        for (int i = 0; i < 1; i++)
        {
            IndestructableDebris current = (IndestructableDebris)CreateObject("IndestructableDebrisPF", GetRandomPosition(), GetRandomAngle());
            current.velocity = GetRandomVelocity(current.maxSpeed);
        }

        HomingMissiles homing = (HomingMissiles)CreateObject("HomingMissilesPF");
    }
 public BlackHoleGravityWellInfo(GravityWell gravityWell)
 {
     Radius  = gravityWell.Radius;
     Gravity = gravityWell.GravityMovement;
 }
Esempio n. 18
0
    void LateUpdate()
    {
        // Gravity Well
        if (Input.GetMouseButton(0) && state.water > 0)
        {
            var pos = camera.ScreenToWorldPoint(Input.mousePosition);
            pos.z = 1f;
            marker.transform.position = pos;
            mgr.SetComponentData(ent, new Translation()
            {
                Value = pos
            });
            if (!gw.enabled)
            {
                marker.gameObject.SetActive(true);
                gw.enabled = true;
                mgr.SetComponentData(ent, gw);
            }
            state.water -= Time.deltaTime * gravityCost;
        }
        else
        {
            if (state.water < 0)
            {
                var pos = camera.ScreenToWorldPoint(Input.mousePosition);
                state.water = 0;
                pos.z       = -1;
                noWaterText.transform.position = pos;
                noWaterText.SetActive(true);
            }
            if (gw.enabled && mgr.Exists(ent))
            {
                gw         = mgr.GetComponentData <GravityWell>(ent);
                gw.enabled = false;
                mgr.SetComponentData(ent, gw);
                marker.gameObject.SetActive(false);
            }
        }

        // Build mines and move ship
        if (Input.GetMouseButtonUp(1))
        {
            var pos = camera.ScreenToWorldPoint(Input.mousePosition);
            var physicsWorldSystem = mgr.World.GetOrCreateSystem <Unity.Physics.Systems.BuildPhysicsWorld>();
            physicsWorldSystem.FinalJobHandle.Complete();
            var          collisionWorld = physicsWorldSystem.PhysicsWorld.CollisionWorld;
            var          hit            = new Unity.Physics.RaycastHit();
            RaycastInput input          = new RaycastInput()
            {
                Ray = new Unity.Physics.Ray()
                {
                    Origin = pos, Direction = new float3(0, 0, 100)
                },
                Filter = new CollisionFilter()
                {
                    CategoryBits = ~0u, MaskBits = ~0u, GroupIndex = 0
                }
            };
            PhysicsCasting.SingleRayCast2(collisionWorld, input, out hit);
            if (hit.RigidBodyIndex >= 0)
            {
                var e = collisionWorld.Bodies[hit.RigidBodyIndex].Entity;
                // Build Mine
                if (mgr.HasComponent(e, typeof(Asteroid)))
                {
                    if (mgr.GetComponentData <Asteroid>(e).minerals <= 0)
                    {
                        pos.z = -1f;
                        asteroidEmptyText.transform.position = pos;
                        asteroidEmptyText.SetActive(true);
                    }
                    else
                    {
                        bool build = false;
                        NativeList <ColliderCastHit> hits = new NativeList <ColliderCastHit>(Allocator.TempJob);
                        PhysicsCasting.SphereCastAll(collisionWorld, blobRange, (uint)blobPhysicsShape.BelongsTo, pos, new float3(0, 0, 100), hits);
                        if (hits.Length >= blobCost)
                        {
                            NativeArray <Entity> torm = new NativeArray <Entity>(10, Allocator.TempJob);
                            int j = 0;
                            for (int i = 0; i < hits.Length && j < 10; i++)
                            {
                                var e2 = collisionWorld.Bodies[hits[i].RigidBodyIndex].Entity;
                                if (mgr.HasComponent(e2, typeof(Blob)))
                                {
                                    torm[j++] = e2;
                                }
                            }
                            if (j == 10)
                            {
                                mgr.DestroyEntity(torm);
                                var f  = mgr.Instantiate(fp);
                                var tr = mgr.GetComponentData <Translation>(e);
                                tr.Value.z -= 0.01f;
                                mgr.SetComponentData(f, tr);
                                var ast = mgr.GetComponentData <Asteroid>(e);
                                ast.mines++;
                                mgr.SetComponentData(e, ast);
                                build = true;
                                audio.Play(tr.Value, 2);
                            }
                            torm.Dispose();
                        }
                        hits.Dispose();
                        if (!build)
                        {
                            pos.z = -1f;
                            costText.transform.position = pos;
                            costText.SetActive(false);
                            costText.SetActive(true);
                        }
                    }
                }
                // Move Ship
                if (mgr.HasComponent(e, typeof(MotherShip)))
                {
                    MotherShip ms = mgr.GetComponentData <MotherShip>(e);
                    if (ms.lerp < 0)
                    {
                        if (state.water > flyCost)
                        {
                            state.water -= flyCost;
                            ms.lerp      = 0;
                            mgr.SetComponentData(e, ms);
                        }
                        else
                        {
                            pos.z = -1;
                            noWaterText.transform.position = pos;
                            noWaterText.SetActive(true);
                        }
                    }
                }
            }
        }
    }