Example #1
0
 /// <summary>
 /// Sets the paddle to the normal texture.
 /// </summary>
 public void setToNormal()
 {
     state                   = PaddleState.NORMAL;
     Texture                 = defaultNormalTexture;
     UseSpriteSheet          = false;
     UseSpriteSheetAnimation = false;
 }
Example #2
0
 public void Stop(PaddleState oldState)
 {
     if (oldState == paddleState)
     {
         paddleState = PaddleState.STOP;
     }
 }
Example #3
0
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            //move left paddle
            if (e.KeyCode == Keys.W)
            {
                LeftPaddle = PaddleState.Up;
            }
            if (e.KeyCode == Keys.S)
            {
                LeftPaddle = PaddleState.Down;
            }
            //move right paddle
            if (e.KeyCode == Keys.Up)
            {
                RightPaddle = PaddleState.Up;
            }
            if (e.KeyCode == Keys.Down)
            {
                RightPaddle = PaddleState.Down;
            }
            if (e.KeyCode == Keys.Return)
            {
                //reset
                Reset();

                lblStart.Visible = false;
                tmrGame.Enabled  = true;
            }
        }
Example #4
0
        public Paddle()
        {
            // Sets up the body part's shape.
            this.Shape = new Polygon
            {
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment = VerticalAlignment.Top,
                StrokeThickness = 3.0,
                Opacity = 1.0,
                Fill = Brushes.Orange,
                Stroke = Brushes.Black
            };
            this.state = PaddleState.PreGame;

            // Sets up the appear animation.
            this.AppearAnimation = new Storyboard();
            DoubleAnimation da = new DoubleAnimation(1.0, new Duration(Paddle.AppearAnimationDuration));
            Storyboard.SetTarget(da, this.Shape);
            Storyboard.SetTargetProperty(da, new PropertyPath(Polygon.OpacityProperty));
            this.AppearAnimation.Children.Add(da);

            // Sets up the hit animation.
            this.FillAnimation = new Storyboard();
            ColorAnimation ca = new ColorAnimation(Colors.Red, Colors.Orange, new Duration(Paddle.HitAnimationDuration));
            Storyboard.SetTarget(ca, this.Shape);
            Storyboard.SetTargetProperty(ca, new PropertyPath("Fill.Color", new object[] { Polygon.FillProperty, SolidColorBrush.ColorProperty }));
            this.FillAnimation.Children.Add(ca);
            this.State = PaddleState.PreGame;
        }
Example #5
0
 public bool initWithTexture(CCTexture2D aTexture)
 {
     if (base.InitWithTexture(aTexture))
     {
         m_state = PaddleState.kPaddleStateUngrabbed;
     }
     return(true);
 }
Example #6
0
		bool onTouchBegan(CCTouch touch, CCEvent touchEvent)
        {
            if (m_state != PaddleState.kPaddleStateUngrabbed) return false;
            if (!containsTouchLocation(touch)) return false;

            m_state = PaddleState.kPaddleStateGrabbed;
            return true;
        }
Example #7
0
 public new bool initWithTexture(CCTexture2D aTexture)
 {
     if (base.initWithTexture(aTexture))
     {
         m_state = PaddleState.kPaddleStateUngrabbed;
     }
     return true;
 }
Example #8
0
        public override bool TouchBegan(CCTouch touch)
        {
            if (m_state != PaddleState.kPaddleStateUngrabbed) return false;
            if (!containsTouchLocation(touch)) return false;

            m_state = PaddleState.kPaddleStateGrabbed;
            return true;
        }
Example #9
0
        public virtual bool ccTouchBegan(CCTouch touch, CCEvent eventer)
        {
            if (m_state != PaddleState.kPaddleStateUngrabbed) return false;
            if (!containsTouchLocation(touch)) return false;

            m_state = PaddleState.kPaddleStateGrabbed;
            return true;
        }
Example #10
0
 protected void UpdateRotateAngle()
 {
     RotateAngle -= kRotateDownSpeed;
     if (RotateAngle < kLeftRestPosition)
     {
         RotateAngle         = kLeftRestPosition;
         mCurrentPaddleState = PaddleState.PaddleAtRest;
     }
 }
Example #11
0
        private void UpdatePaddleFromRest(float angle)
        {
            if (angle == 0f)
            {
                return;
            }

            RotateAngle         = angle;
            mCurrentPaddleState = PaddleState.PaddleReturning;
        }
Example #12
0
 /// <summary>
 /// Starts the red paddle animation and countdown. State will be set to
 /// fire until the animation completes.
 /// </summary>
 public void startFire()
 {
     state = PaddleState.FIRE;
     SetTextureSpriteSheet(defaultFireSpritesheet, SPRITE_WIDTH, SPRITE_HEIGHT);
     SetTextureSpriteAnimationFrames(0, 0,
                                     SPRITE_FINAL_FRAME_COL, SPRITE_FINAL_FRAME_ROW,
                                     TICKS_PER_FRAME, SpriteSheetAnimationMode.AnimateForwardThenStop);
     UseSpriteSheet          = true;
     UseSpriteSheetAnimation = true;
 }
Example #13
0
        public override void Start()
        {
            base.Start();
            characterController = GetComponent <CharacterController>();
            state = GameState.PaddleState;

            state.OnSpawnNewBall += SpawnBall;

            state.ControllerInitialized();
        }
Example #14
0
        /// <summary>
        /// gives the paddle keyboard input movement
        /// </summary>
        /// <param name="gameTime">current gametime</param>
        public void Update(GameTime gameTime)
        {
            var newKeyboardState = Keyboard.GetState();


            if (game.GameState == 0)     //if the game is still going, movement is still enabled. Stops enabling movement if game is over
            {
                if (newKeyboardState.IsKeyDown(Keys.Up))
                {
                    pstate    = PaddleState.up;
                    bounds.Y -= (float)gameTime.ElapsedGameTime.TotalMilliseconds * PLAYER_SPEED;
                }
                else if (newKeyboardState.IsKeyDown(Keys.Down))
                {
                    pstate    = PaddleState.down;
                    bounds.Y += (float)gameTime.ElapsedGameTime.TotalMilliseconds * PLAYER_SPEED;
                }
                else
                {
                    pstate = PaddleState.Idle;
                }
            }

            if (bounds.Y < 0)
            {
                bounds.Y = 0;
            }

            if (bounds.Y > game.GraphicsDevice.Viewport.Height - bounds.Height)
            {
                bounds.Y = game.GraphicsDevice.Viewport.Height - bounds.Height;
            }

            // Update the player animation timer when the player is moving
            if (pstate != PaddleState.Idle)
            {
                timer += gameTime.ElapsedGameTime;
            }

            // Determine the frame should increase.  Using a while
            // loop will accomodate the possiblity the animation should
            // advance more than one frame.
            while (timer.TotalMilliseconds > ANIMATION_FRAME_RATE)
            {
                // increase by one frame
                frame++;
                // reduce the timer by one frame duration
                timer -= new TimeSpan(0, 0, 0, 0, ANIMATION_FRAME_RATE);
            }

            // Keep the frame within bounds (there are four frames)
            frame %= 4;
        }
Example #15
0
        public Paddle(Vector2 pos)
        {
            mCurrentPaddleState = PaddleState.PaddleAtRest;

            Center      = pos;
            Width       = kPaddleWidth;
            Height      = kPaddleHeight;
            RotateAngle = InitialPosition();

            mShowDir = new XNACS1Rectangle();
            mShowDir.SetEndPoints(Center, Center + (3 * FrontDirection), 0.8f);
            mShowDir.Color = Color.Black;
        }
Example #16
0
        public virtual bool TouchBegan(CCTouch touch, CCEvent eventer)
        {
            if (m_state != PaddleState.kPaddleStateUngrabbed)
            {
                return(false);
            }
            if (!containsTouchLocation(touch))
            {
                return(false);
            }

            m_state = PaddleState.kPaddleStateGrabbed;
            return(true);
        }
Example #17
0
        bool onTouchBegan(CCTouch touch, CCEvent touchEvent)
        {
            if (m_state != PaddleState.kPaddleStateUngrabbed)
            {
                return(false);
            }
            if (!containsTouchLocation(touch))
            {
                return(false);
            }

            m_state = PaddleState.kPaddleStateGrabbed;
            return(true);
        }
Example #18
0
        public override bool TouchBegan(CCTouch touch)
        {
            if (m_state != PaddleState.kPaddleStateUngrabbed)
            {
                return(false);
            }
            if (!containsTouchLocation(touch))
            {
                return(false);
            }

            m_state = PaddleState.kPaddleStateGrabbed;
            return(true);
        }
Example #19
0
        private void initialize()
        {
            ShouldTravel = true;
            Velocity     = VelocityDirection = Vector2.Zero;
            speed        = 1.3f;

            if (GameObjects.paddleList == null)
            {
                GameObjects.paddleList = new List <Paddle>();
            }

            GameObjects.paddleList.Add(this);
            state = PaddleState.NORMAL;
        }
Example #20
0
 private void frmPongGame_KeyUp(object sender, KeyEventArgs e)
 {
     //reset paddle movement
     if (e.KeyCode == Keys.W || e.KeyCode == Keys.S)
     {
         LeftPaddle = PaddleState.None;
     }
     else if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down)
     {
         RightPaddle = PaddleState.None;
     }
     else if (e.KeyCode == Keys.Return)
     {
         //reset game
         Reset();
         lblStart.Visible = false;
         tmrGame.Enabled  = true;
     }
 }
Example #21
0
 private void frmPongGame_KeyDown(object sender, KeyEventArgs e)
 {
     //check if paddles should move
     if (e.KeyCode == Keys.W)
     {
         LeftPaddle = PaddleState.Up;
     }
     else if (e.KeyCode == Keys.S)
     {
         LeftPaddle = PaddleState.Down;
     }
     else if (e.KeyCode == Keys.Up)
     {
         RightPaddle = PaddleState.Up;
     }
     else if (e.KeyCode == Keys.Down)
     {
         RightPaddle = PaddleState.Down;
     }
 }
Example #22
0
        private void Form1_KeyUp(object sender, KeyEventArgs e)
        {
            //PaddleState is None for all
            if (e.KeyCode == Keys.W)
            {
                LeftPaddle = PaddleState.None;
            }
            if (e.KeyCode == Keys.S)
            {
                LeftPaddle = PaddleState.None;
            }

            if (e.KeyCode == Keys.Up)
            {
                RightPaddle = PaddleState.None;
            }
            if (e.KeyCode == Keys.Down)
            {
                RightPaddle = PaddleState.None;
            }
        }
Example #23
0
 public Paddle (CCTexture2D aTexture) : base (aTexture)
 {
     m_state = PaddleState.kPaddleStateUngrabbed;
     TouchEnabled = true;
 }
Example #24
0
        protected void UpdateInput()
        {
            KeyboardState newState = Keyboard.GetState();

            ///user press enter key begin
            if (newState.IsKeyDown(Keys.Enter))
            {
                if (!oldKeyState.IsKeyDown(Keys.Enter))
                {
                    if (gameState == GameState.INITIAL)
                    {
                        gameState = GameState.START;
                        StartNewGame();
                    }
                    else if (gameState == GameState.START)
                    {
                        gameState = GameState.PAUSE;
                    }
                    else if (gameState == GameState.PAUSE)
                    {
                        gameState = GameState.START;
                    }
                    else if (gameState == GameState.GAME_OVER)
                    {
                        gameState = GameState.INITIAL;
                    }
                }
            }
            else if (oldKeyState.IsKeyDown(Keys.Enter))
            {
                // Key was down last update, but not down now, so
                // it has just been released.
            }

            ///user press space key begin
            if (newState.IsKeyDown(Keys.Space))
            {
                if (!oldKeyState.IsKeyDown(Keys.Space))
                {
                    if (gameState == GameState.START)
                    {
                        if(ballState != BallState.LAUNCH) ballState = BallState.LAUNCH;
                    }
                }
            }
            else if (oldKeyState.IsKeyDown(Keys.Space))
            {
                // Key was down last update, but not down now, so
                // it has just been released.
            }

            ///user press left key begin
            if (newState.IsKeyDown(Keys.Left))
            {
                if (!oldKeyState.IsKeyDown(Keys.Left))
                {
                    if (gameState == GameState.START)
                    {
                        paddleState = PaddleState.MOVE_LEFT;
                    }
                    else
                    {
                        paddleState = PaddleState.STAY;
                    }
                }
            }
            else if (oldKeyState.IsKeyDown(Keys.Tab))
            {
                // Key was down last update, but not down now, so
                // it has just been released.
                paddleState = PaddleState.STAY;
            }

            ///user press right key begin
            if (newState.IsKeyDown(Keys.Right))
            {
                if (!oldKeyState.IsKeyDown(Keys.Right))
                {
                    if (gameState == GameState.START)
                    {
                        paddleState = PaddleState.MOVE_RIGHT;
                    }
                    else
                    {
                        paddleState = PaddleState.STAY;
                    }
                }
            }
            else if (oldKeyState.IsKeyDown(Keys.Right))
            {
                // Key was down last update, but not down now, so
                // it has just been released.
                paddleState = PaddleState.STAY;
            }

            oldKeyState = newState;
        }
Example #25
0
 public override void TouchEnded(CCTouch touch)
 {
     Debug.Assert(m_state == PaddleState.kPaddleStateGrabbed, "Paddle - Unexpected state!");
     m_state = PaddleState.kPaddleStateUngrabbed;
 }
Example #26
0
 /// <summary>
 /// Creates a paddle
 /// </summary>
 /// <param name="game">Reference to the game the paddle belongs to</param>
 public Paddle(Game1 game)
 {
     this.game = game;
     pstate    = PaddleState.Idle;
     timer     = new TimeSpan(0);
 }
Example #27
0
 public Paddle()
 {
     State = PaddleState.Release;
     MaxSpeed = 1.0f;
 }
Example #28
0
 public Paddle(CCTexture2D aTexture) : base(aTexture)
 {
     m_state = PaddleState.kPaddleStateUngrabbed;
 }
    private void OnCollisionEnter2D(Collision2D other)
    {
        if (other.gameObject.CompareTag("Paddle1") || other.gameObject.CompareTag("Paddle2"))
        {
            collideSound.Play();
            PaddleState paddleState = other.gameObject.GetComponent <PaddleController>().paddleState;

            if (paddleState == PaddleState.PLAYER)
            {
                gradient = Random.Range(3, 6);
            }
            else if (paddleState == PaddleState.COMPUTER)
            {
                if (GameControl.difficulty == Difficulty.EASY)
                {
                    gradient = Random.Range(4, 6);
                }
                else if (GameControl.difficulty == Difficulty.MEDIUM)
                {
                    gradient = Random.Range(3, 6);
                }
                else if (GameControl.difficulty == Difficulty.HARD)
                {
                    gradient = Random.Range(2, 6);
                }
            }


            contact = other.contacts[0].point;

            if (other.gameObject.CompareTag("Paddle1"))
            {
                if ((contact.x - paddles[0].transform.position.x) < 0f)
                {
                    xDir = XDir.LEFT;
                }
                else if ((contact.x - paddles[0].transform.position.x) > 0f)
                {
                    xDir = XDir.RIGHT;
                }
            }

            else if (other.gameObject.CompareTag("Paddle2"))
            {
                if ((contact.x - paddles[1].transform.position.x) < 0f)
                {
                    xDir = XDir.LEFT;
                }
                else if ((contact.x - paddles[1].transform.position.x) > 0f)
                {
                    xDir = XDir.RIGHT;
                }
            }

            if (yDir == YDir.UP)
            {
                yDir = YDir.DOWN;
            }
            else if (yDir == YDir.DOWN)
            {
                yDir = YDir.UP;
            }
        }
    }
Example #30
0
 public void PutOnStandBy()
 {
     this.paddlestate = PaddleState.STANDBY;
 }
Example #31
0
 void onTouchEnded(CCTouch touch, CCEvent touchEvent)
 {
     Debug.Assert(m_state == PaddleState.kPaddleStateGrabbed, "Paddle - Unexpected state!");
     m_state = PaddleState.kPaddleStateUngrabbed;
 }
Example #32
0
 public virtual void ccTouchEnded(CCTouch touch, CCEvent eventer)
 {
     Debug.Assert(m_state == PaddleState.kPaddleStateGrabbed, "Paddle - Unexpected state!");
     m_state = PaddleState.kPaddleStateUngrabbed;
 }
Example #33
0
 protected void StartNewLevel()
 {
     ballVelocity = new Vector2(10.0f, -10.0f);
     paddleVelocity = Vector2.Zero;
     bricks.GenerateBrick();
     ballState = BallState.INITIAL;
     paddleState = PaddleState.STAY;
     ballRect = new Rectangle((int)(this.GraphicsDevice.Viewport.Width - ball.Width) / 2, this.GraphicsDevice.Viewport.Height - paddle.Height - ball.Height - 15, ball.Width, ball.Height);
     paddleRect = new Rectangle((int)(this.GraphicsDevice.Viewport.Width - paddle.Width) / 2, this.GraphicsDevice.Viewport.Height - paddle.Height - 10, paddle.Width, paddle.Height);
 }
Example #34
0
 public Paddle (CCTexture2D aTexture) : base (aTexture)
 {
     m_state = PaddleState.kPaddleStateUngrabbed;
     
 }
Example #35
0
		void onTouchEnded(CCTouch touch, CCEvent touchEvent)
        {
            Debug.Assert(m_state == PaddleState.kPaddleStateGrabbed, "Paddle - Unexpected state!");
            m_state = PaddleState.kPaddleStateUngrabbed;
        }
Example #36
0
 protected void StartNewGame()
 {
     ballVelocity = new Vector2(1.0f, -1.0f);
     paddleVelocity = Vector2.Zero;
     bricks.GenerateBrick();
     scoreText = "Score: 0";
     score = 0;
     numOfLives = 5;
     ballState = BallState.INITIAL;
     paddleState = PaddleState.STAY;
 }
Example #37
0
 public void StartMoving(PaddleState newState)
 {
     paddleState = newState;
 }
Example #38
0
 public void Activate(bool start)
 {
     if (start && this.paddlestate == PaddleState.STANDBY)
     {
         this.paddlestate = PaddleState.PLAYING;
         this.onActive();
     }
 }
Example #39
0
 public virtual void TouchEnded(CCTouch touch, CCEvent eventer)
 {
     Debug.Assert(m_state == PaddleState.kPaddleStateGrabbed, "Paddle - Unexpected state!");
     m_state = PaddleState.kPaddleStateUngrabbed;
 }
Example #40
0
 public override void TouchEnded(CCTouch touch)
 {
     Debug.Assert(m_state == PaddleState.kPaddleStateGrabbed, "Paddle - Unexpected state!");
     m_state = PaddleState.kPaddleStateUngrabbed;
 }
Example #41
0
 public Paddle(CCTexture2D aTexture) : base(aTexture)
 {
     m_state      = PaddleState.kPaddleStateUngrabbed;
     TouchEnabled = true;
 }
Example #42
0
 void OnPaddleStateChange(PaddleState ps)
 {
     Debug.Log (ps);
     state = ps;
 }