Exemple #1
0
        public SpaceThing SmallAsteroid(int x, int y)
        {
            SpaceThing st = new SpaceThing(x, y, new Point(sg.ScreenDim.X, sg.ScreenDim.Y));

            st.SetRotationSpeed(rand.NextDouble() * 6 - 3);

            int    numPoints = 9 + rand.Next() % 6;
            int    i;
            Point  UnitZero = new Point(1.0, 0.0); // a unit vector at 0 degrees
            Matrix m        = (new Matrix());
            Point  p;
            double scalar;

            st.SetMoving(RandomVector(3.4)); //THIS LINE IS DIFFERENT
            st.SetPayout(100);               //THIS LINE IS DIFFERENT

            for (i = 0; i < numPoints; i++)
            {
                scalar = (rand.NextDouble() * 10 + 6);  // THIS LINE IS THE ONLY ONE DIFFERENT
                p      = Point.Multiply(UnitZero, m);
                p.X   *= scalar;
                p.Y   *= scalar;
                st.AddVert(p);
                m.Rotate(360.0 / numPoints);
            }

            return(st);
        }
Exemple #2
0
        public override List <Line> GetLines()
        {
            List <Line> l    = new List <Line>();
            Line        line = SpaceThing.MakeLine(prev, upperLeft, new Point(0, 0), new System.Windows.Media.Matrix());

            //MessageBox.Show("x " + line.X1 + "   y " + line.Y1 + Environment.NewLine + "x " + line.X2 + "   y " + line.Y2);
            l.Add(line);
            return(l);
        }
Exemple #3
0
        public virtual bool Collide(SpaceThing thing)
        {
            List <Line> list1 = this.GetLines();
            List <Line> list2 = thing.GetLines();

            foreach (Line l1 in list1)
            {
                foreach (Line l2 in list2)
                {
                    if (SpaceThing.linesIntersect(l1, l2))
                    {
                        //MessageBox.Show("x " + l1.X1 + "   y " + l1.Y1 + Environment.NewLine + "x " + l1.X2 + "   y " + l1.Y2 + Environment.NewLine +
                        //Environment.NewLine + "x " + l2.X1 + "   y " + l2.Y1 + Environment.NewLine + "x " + l2.X2 + "   y " + l2.Y2);
                        return(true);
                    }
                }
            }
            return(false);
        }
        public override List <Line> GetLines(Point offset)
        {
            List <Line> l = new List <Line>();

            Point p = new Point(offset.X + upperLeft.X, offset.Y + upperLeft.Y);

            l.Add(SpaceThing.MakeLine(verts[0], verts[1], p, rotationMatrix));
            l.Add(SpaceThing.MakeLine(verts[0], verts[2], p, rotationMatrix));
            l.Add(SpaceThing.MakeLine(verts[3], verts[4], p, rotationMatrix));

            if (Thrusting)
            {
                if (count * 5 % 2 == 0)
                {
                    l.Add(SpaceThing.MakeLine(verts[5], verts[6], p, rotationMatrix));
                    l.Add(SpaceThing.MakeLine(verts[5], verts[7], p, rotationMatrix));
                }
            }

            return(l);
        }
Exemple #5
0
        public virtual async void GameLoop()
        {
            long time = DateTime.Now.Ticks;
            int  dt;

            Counter++;

            if (gameLoopRunning)
            {
                foreach (SpaceThing thing in Enemies)
                {
                    thing.Simulate(this);
                }
                foreach (Blastable debris in Debris)
                {
                    debris.Simulate(this);
                }
                foreach (Blastable bullet in Bullets)
                {
                    bullet.Simulate(this);
                }
                foreach (SpaceAlien a in Aliens)
                {
                    a.Simulate(this);
                    a.Shoot(this, Player.GetLocation());
                }

                if ((((Counter * 50000000 + 345) * (Counter + 55)) % 125 == 0) && Aliens.Count < 2)
                {
                    Aliens.Add(factory.GiveMeAnAlien(Score));
                }



                CollideAsteroidsAliensBullets();


                if (PlayerTimer < 0)
                {
                    CollidePlayerAndAsteroidsAndBullets();
                }



                await Task.Delay(1);

                //if (Counter == 3)
                //MessageBox.Show("hullo");

                PlayerTimer--;
                view.Children.Clear();

                // Player Draw
                if (PlayerTimer < 0)
                {
                    Player.Draw(view);
                }
                else
                if (((Counter / 5) % 2 == 0) /*&&(Counter < 50)*/)
                {
                    Player.Draw(view);
                }

                foreach (Blastable thing in Enemies)
                {
                    thing.Draw(view);
                }
                foreach (Blastable debris in Debris)
                {
                    debris.Draw(view);
                }
                foreach (Blastable bullet in Bullets)
                {
                    bullet.Draw(view);
                }
                foreach (SpaceAlien a in Aliens)
                {
                    a.Draw(view);
                }

                // LIVES
                Point p;
                int   i;

                for (i = 0; i < Lives; i++)
                {
                    p = new Point(60 + i * 30, 60);
                    view.Children.Add(SpaceThing.MakeLine((new Point(0, -25)), (new Point(10, 9)), p, new Matrix()));
                    view.Children.Add(SpaceThing.MakeLine((new Point(0, -25)), (new Point(-10, 9)), p, new Matrix()));
                    view.Children.Add(SpaceThing.MakeLine((new Point(-8, 2)), (new Point(8, 2)), p, new Matrix()));
                }



                // END LIVES

                Player.Simulate(this);
                //Player.Draw(view);

                HandleBlasts();
            }


            //if (Counter > 50)
            //MessageBox.Show(time + "");
            await Task.Delay(1);

            time = DateTime.Now.Ticks - time;
            dt   = 60 - (int)(time / 10000);
            if (dt > 0)
            {
                await Task.Delay(60 - (int)(time / 10000));
            }
            if (Enemies.Count < 1)
            {
                StartLevel((int)Math.Sqrt(Score / 600) + 6);
            }
            if (!stopped)
            {
                GameLoop();
            }
        }
Exemple #6
0
 public override void Draw(Canvas c)
 {
     c.Children.Add(SpaceThing.MakeDot(upperLeft));
     //MessageBox.Show("hi");
 }
 public void Draw(Canvas c)
 {
     c.Children.Add(SpaceThing.MakeLine(new Point(0, 1), new Point(0, 0), loc, new System.Windows.Media.Matrix()));
 }