Exemple #1
0
        private void BallTimer_Tick(object sender, EventArgs e)
        {
            if (top == false)
            {
                Ball.Top += speed;
                if (Ball.Top > 800)
                {
                    top = true;
                }
            }

            if (top == true)
            {
                Ball.Top -= speed;
                if (Ball.Top < 5)
                {
                    top = false;
                }
            }

            if (left == false)
            {
                Ball.Left += speed;

                if (Ball.Left == (Player2Picture.Left - Player2Picture.Width) & (Ball.Top >= Player2Picture.Top & Ball.Top <= Player2Picture.Top + Player2Picture.Height))
                {
                    left = true;
                }
            }

            if (left == true)
            {
                Ball.Left -= speed;

                if (Ball.Left == (Player1Picture.Left + Player1Picture.Width) + Player1Picture.Width & (Ball.Top >= Player1Picture.Top & Ball.Top <= Player1Picture.Top + Player1Picture.Height))
                {
                    left = false;
                }
            }

            if (Ball.Left > Player2Picture.Left) //om spelare två förlorar
            {
                BallTimer.Stop();
                label1.ForeColor = Color.Red;
                label1.Text      = "Player 2, you suck...";
                Ball.Left        = 750;
                playerOneScore++;
                PlayerOneScoreLabel.Text = "Player 1: " + playerOneScore.ToString();
            }

            if (Ball.Left < Player1Picture.Left) //om spelare ett förlorar
            {
                BallTimer.Stop();
                label1.ForeColor = Color.Red;
                label1.Text      = "Player 1, try to hit the ball...";
                Ball.Left        = 750;
                playerTwoScore++;
                PlayerTwoScoreLabel.Text = "Player 2: " + playerTwoScore.ToString();
            }
        }
Exemple #2
0
 private void GameForm_Paint(object sender, PaintEventArgs e)
 {
     if (gameStart)
     {
         text.Draw(e.Graphics, "Press space to start and pause" + "\n" + "Use the arrow keys to move around" + "\n" + "Mines reduce the amount of balls collected" + "\n" + "Collect 20 balls to level up", DisplayRectangle.Width / 3, DisplayRectangle.Height / 3);
     }
     text.Draw(e.Graphics, string.Format("Level: {0}", level), DisplayRectangle.Width - 200, 20);
     UpdateBallsCollected(e.Graphics);
     hippo.Draw(e.Graphics);
     foreach (Ball ball in balls)
     {
         ball.Draw(e.Graphics);
     }
     foreach (Mine mine in mines)
     {
         mine.Draw(e.Graphics);
     }
     if (paused)
     {
         text.Draw(e.Graphics, "PAUSED", DisplayRectangle.Width / 2, DisplayRectangle.Height / 2);
     }
     if (ballsCollected >= 20)//balls needed to level up
     {
         level++;
         ballsCollected = 0;
         maxMines      += 2;
         AnimationTimer.Stop();
         BallTimer.Stop();
         text.Draw(e.Graphics, "Level Up. Press Space For The Next level", DisplayRectangle.Width / 3, DisplayRectangle.Height / 2);
     }
 }
Exemple #3
0
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Down)
            {
                Player2TimerDown.Start();
            }
            else if (e.KeyCode == Keys.Up)
            {
                Player2TimerUp.Start();
            }

            if (e.KeyCode == Keys.W)
            {
                Player1TimerUp.Start();
            }
            else if (e.KeyCode == Keys.S)
            {
                Player1TimerDown.Start();
            }

            if (e.KeyCode == Keys.Enter)
            {
                label1.Text = "";
                BallTimer.Start();
            }
        }
 /* Nastan koj se povikuva pri klik na kopcheto New Game (Nova igra).
  * So ovoj nastan se kreira nov objekt od klasata Game so shto
  * se startuva novata igra. Dopolnitelno, se setira i tajmerot za soodvetnoto
  * nivo, preostanatie zhivoti na igrachoot...
  */
 private void PbNewGame_Click(object sender, EventArgs e)
 {
     CurrentGame = new Game(this.Width, this.Height);
     Player.Instance.ResetScore();
     lblScore.Text = Player.Instance.GetScore().ToString();
     TimeRemainingLevel.Maximum     = CurrentGame.Level.getTimeLimit();
     TimeRemainingLevel.Value       = CurrentGame.Level.getTimeLimit();
     Player.Instance.LivesRemaining = 3;
     BallTimer.Enabled = true;
     BallTimer.Start();
     if (this.Width >= 2000 && this.Width < 3000)
     {
         BallTimer.Interval = 20;
     }
     if (this.Width >= 3000)
     {
         BallTimer.Interval = 10;
     }
     ReadyTimer.Enabled = true;
     ReadyTimer.Start();
     lblCoundown.Text    = "READY!\n" + countdown.ToString();
     lblCoundown.Visible = true;
     activated           = true;
     lblLevelNumber.Text = "1";
     Invalidate(true);
 }
Exemple #5
0
 public void Construct(Ball ball, ScoreManager scoreManager, BallTimer ballTimer, PowerupManager pwManager)
 {
     this.ball         = ball;
     this.scoreManager = scoreManager;
     this.ballTimer    = ballTimer;
     this.pwManager    = pwManager;
 }
        private void Awake()
        {
            BallTimer.SetTimeBonuses(RoadPieceTimeBonus, CoinTimeBonus);

            _roadPrefabZSize = 7.5f;
            _generationCount = 1;
            _currentZPoint   = PlayerBall.transform.position.z;
            _furthestZPoint  = _roadPrefabZSize;

            GenerateRoad();
        }
        private void CleanRedundantRoadPieces()
        {
            if (!(_currentZPoint > GeneratedObstacles[0].transform.position.z + _roadPrefabZSize))
            {
                return;
            }

            Destroy(GeneratedObstacles[0]);
            GeneratedObstacles.Remove(GeneratedObstacles[0]);

            // Add some time to remaining time.
            BallTimer.IncrementTimer(BallTimer.RoadPieceTimeBonus);
        }
Exemple #8
0
        /// <summary>
        /// Listens for keys pressed
        /// </summary>
        /// <param name="sender">key pressed object</param>
        /// <param name="e">Key event arguments</param>
        private void GameForm_KeyDown(object sender, KeyEventArgs e)
        {
            if (AnimationTimer.Enabled)
            {
                switch (e.KeyData)
                {
                case Keys.Left:
                {
                    if (!KeyList.Contains(Keys.Left))
                    {
                        KeyList.Add(Keys.Left);
                    }
                    break;
                }

                case Keys.Right:
                {
                    if (!KeyList.Contains(Keys.Right))
                    {
                        KeyList.Add(Keys.Right);
                    }
                    break;
                }

                case Keys.Up:
                {
                    if (!KeyList.Contains(Keys.Up))
                    {
                        KeyList.Add(Keys.Up);
                    }
                    break;
                }

                case Keys.Down:
                {
                    if (!KeyList.Contains(Keys.Down))
                    {
                        KeyList.Add(Keys.Down);
                    }
                    break;
                }
                }
            }

            if (e.KeyData == Keys.Space)
            {
                if (gameStart)
                {
                    gameStart = false;
                }

                if (AnimationTimer.Enabled)
                {
                    paused = true;
                    AnimationTimer.Stop();
                    BallTimer.Stop();
                    Invalidate();
                }
                else
                {
                    paused = false;

                    AnimationTimer.Start();
                    BallTimer.Start();
                }
            }
        }