Click here to Skip to main content
15,889,096 members
Articles / Game Development

Learning XNA 2D Engine IceCream With 1945 Demo Project

Rate me:
Please Sign up or sign in to vote.
5.00/5 (13 votes)
8 Aug 2012CPOL16 min read 66.6K   2.3K   51  
IceCream1945 is a demonstration of XNA and the IceCream 2D library in a 2D top-down scrolling shooter similar to 1942 for the NES.
#if XNATOUCH
using XnaTouch.Framework;
using XnaTouch.Framework.Audio;
using XnaTouch.Framework.Content;
using XnaTouch.Framework.GamerServices;
using XnaTouch.Framework.Graphics;
using XnaTouch.Framework.Input;
using XnaTouch.Framework.Media;
using XnaTouch.Framework.Net;
using XnaTouch.Framework.Storage;
#else
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;

using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


#endif

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;

namespace IceCream.SceneItems
{
    public class Polygon
    {
        /*
        #region static

        public const String NULL_VALUE = "n";

        public static Polygon FromRectangle(Rectangle rect)
        {
            Vertices vertices = new Vertices(4);
            vertices.Add(new Vector2(rect.Left, rect.Top));
            vertices.Add(new Vector2(rect.Right, rect.Top));
            vertices.Add(new Vector2(rect.Right, rect.Bottom));
            vertices.Add(new Vector2(rect.Left, rect.Bottom));
            return new Polygon(vertices);
        }

        public static Polygon FromVector2List(List<Vector2> list)
        {
            Vertices vertices = new Vertices(list.Count);
            vertices.AddRange(list);
            return new Polygon(vertices);
        }

        public static Polygon FromString(String polygonData)
        {
            return FromString(polygonData, Vector2.Zero);
        }

        public static Polygon FromString(String polygonData, Vector2 offset)
        {
            if (String.IsNullOrEmpty(polygonData) || polygonData == NULL_VALUE)
            {
                return null;
            }
            Polygon poly = new Polygon();
            char[] sep = { ';' };
            String[] splitted = polygonData.Split(sep);
            foreach (String v in splitted)
            {
                char[] space_sep = { ' ' };
                String[] values = v.Split(space_sep);
                if (values.Length == 2)
                {
                    Vector2 vector2 = new Vector2(float.Parse(values[0], CultureInfo.InvariantCulture),
                        float.Parse(values[1], CultureInfo.InvariantCulture)) + offset;
                    poly.Vertices.Add(vector2);
                }
            }
            poly.InitialCentroid = poly.Vertices.GetCentroid();
            return poly;
        }

        #endregion

        public Vertices Vertices { get; set; }
        public Vector2 InitialCentroid { get; set; }

        public Polygon()
        {
            this.Vertices = new Vertices();            
        }

        public Polygon(Vertices vertices)
        {
            this.Vertices = vertices;
            this.InitialCentroid = vertices.GetCentroid();
        }

        public override string ToString()
        {
            String output = "";
            for (int i = 0; i < this.Vertices.Count; i++)
            {
                if (i > 0)
                {
                    output += ";";
                }
                Vector2 vertice = this.Vertices[i];
                output += vertice.X.ToString(CultureInfo.InvariantCulture) + " " 
                    + vertice.Y.ToString(CultureInfo.InvariantCulture); 
            }
            return output;
        }

        public Vertices GetHFlipVertices()
        {
            Vertices hVerts = new Vertices(this.Vertices.Count);
            foreach (Vector2 vertice in this.Vertices)
            {
                Vector2 hFlip = new Vector2(-vertice.X, vertice.Y);
                hVerts.Add(hFlip);
            }
            return hVerts;
        }

        public Vertices GetVFlipVertices()
        {
            Vertices vVerts = new Vertices(this.Vertices.Count);
            foreach (Vector2 vertice in this.Vertices)
            {
                Vector2 vFlip = new Vector2(vertice.X, -vertice.Y);
                vVerts.Add(vFlip);
            }
            return vVerts;
        }

        public Vertices GetBothFlipVertices()
        {
            Vertices vVerts = new Vertices(this.Vertices.Count);
            foreach (Vector2 vertice in this.Vertices)
            {
                Vector2 vFlip = new Vector2(-vertice.X, -vertice.Y);
                vVerts.Add(vFlip);
            }
            return vVerts;
        }
        */
    }
}

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)


Written By
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions