Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Sprite Editor for .NET

, 27 Jan 2010 CPOL
Build, edit, and animate your own sprites.
classSprite_C_2008.zip
classSprite
classSprite
classSprite.csproj.user
bin
Release
classSprite.dll
Properties
GraphicsEditor_C_2008.zip
GraphicsEditor CSharp
GraphicsEditor CSharp
graphics editor icon.ico
GraphicsEditor CSharp.csproj.user
Properties
Settings.settings
Resources
Brush_Icon.bmp
click to load image.bmp
colorTemplate.bmp
cursor_cross.bmp
cursor_move.bmp
cursor_resizeDiagonal_BL_TR.bmp
cursor_resizeDiagonal_TL_BR.bmp
cursor_resizeLeftRight.bmp
cursor_resizeUpDown.bmp
Edit_Redo_Icon.bmp
Edit_Undo_Icon.bmp
Eraser_Icon.bmp
FloodFill_Icon.bmp
FloodFill_pnlBackground_sameColor.bmp
FloodFill_pnlBackground_toBorder.bmp
Free-Form Select_Icon.bmp
Gun.bmp
Line_Icon.bmp
Magnify_Icon.bmp
Pencil_Icon.bmp
Pick-color_Icon.bmp
Select_Icon.bmp
sprite Editor.jpg
Straighten_Icon.bmp
Night_Stalker__C_2008.zip
Night Stalker
Night Stalker
Night Stalker.csproj.user
nightstalker.ico
Properties
Settings.settings
Resources
bomb.wav
bulletEaten.wav
BulletEater.spr
bulletEater.wav
bunker.png
bunkerbuster.spr
BunkerBuster.wav
CDbunkerWalls.bmp
Colt Round.png
Colt.spr
colt45.wav
corpse (small).spr
diescream.wav
emptychamber.wav
Evil Jessica (small).spr
Felix the Cat (small).spr
FelixFire.spr
FelixFire.wav
freeLife.wav
gun.png
gun.spr
heartbeat.wav
help_background.jpg
hithard.wav
Jessica Rabbit Small.spr
largeJessica.spr
Laser.spr
laserFire.wav
loadclip.wav
Map WPs.png
Map.jpg
MapCD.bmp
mini bat.spr
NearestWayPointsTable.bfs
nightstalker.bmp
nightstalker.png
red bunker.png
Robot Den New.png
Robot_A.spr
smurf (small).spr
smurf-attack.spr
spider (small).spr
Spider Web.png
splat.wav
WayPointsArray.bfs
WayPointsTable.bfs
Sprites.zip
Sprites
Robot1.bmp
Robot2.bmp
robot3.bmp
Bat
bat.spr
head.bmp
head.jpg
leftwing.bmp
mini bat.spr
wing.bmp
Bullets
bulletEater original.png
bulletEater.bmp
BulletEater.spr
bunkerbuster.bmp
bunkerbuster.spr
Colt.bmp
Colt.spr
Laser.bmp
Laser.spr
master limb.bmp
smurf-attack.bmp
smurf-attack.spr
Claudia Schiffer
alt.spr
Claudia.spr
Claudia_Arm.bmp
Claudia_Foot.bmp
Claudia_Forearm.bmp
Claudia_Hand_Left.bmp
Claudia_Hand_Right.bmp
Claudia_head.bmp
Claudia_head2.bmp
Claudia_mini.spr
Claudia_Schiffer_1.jpg
Claudia_Shin.bmp
Claudia_Thigh.bmp
Claudia_Torso.bmp
gunHand.bmp
Corpse
blood.bmp
corpse (small).spr
Corpse.spr
guts.bmp
master limb.bmp
robot.png
smurfcorpse.png
Evil Jessica
Evil Jessica (small).spr
Evil Jessica.spr
GunHand(near).bmp
JR_Arm.bmp
JR_Arm.png
JR_Dress.bmp
JR_Dress_resized.bmp
JR_Foot.bmp
JR_Forearm.bmp
JR_Hair(far).bmp
JR_Hair(near).bmp
JR_Hand.bmp
JR_Hand_Right.bmp
JR_Head.bmp
JR_MasterBlock.bmp
JR_Shin.bmp
JR_Thigh_far.bmp
JR_Thigh_near.bmp
JR_Torso.bmp
gun
gun.bmp
gun.spr
master block.bmp
Jessica Rabbit
GunHand(near).bmp
Jessica Rabbit Small.spr
Jessica Rabbit.spr
jessica_rabbit at mic.jpg
JR_Arm.bmp
JR_Dress.bmp
JR_Dress_resized.bmp
JR_Foot.bmp
JR_Forearm.bmp
JR_Hair(far).bmp
JR_Hair(near).bmp
JR_Hand.bmp
JR_Hand_Right.bmp
JR_Head.bmp
JR_MasterBlock.bmp
JR_Shin.bmp
JR_Thigh_far.bmp
JR_Thigh_near.bmp
JR_Torso.bmp
Lindsay Lohan
arm.bmp
foot.bmp
forearm.bmp
gunHand.bmp
Hand_Left.bmp
head.bmp
Lindsay Lohan.spr
Mini Lindsay Lohan.spr
shin.bmp
skirt_ass.bmp
skirt_front.bmp
thigh.bmp
torso.bmp
NightStalkerSprites
BulletEater.spr
bunkerbuster.spr
Colt.spr
corpse (small).spr
Evil Jessica (small).spr
gun.spr
Jessica Rabbit Small.spr
Laser.spr
mini bat.spr
Mini Lindsay Lohan.spr
Robot_A.spr
smurf (small).spr
smurf-attack.spr
spider (small).spr
Robot Heart
RobotHeart_Head.bmp
RobotHeart_Torso.bmp
Robot_EyeShut.bmp
ROBOT_heart.bmp
Robot_Heart.spr
Robot_Heart_small.spr
Robot_LeftArm.bmp
Robot_Leg.bmp
Robot_dumb
Arm.bmp
Arm_right_front.bmp
Hand.bmp
Head.bmp
head_back.bmp
Head_Front.bmp
Leg.bmp
leg_back.bmp
leg_front.bmp
Robot_A.spr
Robot_A_original.spr
Robot_A_original_copy.spr
Torso.bmp
Torso_Front.bmp
Smurf
arm(far).bmp
arm(near).bmp
head.bmp
leg.bmp
smurf (small).spr
smurf.spr
Torso.bmp
spider
body.bmp
eyes shut.bmp
head.bmp
legA_left.bmp
legA_right.bmp
legB_left.bmp
legB_right.bmp
LegC_left.bmp
legC_right.bmp
legD_left.bmp
legD_right.bmp
mandible_left.bmp
mandible_right.bmp
spider (small).spr
spider 2.spr
spider.png
spider.spr
sprite_Demo_C_2008.zip
Sprite demo
Sprite demo
Sprite demo.csproj.user
bin
Release
Sprite demo.exe
Properties
Settings.settings
Resources
cartoon grass.jpg
smurf (small).spr
sprite_Editor_C_2008.zip
Sprite Editor
Sprite Editor
Sprite Editor.csproj.user
sprite Editor.ico
bin
Release
cLibPicBoxViewer.dll
Sprite Editor.exe
Properties
Settings.settings
Resources
click to load image.bmp
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace Night_Stalker
{
    #region "unused map generator enum & struct"
    enum unbreakableWallenuDir { North = 0, East, South, West }

    class classWallBasher
    {
        public Point loc;
        public classWallBasher next;
    }

    public class classWallArrayElement
    {
        public wallTypes V;
        public wallTypes H;
    }

    public struct udtDoorInfo
    {
        public bool thereIsADoor;
        public Point FloorTileLoc;
        public bool HorizontalDoor;
    }
    #endregion

    public class classRoom
    {
        #region "unused map generator variables"
        /*
        private classWallBasher udrWallBasherQ;
        bool[,] bolSeenMap;
        public bool bolMapAlreadyGenerated = false;
        public udtDoorInfo udrDoor;
        static Bitmap[] bmpFloorTiles;
        public int  intStandardWallThickness = (int)(callingForm.intStandardWallLength * .05) + 1;
        public classWallArrayElement[,] udrWalls;
        enum enuWallImages { HWall = 0, VWall, HUnbreakableWall, VUnbreakableWall, HDoor, VDoor, _numWallImages }
        static Bitmap[] bmpWalls = new Bitmap[(int)enuWallImages._numWallImages];
        string strValidPositions = "";
        */
        #endregion

        formNightStalker callingForm;

        public classRoom(formNightStalker localcallingForm)
        {
            callingForm = localcallingForm;

         }

        //private void animateBloodSplatter()
        //{
        //    classBloodSplatter thisBloodSplatter = BloodSplatterQ;
        //    while (thisBloodSplatter != null)
        //    {
        //        if (thisBloodSplatter.bolDieNextTurn)
        //        {
        //            thisBloodSplatter.eraseOldImage();
        //            classBloodSplatter nextBloodSplatter = thisBloodSplatter.next;
        //            deQBloodSplatter(ref thisBloodSplatter);
        //            thisBloodSplatter = nextBloodSplatter;
        //        }
        //        else
        //        {
        //            thisBloodSplatter.animate();
        //            thisBloodSplatter = thisBloodSplatter.next;
        //        }
        //    }
        //}

        //public void enQBloodSplatter(ref classBloodSplatter classThisBloodSplatter)
        //{
        //    if (BloodSplatterQ != null)
        //    {
        //        classThisBloodSplatter.next = BloodSplatterQ;
        //        BloodSplatterQ.previous = classThisBloodSplatter;

        //        classThisBloodSplatter.previous = null;
        //        BloodSplatterQ = classThisBloodSplatter;
        //    }
        //    else
        //    {
        //        BloodSplatterQ = classThisBloodSplatter;
        //        classThisBloodSplatter.next = null;
        //        classThisBloodSplatter.previous = null;
        //    }
        //}

        //public void deQBloodSplatter(ref classBloodSplatter classThisBloodSplatter)
        //{
        //    if (classThisBloodSplatter == BloodSplatterQ)
        //    {
        //        BloodSplatterQ = BloodSplatterQ.next;
        //        if (BloodSplatterQ != null)
        //            BloodSplatterQ.previous = null;
        //    }
        //    else
        //    {
        //        try { classThisBloodSplatter.previous.next = classThisBloodSplatter.next; }
        //        catch (Exception) { }
        //        try { classThisBloodSplatter.next.previous = classThisBloodSplatter.previous; }
        //        catch (Exception) { }
        //    }
        //}

        //public void enQRobot(ref classRobot classThisRobot)
        //{

        //    if (RobotQ != null)
        //    {
        //        classThisRobot.next = RobotQ;
        //        RobotQ.previous = classThisRobot;

        //        classThisRobot.previous = null;
        //        RobotQ = classThisRobot;
        //    }
        //    else
        //    {
        //        RobotQ = classThisRobot;
        //        classThisRobot.next = null;
        //        classThisRobot.previous = null;
        //    }
        //}

        //public void deQRobot(ref classRobot classThisRobot)
        //{
        //    if (classThisRobot == RobotQ)
        //    {
        //        RobotQ = RobotQ.next;
        //        if (RobotQ != null)
        //            RobotQ.previous = null;
        //    }
        //    else
        //    {
        //        try { classThisRobot.previous.next = classThisRobot.next; }
        //        catch (Exception) { }
        //        try { classThisRobot.next.previous = classThisRobot.previous; }
        //        catch (Exception) { }
        //    }
        //}

        public void Animate()
        {
            animateRobots();
            //animateBloodSplatter();
        }

        private void animateRobots()
        {
            //classRobot classThisRobot = RobotQ;
            //classRobot nextRobot = null;
            //while (classThisRobot != null)
            //{
            //    nextRobot = classThisRobot.next;
            //    if (!classThisRobot.bolIAmDead)
            //        classThisRobot.animate();
            //    else
            //        deQRobot(ref classThisRobot);

            //    classThisRobot = nextRobot;
            //}
        }


        #region "unused map generator functions"
        /*
        private bool shouldWallBasherBashWall()
        {
            double dblRnd = callingForm.getRnd((int)100 * intLevel);
            return (dblRnd < 10 - intLevel);
        }

        private classWallBasher deQWallBasher()
        {
            if (udrWallBasherQ != null)
            {
                classWallBasher udrReturnWallBasher = new classWallBasher();
                udrReturnWallBasher.loc = udrWallBasherQ.loc;
                udrReturnWallBasher.next = null;
                udrWallBasherQ = udrWallBasherQ.next;
                return udrReturnWallBasher;
            }
            else
                return null;
        }

        private void enQWallBasher(classWallBasher udrWallBasher)
        {
            if (udrWallBasherQ == null)
                udrWallBasherQ = udrWallBasher;
            else
            {
                classWallBasher udrThisWallBasher = udrWallBasherQ;
                while (udrThisWallBasher.next != null)
                    udrThisWallBasher = udrThisWallBasher.next;
                udrThisWallBasher.next = udrWallBasher;
            }
        }

        private void initWalls()
        {
            bolSeenMap = new bool[callingForm.szRoom.Width , callingForm.szRoom.Height ];

            udrWalls = new classWallArrayElement[callingForm.szRoom.Width, callingForm.szRoom.Height];
            double dblSize = 2 * callingForm.intStandardWallLength;

            for (int intXCounter = 0; intXCounter < callingForm.szRoom.Width; intXCounter++)
                for (int intYCounter = 0; intYCounter < callingForm.szRoom.Height; intYCounter++)
                {
                    udrWalls[intXCounter, intYCounter] = new classWallArrayElement();
                    udrWalls[intXCounter, intYCounter].H = wallTypes.wall;
                    udrWalls[intXCounter, intYCounter].V = wallTypes.wall;
                }

            for (int intXCounter = 0; intXCounter < callingForm.szRoom.Width; intXCounter++)
                for (int intYCounter = 0; intYCounter < callingForm.szRoom.Height; intYCounter++)
                    bolSeenMap[intXCounter, intYCounter] = false;
        }

       

        Bitmap getWallImage(wallTypes wallType, bool bolVertical)
        {
            enuWallImages wallImagetype = enuWallImages._numWallImages;
            switch (wallType)
            {
                case wallTypes.open_Door:
                case wallTypes.no_Wall:
                    return null;

                case wallTypes.door:
                    wallImagetype = bolVertical ? enuWallImages.VDoor : enuWallImages.HDoor;
                    break;

                case wallTypes.wall:
                    wallImagetype = bolVertical ? enuWallImages.VWall : enuWallImages.HWall;
                    break;

                case wallTypes.unbreakableWall:
                    wallImagetype = bolVertical ? enuWallImages.VUnbreakableWall : enuWallImages.HUnbreakableWall;
                    break;
            }

            if (bmpWalls[(int)wallImagetype] == null)
            {
                Color clrDoor = Color.Smurf;
                Color clrWall = Color.Brown;
                Color clrUnbreakableWall = Color.Black;

                switch (wallImagetype)
                {
                    case enuWallImages.HDoor:
                        bmpWalls[(int)wallImagetype] = new Bitmap(callingForm.intStandardWallLength, intStandardWallThickness);
                        using (Graphics g = Graphics.FromImage(bmpWalls[(int)wallImagetype]))
                            g.FillRectangle(new SolidBrush(clrDoor), new Rectangle(0, 0, callingForm.intStandardWallLength, intStandardWallThickness));
                        return bmpWalls[(int)wallImagetype];

                    case enuWallImages.HWall:
                        bmpWalls[(int)wallImagetype] = new Bitmap(callingForm.intStandardWallLength, intStandardWallThickness);
                        using (Graphics g = Graphics.FromImage(bmpWalls[(int)wallImagetype]))
                            g.FillRectangle(new SolidBrush(clrWall), new Rectangle(0, 0, callingForm.intStandardWallLength, intStandardWallThickness));
                        return bmpWalls[(int)wallImagetype];

                    case enuWallImages.HUnbreakableWall:
                        bmpWalls[(int)wallImagetype] = new Bitmap(callingForm.intStandardWallLength, intStandardWallThickness);
                        using (Graphics g = Graphics.FromImage(bmpWalls[(int)wallImagetype]))
                            g.FillRectangle(new SolidBrush(clrUnbreakableWall), new Rectangle(0, 0, callingForm.intStandardWallLength, intStandardWallThickness));
                        return bmpWalls[(int)wallImagetype];

                    case enuWallImages.VDoor:
                        bmpWalls[(int)wallImagetype] = new Bitmap(intStandardWallThickness, callingForm.intStandardWallLength);
                        using (Graphics g = Graphics.FromImage(bmpWalls[(int)wallImagetype]))
                            g.FillRectangle(new SolidBrush(clrDoor), new Rectangle(0, 0, intStandardWallThickness, callingForm.intStandardWallLength));
                        return bmpWalls[(int)wallImagetype];

                    case enuWallImages.VWall:
                        bmpWalls[(int)wallImagetype] = new Bitmap(intStandardWallThickness, callingForm.intStandardWallLength);
                        using (Graphics g = Graphics.FromImage(bmpWalls[(int)wallImagetype]))
                            g.FillRectangle(new SolidBrush(clrWall), new Rectangle(0, 0, intStandardWallThickness, callingForm.intStandardWallLength));
                        return bmpWalls[(int)wallImagetype];

                    case enuWallImages.VUnbreakableWall:
                        bmpWalls[(int)wallImagetype] = new Bitmap(intStandardWallThickness, callingForm.intStandardWallLength);
                        using (Graphics g = Graphics.FromImage(bmpWalls[(int)wallImagetype]))
                            g.FillRectangle(new SolidBrush(clrUnbreakableWall), new Rectangle(0, 0, intStandardWallThickness, callingForm.intStandardWallLength));
                        return bmpWalls[(int)wallImagetype];

                    default:
                        return null;
                }
            }
            else
                return bmpWalls[(int)wallImagetype];

        }

        private Point moveCorner(Point ptCorner, unbreakableWallenuDir unbDir)
        {
            switch (unbDir)
            {
                case unbreakableWallenuDir.North:
                    ptCorner.Y--;
                    return ptCorner;

                case unbreakableWallenuDir.East:
                    ptCorner.X++;
                    return ptCorner;

                case unbreakableWallenuDir.South:
                    ptCorner.Y++;
                    return ptCorner;

                case unbreakableWallenuDir.West:
                    ptCorner.X--;
                    return ptCorner;

                default:
                    callingForm.Refresh();
                    return ptCorner;
                //this should not happen
            }
        }


        #region "generate door"
        private void generateDoor(bool bolForceDoor)
        {
            // to add doors to map
            udrDoor.thereIsADoor = true;

            Point ptThisCorner, ptLastCorner, ptStartCorner;
            unbreakableWallenuDir dirStartingWall, dirLastMove, dirThisMove;
            int intStartWall = -1;

            while (intStartWall < 0 || intStartWall > 3)
                intStartWall = callingForm.getRnd(4);
            dirStartingWall = (unbreakableWallenuDir)intStartWall;

            ptLastCorner = new Point(0, 0);

            int intStartPeg = -1;
            switch (intStartWall)
            {
                case (int)unbreakableWallenuDir.North: // north
                    while (intStartPeg < 1 || intStartPeg >= callingForm.szRoom.Width)
                        intStartPeg = callingForm.getRnd(callingForm.szRoom.Width);
                    ptLastCorner.X = intStartPeg; ptLastCorner.Y = 0;
                    break;

                case (int)unbreakableWallenuDir.East:
                    while (intStartPeg < 1 || intStartPeg >= callingForm.szRoom.Height)
                        intStartPeg = callingForm.getRnd(callingForm.szRoom.Height);
                    ptLastCorner.X = callingForm.szRoom.Width; ptLastCorner.Y = intStartPeg;
                    break;

                case (int)unbreakableWallenuDir.South:
                    while (intStartPeg < 1 || intStartPeg >= callingForm.szRoom.Width)
                        intStartPeg = callingForm.getRnd(callingForm.szRoom.Width);
                    ptLastCorner.X = intStartPeg; ptLastCorner.Y = callingForm.szRoom.Height;
                    break;

                case (int)unbreakableWallenuDir.West:
                    while (intStartPeg < 1 || intStartPeg >= callingForm.szRoom.Height)
                        intStartPeg = callingForm.getRnd(callingForm.szRoom.Height);
                    ptLastCorner.X = 0; ptLastCorner.Y = intStartPeg;
                    break;
            }

            // remember where we started
            ptStartCorner = ptLastCorner;
            // take first step and keep track of wall path in a string
            dirThisMove = getOppositeUNBDirection(dirStartingWall);
            string strWallPath = ((int)dirThisMove).ToString();
            ptThisCorner = moveCorner(ptLastCorner, dirThisMove);

            string strEligibleWalls = "";
            int intRndDir;

            while (!thisCornerIsEndOfUnbreakableWall(ptThisCorner))
            {
                ptLastCorner = ptThisCorner; dirLastMove = dirThisMove;

                strEligibleWalls = getEligibleMovesFromThisCorner(dirLastMove, dirStartingWall);
                intRndDir = callingForm.getRnd(strEligibleWalls.Length);
                dirThisMove = (unbreakableWallenuDir)(Convert.ToInt16((strEligibleWalls.Substring(intRndDir, 1))));
                ptThisCorner = moveCorner(ptLastCorner, dirThisMove);
                strWallPath += ((int)dirThisMove).ToString();
            }

            int intRndDoorInUnbreakablePath = callingForm.getRnd(strWallPath.Length);

            // retrace wallpath making unbreakable walls out of regular walls and a door at intRndDoor step
            ptLastCorner = ptThisCorner = ptStartCorner;
            unbreakableWallenuDir dirThisRetraceMove;

            for (int intStepCounter = 0; intStepCounter < strWallPath.Length; intStepCounter++)
            {
                dirThisRetraceMove = (unbreakableWallenuDir)(Convert.ToInt16(strWallPath.Substring(intStepCounter, 1)));

                switch (dirThisRetraceMove)
                {
                    case unbreakableWallenuDir.East:
                        udrWalls[ptThisCorner.X, ptThisCorner.Y].H = (intStepCounter == intRndDoorInUnbreakablePath) ? wallTypes.door : wallTypes.unbreakableWall;
                        break;

                    case unbreakableWallenuDir.North:
                        udrWalls[ptThisCorner.X, ptThisCorner.Y - 1].V = (intStepCounter == intRndDoorInUnbreakablePath) ? wallTypes.door : wallTypes.unbreakableWall;
                        break;

                    case unbreakableWallenuDir.West:
                        udrWalls[ptThisCorner.X - 1, ptThisCorner.Y].H = (intStepCounter == intRndDoorInUnbreakablePath) ? wallTypes.door : wallTypes.unbreakableWall;
                        break;

                    case unbreakableWallenuDir.South:
                        udrWalls[ptThisCorner.X, ptThisCorner.Y].V = (intStepCounter == intRndDoorInUnbreakablePath) ? wallTypes.door : wallTypes.unbreakableWall;
                        break;
                }

                ptLastCorner = ptThisCorner;
                ptThisCorner = moveCorner(ptThisCorner, dirThisRetraceMove);
            }

        }

        private unbreakableWallenuDir getOppositeUNBDirection(unbreakableWallenuDir unbThisDirection)
        {
            switch (unbThisDirection)
            {
                case unbreakableWallenuDir.North:
                    return unbreakableWallenuDir.South;
                case unbreakableWallenuDir.East:
                    return unbreakableWallenuDir.West;
                case unbreakableWallenuDir.South:
                    return unbreakableWallenuDir.North;
                case unbreakableWallenuDir.West:
                    return unbreakableWallenuDir.East;
                default:
                    // this should not happen
                    return unbreakableWallenuDir.North;
            }
        }

        private string getEligibleMovesFromThisCorner(unbreakableWallenuDir unbLastMove, unbreakableWallenuDir unbStartingWall)
        {
            string strEligibleMoves = "0123";
            // never go back in the reverse direction            
            strEligibleMoves = strEligibleMoves.Replace(((int)getOppositeUNBDirection(unbLastMove)).ToString(), "");
            // never go back towards the starting wall
            strEligibleMoves = strEligibleMoves.Replace(((int)unbStartingWall).ToString(), "");
            return strEligibleMoves;
        }

        private bool thisCornerIsEndOfUnbreakableWall(Point ptCorner)
        {
            // reached end when reached a wall
            return (ptCorner.X == 0
                    || ptCorner.X >= callingForm.szRoom.Width
                    || ptCorner.Y == 0
                    || ptCorner.Y >= callingForm.szRoom.Height);
        }
        #endregion

        private void enQFirstBashersOnEitherSideOfDoor()
        {
            Point udrLocA = new Point(), udrLocB = new Point();

            for (int intXCounter = 0; intXCounter < callingForm.szRoom.Width; intXCounter++)
                for (int intYCounter = 0; intYCounter < callingForm.szRoom.Height; intYCounter++)
                {
                    if (udrWalls[intXCounter, intYCounter].H == wallTypes.door)
                    {
                        udrLocB.X = udrLocA.X = intXCounter;
                        udrLocA.Y = intYCounter;
                        udrLocB.Y = intYCounter - 1;
                        goto endLoop;
                    }
                    if (udrWalls[intXCounter, intYCounter].V == wallTypes.door)
                    {
                        udrLocB.Y = udrLocA.Y = intYCounter;
                        udrLocB.X = intXCounter;
                        udrLocA.X = intXCounter - 1;
                        goto endLoop;
                    }
                }

        endLoop:
            if (udrLocA.X < 0 || udrLocA.X > callingForm.szRoom.Width
                || udrLocB.Y < 0 || udrLocB.Y > callingForm.szRoom.Height)
                callingForm.Refresh();

            classWallBasher udrWallBasherA = new classWallBasher();
            udrWallBasherA.loc = udrLocA;
            udrWallBasherA.next = null;
            enQWallBasher(udrWallBasherA);
            bolSeenMap[udrLocA.X, udrLocA.Y] = true;

            classWallBasher udrWallBasherB = new classWallBasher();
            udrWallBasherB.loc = udrLocB;
            udrWallBasherB.next = null;
            enQWallBasher(udrWallBasherB);
            bolSeenMap[udrLocB.X, udrLocB.Y] = true;
        }

        void generateMap(bool bolForceDoor)
        {
        startGenerateMap:
            generateDoor(bolForceDoor);
            enQFirstBashersOnEitherSideOfDoor();

            while (udrWallBasherQ != null)
            {
                // deQ next Basher
                classWallBasher udrCurrentWallBasher;

                udrCurrentWallBasher = deQWallBasher();

                // test if I have seen this basher's current location
                // wall basher is in new location 

                // look in 4 direction 
                //    if location is already seen 
                //           test f(level) if bash wall between current and adjacent position
                //    if location is NOT already seen
                //           bash wall between current and adjacent position
                //           create new basher in new position and enQ it

                // pick a enuDir
                string strAvailableenuDir = "";

                if (udrCurrentWallBasher.loc.X > 0)
                    if (udrWalls[udrCurrentWallBasher.loc.X, udrCurrentWallBasher.loc.Y].V != wallTypes.unbreakableWall
                        && udrWalls[udrCurrentWallBasher.loc.X, udrCurrentWallBasher.loc.Y].V != wallTypes.door)
                        strAvailableenuDir += "W";

                if (udrCurrentWallBasher.loc.X < callingForm.szRoom.Width - 1)
                    if (udrWalls[udrCurrentWallBasher.loc.X + 1, udrCurrentWallBasher.loc.Y].V != wallTypes.unbreakableWall
                        && udrWalls[udrCurrentWallBasher.loc.X + 1, udrCurrentWallBasher.loc.Y].V != wallTypes.door)
                        strAvailableenuDir += "E";

                if (udrCurrentWallBasher.loc.Y < callingForm.szRoom.Height - 1)
                    if (udrWalls[udrCurrentWallBasher.loc.X, udrCurrentWallBasher.loc.Y + 1].H != wallTypes.unbreakableWall
                        && udrWalls[udrCurrentWallBasher.loc.X, udrCurrentWallBasher.loc.Y + 1].H != wallTypes.door)
                        strAvailableenuDir += "S";

                if (udrCurrentWallBasher.loc.Y > 0)
                    if (udrWalls[udrCurrentWallBasher.loc.X, udrCurrentWallBasher.loc.Y].H != wallTypes.unbreakableWall
                        && udrWalls[udrCurrentWallBasher.loc.X, udrCurrentWallBasher.loc.Y].H != wallTypes.door)
                        strAvailableenuDir += "N";

                while (strAvailableenuDir.Length > 1) // keep only one direction
                {
                    int intIndex = callingForm.getRnd(strAvailableenuDir.Length);
                    strAvailableenuDir = strAvailableenuDir.Replace(strAvailableenuDir.Substring(intIndex, 1), "");
                }

                // look North
                if (strAvailableenuDir.Contains("N"))
                {
                    if (udrWalls[udrCurrentWallBasher.loc.X, udrCurrentWallBasher.loc.Y].H == wallTypes.wall)
                    { // there is still a wall here
                        if (bolSeenMap[udrCurrentWallBasher.loc.X, udrCurrentWallBasher.loc.Y - 1])
                        {// location already seen -> there's still a chance I'll break this wall
                            if (shouldWallBasherBashWall())
                            {
                                udrWalls[udrCurrentWallBasher.loc.X, udrCurrentWallBasher.loc.Y].H = wallTypes.no_Wall;
                                bolSeenMap[udrCurrentWallBasher.loc.X, udrCurrentWallBasher.loc.Y - 1] = true;
                            }
                        }
                        else
                        {
                            udrWalls[udrCurrentWallBasher.loc.X, udrCurrentWallBasher.loc.Y].H = wallTypes.no_Wall;
                            bolSeenMap[udrCurrentWallBasher.loc.X, udrCurrentWallBasher.loc.Y - 1] = true;
                        }
                    }
                    classWallBasher udrNewBasher = new classWallBasher();
                    udrNewBasher.loc.X = udrCurrentWallBasher.loc.X;
                    udrNewBasher.loc.Y = udrCurrentWallBasher.loc.Y - 1;
                    enQWallBasher(udrNewBasher);
                }

                // look East
                if (strAvailableenuDir.Contains("E"))
                {
                    if (udrWalls[udrCurrentWallBasher.loc.X + 1, udrCurrentWallBasher.loc.Y].V == wallTypes.wall)
                    { // there is still a wall here
                        if (bolSeenMap[udrCurrentWallBasher.loc.X + 1, udrCurrentWallBasher.loc.Y])
                        {// location already seen -> there's still a chance I'll break this wall
                            if (shouldWallBasherBashWall())
                                udrWalls[udrCurrentWallBasher.loc.X + 1, udrCurrentWallBasher.loc.Y].V = wallTypes.no_Wall;
                            bolSeenMap[udrCurrentWallBasher.loc.X + 1, udrCurrentWallBasher.loc.Y] = true;
                        }
                        else
                        {
                            udrWalls[udrCurrentWallBasher.loc.X + 1, udrCurrentWallBasher.loc.Y].V = wallTypes.no_Wall;
                            bolSeenMap[udrCurrentWallBasher.loc.X + 1, udrCurrentWallBasher.loc.Y] = true;
                        }
                    }
                    classWallBasher udrNewBasher = new classWallBasher();
                    udrNewBasher.loc.X = udrCurrentWallBasher.loc.X + 1;
                    udrNewBasher.loc.Y = udrCurrentWallBasher.loc.Y;
                    enQWallBasher(udrNewBasher);
                }

                // look South
                if (strAvailableenuDir.Contains("S"))
                {
                    if (udrWalls[udrCurrentWallBasher.loc.X, udrCurrentWallBasher.loc.Y + 1].H == wallTypes.wall)
                    { // there is still a wall here
                        if (bolSeenMap[udrCurrentWallBasher.loc.X, udrCurrentWallBasher.loc.Y + 1])
                        {// location already seen -> there's still a chance I'll break this wall
                            if (shouldWallBasherBashWall())
                            {
                                udrWalls[udrCurrentWallBasher.loc.X, udrCurrentWallBasher.loc.Y + 1].H = wallTypes.no_Wall;
                                bolSeenMap[udrCurrentWallBasher.loc.X, udrCurrentWallBasher.loc.Y + 1] = true;
                            }
                        }
                        else
                        {
                            udrWalls[udrCurrentWallBasher.loc.X, udrCurrentWallBasher.loc.Y + 1].H = wallTypes.no_Wall;
                            bolSeenMap[udrCurrentWallBasher.loc.X, udrCurrentWallBasher.loc.Y + 1] = true;
                        }
                    }
                    classWallBasher udrNewBasher = new classWallBasher();
                    udrNewBasher.loc.X = udrCurrentWallBasher.loc.X;
                    udrNewBasher.loc.Y = udrCurrentWallBasher.loc.Y + 1;
                    enQWallBasher(udrNewBasher);
                }

                // look West
                if (strAvailableenuDir.Contains("W"))
                {
                    if (udrWalls[udrCurrentWallBasher.loc.X, udrCurrentWallBasher.loc.Y].V == wallTypes.wall)
                    { // there is still a wall here
                        if (bolSeenMap[udrCurrentWallBasher.loc.X - 1, udrCurrentWallBasher.loc.Y])
                        {// location already seen -> there's still a chance I'll break this wall
                            if (shouldWallBasherBashWall())
                                if (udrWalls[udrCurrentWallBasher.loc.X, udrCurrentWallBasher.loc.Y].V == wallTypes.wall)
                                {
                                    udrWalls[udrCurrentWallBasher.loc.X, udrCurrentWallBasher.loc.Y].V = wallTypes.no_Wall;
                                    bolSeenMap[udrCurrentWallBasher.loc.X - 1, udrCurrentWallBasher.loc.Y] = true;
                                }
                        }
                        else
                        {
                            udrWalls[udrCurrentWallBasher.loc.X, udrCurrentWallBasher.loc.Y].V = wallTypes.no_Wall;
                            bolSeenMap[udrCurrentWallBasher.loc.X - 1, udrCurrentWallBasher.loc.Y] = true;
                        }
                    }
                    classWallBasher udrNewBasher = new classWallBasher();
                    udrNewBasher.loc.X = udrCurrentWallBasher.loc.X - 1;
                    udrNewBasher.loc.Y = udrCurrentWallBasher.loc.Y;
                    enQWallBasher(udrNewBasher);
                }

                // test if all map has been seen
                int intTilesSeen = 0;
                for (int intXCounter = 0; intXCounter < callingForm.szRoom.Width; intXCounter++)
                    for (int intYCounter = 0; intYCounter < callingForm.szRoom.Height; intYCounter++)
                        if (bolSeenMap[intXCounter, intYCounter])
                            intTilesSeen++;
                if (intTilesSeen == (callingForm.szRoom.Width) * (callingForm.szRoom.Height))
                    while (udrWallBasherQ != null)
                        deQWallBasher();
                //    if whole map has been seen destroy Q
            }

            // go over the room again and replace temp_Walls with regular_Walls
            for (int intXCounter = 0; intXCounter < callingForm.szRoom.Width; intXCounter++)
                for (int intYCounter = 0; intYCounter < callingForm.szRoom.Height; intYCounter++)
                {
                    if (udrWalls[intXCounter, intYCounter].H == wallTypes.unbreakableWall)
                        udrWalls[intXCounter, intYCounter].H = wallTypes.wall;
                    if (udrWalls[intXCounter, intYCounter].V == wallTypes.unbreakableWall)
                        udrWalls[intXCounter, intYCounter].V = wallTypes.wall;
                }

            //if (!FindValidPositionsToPlaceCofferAndStairs())
            //{
            //    initWalls();
            //    goto startGenerateMap;
            //}
            bolMapAlreadyGenerated = true;
            drawBMP();
        }

           void drawBMP()
        {
            bmp = new Bitmap(callingForm.szRoom.Width * callingForm.intStandardWallLength + intStandardWallThickness , callingForm.szRoom.Height * callingForm.intStandardWallLength + intStandardWallThickness );

            using (Graphics g = Graphics.FromImage(bmp))
            {
                // draw the floor
                Bitmap bmpFloorTile = bmpFloorTiles[intLevel % bmpFloorTiles.Length ];

                int intNum_HTiles = (int)Math.Ceiling((double)bmp.Width / (double)bmpFloorTile.Width) +1;
                int intNum_VTiles = (int)Math.Ceiling((double)bmp.Height / (double)bmpFloorTile.Height) +1;

                 for (int intX = 0; intX < intNum_HTiles; intX++)
                    for (int intY = 0; intY < intNum_VTiles; intY++)
                        g.DrawImage(bmpFloorTile,
                                    new Point(intX * bmpFloorTile.Width ,
                                              intY * bmpFloorTile.Height));
                //draw the walls (and door)
                for (int intX = 0; intX < callingForm.szRoom.Width; intX++)
                    for (int intY = 0; intY < callingForm.szRoom.Height; intY++)
                    {
                        Point pt = callingForm.getTileLoc(intX, intY);
                        if (udrWalls[intX, intY].H != wallTypes.no_Wall
                            && udrWalls[intX, intY].H != wallTypes.open_Door)
                        {
                            Bitmap bmpThisHWall = intY ==0 ? getWallImage(wallTypes.unbreakableWall, false) : getWallImage(udrWalls[intX, intY].H, false);
                            g.DrawImage(bmpThisHWall, pt);
                        }

                        if (udrWalls[intX, intY].V != wallTypes.no_Wall
                            && udrWalls[intX, intY].V != wallTypes.open_Door)
                        {
                            Bitmap bmpThisVWall = intX == 0 ? getWallImage(wallTypes.unbreakableWall, true): getWallImage(udrWalls[intX, intY].V, true);
                            g.DrawImage(bmpThisVWall, pt);
                        }
                    }

                for (int intX = 0; intX < callingForm.szRoom.Width; intX++)
                    g.DrawImage(getWallImage(wallTypes.unbreakableWall, false), new Point(intX * callingForm.intStandardWallLength, callingForm.szRoom.Height * callingForm.intStandardWallLength));
                for (int intY = 0; intY < callingForm.szRoom.Height; intY++)
                    g.DrawImage(getWallImage(wallTypes.unbreakableWall, true), new Point(callingForm.szRoom.Width * callingForm.intStandardWallLength, intY * callingForm.intStandardWallLength));
                    }
 
       }

           void initFloorTiles()
        {
            if (bmpFloorTiles == null)
            {
                Array.Resize<Bitmap>(ref bmpFloorTiles, 4);
                bmpFloorTiles[0] = Night_Stalker.Properties.Resources.flootiles_hardwood_modified;
                bmpFloorTiles[1] = Night_Stalker.Properties.Resources.floortiles_woodenlattice_modified;
                bmpFloorTiles[2] = Night_Stalker.Properties.Resources.floortiles_terra_y_fuego_modified;
                bmpFloorTiles[3] = Night_Stalker.Properties.Resources.floortiles_encaustic_modified;
            }
        }
         
             private bool CanWalkAround(Point udrFloorTile, enuDir direction)
        {
            Point udrNewTile;
            switch (direction)
            {
                case enuDir.northeast:
                    udrNewTile = callingForm.cLibHelper.movePixel(udrFloorTile, enuDir.east);
                    try { if (udrWalls[udrNewTile.X, udrNewTile.Y].H != wallTypes.no_Wall) return false; }
                    catch (Exception) { return false; }

                    udrNewTile = callingForm.cLibHelper.movePixel(udrNewTile, enuDir.north);
                    try { if (udrWalls[udrNewTile.X, udrNewTile.Y].V != wallTypes.no_Wall) return false; }
                    catch (Exception) { return false; }
                    return true;

                case enuDir.northwest:
                    udrNewTile = callingForm.cLibHelper.movePixel(udrFloorTile, enuDir.west);
                    try { if (udrWalls[udrNewTile.X, udrNewTile.Y].H != wallTypes.no_Wall) return false; }
                    catch (Exception) { return false; }
                    udrNewTile = callingForm.cLibHelper.movePixel(udrNewTile, enuDir.northeast);
                    try { if (udrWalls[udrNewTile.X, udrNewTile.Y].V != wallTypes.no_Wall) return false; }
                    catch (Exception) { return false; }
                    return true;

                case enuDir.southeast:
                    udrNewTile = callingForm.cLibHelper.movePixel(udrFloorTile, enuDir.southeast);
                    try { if (udrWalls[udrNewTile.X, udrNewTile.Y].H != wallTypes.no_Wall || udrWalls[udrNewTile.X, udrNewTile.Y].V != wallTypes.no_Wall) return false; }
                    catch (Exception) { return false; }
                    return true;

                case enuDir.southwest:
                    udrNewTile = callingForm.cLibHelper.movePixel(udrFloorTile, enuDir.southwest);
                    try { if (udrWalls[udrNewTile.X, udrNewTile.Y].H != wallTypes.no_Wall) return false; }
                    catch (Exception) { return false; }

                    udrNewTile = callingForm.cLibHelper.movePixel(udrNewTile, enuDir.east);
                    try { if (udrWalls[udrNewTile.X, udrNewTile.Y].V != wallTypes.no_Wall) return false; }
                    catch (Exception) { return false; }
                    return true;

                default:
                    callingForm.Refresh();  // this should not happen
                    return false;
            }
        }

        private bool ValidCofferPosition(Point ptThisFloorTile)
        {   // valid if it has 4 'walls' around it -> THIS IS THE ONLY TIME ITS OK TO BE NEXT TO A DOOR
            // valid if it has 3 walls around it
            // valid if it has 2 'connected' walls (not parallel) and can walk around
            // valid if it has 1 wall and can walk around in two enuDir e.g. west wall walkaround NE+SE, north wall walkaround SE+SW
            //
            // count the number of walls around the floortile
            Point udrTestFloorTile = ptThisFloorTile;
            int intNumWalls = 0;
            string strWalls = "";
            if (udrWalls[udrTestFloorTile.X, udrTestFloorTile.Y].H == wallTypes.no_Wall)
                strWalls += "0";
            else
            {
                strWalls += (udrWalls[udrTestFloorTile.X, udrTestFloorTile.Y].H == wallTypes.door ? "2" : "1");
                intNumWalls++;
            }

            udrTestFloorTile = callingForm.cLibHelper.movePixel(udrTestFloorTile, enuDir.east);
            if (udrWalls[udrTestFloorTile.X, udrTestFloorTile.Y].V == wallTypes.no_Wall)
                strWalls += "0";
            else
            {
                strWalls += (udrWalls[udrTestFloorTile.X, udrTestFloorTile.Y].V == wallTypes.door ? "2" : "1");
                intNumWalls++;
            }

            udrTestFloorTile = callingForm.cLibHelper.movePixel(udrTestFloorTile, enuDir.southwest);
            if (udrWalls[udrTestFloorTile.X, udrTestFloorTile.Y].H == wallTypes.no_Wall)
                strWalls += "0";
            else
            {
                strWalls += (udrWalls[udrTestFloorTile.X, udrTestFloorTile.Y].H == wallTypes.door ? "2" : "1");
                intNumWalls++;
            }

            udrTestFloorTile = callingForm.cLibHelper.movePixel(udrTestFloorTile, enuDir.north);
            if (udrWalls[udrTestFloorTile.X, udrTestFloorTile.Y].V == wallTypes.no_Wall)
                strWalls += "0";
            else
            {
                strWalls += (udrWalls[udrTestFloorTile.X, udrTestFloorTile.Y].V == wallTypes.door ? "2" : "1");
                intNumWalls++;
            }

            if (strWalls.Contains("2") && intNumWalls != 4)
                return false;

            switch (intNumWalls)
            {
                case 0: // valid if can go around all corners
                    return (CanWalkAround(ptThisFloorTile, enuDir.northeast)
                            && CanWalkAround(ptThisFloorTile, enuDir.northwest)
                            && CanWalkAround(ptThisFloorTile, enuDir.southwest)
                            && CanWalkAround(ptThisFloorTile, enuDir.southeast));

                case 1:
                    switch (strWalls.IndexOf("1"))
                    {
                        case 0: // wall on the north side of this tile
                            // must walk around both SE + SW
                            return (CanWalkAround(ptThisFloorTile, enuDir.southeast)
                                    && CanWalkAround(ptThisFloorTile, enuDir.southwest));

                        case 1: // wall to the east of this tile
                            // must walk around both NW + SW
                            return (CanWalkAround(ptThisFloorTile, enuDir.northwest)
                                    && CanWalkAround(ptThisFloorTile, enuDir.southwest));

                        case 2: // wall on the south side of this tile
                            // must walk around both NW + NE
                            return (CanWalkAround(ptThisFloorTile, enuDir.northwest)
                                   && CanWalkAround(ptThisFloorTile, enuDir.northeast));

                        case 3: // wall to the west of this tile
                            // must walk around both NE + SE
                            return (CanWalkAround(ptThisFloorTile, enuDir.northeast)
                                   && CanWalkAround(ptThisFloorTile, enuDir.southeast));

                        default:
                            callingForm.Refresh(); // this should not happen
                            break;
                    }
                    break;

                case 2:
                    if (strWalls.Contains("101")) // two parallel walls
                        return false;

                    if (string.Compare(strWalls, "1100") == 0)
                    {// walls N+E -> must walk around SW
                        return CanWalkAround(ptThisFloorTile, enuDir.southwest);
                    }
                    else if (string.Compare(strWalls, "0110") == 0)
                    { // walls E+S -> must walk around NW
                        return CanWalkAround(ptThisFloorTile, enuDir.northwest);
                    }
                    else if (string.Compare(strWalls, "0011") == 0)
                    { // walls S+W -> must walk around NE
                        return CanWalkAround(ptThisFloorTile, enuDir.northeast);
                    }
                    else if (string.Compare(strWalls, "1001") == 0)
                    { // walls N+W -> must walk around SE
                        return CanWalkAround(ptThisFloorTile, enuDir.southeast);
                    }
                    else
                        callingForm.Refresh(); // this should not happen
                    break;

                case 3:
                    return true;

                case 4: // a 'closet' with a door
                    return true;

                default:
                    callingForm.Refresh(); /// this should not happen
                    break;
            }
            return false;
        }

        public bool FindValidPositionsToPlaceCofferAndStairs()
        {
            // find all possible places where the coffer can be placed in the room
            Point ptThisFloorTile;
            for (int intX = 0; intX < callingForm.szRoom.Width; intX++)
                for (int intY = 0; intY < callingForm.szRoom.Height; intY++)
                {
                    ptThisFloorTile = new Point(intX, intY);
                    if (ValidCofferPosition(ptThisFloorTile))
                        strValidPositions += callingForm.cLibHelper.getFloorTileID(ptThisFloorTile);
                }
            string strSampleFloorTileID = callingForm.cLibHelper.getFloorTileID(new Point(0, 0));
            int intNumPlacesFound = strValidPositions.Length / strSampleFloorTileID.Length;
            return (intNumPlacesFound > 1);
        }

        */
        #endregion

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Christ Kennedy
CEO unemployable
Canada Canada
Christ Kennedy, published his fourth novel "Cleats of the Counter Revolution" in the summer of 2010. He grew up in the suburbs of Montreal and is a bilingual Quebecois with a bachelor’s degree in computer engineering from McGill University and is currently walking across ontario plotting a new novel, far away from any computer.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150331.1 | Last Updated 27 Jan 2010
Article Copyright 2010 by Christ Kennedy
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid