Example #1
0
 /// <summary>
 /// Listens to User 1 input
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void tmUser1_Tick(object sender, EventArgs e)
 {
     // Checks if test mode activated
     if (!(Globals.mode == 1))
     {
         // Checks for S_key
         if (PInvoke.GetAsyncKeyState(Keys.S) == short.MinValue || PInvoke.GetAsyncKeyState(Keys.S) == 1)
         {
             // OBSOLETE:    Point currloc = new System.Drawing.Point(User1.Location.X, User1.Location.Y);
             //              User1.Location = new System.Drawing.Point(currloc.X, currloc.Y + Properties.Settings.Default.AllowedPPCSpeed);
             gdiuser1y += Properties.Settings.Default.AllowedPPCSpeed;
             if (gdiuser1y > (this.Size.Height - gdiuser1height))
             {
                 // OBSOLETE:    User1.Location = new System.Drawing.Point(User1.Location.X, this.Size.Height - User1.Size.Height);
                 gdiuser1y = this.Size.Height - gdiuser1height;
             }
         }
         // Checks for W_key
         if (PInvoke.GetAsyncKeyState(Keys.W) == short.MinValue || PInvoke.GetAsyncKeyState(Keys.W) == 1)
         {
             // OBSOLETE:    Point currloc = new System.Drawing.Point(User1.Location.X, User1.Location.Y);
             //              User1.Location = new System.Drawing.Point(currloc.X, currloc.Y - Properties.Settings.Default.AllowedPPCSpeed);
             gdiuser1y -= Properties.Settings.Default.AllowedPPCSpeed;
             if (gdiuser1y < 0)
             {
                 // OBSOLETE:    User1.Location = new System.Drawing.Point(User1.Location.X, 0);
                 gdiuser1y = 0;
             }
         }
         tmUser1.Stop();
         tmUser1.Start();
         // TODO: Esc
         if (PInvoke.GetAsyncKeyState(Keys.Escape) == short.MinValue || PInvoke.GetAsyncKeyState(Keys.Escape) == 1)
         {
         }
     }
     else if (Globals.mode == 1)
     {
         // Bot Test mode
         int difference = gdicircley - gdiuser1height / 2 - gdiuser1y;
         if (difference < 0)
         {
             difference = -1 * Properties.Settings.Default.AllowedAiDifference;
         }
         if (difference > 0)
         {
             difference = Properties.Settings.Default.AllowedAiDifference;
         }
         if (!((gdiuser1y + gdiuser1height) > this.Size.Height) & difference > 0 || !((gdiuser1y) < 0) & difference < 0)
         {
             // OBSOLETE:    User1.Location = new Point(0, User1.Location.Y + difference);
             gdiuser1y += difference;
         }
         // OBSOLETE/MERGED:     if (!((gdiuser1y) < 0) & difference < 0)
         //                      User1.Location = new Point(0, User1.Location.Y + difference);
         //                      gdiuser1y += difference;
     }
 }
Example #2
0
 // Ball must be updated
 private void tmBall_Tick(object sender, EventArgs e)
 {
     // checks if it goes to the right
     if (direction == 1)
     {
         // OBSOLETE:    pbCircle.Location = new Point(currloc.X + speed[0] + addSpeedRight, currloc.Y + speed[1]);
         gdicirclex = gdicirclex + speed[0] + addSpeedRight;
         gdicircley = gdicircley + speed[1];
     }
     else
     {
         // ball goes to left
         // OBSOLETE:    pbCircle.Location = new Point(currloc.X + speed[0] - addSpeedLeft, currloc.Y + speed[1]);
         gdicirclex = gdicirclex + speed[0] - addSpeedLeft;
         gdicircley = gdicircley + speed[1];
     }
     if (direction == 1)
     {
         // right direction
         // checks if lower bound is reached
         // OBSOLETE:        if (pbCircle.Location.Y + pbCircle.Size.Height + speed[1] > this.Size.Height)
         //                      speed[1] = speed[1] - (speed[1] * 2);
         if (gdicircley + gdicircleheight + speed[1] > this.Size.Height)
         {
             speed[1] = speed[1] - speed[1] * 2;
         }
         // checks if upper bound reached
         // OBSOLETE:        if (pbCircle.Location.Y + speed[1] < 0)
         //                      speed[1] = speed[1] + (-1 * (speed[1] * 2));
         if (gdicircley + speed[1] < 0)
         {
             speed[1] = speed[1] + (-1 * (speed[1] * 2));
         }
     }
     else
     {
         // left direction
         // checks if lower bound is reached
         // OBSOLETE:        if (pbCircle.Location.Y + pbCircle.Size.Height + speed[1] > this.Size.Height)
         //                      speed[1] = speed[1] - (speed[1] * 2);
         if (gdicircley + gdicircleheight + speed[1] > this.Size.Height)
         {
             speed[1] = speed[1] - speed[1] * 2;
         }
         // checks if upper bound reached
         // OBSOLETE: if (pbCircle.Location.Y + speed[1] < 0)
         //    speed[1] = speed[1] + (-1 * (speed[1] * 2));
         if (gdicircley + speed[1] < 0)
         {
             speed[1] = speed[1] + (-1 * (speed[1] * 2));
         }
     }
     // checks if user 2 has made a point
     if (gdicirclex < gdiuser1width)
     {
         // checks if bar disabled point and returns ball
         if (gdicircley + gdicirclewidth / 2 >= gdiuser1y & gdicircley + gdicirclewidth / 2 <= gdiuser1y + gdiuser1height)
         {
             addSpeedRight++;
             direction = 1;
             // NOT WORKING:     if (speed[1] > 0)
             //                      speed[1] -= speed[1] * 2;
             //                  else
             //                      speed[1] += -1 * speed[1] * 2;
             if (PInvoke.GetAsyncKeyState(Keys.S) == short.MinValue || PInvoke.GetAsyncKeyState(Keys.S) == 1)
             {
                 speed[1] += 3;
             }
             if (PInvoke.GetAsyncKeyState(Keys.W) == short.MinValue || PInvoke.GetAsyncKeyState(Keys.W) == 1)
             {
                 speed[1] -= 3;
             }
             if (speed[1] > 10)
             {
                 speed[1] = 10;
             }
             if (speed[1] < -10)
             {
                 speed[1] = -10;
             }
             speed[0] = speed[0] * -1;
         }
         else
         {
             // user 2 pointed
             score2++;
             lblScore2.Text = score2.ToString();
             stopGame();
         }
     }
     // checks if user 1 has made a point
     if (gdicirclex + gdicirclewidth > this.Size.Width - gdiuser2width)
     {
         // checks if bar disabled point and returns ball
         if (gdicircley + gdicircleheight / 2 >= gdiuser2y & gdicircley + gdicircleheight / 2 <= gdiuser2y + gdiuser2height)
         {
             addSpeedLeft++;
             direction = 0;
             // NOT WORKING:     if (speed[1] > 0)
             //                      speed[1] -= speed[1] * 2;
             //                  else
             //                      speed[1] += -1 * speed[1] * 2;
             if (PInvoke.GetAsyncKeyState(Keys.Down) == short.MinValue || PInvoke.GetAsyncKeyState(Keys.Down) == 1)
             {
                 speed[1] += 3;
             }
             if (PInvoke.GetAsyncKeyState(Keys.Up) == short.MinValue || PInvoke.GetAsyncKeyState(Keys.Up) == 1)
             {
                 speed[1] -= 3;
             }
             if (speed[1] > 10)
             {
                 speed[1] = 10;
             }
             if (speed[1] < -10)
             {
                 speed[1] = -10;
             }
             speed[0] = speed[0] * -1;
         }
         else
         {
             // user 1 pointed
             score1++;
             lblScore1.Text = score1.ToString();
             stopGame();
         }
     }
     // Drunk Ball produces unpredictable Paths
     if (Properties.Settings.Default.DrunkBall)
     {
         if (DrunkBallCounter == 30)
         {
             GetNewSpeeds(direction);
             DrunkBallCounter = 0;
         }
         else
         {
             DrunkBallCounter++;
         }
     }
 }
Example #3
0
 /// <summary>
 /// Listens to user 2 input
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void tmUser2_Tick(object sender, EventArgs e)
 {
     // Checks if Test or AI mode enabled
     if (!(Globals.mode == 1) & !(Globals.mode == 2))
     {
         // Checks if down key pressed
         if (PInvoke.GetAsyncKeyState(Keys.Down) == short.MinValue || PInvoke.GetAsyncKeyState(Keys.Down) == 1)
         {
             // OBSOLETE:    Point currloc = new System.Drawing.Point(User2.Location.X, User2.Location.Y);
             //              User2.Location = new System.Drawing.Point(currloc.X, currloc.Y + Properties.Settings.Default.AllowedPPCSpeed);
             gdiuser2y += Properties.Settings.Default.AllowedPPCSpeed;
             if (gdiuser2y > (this.Size.Height - gdiuser2height))
             {
                 // OBSOLETE:    User2.Location = new System.Drawing.Point(User2.Location.X, this.Size.Height - User2.Size.Height);
                 gdiuser2y = this.Size.Height - gdiuser2height;
             }
         }
         // Checks if up key pressed
         if (PInvoke.GetAsyncKeyState(Keys.Up) == short.MinValue || PInvoke.GetAsyncKeyState(Keys.Up) == 1)
         {
             // OBSOLETE:    Point currloc = new System.Drawing.Point(User2.Location.X, User2.Location.Y);
             //              User2.Location = new System.Drawing.Point(currloc.X, currloc.Y - Properties.Settings.Default.AllowedPPCSpeed);
             gdiuser2y -= Properties.Settings.Default.AllowedPPCSpeed;
             if (gdiuser2y < 0)
             {
                 // OBSOLETE:    User2.Location = new System.Drawing.Point(User2.Location.X, 0);
                 gdiuser2y = 0;
             }
         }
         tmUser2.Stop();
         tmUser2.Start();
     }
     else if (Globals.mode == 1)
     {
         // Bot Test Mode
         int difference = gdicircley - gdiuser2height / 2 - gdiuser2y;
         if (difference < 0)
         {
             difference = -1 * Properties.Settings.Default.AllowedAiDifference;
         }
         if (difference > 0)
         {
             difference = Properties.Settings.Default.AllowedAiDifference;
         }
         if (!((gdiuser2y + gdiuser2height) > this.Size.Height) & difference > 0 || !((gdiuser2y) < 0) & difference < 0)
         {
             // OBSOLETE:    User2.Location = new Point(this.Size.Width - User2.Size.Width, User2.Location.Y + difference);
             gdiuser2y += difference;
         }
         // OBSOLETE/MERGED:     if (!((gdiuser2y) < 0) & difference < 0)
         //                      User2.Location = new Point(this.Size.Width - User2.Size.Width, User2.Location.Y + difference);
         //                      gdiuser2y += difference;
     }
     else if (Globals.mode == 2)
     {
         // AI Mode (Bot has average difficulty)
         int difference = gdicircley - gdiuser2height / 2 - gdiuser2y;
         if (difference < 0)
         {
             difference = -1 * Properties.Settings.Default.AllowedAiDifference;
         }
         if (difference > 0)
         {
             difference = Properties.Settings.Default.AllowedAiDifference;
         }
         if (!((gdiuser2y + gdiuser2height) > this.Size.Height) & difference > 0 || !((gdiuser2y) < 0) & difference < 0)
         {
             // OBSOLETE:    User2.Location = new Point(this.Size.Width - User2.Size.Width, User2.Location.Y + difference);
             gdiuser2y += difference;
         }
         // OBSOLETE/MERGED:     if (!((gdiuser2y) < 0) & difference < 0)
         //                      User2.Location = new Point(this.Size.Width - User2.Size.Width, User2.Location.Y + difference);
         //                      gdiuser2y += difference;
     }
 }