public BallApi CreateBall(Player player, IBallCreationPosition ballCreator, float radius, float mass)
		{
			// calculate mass and scale
			var m = player.TableToWorld;

			var localPos = ballCreator.GetBallCreationPosition(_table).ToUnityFloat3();
			var localVel = ballCreator.GetBallCreationVelocity(_table).ToUnityFloat3();
			localPos.z += radius;
			//float4x4 model = player.TableToWorld * Matrix4x4.TRS(localPos, Quaternion.identity, new float3(radius));

			var worldPos = m.MultiplyPoint(localPos);
			var scale3 = new Vector3(
				m.GetColumn(0).magnitude,
				m.GetColumn(1).magnitude,
				m.GetColumn(2).magnitude
			);
			var scale = (scale3.x + scale3.y + scale3.z) / 3.0f; // scale is only scale (without radiusfloat now, not vector.
			var material = BallMaterial.CreateMaterial();
			var mesh = GetSphereMesh();

			// create ball entity
			EngineProvider<IPhysicsEngine>.Get()
				.BallCreate(mesh, material, worldPos, localPos, localVel, scale, mass, radius);

			return null;
		}
예제 #2
0
 void Awake()
 {
     sidePosition = new Vector3(10, 7, 0);
     abovePosition = new Vector3(0, 10, 0);
     behindPosition = new Vector3(0, 0, -10);
     currentCamPosition = CameraPosition.Side;
     currentMaterial = BallMaterial.Rubber;
     Size = PlayerSizes.Small;
 }
예제 #3
0
    public void AddBot(bool useRandomColor)
    {
        string name = nameGenerator.GetRandomName();

        if (!ballDictionary.ContainsKey(name))
        {
            //Create ball
            GameObject ball = Instantiate(botPrefab);

            ball.transform.parent = parent;
            ball.name             = name;
            ball.transform.GetChild(0).GetComponent <Ball>().gameController = gameObject;
            //not for bots
            //ball.transform.GetChild(0).GetComponent<BallCollision>().ballConfig = ballConfig;
            ball.transform.GetChild(0).GetComponent <BallCollision>().InitializeConfig();

            //Add to dictionary
            if (unusedSpawnpoints.Count == 0)
            {
                GenerateSpawnPoints();
                Debug.Log("Ran out of spawnpoints, reused them");
            }

            ball.transform.position = GetSpawnPoint();
            ballDictionary.Add(name, ball);
            GetComponent <PlayerCount>().AddPlayer();
            if (GetComponent <PlayerCount>() == null)
            {
                Debug.LogError("ERROR! PlayerCount's text is not set in GameController. Did you apply it in this scene?");
            }

            if (useRandomColor)
            {
                MeshRenderer meshRenderer = ball.transform.GetChild(0).GetChild(0).GetChild(0).GetComponent <MeshRenderer>();
                Debug.Log(ball.transform.GetChild(0).GetChild(0).GetChild(0).GetChild(0).name);
                BallMaterial rand = (BallMaterial)(ballDictionary.Count % materialDictionary.Count) + 1;
                if (materialDictionary.ContainsKey("BallMaterial" + rand.ToString()))
                {
                    meshRenderer.material = materialDictionary["BallMaterial" + rand.ToString()];
                }
                else
                {
                    Debug.LogError("Error! Attempted to load a random material (" + rand + ")which could not be found!");
                }
            }
        }
        else
        {
            Debug.LogWarning("Error! Attempted to create ball using a name that already exists");
        }
    }
예제 #4
0
파일: Ball.cs 프로젝트: AlexeyInc/JumpBalls
    public void Fly(Quaternion rotation, float impulseForce,
                    BallMaterial ballMaterial, BallLayer ballLayer, bool trail = true)
    {
        if (_rb2D.bodyType == RigidbodyType2D.Static)
        {
            SetRigidbodyType(RigidbodyType2D.Dynamic);
        }
        SetColliderMaterial(ballMaterial);
        SetLayer(ballLayer);
        ActiveTrail(trail);

        this.gameObject.transform.rotation = rotation;

        _rb2D.AddForce(this.transform.up * impulseForce, ForceMode2D.Impulse);
    }
예제 #5
0
파일: Ball.cs 프로젝트: AlexeyInc/JumpBalls
    private void SetColliderMaterial(BallMaterial ballMaterial)
    {
        switch (ballMaterial)
        {
        case BallMaterial.Standard:
            _collider2D.sharedMaterial = solidMat;
            break;

        case BallMaterial.Bouncing:
            _collider2D.sharedMaterial = bouncingMat;
            break;

        default:
            break;
        }
    }
예제 #6
0
    public GameObject AddBall(string name, BallMaterial ballMaterial)
    {
        Debug.Log(ballMaterial);
        if (!ballDictionary.ContainsKey(name))
        {
            //Create ball
            GameObject ball = Instantiate(ballPrefab);

            ball.transform.parent = parent;
            ball.name             = name;

            ball.transform.GetChild(0).gameObject.GetComponent <Ball>().gameController      = gameObject;
            ball.transform.GetChild(0).gameObject.GetComponent <BallCollision>().ballConfig = ballConfig;
            ball.transform.GetChild(0).gameObject.GetComponent <BallCollision>().InitializeConfig();

            //Add to dictionary
            if (unusedSpawnpoints.Count == 0)
            {
                GenerateSpawnPoints();
                Debug.Log("Ran out of spawnpoints, reused them");
            }

            ball.transform.position = GetSpawnPoint();
            ballDictionary.Add(name, ball);
            GetComponent <PlayerCount>().AddPlayer();
            if (GetComponent <PlayerCount>() == null)
            {
                Debug.LogError("ERROR! PlayerCount's text is not set in GameController. Did you apply it in this scene?");
            }

            MeshRenderer meshRenderer = ball.transform.GetChild(0).GetChild(0).GetChild(0).GetComponent <MeshRenderer>();

            //Set material
            switch (ballMaterial)
            {
            case BallMaterial.RANDOM:
                BallMaterial rand = (BallMaterial)(ballDictionary.Count % materialDictionary.Count) + 1;
                if (materialDictionary.ContainsKey("BallMaterial" + rand.ToString()))
                {
                    meshRenderer.material = materialDictionary["BallMaterial" + rand.ToString()];
                    Debug.Log(meshRenderer.material);
                }
                else
                {
                    Debug.LogError("Error! Attempted to load a random material (" + rand + ")which could not be found!");
                }
                break;

            default:
                if (materialDictionary.ContainsKey("BallMaterial" + ballMaterial.ToString()))
                {
                    meshRenderer.material = materialDictionary["BallMaterial" + ballMaterial.ToString()];
                }
                else
                {
                    Debug.LogError("Error! Attempted to load the material " + ballMaterial.ToString() + " which could not be found!");
                }
                break;
            }

            if (name == "Ragntard")
            {
                EquipImageMaterial("Materials/BallIcons/BallMaterialRagntard", ball);
            }
            else if (name == "Mickster_man")
            {
                EquipImageMaterial("Materials/BallIcons/BallMaterialMickster_man", ball);
            }
            else if (name == "Jellyfranky")
            {
                EquipImageMaterial("Materials/BallIcons/BallMaterialJellyFranky", ball);
            }
            else if (name == "Lofi_lime")
            {
                EquipImageMaterial("Materials/BallIcons/BallMaterialLofi_Lime", ball);
            }
            else if (name == "Ksmoonblast")
            {
                EquipImageMaterial("Materials/BallIcons/BallMaterialKsmoonblast", ball);
            }
            else if (name == "Scoutovich")
            {
                EquipImageMaterial("Materials/BallIcons/BallMaterialScoutovich", ball);
            }
            else if (name == "Streamspinners")
            {
                EquipImageMaterial("Materials/BallIcons/BallMaterialStreamSpinners", ball);
            }
            else if (name == "Felix_time")
            {
                EquipImageMaterial("Materials/BallIcons/BallMaterialFelix_Time", ball);
            }
            else if (name == "Droopygoop")
            {
                EquipImageMaterial("Materials/BallIcons/BallMaterialDroopygoop", ball);
            }
            else if (name == "Swarmsurvivor")
            {
                EquipImageMaterial("Materials/BallIcons/BallMaterialSwarmsurvivor", ball);
            }
            else if (name == "Mariliez")
            {
                EquipImageMaterial("Materials/BallIcons/BallMaterialMariliez", ball);
            }
            else if (name == "Torthom")
            {
                EquipImageMaterial("Materials/BallIcons/BallMaterialTorthom", ball);
            }
            else if (name == "Obagovo")
            {
                EquipImageMaterial("Materials/BallIcons/BallMaterialObagovo", ball);
            }
            return(ball);
        }
        else
        {
            Debug.LogWarning("Error! Attempted to create ball using a name that already exists");
            return(null);
        }
    }
예제 #7
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if(!Input.anyKey)
            currentKey = KeyCode.None;

        if(Input.GetKey(KeyCode.PageUp))
        {
            currentKey = KeyCode.PageUp;

            if(previousKey != currentKey)
                GrowPlayer();
        }

        if(Input.GetKey(KeyCode.PageDown))
        {
            currentKey = KeyCode.PageDown;

            if(previousKey != currentKey)
                ShrinkPlayer();
        }
        /*
        if(Input.GetKey(KeyCode.DownArrow))
        {
            rigidbody.AddForce (-Vector3.forward*(speed/2));
            currentKey = KeyCode.DownArrow;
        }

        if(Input.GetKey(KeyCode.UpArrow))
        {
            rigidbody.AddForce (Vector3.forward*speed);
            currentKey = KeyCode.UpArrow;
        }

        if(Input.GetKey(KeyCode.RightArrow))
        {
            rigidbody.AddForce (Vector3.right*speed);
            currentKey = KeyCode.RightArrow;
        }

        if(Input.GetKey(KeyCode.LeftArrow))
        {
            rigidbody.AddForce (Vector3.left*speed);
            currentKey = KeyCode.LeftArrow;
        }
        */

        HandleMovement();

        if(Input.GetKey(KeyCode.Q))
        {
            currentKey = KeyCode.Space;
            if(previousKey != currentKey)
            {
                if(currentMaterial == BallMaterial.Rubber)
                {
                    currentMaterial = BallMaterial.Metal;
                    collider.material = Metal;
                    renderer.material.color = new Color32(81,81,81,255);
                }
                else if(currentMaterial == BallMaterial.Sandpaper)
                {
                    currentMaterial = BallMaterial.Rubber;
                    collider.material = Bouncer;
                    renderer.material.color = new Color32(255,156,255,255);
                }
                else
                {
                    currentMaterial = BallMaterial.Sandpaper;
                    collider.material = Paper;
                    renderer.material.color = new Color32(241,255,112,255);
                }
            }
        }

        if(Input.GetKey(KeyCode.Space))
        {
            currentKey = KeyCode.Space;
            if(previousKey != currentKey)
            {
                if((int)currentCamPosition == Enum.GetValues(typeof(CameraPosition)).Length-1)
                    currentCamPosition = (CameraPosition)0;
                else
                    currentCamPosition = (CameraPosition)((int)currentCamPosition+1);
            }
        }

        previousKey = currentKey;
    }