Click here to Skip to main content
15,886,664 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.5K   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.
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;

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Xml.Serialization;
using System.Xml;

namespace IceCream
{
    public static class IceCreamExtensions 
    {
        #if WINDOWS
        public static void AppendChildIfNotNull(this XmlNode node, XmlNode childNode)
        {
            if (childNode != null)
            {
                node.AppendChild(childNode);
            }
        }
        #endif

        public static Vector2 GetSide(this Vector2 vector2)
        {
            return new Vector2(-vector2.Y, vector2.X);
        }

        public static float Angle(this Vector2 vector2)
        {
            return (float)Math.Atan2((float)vector2.Y, (float)vector2.X);
        }

        public static Vector2 Size(this Texture2D tex)
        {
            return new Vector2(tex.Width, tex.Height);
        }

        public static Vector3 ToVector3(this Vector2 vector2)
        {
            Vector3 vector3 = new Vector3();
            vector3.X = vector2.X;
            vector3.Y = vector2.Y;
            return vector3;
        }

        public static Vector2 ToVector2(this Vector3 vector3)
        {
            return new Vector2(vector3.X, vector3.Y);
        }

        /// <summary>
        /// Checks if a float value is equal to another value within a given threshold limit, with extremes excluded
        /// </summary>
        /// <param name="comparisonValue">The value to compare to</param>
        /// <param name="threshold">The thresold above and below the comparaison value</param>
        /// <returns>True if the value is contained within (comparisonValue-threshold and comparisonValue+threshold)</returns>
        public static bool IsWithinValue(this float value, float comparisonValue, float threshold)
        {
            if (value < comparisonValue + threshold && value > comparisonValue - threshold)
            {
                return true;
            }
            return false;
        }
		
		#if !REACH
        /// <summary>
        /// Returns true if the PlayerIndex is allowed to purchase content from the marketplace
        /// </summary>
        public static bool CanBuyGame(this PlayerIndex player)
        {
            Microsoft.Xna.Framework.GamerServices.SignedInGamer gamer = Microsoft.Xna.Framework.GamerServices.Gamer.SignedInGamers[player];
            if (gamer == null)
            {
                return false;
            }
            return gamer.Privileges.AllowPurchaseContent;
        }
		#endif
    }
}

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