Saturday, March 5, 2011

7DRL Day 1

   I have mostly just been setting up my project so far. I have the '@' walking around the screen at least. Most of my time was taken by figuring out Malison which is a C# terminal graphics library similar to curses. I also set up a few classes including an important one that will be of much help. It is a Direction class that I basically took from These Two articles on the blog "Writing Kode". Here is the Direction class I have:
    class Direction
    {
        private int Index, DX, DY;
        private string Name;
        public static readonly Direction North = new Direction() { Index = 0, DX = 0, DY = -1, Name = "North" };
        public static readonly Direction East = new Direction() { Index = 1, DX = 1, DY = 0, Name = "East" };
        public static readonly Direction South = new Direction() { Index = 2, DX = 0, DY = 1, Name = "South" };
        public static readonly Direction West = new Direction() { Index = 3, DX = -1, DY = 0, Name = "West" };
        public static readonly Direction Northeast = new Direction() { Index = 4, DX = 1, DY = -1, Name = "Norhteast" };
        public static readonly Direction Southeast = new Direction() { Index = 5, DX = 1, DY = 1, Name = "Southeast" };
        public static readonly Direction Northwest = new Direction() { Index = 6, DX = -1, DY = -1, Name = "Northwest" };
        public static readonly Direction Southwest = new Direction() { Index = 7, DX = -1, DY = 1, Name = "Southwest" };
        public Vec ApplyTransform(Vec Location)
        {
            return new Vec(Location.X + DX, Location.Y + DY);
        }
        public Direction Inverse
        {
            get
            {
                switch (Name)
                {
                    case "North":
                        return Direction.South;
                    case "Northeast":
                        return Direction.Southwest;
                    case "East":
                        return Direction.West;
                    case "Southeast":
                        return Direction.Northwest;
                    case "South":
                        return Direction.North;
                    case "Southwest":
                        return Direction.Northeast;
                    case "West":
                        return Direction.East;
                    case "Northwest":
                        return Direction.Southeast;
                    default:
                        throw new InvalidOperationException();
                }
            }
        }
        public Direction NextPerpendicular
        {
            get
            {
                switch (Name)
                {
                    case "North":
                        return Direction.East;
                    case "Northeast":
                        return Direction.Southeast;
                    case "East":
                        return Direction.South;
                    case "Southeast":
                        return Direction.Southwest;
                    case "South":
                        return Direction.West;
                    case "Southwest":
                        return Direction.Northeast;
                    case "West":
                        return Direction.North;
                    case "Northwest":
                        return Direction.Northeast;
                    default:
                        throw new InvalidOperationException();
                }
            }
        }
        public Direction PreviousPerpendicular
        {
            get
            {
                switch (Name)
                {
                    case "North":
                        return Direction.West;
                    case "Northeast":
                        return Direction.Northwest;
                    case "East":
                        return Direction.North;
                    case "Southeast":
                        return Direction.Northeast;
                    case "South":
                        return Direction.East;
                    case "Southwest":
                        return Direction.Southeast;
                    case "West":
                        return Direction.South;
                    case "Northwest":
                        return Direction.Southwest;
                    default:
                        throw new InvalidOperationException();
                }
            }
        }
        public Direction Next
        {
            get
            {
                switch (Name)
                {
                    case "North":
                        return Direction.Northeast;
                    case "Northeast":
                        return Direction.East;
                    case "East":
                        return Direction.Southeast;
                    case "Southeast":
                        return Direction.South;
                    case "South":
                        return Direction.Southwest;
                    case "Southwest":
                        return Direction.West;
                    case "West":
                        return Direction.Northwest;
                    case "Northwest":
                        return Direction.North;
                    default:
                        throw new InvalidOperationException();
                }
            }
        }
        public Direction Previous
        {
            get
            {
                switch (Name)
                {
                    case "North":
                        return Direction.Northwest;
                    case "Northeast":
                        return Direction.North;
                    case "East":
                        return Direction.Northeast;
                    case "Southeast":
                        return Direction.East;
                    case "South":
                        return Direction.Southeast;
                    case "Southwest":
                        return Direction.South;
                    case "West":
                        return Direction.Southwest;
                    case "Northwest":
                        return Direction.West;
                    default:
                        throw new InvalidOperationException();
                }
            }
        }
    }
   The "Vec" in ApplyTransform is a Point that is special to Malison. By using it I can simply put
Vec a = new Vec(1,0);
Terminal[a].Write("Hello World");
and it will write at 1,0. Vec is nice because you can add it to another so I could do a = a + a; and it would print at 2,0. Points can not be added together so this is quite useful because I can just for movement put Player.Location += Direction.West.ApplyTransform(Player.Location); and it would move the location west. I can do this anytime I need to move something.
   Another useful thing with the Direction class is those things with the switches in them. Direction.Next will get the next clockwise direction so when a monster wants to get to the player if the way is blocked I can easily check other directions. There is also previous, inverse, next perpendicular, and previous perpendicular.
   Of course till I have more than a lame tech demo this is all just hot air but at the least I can fly high in my hot air balloon.

No comments:

Post a Comment