Click here to Skip to main content
15,896,063 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 67.3K   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 IceCream;
using IceCream.SceneItems;
using IceCream.Drawing;
using Milkshake.Editors;

namespace Milkshake.SelectorDialogs
{
    public partial class TileSheetSelectorDialog : Form
    {
        #region Fields

        private TileSheet _selectedTileSheet;
        private bool _showLocalTextures = false;

        #endregion

        public bool ShowLocalTextures
        {
            get { return _showLocalTextures; }
            set { _showLocalTextures = value;  }
        }

        public TileSheet TileSheet
        {
            get { return _selectedTileSheet; }
            set { _selectedTileSheet = value; }
        }

        public TileSheetSelectorDialog()
        {
            InitializeComponent();            
        }

        private void LoadTreeNodeData(TreeNode rootNode, bool isGlobal)
        {
            rootNode.Nodes.Clear();
            SceneBase sceneBase = SceneManager.GlobalDataHolder;
            if (isGlobal == false)
            {
                sceneBase = SceneManager.ActiveScene;
            }
            /*
            foreach (SceneItem item in sceneBase.TemplateItems)
            {
                if (item is TileSheet)
                {
                    TreeNode newNode = rootNode.Nodes.Add(item.Name + "Node" + item.Name,
                        item.Name, "color_swatch.png", "color_swatch.png");
                    newNode.Tag = (TileSheet)item;
                }
            }*/
        }

        private void TextureSelectorDialog_Load(object sender, EventArgs e)
        {
            LoadTreeNodeData(treeViewTileSheets.Nodes[0], true);
            LoadTreeNodeData(treeViewTileSheets.Nodes[1], false);
        }
        
        private void SelectTileSheet(TileSheet tileSheet)
        {
            _selectedTileSheet = tileSheet;
            materialPreviewControl.Texture = tileSheet.Material.Texture;          
        }

        private void treeViewTextures_AfterSelect(object sender, TreeViewEventArgs e)
        {
            // if it's a material
            if (e.Node.Tag is TileSheet)
            {
                SelectTileSheet(e.Node.Tag as TileSheet);
            }
        }

        private void treeViewMaterials_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            // if it's a material
            if (e.Node.Tag is Material)
            {
                // direct close
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }
    } 
}

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