Пример #1
0
 static GameObject()
 {
     exponents["spawnpoint"] = new Spawnpoint("main", -1, -1);
     exponents["bell"]       = new SpatialGameObject("bell", -1, -1);
     exponents["powerup"]    = new PowerUp(-1, -1);
     foreach (string name in new string[] { "angrystone", "bouncingsnowball", "dispenser", "fish", "flame", "flyingsnowball", "jumpy", "kugelblitz", "mrbomb", "mriceblock", "mrrocket", "mrtree", "plant", "poisonivy", "skullyhop", "snowball", "snowsnail", "spidermite", "spiky", "sspiky", "stalactite", "yeti", "yeti_stalactite", "zeekling" })
     {
         exponents[name] = new Badguy(name, -1, -1);
     }
 }
Пример #2
0
        private void resizeTilemapsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (currentSector == null)
            {
                return;
            }

            int currentSizeX = 0;
            int currentSizeY = 0;

            foreach (Tilemap tilemap in currentSector.tilemaps)
            {
                if (tilemap.width > currentSizeX)
                {
                    currentSizeX = tilemap.width;
                }
                if (tilemap.height > currentSizeY)
                {
                    currentSizeY = tilemap.height;
                }
            }

            SectorResizeDialog srd = new SectorResizeDialog(currentSizeX, currentSizeY);

            if (srd.ShowDialog() == DialogResult.OK)
            {
                foreach (Tilemap tilemap in currentSector.tilemaps)
                {
                    tilemap.OffsetBy(srd.OffsetX, srd.OffsetY);
                    tilemap.ResizeTo(srd.SectorWidth, srd.SectorHeight);
                }
                foreach (GameObject go in currentSector.gameObjects)
                {
                    if (!(go is SpatialGameObject))
                    {
                        continue;
                    }
                    SpatialGameObject sgo = (SpatialGameObject)go;
                    sgo.X += 32 * srd.OffsetX;
                    sgo.Y += 32 * srd.OffsetY;
                }
                cbSector_SelectedIndexChanged(sender, e);
            }
        }
Пример #3
0
        private SpatialGameObject getNearestGameObject(int x, int y, double maxDistance)
        {
            SpatialGameObject nearestObject = null;

            foreach (GameObject gameObject in currentSector.gameObjects)
            {
                if (!(gameObject is SpatialGameObject))
                {
                    continue;
                }
                SpatialGameObject spatialGameObject = (SpatialGameObject)gameObject;

                double dst = Math.Sqrt(Math.Pow((x - spatialGameObject.X), 2) + Math.Pow((y - spatialGameObject.Y), 2));
                if (dst <= maxDistance)
                {
                    maxDistance   = dst;
                    nearestObject = spatialGameObject;
                }
            }
            return(nearestObject);
        }
Пример #4
0
        private void pbCanvas_MouseDown(object sender, MouseEventArgs e)
        {
            int tx = e.X / 32;
            int ty = e.Y / 32;

            if (currentSector == null) return;

            if ((e.Button == MouseButtons.Left) && (tcToolSettings.SelectedTab == tpTiles)) {
                currentCanvasAction = CanvasAction.drawingTiles;
            }

            if ((e.Button == MouseButtons.Left) && (tcToolSettings.SelectedTab == tpTileManip)) {
                if ((currentFloatingTilemap != null) && (currentFloatingTilemapPos.Contains(tx,ty))) {
                    currentCanvasAction = CanvasAction.movingFloatingTilemap;
                } else
                if (currentSelection.Contains(tx, ty)) {
                    createFloatingTilemapFromSelection(true);
                    currentCanvasAction = CanvasAction.movingFloatingTilemap;
                    pbCanvas.Invalidate();
                } else {
                    anchorFloatingTilemap();
                    pbCanvas.Invalidate();
                    currentCanvasAction = CanvasAction.selecting;
                    currentSelection = new Rectangle(tx, ty, 0, 0);
                }
            }
            if ((e.Button == MouseButtons.Left) && (tcToolSettings.SelectedTab == tpObjects)) {
                GameObject selectedObject = (GameObject)lbGameObjects.SelectedItem;
                if ((selectedObject != null) && (selectedObject is SpatialGameObject)) {
                    SpatialGameObject spatialGameObject = (SpatialGameObject)selectedObject.Clone();
                    spatialGameObject.X = e.X;
                    spatialGameObject.Y = e.Y;
                    currentSector.gameObjects.Add(spatialGameObject);
                    pbCanvas.Invalidate();
                }
            }
            if ((e.Button == MouseButtons.Left) && (tcToolSettings.SelectedTab == tpGameObjectManip)) {
                currentGameObject = getNearestGameObject(e.X, e.Y, 32);
                if (currentGameObject != null) {
                    currentCanvasAction = CanvasAction.movingObject;
                    pbCanvas.Invalidate();
                }
            }
            if ((e.Button == MouseButtons.Left) && (tcToolSettings.SelectedTab == tpBrushes)) {
                currentCanvasAction = CanvasAction.drawingBrush;
            }

            canvasActionStart.X = e.X;
            canvasActionStart.Y = e.Y;
            pbCanvas_MouseMove(sender, e);
        }
Пример #5
0
        private void pbCanvas_Paint(object sender, PaintEventArgs e)
        {
            Graphics gr = e.Graphics;

            if (currentSector == null)
            {
                return;
            }
            if (tileRepository == null)
            {
                return;
            }

            foreach (Tilemap tilemap in currentSector.tilemaps)
            {
                if (!clTilemaps.CheckedItems.Contains(tilemap))
                {
                    continue;
                }

                for (int ty = 0; ty < tilemap.height; ty++)
                {
                    for (int tx = 0; tx < tilemap.width; tx++)
                    {
                        int px = tx * 32;
                        int py = ty * 32;

                        if (px + 32 < e.ClipRectangle.Left)
                        {
                            continue;
                        }
                        if (px > e.ClipRectangle.Right)
                        {
                            continue;
                        }
                        if (py + 32 < e.ClipRectangle.Top)
                        {
                            continue;
                        }
                        if (py > e.ClipRectangle.Bottom)
                        {
                            continue;
                        }

                        int   id   = tilemap.getTileAt(tx, ty);
                        Image tile = tileRepository.getTile(id);

                        if (tile == null)
                        {
                            continue;
                        }
                        gr.DrawImageUnscaled(tile, px, py);
                    }
                }

                if (currentTilemap == tilemap)
                {
                    if (currentSelection.Width > 0)
                    {
                        gr.DrawRectangle(Pens.Red, new Rectangle(currentSelection.X * 32, currentSelection.Y * 32, currentSelection.Width * 32, currentSelection.Height * 32));
                    }
                    if (currentFloatingTilemap != null)
                    {
                        for (int ty = 0; ty < currentFloatingTilemap.GetLength(1); ty++)
                        {
                            for (int tx = 0; tx < currentFloatingTilemap.GetLength(0); tx++)
                            {
                                int px = (currentFloatingTilemapPos.X + tx) * 32;
                                int py = (currentFloatingTilemapPos.Y + ty) * 32;

                                if (px + 32 < e.ClipRectangle.Left)
                                {
                                    continue;
                                }
                                if (px > e.ClipRectangle.Right)
                                {
                                    continue;
                                }
                                if (py + 32 < e.ClipRectangle.Top)
                                {
                                    continue;
                                }
                                if (py > e.ClipRectangle.Bottom)
                                {
                                    continue;
                                }

                                int   id   = currentFloatingTilemap[tx, ty];
                                Image tile = tileRepository.getTile(id);

                                if (tile == null)
                                {
                                    continue;
                                }
                                gr.DrawImageUnscaled(tile, px, py);
                            }
                        }

                        gr.DrawRectangle(Pens.Lime, new Rectangle(currentFloatingTilemapPos.X * 32, currentFloatingTilemapPos.Y * 32, currentFloatingTilemapPos.Width * 32, currentFloatingTilemapPos.Height * 32));
                    }
                }
            }

            foreach (GameObject gameObject in currentSector.gameObjects)
            {
                if (!(gameObject is SpatialGameObject))
                {
                    continue;
                }
                SpatialGameObject spatialGameObject = (SpatialGameObject)gameObject;

                int px = (int)spatialGameObject.X;
                int py = (int)spatialGameObject.Y;

                gr.DrawEllipse(Pens.Blue, new Rectangle(px - 16, py - 16, 32, 32));
                gr.DrawString(gameObject.DescriptiveText(), new Font(FontFamily.GenericSansSerif, 8), Brushes.Blue, px + 12, py - 18);
            }
        }
Пример #6
0
        private void pbCanvas_MouseDown(object sender, MouseEventArgs e)
        {
            int tx = e.X / 32;
            int ty = e.Y / 32;

            if (currentSector == null)
            {
                return;
            }

            if ((e.Button == MouseButtons.Left) && (tcToolSettings.SelectedTab == tpTiles))
            {
                currentCanvasAction = CanvasAction.drawingTiles;
            }

            if ((e.Button == MouseButtons.Left) && (tcToolSettings.SelectedTab == tpTileManip))
            {
                if ((currentFloatingTilemap != null) && (currentFloatingTilemapPos.Contains(tx, ty)))
                {
                    currentCanvasAction = CanvasAction.movingFloatingTilemap;
                }
                else
                if (currentSelection.Contains(tx, ty))
                {
                    createFloatingTilemapFromSelection(true);
                    currentCanvasAction = CanvasAction.movingFloatingTilemap;
                    pbCanvas.Invalidate();
                }
                else
                {
                    anchorFloatingTilemap();
                    pbCanvas.Invalidate();
                    currentCanvasAction = CanvasAction.selecting;
                    currentSelection    = new Rectangle(tx, ty, 0, 0);
                }
            }
            if ((e.Button == MouseButtons.Left) && (tcToolSettings.SelectedTab == tpObjects))
            {
                GameObject selectedObject = (GameObject)lbGameObjects.SelectedItem;
                if ((selectedObject != null) && (selectedObject is SpatialGameObject))
                {
                    SpatialGameObject spatialGameObject = (SpatialGameObject)selectedObject.Clone();
                    spatialGameObject.X = e.X;
                    spatialGameObject.Y = e.Y;
                    currentSector.gameObjects.Add(spatialGameObject);
                    pbCanvas.Invalidate();
                }
            }
            if ((e.Button == MouseButtons.Left) && (tcToolSettings.SelectedTab == tpGameObjectManip))
            {
                currentGameObject = getNearestGameObject(e.X, e.Y, 32);
                if (currentGameObject != null)
                {
                    currentCanvasAction = CanvasAction.movingObject;
                    pbCanvas.Invalidate();
                }
            }
            if ((e.Button == MouseButtons.Left) && (tcToolSettings.SelectedTab == tpBrushes))
            {
                currentCanvasAction = CanvasAction.drawingBrush;
            }


            canvasActionStart.X = e.X;
            canvasActionStart.Y = e.Y;
            pbCanvas_MouseMove(sender, e);
        }
Пример #7
0
        public override GameObject Clone()
        {
            SpatialGameObject clone = new SpatialGameObject(Type, X, Y);

            return(clone);
        }
Пример #8
0
 public override GameObject Clone()
 {
     SpatialGameObject clone = new SpatialGameObject(Type, X, Y);
     return clone;
 }
Пример #9
0
 static GameObject()
 {
     exponents["spawnpoint"] = new Spawnpoint("main", -1, -1);
     exponents["bell"] = new SpatialGameObject("bell", -1, -1);
     exponents["powerup"] = new PowerUp(-1, -1);
     foreach (string name in new string[] { "angrystone", "bouncingsnowball", "dispenser", "fish", "flame", "flyingsnowball", "jumpy", "kugelblitz", "mrbomb", "mriceblock", "mrrocket", "mrtree", "plant", "poisonivy", "skullyhop", "snowball", "snowsnail", "spidermite", "spiky", "sspiky", "stalactite", "yeti", "yeti_stalactite", "zeekling" }) {
         exponents[name] = new Badguy(name, -1, -1);
     }
 }