Пример #1
0
        public override void init()
        {
            Player = new PlayerGameObject();

            Player.Circle.Center = new PointF(W / 2, 0);
            Player.Commands.Add(new MovementAICommand()); // @Player jump by himself - no user input
            Player.Commands.Add(new CollisionDetectionCommand());

            // draw one horizontal @Line throughout the entire screen for the @Player to jump on
            LineGameObject l1 = new LineGameObject(new Line2D(new PointF(0, 260), new PointF(W, 260)));
            this.GameObjects.Add(l1);

            base.init();
        }
Пример #2
0
        // generate lines
        private void generateLines(int numLonesToGenerate, bool move)
        {
            for (int i = 0; i < numLonesToGenerate; i++)
            {
                // assume that the line to be generated is not overlapping existing line
                bool acceptable = true;

                // generate string and end point x-axis coordinates
                int start = rand.Next(w - 200 - MinLineSize) + 100;
                int end = start + MinLineSize + rand.Next(MaxLineSize - MinLineSize);
                end = Math.Min(end, w - 100);

                // each 3rd line should be on the same level as the previous line in average
                if (rand.Next(3) != 0)
                {
                    Height -= 100;
                }
                else
                {
                    // check if the generated line overlaps some previous generated line
                    foreach (GameObject go in GameObjects)
                    {
                        LineGameObject lgo1 = go as LineGameObject;
                        if (Math.Abs(lgo1.Line.Start.Y - Height) < 10
                            && (
                                (lgo1.Line.Start.X < start && lgo1.Line.End.X > start)
                                || (lgo1.Line.Start.X < end && lgo1.Line.End.X > end)
                                || (lgo1.Line.Start.X < start && lgo1.Line.End.X > end)
                                || (lgo1.Line.Start.X > start && lgo1.Line.End.X < end)
                                )
                            )
                        {
                            i--;
                            acceptable = false;
                            break;
                        }
                    }
                    if (!acceptable)
                    {
                        continue;
                    }
                }

                // if the new line passes all tests - it gets to be generated
                LineGameObject lgo = new LineGameObject(new Line2D(new Point(start, (int)Height), new Point(end, (int)Height)));
                if (move) // if the line should be moving downwards - add @Command accordingly
                {
                    lgo.Commands.Add(new AILineMoveDownCommand());
                }
                GameObjects.Add(lgo);
            }
        }