Click here to Skip to main content
15,894,540 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.8K   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 System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
using IceCream;
using IceCream.Drawing;
using IceCream.SceneItems;
using MilkshakeLibrary;
using Milkshake.SelectorDialogs;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using XPTable;
using XPTable.Models;
using Rectangle = Microsoft.Xna.Framework.Rectangle;
using Point = Microsoft.Xna.Framework.Point;
using XnaColor = Microsoft.Xna.Framework.Color;

namespace Milkshake.Editors.TileSheetEditor
{
    public partial class TileSheetEditor : SceneItemEditor
    {
        public static TileSheetEditor Instance;

        public override SceneItem SceneItem
        {
            get
            {
                return base.SceneItem;
            }
            set
            {
                base.SceneItem = value;                
            }
        }

        internal TileSheet TileSheet
        {
            get;
            set;
        }


        private int _selectedBrushTile = 0;
        internal int SelectedBrushTile
        {
            get { return _selectedBrushTile; }
            set { _selectedBrushTile = value; }
        }


        public TileSheetEditor()
        {
            InitializeComponent();
            this.TileSheet = new TileSheet();
            TileSheetEditor.Instance = this;
        }

        private void TileGridEditor_Load(object sender, EventArgs e)
        {         
            labelTextureName.Text = TileSheet.Material.ToString();        
            checkBoxUseSafeBorder.Checked = TileSheet.UseTilingSafeBorders;
            textBoxTileWidth.Text = TileSheet.TileSize.X.ToString(CultureInfo.InvariantCulture);
            textBoxTileHeight.Text = TileSheet.TileSize.Y.ToString(CultureInfo.InvariantCulture);
        }        

        #region Properties tab event

        private void buttonSelectTexture_Click(object sender, EventArgs e)
        {
            MaterialSelectorDialog materialSelectorDialog = new MaterialSelectorDialog();
            materialSelectorDialog.SelectedMaterial = this.TileSheet.Material;
            materialSelectorDialog.ShowLocalTextures = ItemIsLocal;
            if (materialSelectorDialog.ShowDialog() == DialogResult.OK)
            {
                this.TileSheet.Material = materialSelectorDialog.SelectedMaterial;                                
                labelTextureName.Text = materialSelectorDialog.SelectedMaterial.ToString();
            }
        }

        private void checkBoxUseSafeBorder_CheckedChanged(object sender, EventArgs e)
        {
            this.TileSheet.UseTilingSafeBorders = checkBoxUseSafeBorder.Checked;
        }

        private void textBoxTileWidth_Validated(object sender, EventArgs e)
        {
            try
            {
                int newW = int.Parse(textBoxTileWidth.Text, System.Globalization.CultureInfo.InvariantCulture);
                this.TileSheet.TileSize = new Point(newW, this.TileSheet.TileSize.Y);
            }
            catch (Exception ex)
            {
                if (ex != null)
                {
                    textBoxTileWidth.Text = this.TileSheet.TileSize.X.ToString(CultureInfo.InvariantCulture);
                }
            }
        }

        private void textBoxTileHeight_Validated(object sender, EventArgs e)
        {
            try
            {
                int newH = int.Parse(textBoxTileHeight.Text, System.Globalization.CultureInfo.InvariantCulture);
                this.TileSheet.TileSize = new Point(this.TileSheet.TileSize.X, newH);
            }
            catch (Exception ex)
            {
                if (ex != null)
                {
                    textBoxTileHeight.Text = this.TileSheet.TileSize.Y.ToString(CultureInfo.InvariantCulture);
                }
            }
        }      
 
        #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)


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