Inheritance: MonoBehaviour
Exemplo n.º 1
0
    void OnTriggerEnter(Collider c)
    {
        if(!activated)
        {
            ball = c.gameObject.GetComponent<Ball>();

            timer = timerLimit;

            activate();

            //get the GrameObject and Component for the GridManager
            GameObject grid = GameObject.Find("GridManager");
            GridManager manager = grid.GetComponent<GridManager>();

            //cast a ray from the camera, through the powerup, to the Grid-Plane
            Ray r = new Ray(Camera.main.transform.localPosition, transform.localPosition - Camera.main.transform.localPosition);
            Plane p = new Plane(new Vector3(0, 0, -1), grid.transform.localPosition);
            float f;
            p.Raycast(r, out f);

            //convert the ray-plane intersection into grid coordinates
            int gridHalfWidth = (int)(manager.gridWidth * manager.cubeXOffset / 2);
            int gridHalfHeight = (int)(manager.gridHeight * manager.cubeYOffset / 2);
            int gridPosX = (int)(((r.direction * f).x + gridHalfWidth) / manager.cubeXOffset);
            int gridPosY = manager.gridHeight - (int)(((r.direction * f).y + gridHalfHeight) / manager.cubeYOffset);

            //send a grid pulse from this location
            manager.gridPulseFromLocation(gridPosX, gridPosY);

            //Setting visibility to false, powerup is destroyed only after its time is over.
            gameObject.renderer.enabled = false;
        }
    }
 public void Awake()
 {
     if (ball == null)
     {
         ball = (Ball)target;
     }
 }
Exemplo n.º 3
0
    void Start()
    {
        Player1Score = 0;
        Player2Score = 0;
        ball = FindObjectOfType<Ball>();

    }
Exemplo n.º 4
0
        public void Action(Team myTeam, Team enemyTeam, Ball ball, MatchInfo matchInfo)
        {
            var pl1 = myTeam.Players.First(pl => pl.PlayerType == PlayerType.RightDefender);

            myTeam.DevMessage = string.Format("speed {0}", pl1.Velocity.Length);

            if (maxReached)
            {
                if (pl1.Velocity.Length > 0.05)
                {
                    pl1.ActionWait();
                    return;
                }

                myTeam.DevMessage += "\r\n0.05 minReached";
                maxReached = false;
                point = pl1.Position.X < Field.Borders.Center.X ? Field.EnemyGoal : Field.MyGoal;
            }

            if (pl1.Velocity.Length > 3 * 0.95)
            {
                myTeam.DevMessage += "\r\n0.95 maxReached";
                maxReached = true;
                prevVelocity = 0;
                pl1.ActionWait();
            }
            else
            {
                pl1.ActionGo(point);
                prevVelocity = pl1.Velocity.Length;
            }
        }
Exemplo n.º 5
0
 public Walls(World world, Rectangle screenBounds, Ball ball, Paddle paddle)
 {
     _world = world;
     _screenBounds = screenBounds;
     _ball = ball;
     _paddle = paddle;
 }
Exemplo n.º 6
0
 public Frame(int frameNumber, Ball ball1, Ball ball2, Ball ball3)
 {
     this.FrameNumber = frameNumber;
     this.Ball_1 = ball1;
     this.Ball_2 = ball2;
     this.Ball_3 = ball3;
 }
Exemplo n.º 7
0
 public override void BallHit(Ball _BH)
 {
     //Als de bal door het goal gaat; verhoog de score en aantal goals.
     GameObject.Find("_ScoreManager").GetComponent<ScoreCounter>().scoreToAdd -= 1000f;
     GameObject.Find("_GoalManager").GetComponent<GoalCounter>().goalToAddRobot += 1f;
     base.BallHit(_BH);
 }
Exemplo n.º 8
0
        public string HitLocation(Ball ball)
        {
            string _location = "noHit";

            //treffer von unten
            if (ball.Bottom > this._Bottom)
            {
                _location = "bottom";
            }

            //treffer von oben
            else if (ball.Top < this._Top )
            {
                _location = "top";
            }

            //treffer von links
            else if (ball.Left < this._Left)
            {
                 _location = "left";
            }

            //treffer von rechts
            else if (ball.Right > this._Right)
            {
                _location = "right";
            }

            return _location;
        }
Exemplo n.º 9
0
 public Pitch(Team my, Team enemy, Ball ball, MatchInfo info)
 {
     My = my;
     Enemy = enemy;
     Ball = ball;
     Info = info;
 }
Exemplo n.º 10
0
    public void BuildInitialFloors()
    {
        ball = GameObject.FindObjectOfType<Ball>();

        RemovePowerUps(); // remove any previous power ups

        var floors = GameObject.FindGameObjectsWithTag("floor");
        for (var i = 0; i < floors.Length; i++)
        {
            Destroy(floors[i]);
        }

        var firstFloor = GameObject.Instantiate(floor);
        var size = Random.Range(3.5f, 5.0f);
        firstFloor.transform.localScale = new Vector3(size, 1.0f, size) * aspect;
        firstFloor.transform.position = new Vector3(0, 0, 0);
        firstFloor.transform.rotation = Quaternion.Euler(new Vector3(0, 90, 0));
        lastScale = firstFloor.transform.localScale;
        lastPosition = firstFloor.transform.position;

        for (var i = 0; i < 30; i++)
        { GetNewFloor(); }

        ball = GameObject.FindObjectOfType<Ball>();
    }
        public void TestIntersect1pxOverlapBot()
        {
            //Preconfig
            Vector position1 = new Vector(0f, 50f);
            Vector target1 = new Vector(50f, 50f);

            int radius2 = 20;
            Vector center2 = new Vector(20, 49);
            Vector ballSpeed = new Vector(0, -5);

            Vector hitPoint;
            bool isIntersec = false;

            //Creation
            Line parent = new Line();
            Ball ball = new Ball();
            BoundingContainer bCont = new BoundingContainer(parent);
            BoundingContainer bCont2 = new BoundingContainer(ball);

            BoundingLine bL1 = new BoundingLine(position1, target1);
            BoundingCircle bC2 = new BoundingCircle(radius2, center2);

            bCont.AddBoundingBox(bL1);
            bCont2.AddBoundingBox(bC2);
            ball.Velocity = ballSpeed;
            parent.Location = (new Vector(0, 0));

            //Operation
            isIntersec = bC2.Intersect(bL1, out hitPoint);

            //Assertion
            Assert.IsTrue(isIntersec);
            Assert.AreEqual(new Vector(40,50), hitPoint);
        }
Exemplo n.º 12
0
    public void Awake()
    {
        _spriteStates = new Dictionary<GoalkeeperState, Vector3>();
        _random = new SystemRandom(DateTime.Now.Millisecond);

        // Get the transform and renderer;
        _transform = GetComponent<Transform>();
        _renderer = GetComponent<SpriteRenderer>();

        // Get the zones.
        _leftZone = GameObject.Find("Left-Zone").GetComponent<GoalZone>();
        _centerZone = GameObject.Find("Center-Zone").GetComponent<GoalZone>();
        _rightZone = GameObject.Find("Right-Zone").GetComponent<GoalZone>();

        // Get the ball.
        _ball = GameObject.Find("Ball").GetComponent<Ball>();

        // Initialize all sprite states.
        _spriteStates.Add(GoalkeeperState.Playing, new Vector3(0, 0, 0));
        _spriteStates.Add(GoalkeeperState.CatchLeft, new Vector3(-4, 0, 0));
        _spriteStates.Add(GoalkeeperState.CatchRight, new Vector3(4, 0, 0));
        _spriteStates.Add(GoalkeeperState.CatchCenter, new Vector3(0, 0, 0));
        _spriteStates.Add(GoalkeeperState.MissLeft, new Vector3(-4, 0, 0));
        _spriteStates.Add(GoalkeeperState.MissCenter, new Vector3(0, 0, 0));
        _spriteStates.Add(GoalkeeperState.MissRight, new Vector3(4, 0, 0));

        // Set the default state.
        SetGoalkeeperState(GoalkeeperState.Playing);
    }
Exemplo n.º 13
0
        public static Vector ChooseDirection(Player player, Ball ball)
        {
            var k1 = Line.K0(ball.Position, Field.MyGoal.Top);
            var k2 = Line.K0(ball.Position, Field.MyGoal.Bottom);
            var kball = ball.Velocity.Y / ball.Velocity.X;
            var lineball = Line.One(ball.Position, ball.Position + ball.Velocity);

            if ( ball.Owner == null
                && lineball.K >= Math.Min(k1, k2)
                && lineball.K <= Math.Max(k1, k2))
            {
                var nball = Line.Normal(lineball, player.Position);
                var intpos = Line.Cross(lineball, nball);
                if (Field.Borders.Contains(intpos)) return intpos;
                return Line.Cross(lineball, Line.One(Field.MyGoal.Top, Field.MyGoal.Bottom));
            }

            var line = Line.One(ball.Position, Field.MyGoal.Center);

            var n1 = Line.Normal(line, Field.MyGoal.Top);
            var n2 = Line.Normal(line, Field.MyGoal.Bottom);
            var a = Line.Cross(line, n1);
            var b = Line.Cross(line, n2);

            if (ball.GetDistanceTo(a) <= ball.GetDistanceTo(b))
                return a;
            return b;
        }
Exemplo n.º 14
0
	public Vector3 AssistedShotVector (Ball ball, Vector3 intendedDirectionNormalized)
	{
		Vector3 ballPos = ball.transform.position;
		
		Vector3 leftPosDir = (leftPos.position - ballPos).normalized;
		Vector3 rightPosDir = (rightPos.position - ballPos).normalized;
		
		float eulerSwingY = Quaternion.LookRotation (intendedDirectionNormalized, Vector3.forward).eulerAngles.y;
		float eulerLeftY = Quaternion.LookRotation (leftPosDir, Vector3.forward).eulerAngles.y;
		float eulerRightY = Quaternion.LookRotation (rightPosDir, Vector3.forward).eulerAngles.y;
		
		//Workaround to be able to compare angles
		eulerSwingY = eulerSwingY < 180 ? eulerSwingY + 360 : eulerSwingY;
		eulerLeftY = eulerLeftY < 180 ? eulerLeftY + 360 : eulerLeftY;
		eulerRightY = eulerRightY < 180 ? eulerRightY + 360 : eulerRightY;
		
		if (eulerSwingY < eulerRightY && eulerSwingY > eulerLeftY) {
		} else if (eulerSwingY >= eulerRightY) {
			eulerSwingY = Mathf.Lerp(eulerSwingY, eulerRightY, assistanceByDeviation.Evaluate(Mathf.Abs(eulerSwingY - eulerRightY)));
		} else if (eulerSwingY <= eulerLeftY) {
			eulerSwingY = Mathf.Lerp(eulerSwingY, eulerLeftY, assistanceByDeviation.Evaluate(Mathf.Abs(eulerSwingY - eulerLeftY)));
		}
		
		ball.rotationObject.eulerAngles = new Vector3(0, eulerSwingY, 0);
		
		return ball.rotationObject.forward;
	}
Exemplo n.º 15
0
        private void CheckCollision(Ball b, List<Obstacle> ObsFrame)
        {
            while (true)
            {

            }
        }
        public void TestIntersectIntersectBallSpeedZero()
        {
            //Preconfig
            int radius1 = 20;
            Vector center1 = new Vector(0f, 0f);
            int radius2 = 20;
            Vector center2 = new Vector(-19, 0f);
            Vector ballSpeed = new Vector(0, 0);

            Vector hitPoint;
            bool isIntersec = false;

            //Creation
            Bumper parent = new Bumper();
            Ball ball = new Ball();
            BoundingContainer bCont = new BoundingContainer(parent);
            BoundingContainer bCont2 = new BoundingContainer(ball);
            BoundingCircle bC1 = new BoundingCircle(radius1, center1);
            BoundingCircle bC2 = new BoundingCircle(radius2, center2);
            bCont.AddBoundingBox(bC1);
            bCont2.AddBoundingBox(bC2);
            ball.Velocity = ballSpeed;
            parent.Location = (new Vector(0, 0));
            parent.Width = 2 * radius1;
            parent.Height = 2 * radius1;

            //Operation
            isIntersec = bC1.Intersect(bC2, out hitPoint, ballSpeed);

            //Assertion
            Assert.IsTrue(isIntersec);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Load graphics content for the game.
        /// </summary>
        public override void Activate(bool instancePreserved)
        {
            if (!instancePreserved)
            {
                if (content == null)
                    content = new ContentManager(ScreenManager.Game.Services, "Content");

                gameFont = content.Load<SpriteFont>("gamefont");

                Mesa mesa = new Mesa(ScreenManager.Game);
                ScreenManager.Game.Components.Add(mesa);

                gerenciados = new GerenciadorCopos(ScreenManager.Game);
                gerenciados.InitCopos();

                this.ball = new Ball(ScreenManager.Game, ScreenManager.Graphics);
                ScreenManager.Game.Components.Add(this.ball);

                // A real game would probably have more content than this sample, so
                // it would take longer to load. We simulate that by delaying for a
                // while, giving you a chance to admire the beautiful loading screen.
                Thread.Sleep(1000);

                // once the load has finished, we use ResetElapsedTime to tell the game's
                // timing mechanism that we have just finished a very long frame, and that
                // it should not try to catch up.
                ScreenManager.Game.ResetElapsedTime();
            }
        }
Exemplo n.º 18
0
 private void Start()
 {
     m_Ball = FindObjectOfType<Ball>();
     m_StartWait = new WaitForSeconds(3.0f);
     m_EndWait = new WaitForSeconds(3.0f);
     StartCoroutine(GameLoop());
 }
Exemplo n.º 19
0
    public static void InsertBallToGrid(Ball ball)
    {
        Vector2 ballPosition= GetCurrentBallPosition(ball);
        insertBallIntoGrid (ballPosition,ball);

        CanCheck((int) GetCurrentBallPosition(ball).x,(int) GetCurrentBallPosition(ball).y,ball.GetBallColor());
    }
Exemplo n.º 20
0
 public bool sameColor(Ball ball)
 {
     if(this.getColor()== ball.getColor()){
         return true;
     }
     return false;
 }
Exemplo n.º 21
0
        public void Action(Team myTeam, Team enemyTeam, Ball ball, MatchInfo matchInfo)
        {
            foreach (Player player in myTeam.Players)
            {
                Player closestEnemy = player.GetClosest(enemyTeam);

                if (ball.Owner == player)  //Allways shoots for the enemy goal.
                    player.ActionShootGoal();
                else if (player.CanPickUpBall(ball))  //Picks up the ball if posible.
                    player.ActionPickUpBall();
                else if (player.CanTackle(closestEnemy))  //Tackles any enemy that is close.
                    player.ActionTackle(closestEnemy);
                else  //If the player cannot do anything urgently usefull, move to a good position.
                {
                    if (player == ball.GetClosest(myTeam))  //If the player is closest to the ball, go for it.
                        player.ActionGo(ball);
                    else if (player.PlayerType == PlayerType.Keeper)  //The keeper protects the goal.
                        player.ActionGo(new Vector(50, Math.Max(Math.Min(ball.Position.Y, Field.MyGoal.Bottom.Y), Field.MyGoal.Top.Y))); //The keeper positions himself 50 units out from the goal                                                                                                            //at the same height as the ball, although never leaving the goal
                    else if (player.PlayerType == PlayerType.LeftDefender)
                        player.ActionGo(new Vector(Field.Borders.Width * 0.2, ball.Position.Y));  //The left defender helps protect the goal
                    else if (player.PlayerType == PlayerType.RightDefender)
                        player.ActionGo(Field.MyGoal.GetClosest(enemyTeam));   //The right defender chases the enemy closest to myGoal
                    else if (player.PlayerType == PlayerType.RightForward)
                        player.ActionGo((Field.Borders.Center + Field.Borders.Bottom + ball.Position) / 3);  //Right forward stays in position on the midline, untill the ball comes close.
                    else if (player.PlayerType == PlayerType.LeftForward)
                        player.ActionGo((Field.Borders.Center + Field.Borders.Top + ball.Position) / 3);   //Left forward stays in position on the midline, untill the ball comes close.
                    else if (player.PlayerType == PlayerType.CenterForward)
                        player.ActionGo((Field.Borders.Center + Field.EnemyGoal.Center + ball.Position) / 3);    //Center forward stays in position on the enemy side of the field.
                }
            }
        }
Exemplo n.º 22
0
    /// <summary>
    /// Prevents the ball from moving out of the screen.
    /// </summary>
    private void Boundaries(Ball b)
    {
        if (b.BoundingBox.Top < 0)
        {
            b.position.Y = b.Texture.Height / 2;
            b.direction.Y *= -1;
        }

        if (b.BoundingBox.Bottom > Data.fieldSize.Y)
        {
            b.position.Y = Data.fieldSize.Y - b.Texture.Height / 2;
            b.direction.Y *= -1;
        }

        if (b.BoundingBox.Left < 0)
        {
            b.position.X = b.Texture.Width / 2;
            b.direction.X *= -1;
            this.paddleRight.score += 1;
            b.Reset(new Vector2(Data.fieldSize.X / 2 + 100, Data.fieldSize.Y / 2));
        }

        if (b.BoundingBox.Right > Data.fieldSize.X)
        {
            b.position.X = Data.fieldSize.X - b.Texture.Width / 2;
            b.direction.X *= -1;
            this.paddleLeft.score += 1;
            b.Reset(new Vector2(Data.fieldSize.X / 2 - 100, Data.fieldSize.Y / 2));
        }
    }
Exemplo n.º 23
0
    void Start()
    {
        FutileParams fParams = new FutileParams(true, true, true, true);
        fParams.AddResolutionLevel(1366, 1, 1, "");
        fParams.origin = new Vector2(0.5f, 0.5f);

        Futile.instance.Init(fParams);
        Futile.atlasManager.LoadAtlas("Atlases/Breakout");

        BreakoutBackground bg = new BreakoutBackground(1.4f, 1);
        _player = new Paddle();

        bricks = new List<Brick>();
        Brick b1 = new Brick();
        b1.x = -Futile.screen.halfWidth/2;
        b1.y = -Futile.screen.halfHeight/2;
        Brick b2 = new Brick();
        b2.x = Futile.screen.halfWidth/2;
        b2.y = -Futile.screen.halfHeight/2;
        Brick b3 = new Brick();
        b3.x = -Futile.screen.halfWidth / 2;
        b3.y = Futile.screen.halfHeight / 2;
        Brick b4 = new Brick();
        b4.x = Futile.screen.halfWidth / 2;
        b4.y = Futile.screen.halfHeight / 2;
        bricks.Add(b1);
        bricks.Add(b2);
        bricks.Add(b3);
        bricks.Add(b4);

        _ball = new Ball();
    }
Exemplo n.º 24
0
 // Use this for initialization
 void Start()
 {
     triggered = false;
     BallObject = GameObject.Find("RollerBall");
     TheBall = (Ball)BallObject.GetComponent(typeof(Ball));
     ExplosionForze = 200;
 }
Exemplo n.º 25
0
 public void Action(Team myTeam, Team enemyTeam, Ball ball, MatchInfo matchInfo)
 {
     foreach (var player in myTeam.Players)
     {
         player.ActionWait();
     }
 }
Exemplo n.º 26
0
 void Start()
 {
     levelManager = GameObject.FindObjectOfType<LevelManager>();
     ball = GameObject.FindObjectOfType<Ball>();
     textLife = GameObject.FindObjectOfType<Text>();
     paddle = GameObject.FindObjectOfType<Paddle>();
 }
Exemplo n.º 27
0
    /// <summary>
    /// Checks whether or not the given ball is colliding with this paddle.
    /// </summary>
    /// <param name="b"></param>
    /// <returns></returns>
    public bool CollisionCheck(Ball b)
    {
        Rectangle recBall = new Rectangle((int)b.position.X - b.texture.Width / 2, (int)b.position.Y - b.texture.Height / 2, b.texture.Width, b.texture.Height);
        Rectangle recPaddle = new Rectangle((int)this.position.X - this.texture.Width / 2, (int)this.position.Y - this.texture.Height / 2, this.texture.Width, this.texture.Height);

        return !(Rectangle.Empty == Rectangle.Intersect(recBall, recPaddle));
    }
Exemplo n.º 28
0
    void Start()
    {
        b1 = ball1.GetComponent<Ball>();
        b2 = ball2.GetComponent<Ball>();

        reactionTimer = reactionTime;
    }
Exemplo n.º 29
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OpenPool.BallTracker"/> class.
 /// </summary>
 /// <param name="maxcount">Maxcount.</param>
 public BallTracker(int maxcount)
 {
     balls = new Ball[maxcount];
     for(int i=0; i<balls.Length; ++i) {
     balls[i] = new Ball(false);
     }
 }
Exemplo n.º 30
0
 public void Action(Team myTeam, Team enemyTeam, Ball ball, MatchInfo matchInfo)
 {
     foreach (var player in myTeam.Players)
     {
         if (player.CanPickUpBall(ball))
         {
             player.ActionPickUpBall();
         }
         else if (player == ball.Owner)
         {
             player.ActionShootGoal();
         }
         else if (ball.Owner != null && ball.Owner.Team != myTeam && player.CanTackle(ball.Owner))
         {
             player.ActionTackle(ball.Owner);
         }
         else if (WallPositions[player.PlayerType].GetDistanceTo(player) > 1.0)
         {
             player.ActionGo(WallPositions[player.PlayerType]);
         }
         else
         {
             player.ActionWait();
         }
     }
 }