Silverlight Game Tutorials

by Cameron Albert 22. August 2007 11:17
I found a good resource for creating games in Silverlight at SilverLight Games 101. Some basic tutorials and a game loop and key handler classes for use in your own projects. I am currently working on making some small Silverlight games and will eventually write a PBBG in Silverlight. I find it a little easier to use than Flash, escpecially the 1.1 Alpha since I can code in C# instead of JavaScript.

Tags: , , ,

Game Development

X, Y, Z Coordinate Struct for .NET PBBGs

by Cameron Albert 16. July 2007 15:18

I created a struct in C# for storing the X, Y and Z coordinates for characters, objects and rooms within my current PBBG project Perenthia. The struct, called Vector, is serializable and can be used as the key value in a sorted or generic dictionary. Here is the code for the class.

[Serializable]
    public struct Vector : IEquatable<Vector>
    {
        public static readonly Vector Empty = new Vector(0, 0, 0);

        public Vector(int x, int y, int z)
        {
            _x = x;
            _y = y;
            _z = z;
        }

        public void SetLocation(int x, int y)
        {
            this.SetLocation(x, y, this.Z);
        }

        public void SetLocation(int x, int y, int z)
        {
            _x = x;
            _y = y;
            _z = z;
        }

        public Vector Copy()
        {
            return new Vector(this.X, this.Y, this.Z);
        }

        public static Vector FromString(string value)
        {
            if (!String.IsNullOrEmpty(value))
            {
                string[] parts = value.Split(',');
                if (parts != null && parts.Length == 3)
                {
                    int x, y, z;
                    if (Int32.TryParse(parts[0], out x))
                    {
                        if (Int32.TryParse(parts[1], out y))
                        {
                            if (Int32.TryParse(parts[2], out z))
                            {
                                return new Vector(x, y, z);
                            }
                        }
                    }
                }
            }
            return Vector.Empty;
        }

        #region GetHashCode
        public override int GetHashCode()
        {
            // The Y value should always come first in any kind of sorting, comparison or hashing operations
            // followed by X and then Z because typical loops would start with the Y value.
            return (this.Y.GetHashCode() + this.X.GetHashCode() + this.Z.GetHashCode());
        }
        #endregion

        #region Equals
        public bool Equals(Vector obj)
        {
            // The Y value should always come first in any kind of sorting, comparison or hashing operations
            // followed by X and then Z because typical loops would start with the Y value.
            if (obj != null)
            {
                if (obj.Y == this.Y)
                {
                    if (obj.X == this.X)
                    {
                        return (obj.Z == this.Z);
                    }
                }
            }
            return false;
        }

        public override bool Equals(object obj)
        {
            if (obj is Vector)
            {
                return this.Equals((Vector)obj);
            }
            return base.Equals(obj);
        }
        #endregion

        #region ToString
        public override string ToString()
        {
            return String.Format("{0},{1},{2}", _x, _y, _z);
        }
        public string ToString(bool forDisplay)
        {
            if (forDisplay)
            {
                return String.Format("X = {0}, Y = {1}, Z = {2}", _x, _y, _z);
            }
            return this.ToString();
        }
        #endregion

        #region Operators
        public static Vector operator +(Vector v1, Vector v2)
        {
            return new Vector(v1.X + v2.X, v1.Y + v2.Y, v1.Z + v2.Z);
        }

        public static Vector operator -(Vector v1, Vector v2)
        {
            return new Vector(v1.X - v2.X, v1.Y - v2.Y, v1.Z - v2.Z);
        }

        public static bool operator ==(Vector v1, Vector v2)
        {
            return v1.Equals(v2);
        }

        public static bool operator !=(Vector v1, Vector v2)
        {
            return (!v1.Equals(v2));
        }

        public static bool operator >=(Vector v1, Vector v2)
        {
            // The Y value should always come first in any kind of sorting, comparison or hashing operations
            // followed by X and then Z because typical loops would start with the Y value.
            if (v1.Y >= v2.Y)
            {
                if (v1.X >= v2.X)
                {
                    return (v1.Z >= v2.Z);
                }
            }
            return false;
        }

        public static bool operator <=(Vector v1, Vector v2)
        {
            // The Y value should always come first in any kind of sorting, comparison or hashing operations
            // followed by X and then Z because typical loops would start with the Y value.
            if (v1.Y <= v2.Y)
            {
                if (v1.X <= v2.X)
                {
                    return (v1.Z <= v2.Z);
                }
            }
            return false;
        }
        #endregion

        #region Properties
        private int _x;

        public int X
        {
            get { return _x; }
            set { _x = value; }
        }

        private int _y;

        public int Y
        {
            get { return _y; }
            set { _y = value; }
        }

        private int _z;

        public int Z
        {
            get { return _z; }
            set { _z = value; }
        }
        #endregion

        #region IEquatable<Vector> Members

        bool IEquatable<Vector>.Equals(Vector other)
        {
            return this.Equals(other);
        }

        #endregion
    }

Tags: , , , ,

ASP.NET Development | Game Development | General

Other Views on the Future of Web Gaming

by Cameron Albert 16. July 2007 12:52

Open Bracket has a great article on the future of web gaming. The article mentions that game play should be the core of any PBBG game design rather than the UI. While game play and player interactivity should be the core focus the user interface and overall look and feel of your site is equally important. How a game looks and how easy it is to navigate lends a lot when it comes to player perception. If your site and game look professional it will be perceived as professional. If the game is easy to navigate and understand it will be perceived as professional, that is just the way of it. Another thing to consider is profitability. If you wish to make a profit on your games then you will need to design with marketing and profitability in mind which there again you will need a professional, user friendly site.

In short, while game play is core, usability and a professional feel are equally important in the business of web games. 

Tags: , ,

Game Development

PBBG Mapper

by Cameron Albert 10. July 2007 17:44
I've been working on a tile mapping tool I call PBBG Mapper here lately while working on my persistent browser based games. The tool is a Windows based application written in C# 2.0 and will include some plugin functionality so that other developers can extend it an customize it. The progam saves all tile maps as XML for easy portability and works pretty well. I will post some screenshots once I get it into a full working version.

Powered by BlogEngine.NET 1.5.0.7
Modified Theme by Mads Kristensen

About the Author

CameronAlbert.com I am Senior Software Development Consultant specializing in Silverlight, WPF and the Microsoft .NET Framework. 

I have released an iPhone game called the Adventures of Puppyman that was built using ExEn and am currently working on a WP7 and iPhone version of Perenthia soon to be released.

View Cameron Albert's profile on LinkedIn
See how we're connected

Follow cameronalbert on Twitter

 

Recommended Books

Silverlight 4 Business Application Development - Beginner's Guide:

http://www.packtpub.com/microsoft-silverlight-4-business-application-development-beginners-guide/book

Microsoft Silverlight 4 Business Application Development: Beginner’s Guide