Beispiel #1
0
 void SetupObjects()
 {
     objects    = new MovingObject[3];
     objects[0] = new BallObject("ball1");
     objects[1] = new PlayerObject("player1");
     objects[2] = new PlayerObject("player2");
 }
 private void HandleDrawing()
 {
     // screen released OR ballTouched event triggers.
     if (Input.GetMouseButtonUp(0) || ballTouchedEventTriggered)
     {
         // adapt curve to end at center of touched ball.
         if (ballTouchedEventTriggered)
         {
             InterpolateLine();
         }
         ballTouchedEventTriggered = false;
         firstTouchBall            = null;
         currentCursor.BeginLooping();
         EventManager.CallLooping();
         currentState = State.LOOP_LINE;
     }
     // black event triggers.
     else if (blackEventTriggered)
     {
         blackEventTriggered = false;
         currentCursor.DestroyCursor();
         EventManager.CallLevelRestart();
         currentState = State.AWAIT_INPUT;
     }
 }
    public static void MoveBall(BListObject ballListObj)
    {
        GameObject ball    = ballListObj.value;
        BallObject ballObj = ball.GetComponent <BallScript>().ballObj;

        CalculateLerpVector(ballObj);

        int movementSpeed = ballObj.forCounter;

        bool special = ballObj.specialMove;

        for (int i = 0; i < movementSpeed; ++i)
        {
            CalculateLerpVector(ballObj);
            AddLerpVector(ball, ballObj);
            if (Vector3.Distance(ball.transform.position, ballObj.destinationPosition) <= safeDistance)
            {
                ChangeToNextDestination(ballObj);
                if (special)
                {
                    break;
                }
            }
        }
        if (ballObj.specialMove)
        {
            changeSpecialMoveToFalse = false;
        }
    }
    public static Vector3 FindNewPositionForFirstLastBallOnBallAdding(GameObject first, int firstLast)
    {
        BallObject ballObj  = first.GetComponent <BallScript>().ballObj;
        int        dest     = ballObj.destination;
        Vector3    newPos   = first.transform.position;
        float      distance = 0.0f;

        ballObj.forwardBackward *= firstLast;
        if (firstLast < 0)
        {
            ballObj.destination--;
        }
        do
        {
            CalculateLerpVector(ballObj);
            newPos   += ballObj.lerpVector;
            distance += ballObj.lerpVector.magnitude;

            if (Vector3.Distance(newPos, ballObj.destinationPosition) < safeDistance)
            {
                ChangeToNextDestination(ballObj, false);
            }
        } while (distance < GameManagerScript.spawningSafeDistance);

        ballObj.forwardBackward *= firstLast;
        ballObj.destination      = dest;

        return(newPos);
    }
 public static void CalculateLerpVector(BallObject ballObj)
 {
     if (ballObj.lerpVector == new Vector3())
     {
         ballObj.lerpVector = (Vector3.Lerp(ballObj.sourcePosition, ballObj.destinationPosition, ballObj.speed) - ballObj.sourcePosition) / Vector3.Distance(ballObj.sourcePosition, ballObj.destinationPosition);
     }
 }
Beispiel #6
0
        public void InitializeGame()
        {
            if (!offline && (!client.Initialized() || !server.Initialized()))
            {
                throw new Exception("Connection unitialized. Can't start a game");
            }
            if (offline)
            {
                left  = new HumanPlayer(Side.LEFT);
                right = new HumanPlayer(Side.RIGHT);
            }
            else if (isServer)
            {
                left  = new HumanPlayer(Side.LEFT);
                right = new NetworkPlayer(Side.RIGHT);
            }
            else
            {
                left  = new NetworkPlayer(Side.LEFT);
                right = new HumanPlayer(Side.RIGHT);
            }
            WorldController wrld     = new WorldController(left, right, server, client, isServer);
            Overseer        overseer = new Overseer(wrld);
            BallObject      ball     = new BallObject(left, right, overseer);

            wrld.AttachBall(ball);
            using (var game = new Pong(left, right, ball))
                game.Run();
        }
 // Sets a flag to trigger ballTouched event when checking FSM.
 private void TriggerBallTouchedEvent(BallObject ball)
 {
     if (currentState != State.LOOP_LINE)
     {
         ballTouchedEventTriggered = true;
         firstTouchBall            = ball;
     }
 }
    private void OnTriggerEnter2D(Collider2D other)
    {
        GameObject target = other.gameObject.transform.parent.gameObject;
        BallObject data   = target.GetComponent <BallConfigurations>().data;

        spawnCtrl.RemoveFromActive(data);
        Destroy(target);
    }
    private void CreateActiveObject(GameObject gObj, BallObject data)
    {
        ActiveBall newBall = new ActiveBall();

        newBall.data       = data;
        newBall.gameObject = gObj;
        activeQueue[data.exercise].Add(newBall);
    }
Beispiel #10
0
 public Pong(Player left, Player right, BallObject ball) : base()
 {
     this.left             = left;
     this.right            = right;
     this.ball             = ball;
     graphics              = new GraphicsDeviceManager(this);
     Content.RootDirectory = "Content";
 }
    public static void Create()
    {
        BallObject asset = ScriptableObject.CreateInstance <BallObject>();

        AssetDatabase.CreateAsset(asset, "Assets/NewBallObject.asset");
        AssetDatabase.SaveAssets();
        EditorUtility.FocusProjectWindow();
        Selection.activeObject = asset;
    }
Beispiel #12
0
 // decrease by one the number of active balls in scene.
 private void DecreaseBallCount(BallObject ball)
 {
     remainingBalls--;
     // upon successfull removal of all active balls, notify about level completion.
     if (remainingBalls == 0)
     {
         EventManager.CallLevelCompleted();
     }
 }
    public void RemoveFromActive(BallObject data)
    {
        List <ActiveBall> q      = activeQueue[data.exercise];
        ActiveBall        target = q.Single(t => t.data.id == data.id);

        q.Remove(target);

        CheckLevelEnd();
    }
    private void SpawnBall()
    {
        int        last       = ballQueue.Count - 1;
        BallObject lastBall   = ballQueue[last];
        Sprite     exerSprite = gameSprites.GetSprite(lastBall.exercise);
        GameObject cannonBall = CannonController.FireProjectile(lastBall, exerSprite);

        ballQueue.RemoveAt(last);
        previewPanel.UpdatePreview();
        CreateActiveObject(cannonBall, lastBall);
        timeout = lastBall.timeDelay;
    }
    private void RevertBonus(Bonus bonus)
    {
        if (bonus.bonusKind == BonusKind.slower)
        {
            BallObject.IncreaseNormalSpeedLevel(3);
        }

        //if (bonus.bonusKind == BonusKind.rollBack)
        //{
        //    GameObject.Find("GameManager").GetComponent<GameManagerScript>().RevertBallsDirection();
        //}
    }
 private void Clear()
 {
     spawningSafeDistance = ballPrefab.transform.lossyScale.y;
     balls = new BList();
     ballsThatCouldBeInSequence       = new List <BListObject>();
     ballsThatHasToReturnWithSequence = new List <BListObject>();
     ballsCount  = 0;
     lost        = false;
     levelEnded  = false;
     _canShoot   = false;
     ballsToAdd  = new List <NewBallToAdd>();
     ballsToHide = new Queue <GameObject>();
     BallObject.ClearStatic();
 }
Beispiel #17
0
        public void ProcessMovement(double timestamp, PlayerMovement movement)
        {
            if (timestamp > latestMovementTimestamp)
            {
                Rigidbody ballRb = BallObject.GetComponent <Rigidbody>();

                BallObject.transform.position = movement.Position;
                BallObject.transform.rotation = movement.Rotation;
                ballRb.velocity            = movement.Velocity;
                ballRb.angularVelocity     = movement.AngularVelocity;
                BallObject.DirectionVector = movement.DirectionVector;

                latestMovementTimestamp = timestamp;
            }
        }
    public GameObject FireProjectile(BallObject d, Sprite exercise)
    {
        GameObject cannonBall = Instantiate(
            shotBall,
            new Vector2(transform.position.x + 0.387f, transform.position.y + 1.748f),
            transform.rotation
            );

        AudioSource.PlayClipAtPoint(projectile, Camera.main.transform.position, 0.5f);
        BallConfigurations ballConfigs = cannonBall.GetComponent <BallConfigurations>();

        ballConfigs.data = d;
        ballConfigs.SetExercise(exercise);
        ballConfigs.SetParachuteLift(d.fallDelay);
        return(cannonBall);
    }
 public static void ChangeToNextDestination(BallObject ballObj, bool decrease = true)
 {
     if ((ballObj.destination = LevelManager.GetNextLevelPoint(ballObj.destination, ballObj.forwardBackward)) == -1)
     {
         playing = false;
     }
     else if (ballObj.destination == -2)
     {
         // HideBall()
         playing = false;
     }
     if (decrease && ballObj.forwardBackward > 0)
     {
         ballObj.DecreaseSpeedLevel();
     }
 }
Beispiel #20
0
        public BallDaemon(
            string serverAddress,
            int serverPort,
            Guid bubbleId,
            string daemonIdentifier,
            string daemonSecret
            )
        {
            this.serverAddress    = serverAddress;
            this.serverPort       = serverPort;
            this.bubbleId         = bubbleId;
            this.daemonIdentifier = daemonIdentifier;
            this.daemonSecret     = daemonSecret;
            String programName         = "Ball Daemon";
            byte   programMajorVersion = 0;
            byte   programMinorVersion = 1;

            client = new CloudView(100, programName, programMajorVersion, programMinorVersion);

            Random random = new Random();
            int    i      = 0;

            BallArray[i]                      = new BallObject();
            BallArray[i].ObjectId             = Guid.NewGuid();
            BallArray[i].ObjectName           = "Ball Daemon Avatar";
            BallArray[i].OrbitRadius          = 0;
            BallArray[i].OrbitAngle           = 0;
            BallArray[i].OrbitAngularVelocity = 0;
            BallArray[i].Location.X           = 0;
            BallArray[i].Location.Y           = 0;
            BallArray[i].Location.Z           = 0;
            Balls.Add(BallArray[i].ObjectId, BallArray[i]);

            for (i = 1; i < NumberOfObjects; i++)
            {
                BallArray[i]                      = new BallObject();
                BallArray[i].ObjectId             = Guid.NewGuid();
                BallArray[i].ObjectName           = "Test Object " + i;
                BallArray[i].OrbitRadius          = (float)(random.NextDouble() * 45) + 5;
                BallArray[i].OrbitAngle           = (float)(random.NextDouble() * 2 * Math.PI);
                BallArray[i].OrbitAngularVelocity = (float)(random.NextDouble() * 2 * Math.PI / 8);
                BallArray[i].Location.X           = (float)(BallArray[i].OrbitRadius * Math.Cos(BallArray[i].OrbitAngle));
                BallArray[i].Location.Y           = 0.5f;
                BallArray[i].Location.Z           = (float)(BallArray[i].OrbitRadius * Math.Sin(BallArray[i].OrbitAngle));
                Balls.Add(BallArray[i].ObjectId, BallArray[i]);
            }
        }
Beispiel #21
0
    void SpawnPlayer(object sender, MessageReceivedEventArgs e)
    {
        using (Message message = e.GetMessage())
            using (DarkRiftReader reader = message.GetReader()) {
                if (message.Tag == Tags.SpawnPlayerTag)
                {
                    if (reader.Length % 17 != 0)
                    {
                        Debug.LogWarning("Received malformed spawn packet.");
                        return;
                    }

                    while (reader.Position < reader.Length)
                    {
                        ushort  id       = reader.ReadUInt16();
                        Vector3 position = new Vector3(reader.ReadSingle(), reader.ReadSingle());
                        Color32 color    = new Color32(
                            reader.ReadByte(),
                            reader.ReadByte(),
                            reader.ReadByte(),
                            255
                            );

                        GameObject obj;
                        if (id == client.ID)
                        {
                            obj = Instantiate(controllablePrefab, position, Quaternion.identity) as GameObject;

                            Ball ball = obj.GetComponent <Ball> ();
                            ball.Client = client;
                        }
                        else
                        {
                            obj = Instantiate(networkPrefab, position, Quaternion.identity) as GameObject;
                        }

                        BallObject ballObject = obj.GetComponent <BallObject> ();

                        ballObject.SetColor(color);
                    }
                }
            }
    }
    private void ChangeBallsDirectionOnInsert(GameObject newBall, Vector3 positionForFirstBall, Vector3 posForNewBall)
    {
        BListObject actual = balls.InitEnumerationFromRightBListObject();

        BallObject ballObj = actual.value.GetComponent <BallScript>().ballObj;

        bool curveChange = false;

        ballObj.destination--;
        ballObj.destinationPosition = positionForFirstBall;
        ballObj.IncreaseSpeedLevel();
        if (actual.value != newBall)
        {
            while ((actual = balls.PreviousBListObject()) != null && actual.value != newBall)
            {
                ballObj = actual.value.GetComponent <BallScript>().ballObj;
                ballObj.destination--;
                if (actual.rightNeighbour.value.GetComponent <BallScript>().ballObj.destination > ballObj.destination && !curveChange)
                {
                    ballObj.destination++;
                    curveChange = true;
                }
                else if (curveChange)
                {
                    curveChange = false;
                }

                ballObj.destinationPosition = actual.rightNeighbour.value.transform.position;
                ballObj.IncreaseSpeedLevel();
            }
            ballObj = actual.value.GetComponent <BallScript>().ballObj;
            ballObj.destination--;
            if (actual.rightNeighbour.value.GetComponent <BallScript>().ballObj.destination > ballObj.destination && !curveChange)
            {
                ballObj.destination++;
                curveChange = true;
            }
            ballObj.destinationPosition = posForNewBall;
            ballObj.IncreaseSpeedLevel();
        }
    }
    private static void UseBonus(Bonus bonus)
    {
        if (GameManagerScript.playing)
        {
            if (bonus.bonusKind == BonusKind.slower)
            {
                BallObject.DecreaseNormalSpeedLevels(3);
                bonus.bonusEndTime = Time.time + bonusDurationTime;
                actualBonuses.Add(bonus);
            }

            //if (bonus.bonusKind == BonusKind.rollBack)
            //{
            //    GameObject.Find("GameManager").GetComponent<GameManagerScript>().RevertBallsDirection();
            //}

            if (bonus.bonusKind == BonusKind.colorDestroy)
            {
                GameObject.Find("GameManager").GetComponent <GameManagerScript>().DestroyBallsWithSpecificColor(bonus.ballColor);
            }
        }
    }
    private static void AddLerpVector(GameObject ball, BallObject ballObj)
    {
        Vector3 ballPos = ball.transform.position;
        bool    change  = false;

        float prevDistanceToDestinationPoint = Vector3.Distance(ballPos, ballObj.destinationPosition);

        if (Mathf.Abs(ball.transform.position.x - ballObj.destinationPosition.x) > Mathf.Abs(ballObj.lerpVector.x))
        {
            ballPos.x += ballObj.lerpVector.x;
            change     = true;
        }

        if (Mathf.Abs(ball.transform.position.y - ballObj.destinationPosition.y) > Mathf.Abs(ballObj.lerpVector.y))
        {
            ballPos.y += ballObj.lerpVector.y;
            change     = true;
        }

        if (Mathf.Abs(ball.transform.position.z - ballObj.destinationPosition.z) > Mathf.Abs(ballObj.lerpVector.z))
        {
            ballPos.z += ballObj.lerpVector.z;
            change     = true;
        }

        float actualDistanceToDestinationPoint = Vector3.Distance(ballPos, ballObj.destinationPosition);

        if (change == true && !(actualDistanceToDestinationPoint >= prevDistanceToDestinationPoint))
        {
            ball.transform.position = ballPos;
        }
        else
        {
            ball.transform.position = ballObj.destinationPosition;
        }
    }
    public void UpdateActiveObject(GameObject newObj, BallObject d)
    {
        ActiveBall target = activeQueue[d.exercise].First(x => x.data.id == d.id);

        target.gameObject = newObj;
    }
Beispiel #26
0
 public void AttachBall(BallObject ball)
 {
     this.ball = ball;
 }
 public static void CallBallTouched(BallObject ball)
 {
     BallTouched?.Invoke(ball);
 }
Beispiel #28
0
 public BallObject(BallObject ballObj)
 {
     destination         = ballObj.destination;
     forwardBackward     = ballObj.forwardBackward;
     destinationPosition = ballObj.destinationPosition;
 }
Beispiel #29
0
 public void SetBallObject(Color color, int speedLevel = 0)
 {
     ballObj = new BallObject(color, gameObject, speedLevel);
     SetBallColor();
 }
 void Awake()
 {
     BallObject = GetComponent <BallObject> ();
 }