示例#1
0
    protected override void Paint(Canvas canvas)
    {
        canvas.BrushColor = Color.White;
        canvas.DrawLine(canvas.TopLeft, canvas.TopRight);
        canvas.DrawLine(canvas.TopRight, canvas.BottomRight);
        canvas.DrawLine(canvas.BottomRight, canvas.BottomLeft);
        canvas.DrawLine(canvas.BottomLeft, canvas.TopLeft);

        canvas.BrushColor = Color.LightGray;
        canvas.DrawLine(canvas.Left + 50, canvas.Top - 50, canvas.Right - 50, canvas.Top - 50);
        canvas.DrawLine(canvas.Right - 50, canvas.Top - 50, canvas.Right - 50, canvas.Bottom + 50);
        canvas.DrawLine(canvas.Right - 50, canvas.Bottom + 50, canvas.Left + 50, canvas.Bottom + 50);
        canvas.DrawLine(canvas.Left + 50, canvas.Bottom + 50, canvas.Left + 50, canvas.Top - 50);

        canvas.BrushColor = Color.Teal;
        canvas.DrawLine(canvas.TopLeft, canvas.BottomRight);
        canvas.DrawLine(canvas.TopRight, canvas.BottomLeft);

        canvas.BrushColor = Color.White;
        canvas.DrawLine(Mouse.PositionOnWorld + new Vector(10, -20), Mouse.PositionOnWorld);
        canvas.DrawLine(Mouse.PositionOnWorld, Mouse.PositionOnWorld + new Vector(20, -10));

        double radius = 1;

        if (Mouse.GetButtonState(MouseButton.Left) == ButtonState.Down)
        {
            radius += 10;
        }
        if (Mouse.GetButtonState(MouseButton.Right) == ButtonState.Down)
        {
            radius += 20;
        }

        for (int i = 0; i < 10; i++)
        {
            canvas.BrushColor = RandomGen.NextColor();
            Vector from = Mouse.PositionOnWorld + RandomGen.NextVector(3, radius);
            Vector to   = Mouse.PositionOnWorld + RandomGen.NextVector(3, radius);
            canvas.DrawLine(from, to);
        }

        foreach (Vector piste in norsut)
        {
            canvas.DrawImage(piste, norsunkuva);
        }

        base.Paint(canvas);
    }
示例#2
0
文件: Pong.cs 项目: Jypeli-JYU/Jypeli
    void Sparkle()
    {
        PhysicsObject sparkle = new PhysicsObject(3, 1);

        sparkle.Position = Mouse.PositionOnWorld;
        //sparkle.IgnoresCollisionResponse = true;
        sparkle.IgnoresGravity  = true;
        sparkle.Angle           = RandomGen.NextAngle();
        sparkle.Color           = RandomGen.NextColor(Color.LightYellow, Color.Yellow);
        sparkle.MaximumLifetime = RandomGen.NextTimeSpan(0.1, 2);
        Add(sparkle);

        double force = RandomGen.NextDouble(100, 200);

        sparkle.Hit(Vector.FromLengthAndAngle(force, sparkle.Angle));
    }
示例#3
0
 //Ammus on osunut ja törmäyksien käsittelijä kutsuu AmmusOsuu -aliohjelmaa
 void AmmusOsuu(PhysicsObject tormaaja, PhysicsObject kohde)
 {
     //Meteori1 pysäytetään ja väriä muutetaan
     if (kohde.Tag == "meteori1")
     {
         kohde.Color = RandomGen.NextColor();
         kohde.Stop();
         //kohde.Destroy();
         kohde.IgnoresGravity = true;
     }
     //Meteori2 räjäytetään
     if (kohde.Tag == "meteori2")
     {
         Explosion rajahdys = new Explosion(70);
         rajahdys.Position = kohde.Position;
         Add(rajahdys);
         tormaaja.Destroy();
         kohde.Destroy();
     }
     //Kuun väri muutetaan keltaiseksi ja sen kokoa muutetaan
     if (kohde == kuu)
     {
         kohde.Color = Color.Yellow;
         tormaaja.Destroy();
         if (kohde.Width < 500 && kuuKasvaa)
         {
             kohde.Size = new Vector(kohde.Width + 10, kohde.Height + 10);
         }
         else if (kohde.Width > 20)
         {
             kuuKasvaa  = false;
             kohde.Size = new Vector(kohde.Width - 10, kohde.Height - 10);
         }
         else
         {
             kuuKasvaa = true;
         }
     }
 }
示例#4
0
    int generoi3()
    {
        tahtilista = new List <PhysicsObject>();
        Vector alkupiste = pallo1.Position;
        Angle  suunta1   = RandomGen.NextAngle();
        Vector tp        = alkupiste;

        for (int i = 0; i < 100; i++)
        {
            if (i % KAANTOVALI < 1)
            {
                Angle känsä = RandomGen.NextAngle(
                    Angle.FromDegrees(-KAANTOKULMA - 20),
                    Angle.FromDegrees(KAANTOKULMA + 20));
                suunta1 = känsä;
            }
            Vector vp = Vector.FromLengthAndAngle(94, suunta1);
            tp = tp + vp;
            Vector newtp = new Vector(tp.X, tp.Y);
            Timer.SingleShot(1.7 + PALLONTEKONOPEUS * i, () => luotahti(newtp, RandomGen.NextColor()));
        }
        return(100);
    }
示例#5
0
 //Kun kuu törmää meteoriin, muutetaan sen väriä randomilla
 void MeteoriOsuuKuuhun(PhysicsObject tormaaja, PhysicsObject kohde)
 {
     tormaaja.Color = RandomGen.NextColor();
 }
示例#6
0
 /// <summary>
 /// Vaihtaa törmäyskohteen värin satunnaiseen.
 /// </summary>
 /// <param name="collidingObject"></param>
 /// <param name="targetObject"></param>
 /// <returns></returns>
 public static void SetRandomTargetColor(PhysicsObject collidingObject, PhysicsObject targetObject)
 {
     targetObject.Color = RandomGen.NextColor();
 }
示例#7
0
 /// <summary>
 /// Tehdään taulukko erilaisille karkeille ja luodaan karkit karkkitaulukosta
 /// </summary>
 private void LuoKarkki()
 {
     string[] karkkitaulukko = { "karkki", "kuva2", "karkki3" };
     for (int i = 0; i < KARKKIENMAARA; i++)
     {
         PhysicsObject karkki = Olio(this, KARKKIPAIKKA, KARKKIPAIKKA, RandomGen.NextDouble(Level.Left, Level.Right), RandomGen.NextDouble(Level.Bottom, Level.Top), "karkki", false, false, true, 10, RandomGen.SelectOne(karkkitaulukko), RandomGen.NextColor(), Shape.Circle, true);
         Add(karkki);
     }
 }
    public static void GenMap(int numberOfOtherCountries, int bigCountryThickness, double gridCellSize, ref GameObject[,] cells)
    {
        int MAP_WIDTH  = cells.GetLength(0);
        int MAP_HEIGHT = cells.GetLength(1);

        // Grid corner vertices (with slight deform)
        Vector[,] gridPoints = new Vector[MAP_WIDTH + 1, MAP_HEIGHT + 1];
        for (int x = 0; x < MAP_WIDTH + 1; x++)
        {
            for (int y = 0; y < MAP_HEIGHT + 1; y++)
            {
                gridPoints[x, y] = new Vector(-gridCellSize * (MAP_WIDTH / 2) + x * gridCellSize, gridCellSize * (MAP_HEIGHT / 2) - y * gridCellSize)
                                   + RandomGen.NextVector(gridCellSize / 5, gridCellSize / 3);
            }
        }

        IndexTriangle[] idxTriRect = new IndexTriangle[] { new IndexTriangle(0, 2, 1), new IndexTriangle(2, 0, 3) };
        for (int x = 0; x < MAP_WIDTH; x++)
        {
            for (int y = 0; y < MAP_HEIGHT; y++)
            {
                Vector cellPosition = (gridPoints[x, y] + gridPoints[x, y + 1] + gridPoints[x + 1, y] + gridPoints[x + 1, y + 1]) / 4;

                var polyshape = new Polygon(new ShapeCache(
                                                new Vector[] { gridPoints[x, y] - cellPosition, gridPoints[x, y + 1] - cellPosition, gridPoints[x + 1, y + 1] - cellPosition, gridPoints[x + 1, y] - cellPosition }, // corners
                                                idxTriRect                                                                                                                                                           // triangles
                                                ), false);
                var cell = new GameObject(gridCellSize, gridCellSize, polyshape);
                cell.Position = cellPosition;
                //cell.Color = RandomGen.NextColor();

                cells[x, y] = cell;
            }
        }

        int freeCellCnt = MAP_WIDTH * MAP_HEIGHT;

        // 1. Outside is USSR
        for (int x = 0; x < MAP_WIDTH; x++)
        {
            for (int y = 0; y < bigCountryThickness; y++)
            {
                cells[x, y].Color = USSR_COLOR;                  //TODO: Translucient
                //TODO: Set the contry to the tag
                cells[x, MAP_HEIGHT - 1 - y].Color = USSR_COLOR; //TODO: Translucient
                freeCellCnt -= 2;
            }
        }
        for (int y = bigCountryThickness; y < MAP_HEIGHT - bigCountryThickness; y++)
        {
            for (int x = 0; x < bigCountryThickness; x++)
            {
                cells[x, y].Color = USSR_COLOR;                 //TODO: Translucient
                //TODO: Set the contry to the tag
                cells[MAP_WIDTH - 1 - x, y].Color = USSR_COLOR; //TODO: Translucient
                freeCellCnt -= 2;
            }
        }

        // 2. You are at the center
        cells[MAP_WIDTH / 2, MAP_HEIGHT / 2].Color = YOURZISTAN;
        //TODO: Set tag to point to your country
        freeCellCnt--;

        // 3. Other countries are placed randomly
        for (int i = 0; i < numberOfOtherCountries; i++)
        {
            bool foundSpot = false;
            do
            {
                int x = RandomGen.NextInt(1, MAP_WIDTH - 2);
                int y = RandomGen.NextInt(1, MAP_HEIGHT - 2);
                if (cells[x, y].Color == Color.White)
                {
                    freeCellCnt--;
                    cells[x, y].Color = RandomGen.NextColor();
                    foundSpot         = true;
                    //TODO: Set tag to point to a country
                }
            } while (!foundSpot);
        }

        // Evolve
        bool foundWhite = false;

        do
        {
            foundWhite = false;
            List <Tuple <int, int, Color> > toFill = new List <Tuple <int, int, Color> >();
            for (int x = 1; x < MAP_WIDTH - 1; x++)
            {
                for (int y = 1; y < MAP_HEIGHT - 1; y++)
                {
                    // Free to fill
                    if (cells[x, y].Color == Color.White)
                    {
                        foundWhite = true;
                        List <Color> nearbyColors = new List <Color>();
                        for (int dx = -1; dx < 2; dx++)
                        {
                            Color neighbourColor = cells[x + dx, y].Color;
                            if (neighbourColor != Color.White && (neighbourColor != USSR_COLOR || RandomGen.NextInt(10) == 1))
                            {
                                nearbyColors.Add(neighbourColor);
                            }
                        }
                        for (int dy = -1; dy < 2; dy++)
                        {
                            Color neighbourColor = cells[x, y + dy].Color;
                            if (neighbourColor != Color.White && (neighbourColor != USSR_COLOR || RandomGen.NextInt(10) == 1))
                            {
                                nearbyColors.Add(neighbourColor);
                            }
                        }
                        if (nearbyColors.Count > 0)
                        {
                            Color mostOccuring = nearbyColors.GroupBy(i => i).OrderByDescending(grp => grp.Count()).Select(grp => grp.Key).First();
                            // Store into temp list so that for this round it is a level ground
                            toFill.Add(new Tuple <int, int, Color>(x, y, mostOccuring));
                        }
                    }
                }
            }
            foreach (var tf in toFill)
            {
                // Little bit of stochasticity
                if (RandomGen.NextInt(5) < 4)
                {
                    cells[tf.Item1, tf.Item2].Color = tf.Item3;
                    freeCellCnt--;
                }
            }
        } while (foundWhite);
    }