示例#1
0
文件: AIPlayer.cs 项目: lipusal/VJI
    private void HitBall()
    {
        BallLogic ball        = BallLogic.Instance;
        Vector3   aimPosition = _AIStrategy.GeneratePositionBasedOnDifficulty(difficulty);
        Vector3   velocity    = BallLogic.Instance.GetVelocity(aimPosition, _timeToBounce);//change time in function of currentHitForce

        AudioManager.Instance.PlaySound(ball.transform.position, (int)SoundId.SOUND_HIT);
        ball.GetComponent <Rigidbody>().velocity = velocity;
        ball.SetHittingPlayer(_id);
        _newPosition = true;
    }
示例#2
0
文件: AIPlayer.cs 项目: lipusal/VJI
    public void Serve()
    {
        Vector3   currentPosition = transform.position;
        BallLogic ball            = BallLogic.Instance;

        ball.AppearBall(new Vector3(currentPosition.x + 0.1f, 4.05f, currentPosition.z), Vector3.zero);
        Vector3 ballVelocity = ball.GetVelocity(_serveTarget, 1.5f);

        ball.GetComponent <Rigidbody>().velocity = ballVelocity;
        BallLogic.Instance.SetHittingPlayer(_id);
        Destroy(_animatedServingBall);
    }
示例#3
0
    private IEnumerator BallFlow()
    {
        bool ballIsAlive = true;

        BallLogic ballLogic = createBall();

        ballLogic.OnDestroyed += () => ballIsAlive = false;

        while (ballIsAlive)
        {
            yield return(null);
        }
    }
示例#4
0
    private void Serve()
    {
        Vector3   currentPosition = transform.position;
        BallLogic ball            = BallLogic.Instance;

        ball.AppearBall(new Vector3(currentPosition.x + 0.1f, 4.05f, currentPosition.z), Vector3.zero);
        float   minTime  = GetServeMinTime();
        float   maxTime  = GetServeMaxTime();
        float   time     = GetTimeToBounce(minTime, maxTime);
        Vector3 velocity = BallLogic.Instance.GetVelocity(aimTarget.position, time);

        ball.GetComponent <Rigidbody>().velocity = velocity;
        BallLogic.Instance.SetHittingPlayer(_id);
        Destroy(_animatedServingBall);
    }
示例#5
0
        private void GameScreen_Loaded(object sender, RoutedEventArgs e)
        {
            MainWindow win = (MainWindow)Window.GetWindow(this);

            if (win.IsNewGame)
            {
                this.GameModel      = new GameModel(win.PlayerName);
                this.ballLogic      = new BallLogic(this.GameModel.Ball);
                this.characterLogic = new CharacterLogic(this.GameModel.Ball, this.GameModel.Character, this.GameModel.Score, this.GameModel.Timer);
                this.scoreLogic     = new ScoreLogic(this.GameModel.Score, this.GameModel.Ball);
                this.timerLogic     = new TimerLogic(this.GameModel.Timer, this.GameModel);
            }
            else
            {
                this.GameModel = win.GameModel;
                this.GameModel.Character.Blocked = false;
                this.ballLogic      = new BallLogic(this.GameModel.Ball);
                this.characterLogic = new CharacterLogic(this.GameModel.Ball, this.GameModel.Character, this.GameModel.Score, this.GameModel.Timer);
                this.scoreLogic     = new ScoreLogic(this.GameModel.Score, this.GameModel.Ball);
                this.timerLogic     = new TimerLogic(this.GameModel.Timer, this.GameModel);
            }

            this.render = new GameRenderer(this.GameModel);

            if (win != null)
            {
                this.tickTimer        = new DispatcherTimer();
                this.tickTimerSeconds = new DispatcherTimer
                {
                    Interval = TimeSpan.FromMilliseconds(1000),
                };
                this.tickTimer.Interval = TimeSpan.FromMilliseconds(20);

                this.tickTimer.Tick        += this.Timer_Tick;
                this.tickTimerSeconds.Tick += this.Timer_Tick_Seconds;

                this.tickTimerSeconds.Start();
                this.tickTimer.Start();

                win.KeyDown += this.Win_KeyDown;
                win.KeyUp   += this.Win_KeyUp;
            }

            this.ballLogic.RefreshScreen += (obj, args) => this.InvalidateVisual();
            this.InvalidateVisual();
        }
示例#6
0
    void collisionBall(BallLogic ball)
    {
        if (ball == null)
        {
            return;
        }

        if (ball.id == 0)
        {
            onDie();
            return;
        }

        Event <PlaySoundEvent> .Broadcast(new PlaySoundEvent(m_eatRightBallClip));

        m_id    = ball.id;
        m_color = ball.color;
        m_time  = ball.effectTime;
        Destroy(ball.gameObject);
    }
示例#7
0
文件: AIPlayer.cs 项目: lipusal/VJI
    // Update is called once per frame
    void Update()
    {
        if (_isServing)
        {
            if (!_playerAnimation.isCelebratingOrAngry())
            {
                if (Math.Abs(_timeToServe) < 0.01)
                {
                    _timeToServe = Random.Range(0.0f, 1.0f) + 1.0f;
                }

                _elapsedTime = _elapsedTime + Time.deltaTime;
                if (_elapsedTime >= _timeToServe)
                {
                    AimServe();
                    _elapsedTime = 0;
                    _timeToServe = 0;
                    SetServing(false);
                }
            }
        }
        else
        {
            BallLogic ballLogic = BallLogic.Instance;
            bool      hasMoved  = false;
            if (ballLogic.IsEnabled() && ballLogic.GetHittingPlayer() != _id &&
                ballLogic.GetHittingPlayer() != 0)
            {
                hasMoved = MoveToBall();
            }

            if (!hasMoved)
            {
                _playerAnimation.StartMoveAnimation(MovementDirection.IDLE);
            }
        }
    }
示例#8
0
文件: Ball.cs 项目: carscan/Pong
 void OnTriggerEnter(Collider collider)
 {
     BallLogic.Hit(collider.gameObject.tag);
 }
示例#9
0
文件: Ball.cs 项目: carscan/Pong
 void FixedUpdate()
 {
     BallLogic.FixedUpdate(Time.fixedDeltaTime);
 }
示例#10
0
文件: Ball.cs 项目: carscan/Pong
 void Awake()
 {
     ballSimulation         = new BallSimulation(InitialVelocity);
     BallLogic              = new BallLogic(this, ballSimulation);
     BallLogic.OnDestroyed += () => Destroy(gameObject);
 }
示例#11
0
 void Awake()
 {
     _ballLogic            = new BallLogic();
     _ballSimulation       = new BallSimulation(this);
     _ballLogic.OnDestroy += DestroyBall;
 }
示例#12
0
 // Start is called before the first frame update
 void Start()
 {
     gameSession = FindObjectOfType <GameSessionLogic>();
     ball        = FindObjectOfType <BallLogic>();
 }
示例#13
0
    private void ReadInput()
    {
        moveLeftRightValue       = 0;
        moveForwardBackwardValue = 0;
        _finishHitting           = false;
        BallLogic ball = BallLogic.Instance;


        if (ActionMapper.GetMoveLeft(leftButton, horizontalAxis))
        {
            moveLeftRightValue += -1;
        }

        if (ActionMapper.GetMoveRight(rightButton, horizontalAxis))
        {
            moveLeftRightValue += 1;
        }

        if (ActionMapper.GetMoveForward(forwardButton, verticalAxis))
        {
            moveForwardBackwardValue += 1;
        }

        if (ActionMapper.GetMoveBackward(backwardButton, verticalAxis))
        {
            moveForwardBackwardValue += -1;
        }

        if (ActionMapper.GetHitPressed(hitButton, hitJoystickButton) && ball.GetHittingPlayer() != _id)
        {
            if (!_isCharging && _isServing)
            {
                _currentHitForce = minHitForce;
                _isCharging      = true;
            }
            else if (!_isCharging && ball.GetHittingPlayer() != 0)
            {
                _currentHitForce = minHitForce;
                if (!_isServing)
                {
                    aimTarget.position = _aimStartPosition;
                    _ballSide          = BallLogic.Instance.GetSide(transform.position);
                    _playerAnimation.StartHittingAnimation(_ballSide);
                }
                _isCharging = true;
            }
            else if (_isCharging)
            {
                _currentHitForce += deltaHitForce * Time.deltaTime;
                _currentHitForce  = Math.Min(_currentHitForce, maxHitForce);
            }
        }

        if (ActionMapper.GetHitReleased(hitButton, hitJoystickButton))
        {
            if (_isServing && ball.GetHittingPlayer() == 0)
            {
                _isCharging = false;
                _playerAnimation.StartServeAnimation();

                _animatedServingBall = Instantiate(animatableServeBallPrefab, transform.position + Vector3.up * animatableServeBallPrefab.GetComponent <BallServeAnimation>().verticalAppearOffset, Quaternion.identity);
            }
        }
    }