Beispiel #1
0
        private void MoveBackgroundRight()
        {
            if (pointer >= controls.Length - gameWidth)
            {
                return;
            }
            Point help = players.Location;

            if (help.X > gameWidth * Settings.width - border)
            {
                for (int f = 0; f < controls[0].Length; f++)
                {
                    if (controls[pointer][f] != null)
                    {
                        if (controls[pointer][f].Tag.Equals("coin"))
                        {
                            if (!players.IsGameControl(controls[pointer][f]))
                            {
                                controls[pointer][f] = null;
                            }
                        }
                        else if ((controls[pointer][f].Tag.ToString().Split('_').Length > 1))
                        {
                            if (controls[pointer][f].Tag.ToString().Split('_')[1].Equals("coin"))
                            {
                                if (!players.IsGameControl(controls[pointer][f]))
                                {
                                    controls[pointer][f] = ReadFile.NewControl(Properties.Resources.box, "obstacle_destroy");;
                                }
                            }
                        }
                        int index = players.GetGameControlIndexOf(controls[pointer][f]);
                        if (index != -1)
                        {
                            controlCollection.Remove(players.GetGameControlItem(index));
                            players.GameControlRemoveAt(index);
                        }
                    }
                }
                foreach (Control control in players.GetGameControl())
                {
                    if (control != null)
                    {
                        Point location = control.Location;
                        location.Offset(-Settings.width, 0);
                        control.Location = location;
                    }
                }
                for (int f = 0; f < controls[0].Length; f++)
                {
                    if (controls[pointer + gameWidth][f] != null)
                    {
                        controls[pointer + gameWidth][f].Location = new Point((gameWidth - 1) * Settings.width, f * Settings.height);
                        players.GameControlAdd(controls[pointer + gameWidth][f]);
                        controlCollection.Add(controls[pointer + gameWidth][f]);
                        if (controls[pointer + gameWidth][f] is Enemy)
                        {
                            players.GameControlRemove(controls[pointer + gameWidth][f]);
                            players.EnemyAdd(controls[pointer + gameWidth][f] as Enemy);
                            players.StartEnemies();
                            controls[pointer + gameWidth][f] = null;
                        }
                    }
                }
                pointer++;
                Point temp = players.Location;
                temp.Offset(-Settings.width, 0);
                players.Location = temp;
                foreach (Enemy enemy in players.GetEnemy())
                {
                    if (enemy != null)
                    {
                        Point help2 = enemy.Location;
                        help2.Offset(-Settings.width, 0);
                        enemy.Location = help2;
                        if (help.X < 0)
                        {
                            players.EnemyRemove(enemy);
                        }
                    }
                }
            }
        }
Beispiel #2
0
        private void MoveBackgroundLeft()
        {
            if (pointer < 1)
            {
                return;
            }
            Point help = players.Location;

            if (help.X < border)
            {
                for (int f = 0; f < controls[0].Length; f++)
                {
                    if (controls[pointer + gameWidth - 1][f] != null)
                    {
                        if (controls[pointer + gameWidth - 1][f].Tag.Equals("coin"))
                        {
                            if (!players.IsGameControl(controls[pointer + gameWidth - 1][f]))
                            {
                                controls[pointer + gameWidth - 1][f] = null;
                            }
                        }
                        else if ((controls[pointer + gameWidth - 1][f].Tag.ToString().Split('_').Length > 1))
                        {
                            if (controls[pointer + gameWidth - 1][f].Tag.ToString().Split('_')[1].Equals("coin"))
                            {
                                if (!players.IsGameControl(controls[pointer + gameWidth - 1][f]))
                                {
                                    controls[pointer + gameWidth - 1][f] = ReadFile.NewControl(Properties.Resources.box, "obstacle_destroy");
                                }
                            }
                        }
                        int index = players.GetGameControlIndexOf(controls[pointer + gameWidth - 1][f]);
                        if (index != -1)
                        {
                            controlCollection.Remove(players.GetGameControlItem(index));
                            players.GameControlRemoveAt(index);
                        }
                    }
                }
                foreach (Control control in players.GetGameControl())
                {
                    if (control != null)
                    {
                        Point location = control.Location;
                        location.Offset(Settings.width, 0);
                        control.Location = location;
                    }
                }
                for (int f = 0; f < controls[0].Length; f++)
                {
                    if (controls[pointer - 1][f] != null)
                    {
                        controls[pointer - 1][f].Location = new Point(0, f * Settings.height);
                        players.GameControlAdd(controls[pointer - 1][f]);
                        controlCollection.Add(controls[pointer - 1][f]);
                        if (controls[pointer - 1][f] is Enemy)
                        {
                            players.GameControlRemove(controls[pointer - 1][f]);
                            players.EnemyAdd(controls[pointer - 1][f] as Enemy);
                            players.StartEnemies();
                            controls[pointer - 1][f] = null;
                        }
                    }
                }

                /* for (int f = 0; f < players.GetEnemy().Count; f++)
                 * {
                 *   if (players.GetEnemy()[f].Location.Y == Settings.width * (pointer - 1))
                 *   {
                 *       try
                 *       {
                 *           controlCollection.Add(players.GetEnemy()[f]);
                 *           players.GetEnemy()[f].Start(players);
                 *       }
                 *       catch (Exception) { }
                 *   }
                 * }*/
                pointer--;
                Point temp = players.Location;
                temp.Offset(Settings.width, 0);
                players.Location = temp;
                foreach (Enemy enemy in players.GetEnemy())
                {
                    if (enemy != null)
                    {
                        Point help2 = enemy.Location;
                        help2.Offset(Settings.width, 0);
                        enemy.Location = help2;
                        if (help.X > Screen.PrimaryScreen.WorkingArea.Width)
                        {
                            players.EnemyRemove(enemy);
                        }
                    }
                }
            }
        }