예제 #1
0
    //public Camera camera;

    void Awake()
    {
        model = GetComponent <GameModel>();
        view  = GetComponent <GameView>();
        ball  = GameObject.Find("Ball").GetComponent <BallView>();
        //camera = GameObject.Find("Main Camera").GetComponent<Camera>();


        /***********************SUBSCRICOES AOS EVENTOS*******************/
        //movimentacoes: barras e bola
        MoveLeftBarEvent  += view.OnMoveLeftbar;
        MoveRightBarEvent += view.OnMoveRightbar;
        MoveBallEvent     += model.OnMoveBall;
        //MoveBallEvent += ball.OnMoveBall;
        GameModel.ChangeBallDirectionEvent += ball.OnMoveBall;

        //colisoes da bola com os limites e barras

        /*BallView.BoundColisionEvent += model.OnBoundCollision;
         * BallView.BarColisionEvent += model.OnBarCollision;*/
        BallView.ColisionEvent += model.OnBallCollision;

        //pontuacao jogadores
        PlayerScoresEvent           += model.OnPlayerScores;
        PlayerScoresEvent           += ball.OnPlayerScore;
        GameModel.PlayerScoresEvent += view.OnPlayerScores;
    }
예제 #2
0
    private void GetLinkedBalls(BallView ballView, ref List <BallView> linkedBalls)
    {
        var allNearbyBalls = ballView.GetCollideWith();
        var matchBalls     = allNearbyBalls.FindAll(n => n.ballConfig.id == ballView.ballConfig.id);

        if (matchBalls.Count > 0)
        {
            //Remove already listed balls
            for (int i = 0; i < linkedBalls.Count; i++)
            {
                if (matchBalls.Contains(linkedBalls[i]))
                {
                    matchBalls.Remove(linkedBalls[i]);
                }
            }

            //Add new matched balls
            linkedBalls.AddRange(matchBalls);

            //Run recursive search of others balls
            for (int i = 0; i < matchBalls.Count; i++)
            {
                GetLinkedBalls(matchBalls[i], ref linkedBalls);
            }
        }
    }
예제 #3
0
    public void AddBall(BallView ball)
    {
        var position = ball.Ball.localPosition;

        ball.Ball.localPosition = new Vector3(position.x, position.y, _rectDesck.position.z);
        ball.transform.SetParent(_rectDesck);
    }
예제 #4
0
        public static void doDone(InstantBallMovingAction actionObject)
        {
            BallView entity = SceneViews.instance.getCurFBScene().ball;

            entity.setPosition(actionObject.targetPosition);
            entity.startSamplePosition = actionObject.targetPosition;
        }
예제 #5
0
 public BallModel(int _Row, int _Column)
 {
     Row         = _Row;
     Column      = _Column;
     RowVelocity = ColumnVelocity = Power = PreviousRow = PreviousColumn = 0;
     View        = GameObject.FindGameObjectWithTag("Ball").GetComponent <BallView>();
 }
예제 #6
0
    private async Task DestroyBall(BallView ballView)
    {
        //Check for resource
        if (ballView.resourceConfig != null)
        {
            switch (ballView.resourceConfig.id)
            {
            case 0:
            {
                wood++;
            }
            break;

            case 1:
            {
                stones++;
            }
            break;

            case 2:
            {
                water++;
            }
            break;
            }
        }


        await ballView.Explode();

        ballView.onMouseDown -= OnBallClicked;
        ballViews.Remove(ballView);
        ballView.Dispose();
    }
예제 #7
0
        public BounceView()
        {
            ballView = new BallView();
            waveView = new WaveView();

            ballView.Hidden = true;

            AddSubview(ballView);
            AddSubview(waveView);

            waveView.didEndPull = () =>
            {
                Helpers.CreateScheduledTimer(0.2, () =>
                {
                    ballView.Hidden = false;
                    ballView.StartAnimation();
                });
            };

            BallSize = 28f;
            BallMovementTimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseOut);
            BallMoveUpDuration = 0.2;
            BallMoveUpDistance = 32f * 1.5f;
            BallViewHeight = 100f;
            WaveBounceDuration = 0.8;
            BallColor = UIColor.White;
            WaveColor = UIColor.White;
        }
예제 #8
0
        public static void doProgress(BallMovingAction actionObject, float progress)
        {
            BallView entity = SceneViews.instance.getCurFBScene().ball;
            //获取本次移动位置
            Vector3 thisEndPostion = MovingProcessorUtility.getMovePosition(entity.startSamplePosition, actionObject.targetPosition, progress);

            entity.setPosition(thisEndPostion);
        }
예제 #9
0
 private void ReturnToPool(BallView ball)
 {
     _activeBalls.Remove(ball);
     _pool.Add(ball);
     ball.gameObject.SetActive(false);
     SetBallSettings(ball);
     ball.Init();
 }
예제 #10
0
 /// <summary>
 /// LoadContent will be called once per game and is the place to load
 /// all of your content.
 /// </summary>
 protected override void LoadContent()
 {
     // Create a new SpriteBatch, which can be used to draw textures.
     spriteBatch    = new SpriteBatch(GraphicsDevice);
     ballTexture    = Content.Load <Texture2D>("aqua-ball.png");
     ballSimulation = new BallSimulation();
     ballView       = new BallView(graphics, ballSimulation, ballTexture);
 }
예제 #11
0
 public BallPool(int poolSize, BallView ball)
 {
     _freeBallPool = new Queue <BallView>(poolSize);
     for (int i = 0; i < poolSize; i++)
     {
         _freeBallPool.Enqueue(Object.Instantiate(ball));
     }
 }
예제 #12
0
 public BallController(BallView view, GameContext context)
 {
     _view = view;
     if (_view != null)
     {
         _viewIsNull = false;
     }
     _context = context;
 }
예제 #13
0
    public override void Init()
    {
        base.Init();

        m_view = GetComponent <BallView>();

        m_view.Init(this);
        this.StateTransion(new BallIdle());
    }
예제 #14
0
파일: Ball.cs 프로젝트: asmCode/soccer_game
    public Ball(BallView ballView)
    {
        m_ballView = ballView;

        Collider        = new ssg.SphereCollider();
        Collider.Radius = Radius;
        Collider.Trans  = this;
        Collider.Tag    = (int)ObjectId.Ball;
    }
예제 #15
0
    public void Init()
    {
        model = GetComponent <BallModel>();
        view  = GetComponent <BallView>();

        view.MoveInput += OnInput;
        view.Died      += OnDeath;
        view.Jump      += OnJump;
    }
예제 #16
0
 public void delAllBallView()
 {
     for (int i = 0; i < listBallView.Count; i++)
     {
         BallView ball = listBallView[i];
         TrashMan.despawn(ball.gameObject);
     }
     listBallView.Clear();
 }
예제 #17
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
            Texture2D ball = Content.Load <Texture2D>("ball4");

            model = new BallSimulation();
            view  = new BallView(GraphicsDevice, ball);
        }
예제 #18
0
    private void StartGame()
    {
        var obj = Instantiate(ballPrefab, initialPosition, Quaternion.identity);

        obj.GetComponent <BallModel>();
        ball       = obj.GetComponent <BallView>().Init(initialPosition);
        ball.Died += OnDied_Ball;
        obj.GetComponent <BallController>().Init();

        dispatcher.Notify("ball_spawned", ball);
    }
예제 #19
0
    private BallView CreateBall()
    {
        BallView ball = Instantiate(_ballPrefab, gameObject.transform);

        SetBallSettings(ball);
        ball.gameObject.SetActive(false);
        ball.ReturnToPool = ReturnToPool;
        ball.AddPoints    = AddPoints;
        ball.Init();
        return(ball);
    }
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.

            spriteBatch = new SpriteBatch(GraphicsDevice);
            ballSimulation = new BallSimulation();
            ballVIew = new BallView(graphics, ballSimulation, Content);

            // TODO: use this.Content to load your game content here
            //camera = new Camera(GraphicsDevice.Viewport);
        }
예제 #21
0
    public BallView CreateBall(NetObject netObj)
    {
        GameObject    obj  = TrashMan.spawn("Ball");
        BallView      ball = obj.GetComponent <BallView>();
        RectTransform rect = obj.GetComponent <RectTransform>();

        ball.uid              = netObj.uid;
        obj.transform.parent  = GameObject.Find("Canvas").transform;
        rect.anchoredPosition = GraphicUtil.ToVector2(netObj.body.center);
        ball.setData(netObj);
        return(ball);
    }
예제 #22
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
            ballSimulation = new BallSimulation();
            ballTexture    = Content.Load <Texture2D>("Ball.png");
            Camera camera = new Camera(GraphicsDevice.Viewport);

            ballView = new BallView(ballSimulation, camera, GraphicsDevice, ballTexture);
        }
예제 #23
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            m_camera  = new Camera(GraphicsDevice.Viewport);
            m_bv      = new BallView();
            m_bs      = new BallSimulation();
            m_gameCon = new GameController(Content);

            this.IsMouseVisible = true;

            base.Initialize();
        }
예제 #24
0
    private void SpawnBall()
    {
        if (_pool.Count == 0)
        {
            _pool.Add(CreateBall());
        }
        BallView ball = _pool[0];

        _pool.RemoveAt(0);
        _activeBalls.Add(ball);
        ball.gameObject.SetActive(true);
    }
예제 #25
0
 public BallController(BallView ballView, int xPositinon, int yPosition, TypeBall typeBall, ResourcesCount typeResources)
 {
     _ballView      = ballView;
     _xPositinon    = xPositinon;
     _yPosition     = yPosition;
     _typeBall      = typeBall;
     _typeResources = typeResources;
     _moveAnimator  = _ballView.MoveAnimator;
     _ballView.PointerObject.BallMoveSide += PointerObject_BallMoveSide;
     _ballView.MoveAnimator.EndAnimation  += OnEndAnimation;
     _isChanged = true;
 }
예제 #26
0
 public void shoot(int id)
 {
     for (int i = 0; i < listBallView.Count; i++)
     {
         BallView ball = listBallView[i];
         if (ball.uid == id)
         {
             ball.performShoot();
             return;
         }
     }
 }
예제 #27
0
        public void Initialize()
        {
            _gameObjectsContainerInstance = Instantiate(GameObjectsContainerPrefab);

            _fieldViewInstance = Instantiate(FieldViewPrefab, _gameObjectsContainerInstance.gameObject.transform);

            _topRacketViewInstance = Instantiate(RacketViewPrefab, _fieldViewInstance.gameObject.transform);
            _topRacketViewInstance.gameObject.transform.position = new Vector3(0, 4.5f, 0);
            _bottomRacketViewInstance = Instantiate(RacketViewPrefab, _fieldViewInstance.gameObject.transform);
            _bottomRacketViewInstance.gameObject.transform.position = new Vector3(0, -4.5f, 0);

            _ballViewInstance = Instantiate(BallViewPrefab, _fieldViewInstance.gameObject.transform);
        }
예제 #28
0
    public void createBallView(int id)
    {
        GameObject obj  = TrashMan.spawn(ballPrefab.gameObject);
        BallView   ball = obj.GetComponent <BallView>();

        listBallView.Add(ball);
        ball.uid = id;
        obj.transform.SetParent(this.transform, false);
        obj.transform.localPosition = Vector3.zero;
        NetObject data = NetScene.getInstance().GetBall(ball.uid);

        ball.setData(data);
    }
예제 #29
0
 public void delBallView(int id)
 {
     for (int i = 0; i < listBallView.Count; i++)
     {
         BallView ball = listBallView[i];
         if (ball.uid == id)
         {
             listBallView.Remove(ball);
             TrashMan.despawn(ball.gameObject);
             return;
         }
     }
 }
예제 #30
0
        public void Initialize()
        {
            _brickViewInstances.CollectionChanged += BrickViewInstancesOnCollectionChanged;

            _gameObjectsContainerInstance = Instantiate(GameObjectsContainerPrefab);

            _fieldViewInstance = InstantiateElement(FieldViewPrefab, _gameObjectsContainerInstance);

            _bricksContainerInstance = InstantiateElement(BricksContainerPrefab, _gameObjectsContainerInstance, new Vector3(0, 3.5f, 0));
            _bricksContainerInstance.BrickPositioningCompleted += BricksContainerInstanceOnBrickPositioningCompleted;
            var brickTypes = Enum.GetValues(typeof(BrickType)).Cast <BrickType>().Reverse();

            foreach (var brickType in brickTypes)
            {
                for (var j = 0; j < bricksCountPerType; j++)
                {
                    var brickViewInstance = InstantiateElement <BrickView>(BrickViewPrefab, _bricksContainerInstance.transform);
                    brickViewInstance.Initialize(brickType);
                    brickViewInstance.WasDestroyed += BrickViewInstanceOnWasDestroyed;

                    _brickViewInstances.Add(brickViewInstance);
                }
            }

            if (_randomLevelGeneration)
            {
                foreach (var brickViewInstance in _brickViewInstances)
                {
                    var destroyBrick = _random.Next(0, 2);
                    if (destroyBrick > 0)
                    {
                        _brickViewInstancesForDestruction.Add(brickViewInstance);
                    }
                }
            }

            if (_advantageousPositioningOfTargetBrick)
            {
                var randomBrick = _brickViewInstances.Last();
                randomBrick.Targeted = true;
            }
            else
            {
                var randomBrick = _brickViewInstances[_random.Next(_brickViewInstances.Count)];
                randomBrick.Targeted = true;
            }

            _racketViewInstance = InstantiateElement(RacketViewPrefab, _fieldViewInstance.gameObject.transform, new Vector3(0, -4.5f, 0));

            _ballViewInstance = InstantiateElement(BallViewPrefab, _fieldViewInstance.gameObject.transform, new Vector3(0, -1f, 0));
        }
예제 #31
0
    private void OnBallClicked(BallView ballView)
    {
        var linkedBalls = new List <BallView>();

        GetLinkedBalls(ballView, ref linkedBalls);
        if (linkedBalls.Count >= 3)
        {
            linkedBalls.ForEach(n => DestroyBall(n));
        }
        else
        {
            ballView.Decoy();
        }
    }
예제 #32
0
        public void Initialize()
        {
            CellViewInstances = new List <CellView>();

            _directionalLightInstance = Instantiate(_directionalLightPrefab);
            _cameraInstance           = Instantiate(_cameraPrefab);

            _fieldViewInstance = Instantiate(_fieldViewPrefab);
            BallViewInstance   = Instantiate(_ballViewPrefab);
            BallViewInstance.transform.position = new Vector3(
                BallViewInstance.gameObject.transform.position.x,
                BallViewInstance.gameObject.transform.position.y + 1,
                BallViewInstance.gameObject.transform.position.z);
        }
예제 #33
0
        public GameController(ContentManager cm, Camera cam, SpriteBatch sprite, MouseState mouse, GraphicsDevice graphics, BallSimulation ballSim)
        {
            content = cm;
            camera = cam;
            spriteBatch = sprite;
            this.graphics = graphics;
            this.ballSim = ballSim;

            explosionTexture = content.Load<Texture2D>("explosion");
            splitterTexture = content.Load<Texture2D>("spark");
            smokeTexture = content.Load<Texture2D>("smokePic");
            ballTexture = content.Load<Texture2D>("ball");
            pistolEffect = content.Load<SoundEffect>("fire");

            splitterView = new SplitterView(spriteBatch,camera, splitterTexture);
            smokeView = new SmokeView(spriteBatch, camera, smokeTexture);
            ballView = new BallView(ballSim, camera, graphics, ballTexture);
        }