Example #1
0
 private void Form1_KeyDown(object sender, KeyEventArgs e)
 {
     // Determine what key is pressed and assign that direction to player 1.
     if (e.KeyCode == Keys.Up)
     {
         Settings.direction = Direction.Up;
     }
     if (e.KeyCode == Keys.Down)
     {
         Settings.direction = Direction.Down;
     }
     if (e.KeyCode == Keys.Left)
     {
         Settings.direction = Direction.Left;
     }
     if (e.KeyCode == Keys.Right)
     {
         Settings.direction = Direction.Right;
     }
     if (Settings.GameOver && e.KeyCode == Keys.Enter)
     {
         StartGame();
     }
     if (e.KeyCode == Keys.P)
     {
         MoveApple.SpawnApple(apple);
     }
 }
Example #2
0
        private void Timer1_Tick(object sender, EventArgs e)
        {
            aPictureBoxDisplay.Invalidate();
            Rectangle Head = new Rectangle(Snake[0].X, Snake[0].Y,
                                           Settings.PlayerWidth, Settings.PlayerHeight);

            // Detect if player hits wall
            if (HitDetect.DetectWallHit(Head, aPictureBoxDisplay))
            {
                Die(aLabelGameOver);
                timer1.Stop();
            }
            // Detect if player hits food
            if (HitDetect.DetectFoodHit(Head, apple))
            {
                Eat(apple);
                MoveApple.SpawnApple(apple);
            }
            // Move player every tick
            MovePlayer.Now(Snake);

            // Update score and body size labels
            aLabelScore.Text    = Settings.Score.ToString();
            aLabelBodySize.Text = Settings.BodySize.ToString();
        }
Example #3
0
        private void Form1_Load(object sender, EventArgs e)
        {
            // SETUP PLAYER 1
            //P1.Segment_PictureBox = aPictureBoxBodySegmant;
            //P1.Segment_PictureBox.Size = new Size(Settings.PlayerWidth, Settings.PlayerHeight);
            //P1.Start(aLabelGameOver, timer1);

            // SETUP APPLE
            apple.AppleBody      = AppleBody; // Second AppleBody is on-screen apple.
            apple.AppleBody.Size = new Size(Settings.FoodWidth, Settings.FoodHeight);
            apple.Value          = 10;
            MoveApple.SpawnApple(apple);



            // Start Game
            timer1.Start();
            StartGame();
        }