Пример #1
0
        public void forget(Tilemap tilemap, int tx, int ty)
        {
            Tilemap        tm = tilemap;
            TileRepository tr = tileRepository;

            int[,] m1 = new int[3, 3] {
                { tm.getTileAt(tx - 1, ty - 1), tm.getTileAt(tx + 0, ty - 1), tm.getTileAt(tx + 1, ty - 1) },
                { tm.getTileAt(tx - 1, ty + 0), tm.getTileAt(tx + 0, ty + 0), tm.getTileAt(tx + 1, ty + 0) },
                { tm.getTileAt(tx - 1, ty + 1), tm.getTileAt(tx + 0, ty + 1), tm.getTileAt(tx + 1, ty + 1) }
            };
            bool[,] m2 = new bool[3, 3] {
                { tr.isSolid[tm.getTileAt(tx - 1, ty - 1)], tr.isSolid[tm.getTileAt(tx + 0, ty - 1)], tr.isSolid[tm.getTileAt(tx + 1, ty - 1)] },
                { tr.isSolid[tm.getTileAt(tx - 1, ty + 0)], tr.isSolid[tm.getTileAt(tx + 0, ty + 0)], tr.isSolid[tm.getTileAt(tx + 1, ty + 0)] },
                { tr.isSolid[tm.getTileAt(tx - 1, ty + 1)], tr.isSolid[tm.getTileAt(tx + 0, ty + 1)], tr.isSolid[tm.getTileAt(tx + 1, ty + 1)] }
            };

            for (int i = 0; i < id_matrices.Count; i++)
            {
                if (equal(m1, id_matrices[i]))
                {
                    id_matrices.RemoveAt(i);
                    solid_matrices.RemoveAt(i);
                }
            }
        }
Пример #2
0
        public Form1()
        {
            InitializeComponent();

            if (!File.Exists("data\\images\\tiles.strf"))
            {
                MessageBox.Show("Cobble was unable to find data\\images\\tiles.strf.\n\nMake sure your current working directory is the SuperTux main directory.\n\nAborting.", "Cobble - Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                throw new ArgumentException("Abort");
            }

            tileRepository = new TileRepository("data\\images\\tiles.strf");
            currentBrush   = new Brush(tileRepository);
            foreach (TileGroup tileGroup in tileRepository.getTileGroups())
            {
                cbTilegroup.Items.Add(tileGroup);
            }
            if (cbTilegroup.Items.Count >= 1)
            {
                cbTilegroup.SelectedIndex = 0;
            }

            foreach (GameObject gameObject in GameObject.getExponents())
            {
                lbGameObjects.Items.Add(gameObject);
            }
            if (lbGameObjects.Items.Count >= 1)
            {
                lbGameObjects.SelectedIndex = 0;
            }

            btnModeTileAdd_Click(null, null);
        }
Пример #3
0
        public static Brush loadFromFile(TileRepository tileRepository, string fname)
        {
            TileRepository tr = tileRepository;

            Brush brush = new Brush(tileRepository);

            FileStream fs  = new FileStream(fname, FileMode.Open);
            TextReader trd = new StreamReader(fs);

            try {
                string s;
                while ((s = trd.ReadLine()) != null)
                {
                    string[] v = s.Split(',');
                    if (v.Length < 9)
                    {
                        continue;
                    }
                    int[,] ids = new int[3, 3] {
                        { int.Parse(v[0]), int.Parse(v[1]), int.Parse(v[2]) },
                        { int.Parse(v[3]), int.Parse(v[4]), int.Parse(v[5]) },
                        { int.Parse(v[6]), int.Parse(v[7]), int.Parse(v[8]) }
                    };
                    bool[,] sols = new bool[3, 3] {
                        { tr.isSolid[int.Parse(v[0])], tr.isSolid[int.Parse(v[1])], tr.isSolid[int.Parse(v[2])] },
                        { tr.isSolid[int.Parse(v[3])], tr.isSolid[int.Parse(v[4])], tr.isSolid[int.Parse(v[5])] },
                        { tr.isSolid[int.Parse(v[6])], tr.isSolid[int.Parse(v[7])], tr.isSolid[int.Parse(v[8])] }
                    };
                    brush.id_matrices.Add(ids);
                    brush.solid_matrices.Add(sols);
                }
            }
            catch (IOException) {
            }

            trd.Close();
            fs.Close();

            return(brush);
        }
Пример #4
0
        //if (!careful) {
        //    if (!matrixExists(new int[3, 3] {
        //       { tm.getTileAt(tx-2,ty-1), m1[0, 0], m1[0, 1] },
        //       { getTileAt(tx-2,ty+0), m1[1, 0], m1[1, 1] },
        //       { getTileAt(tx-2,ty+1), m1[2, 0], m1[2, 1] }
        //       })) thisSimilarity -= 100;
        //    if (!matrixExists(new int[3, 3] {
        //       { m1[0, 1], m1[0, 1], getTileAt(tx+2,ty-1)},
        //       { m1[1, 1], m1[1, 2], getTileAt(tx+2,ty+0)},
        //       { m1[2, 1], m1[2, 2], getTileAt(tx+2,ty+1)}
        //       })) thisSimilarity -= 100;


        //}

        public void learn(Tilemap tilemap, int tx, int ty)
        {
            Tilemap        tm = tilemap;
            TileRepository tr = tileRepository;

            int[,] m1 = new int[3, 3] {
                { tm.getTileAt(tx - 1, ty - 1), tm.getTileAt(tx + 0, ty - 1), tm.getTileAt(tx + 1, ty - 1) },
                { tm.getTileAt(tx - 1, ty + 0), tm.getTileAt(tx + 0, ty + 0), tm.getTileAt(tx + 1, ty + 0) },
                { tm.getTileAt(tx - 1, ty + 1), tm.getTileAt(tx + 0, ty + 1), tm.getTileAt(tx + 1, ty + 1) }
            };
            bool[,] m2 = new bool[3, 3] {
                { tr.isSolid[tm.getTileAt(tx - 1, ty - 1)], tr.isSolid[tm.getTileAt(tx + 0, ty - 1)], tr.isSolid[tm.getTileAt(tx + 1, ty - 1)] },
                { tr.isSolid[tm.getTileAt(tx - 1, ty + 0)], tr.isSolid[tm.getTileAt(tx + 0, ty + 0)], tr.isSolid[tm.getTileAt(tx + 1, ty + 0)] },
                { tr.isSolid[tm.getTileAt(tx - 1, ty + 1)], tr.isSolid[tm.getTileAt(tx + 0, ty + 1)], tr.isSolid[tm.getTileAt(tx + 1, ty + 1)] }
            };

            if (!matrixExists(m1))
            {
                id_matrices.Add(m1);
                solid_matrices.Add(m2);
            }
        }
Пример #5
0
        public Form1()
        {
            InitializeComponent();

            if (!File.Exists("data\\images\\tiles.strf")) {
                MessageBox.Show("Cobble was unable to find data\\images\\tiles.strf.\n\nMake sure your current working directory is the SuperTux main directory.\n\nAborting.", "Cobble - Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                throw new ArgumentException("Abort");
            }

            tileRepository = new TileRepository("data\\images\\tiles.strf");
            currentBrush = new Brush(tileRepository);
            foreach (TileGroup tileGroup in tileRepository.getTileGroups()) {
                cbTilegroup.Items.Add(tileGroup);
            }
            if (cbTilegroup.Items.Count >= 1) cbTilegroup.SelectedIndex = 0;

            foreach (GameObject gameObject in GameObject.getExponents()) {
                lbGameObjects.Items.Add(gameObject);
            }
            if (lbGameObjects.Items.Count >= 1) lbGameObjects.SelectedIndex = 0;

            btnModeTileAdd_Click(null, null);
        }
Пример #6
0
        public static Brush loadFromFile(TileRepository tileRepository, string fname)
        {
            TileRepository tr = tileRepository;

            Brush brush = new Brush(tileRepository);

            FileStream fs = new FileStream(fname, FileMode.Open);
            TextReader trd = new StreamReader(fs);

            try {
                string s;
                while ((s = trd.ReadLine()) != null) {
                    string[] v = s.Split(',');
                    if (v.Length < 9) continue;
                    int[,] ids = new int[3, 3] {
                        {int.Parse(v[0]), int.Parse(v[1]), int.Parse(v[2])},
                        {int.Parse(v[3]), int.Parse(v[4]), int.Parse(v[5])},
                        {int.Parse(v[6]), int.Parse(v[7]), int.Parse(v[8])}
                    };
                    bool[,] sols = new bool[3, 3] {
                        {tr.isSolid[int.Parse(v[0])], tr.isSolid[int.Parse(v[1])], tr.isSolid[int.Parse(v[2])]},
                        {tr.isSolid[int.Parse(v[3])], tr.isSolid[int.Parse(v[4])], tr.isSolid[int.Parse(v[5])]},
                        {tr.isSolid[int.Parse(v[6])], tr.isSolid[int.Parse(v[7])], tr.isSolid[int.Parse(v[8])]}
                    };
                    brush.id_matrices.Add(ids);
                    brush.solid_matrices.Add(sols);
                }
            }
            catch (IOException) {
            }

            trd.Close();
            fs.Close();

            return brush;
        }
Пример #7
0
        //protected int[,] getIdMatrix(int tx, int ty) {
        //    return new int[3, 3] {
        //               { getTileAt(tx-1,ty-1), getTileAt(tx+0,ty-1), getTileAt(tx+1,ty-1) },
        //               { getTileAt(tx-1,ty+0), getTileAt(tx+0,ty+0), getTileAt(tx+1,ty+0) },
        //               { getTileAt(tx-1,ty+1), getTileAt(tx+0,ty+1), getTileAt(tx+1,ty+1) }
        //            };
        //}

        public Brush(TileRepository tileRepository)
        {
            this.tileRepository = tileRepository;
        }
Пример #8
0
        protected void draw(Tilemap tilemap, int tx, int ty, bool erase)
        {
            Tilemap        tm = tilemap;
            TileRepository tr = tileRepository;

            int[,] desiredIdPattern = new int[3, 3] {
                { tm.getTileAt(tx - 1, ty - 1), tm.getTileAt(tx + 0, ty - 1), tm.getTileAt(tx + 1, ty - 1) },
                { tm.getTileAt(tx - 1, ty + 0), tm.getTileAt(tx + 0, ty + 0), tm.getTileAt(tx + 1, ty + 0) },
                { tm.getTileAt(tx - 1, ty + 1), tm.getTileAt(tx + 0, ty + 1), tm.getTileAt(tx + 1, ty + 1) }
            };

            bool[,] desiredSolPattern = new bool[3, 3] {
                { tr.isSolid[tm.getTileAt(tx - 1, ty - 1)], tr.isSolid[tm.getTileAt(tx + 0, ty - 1)], tr.isSolid[tm.getTileAt(tx + 1, ty - 1)] },
                { tr.isSolid[tm.getTileAt(tx - 1, ty + 0)], !erase, tr.isSolid[tm.getTileAt(tx + 1, ty + 0)] },
                { tr.isSolid[tm.getTileAt(tx - 1, ty + 1)], tr.isSolid[tm.getTileAt(tx + 0, ty + 1)], tr.isSolid[tm.getTileAt(tx + 1, ty + 1)] }
            };

            float bestSimilarity = 0;

            int[,] bestPattern = new int[3, 3] {
                { tm.getTileAt(tx - 1, ty - 1), tm.getTileAt(tx + 0, ty - 1), tm.getTileAt(tx + 1, ty - 1) },
                { tm.getTileAt(tx - 1, ty + 0), tm.getTileAt(tx + 0, ty + 0), tm.getTileAt(tx + 1, ty + 0) },
                { tm.getTileAt(tx - 1, ty + 1), tm.getTileAt(tx + 0, ty + 1), tm.getTileAt(tx + 1, ty + 1) }
            };

            for (int i = 0; i < id_matrices.Count; i++)
            {
                int[,] m1 = id_matrices[i];
                int[,] m2 = desiredIdPattern;

                bool[,] m3 = solid_matrices[i];
                bool[,] m4 = desiredSolPattern;

                float thisSimilarity = 0;
                for (int px = 0; px < 3; px++)
                {
                    for (int py = 0; py < 3; py++)
                    {
                        if ((px == 1) && (py == 1))
                        {
                            if (tr.isSolid[m1[px, py]] == (!erase))
                            {
                                thisSimilarity += 1000;
                            }
                            continue;
                        }
                        if (m1[px, py] == m2[px, py])
                        {
                            thisSimilarity += 1;
                        }
                        if (m3[px, py] == m4[px, py])
                        {
                            thisSimilarity += 100;
                        }
                    }
                }

                if (thisSimilarity > bestSimilarity)
                {
                    bestSimilarity = thisSimilarity; bestPattern = m1;
                }
            }

            if (bestSimilarity > 0)
            {
                int[,] m1 = bestPattern;

                tm.setTileAt(tx - 1, ty - 1, m1[0, 0]);
                tm.setTileAt(tx + 0, ty - 1, m1[0, 1]);
                tm.setTileAt(tx + 1, ty - 1, m1[0, 2]);
                tm.setTileAt(tx - 1, ty + 0, m1[1, 0]);
                tm.setTileAt(tx + 0, ty + 0, m1[1, 1]);
                tm.setTileAt(tx + 1, ty + 0, m1[1, 2]);
                tm.setTileAt(tx - 1, ty + 1, m1[2, 0]);
                tm.setTileAt(tx + 0, ty + 1, m1[2, 1]);
                tm.setTileAt(tx + 1, ty + 1, m1[2, 2]);
            }
        }
Пример #9
0
 //protected int[,] getIdMatrix(int tx, int ty) {
 //    return new int[3, 3] {
 //               { getTileAt(tx-1,ty-1), getTileAt(tx+0,ty-1), getTileAt(tx+1,ty-1) },
 //               { getTileAt(tx-1,ty+0), getTileAt(tx+0,ty+0), getTileAt(tx+1,ty+0) },
 //               { getTileAt(tx-1,ty+1), getTileAt(tx+0,ty+1), getTileAt(tx+1,ty+1) }
 //            };
 //}
 public Brush(TileRepository tileRepository)
 {
     this.tileRepository = tileRepository;
 }