Esempio n. 1
0
        private static void Window_UpdateFrame(object sender, OpenTK.FrameEventArgs e)
        {
            KeyPress keyPress = window.CogKeyboard.GetKeyPress();

            if (keyPress != null)
            {
                if (keyPress.Key == Key.Up)
                {
                    y--;
                }
                else if (keyPress.Key == Key.Down)
                {
                    y++;
                }
                else if (keyPress.Key == Key.Left)
                {
                    x--;
                }
                else if (keyPress.Key == Key.Right)
                {
                    x++;
                }
                if (keyPress.Key == Key.Escape)
                {
                    window.Close();
                }
            }

            grid.ClearTiles(0, new OpenTK.Vector4(1f, 1f, 1f, 1f));
            sprite.position.X = x;
            sprite.position.Y = y;
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            window = new CogWindow(800, 600);

            window.UpdateFrame += Window_UpdateFrame;

            grid            = new TileGrid(new TiledTexture("ascii_8x8.png", 8, 8), 0, 0, 0, 100, 75, 1f, 1f, false);
            spriteBatch     = new SpriteBatch(new TiledTexture("ascii_8x8.png", 8, 8), 0, 0, 1, 1f, 1f);
            sprite          = new Sprite();
            sprite.tile     = 2;
            sprite.position = new OpenTK.Vector2(32f, 32f);
            sprite.rotation = 1f;
            sprite.color    = new OpenTK.Vector4(1f, 1f, 1f, .5f);
            sprite.scale    = new OpenTK.Vector2(1f, 1f);
            sprite.size     = new OpenTK.Vector2(1f, 1f);

            spriteBatch.Sprites.Add(sprite);

            window.DrawElements.Add(grid);
            window.DrawElements.Add(spriteBatch);

            grid.ClearTiles(0, new OpenTK.Vector4(1f, 1f, 1f, 1f));

            window.Run(30d, 30d);
        }
Esempio n. 3
0
        private void LoadTileMap(string fileName, bool compressed = false)
        {
            if (System.IO.Path.GetExtension(fileName) != ".tmap" && System.IO.Path.GetExtension(fileName) != ".txt")
            {
                System.Windows.MessageBox.Show(fileName, "Invalid file");
                return;
            }

            currentMap = fileName;
            TileGrid.ClearTiles();

            TileMapWrapper tileMap = tileMapRepository.LoadMap(fileName, compressed);

            if (tileMap != null)
            {
                TileGrid.AddLayers(tileMap.Layers);
                TileGrid.Update(model.Sprites);

                model.CanvasWidth      = tileMap.Width;
                model.CanvasHeight     = tileMap.Height;
                Status.Text            = "Loaded tilemap from: " + currentMap;
                TileGrid.SelectedLayer = 0;
            }
            else
            {
                Status.Text = "Tilemap load failed: " + currentMap;
            }
        }
Esempio n. 4
0
        private void New_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new SaveFileDialog();

            if (lastFolder != null)
            {
                dialog.InitialDirectory = lastFolder;
            }
            dialog.Filter = "Map Files|*.tmap|Text Files|*.txt";
            DialogResult result = dialog.ShowDialog();

            if (result == System.Windows.Forms.DialogResult.OK)
            {
                TileGrid.ClearTiles();
                TileGrid.AddNewLayer("Main");
                File.Create(dialog.FileName);
                FilePath.Text = dialog.FileName;
                currentMap    = dialog.FileName;
                Status.Text   = "Created new tilemap in: " + dialog.FileName;
            }
        }