Click here to Skip to main content
15,892,005 members
Articles / Mobile Apps / Windows Phone 7

BounceBall - XNA Farseer Magic

Rate me:
Please Sign up or sign in to vote.
4.97/5 (72 votes)
12 Apr 2011CPOL62 min read 194.6K   19K   119  
In this article we are going to develop a game using Farseer Physics Engine and XNA for Windows Phone 7. This article provides you base for your games to make game development easy and fast.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace LevelEditor
{
    /// <summary>
    /// Interaction logic for LevelData.xaml
    /// </summary>
    public partial class LevelData : Window
    {
        public delegate void SaveLevel(Level lvl);
        public SaveLevel OnSaveLevel;

        private Level lvlData;

        public LevelData()
        {
            InitializeComponent();
            lvlData = new Level();
            lvlData.Height = 480;
            this.DataContext = lvlData;

            //Backgrounds
            cboBakcground.ItemsSource = Enum.GetValues(typeof(BackgroundType));
            cboBakcground.SelectedIndex = 0;
        }
        public LevelData(Level lvlData)
            : this()
        {
            this.DataContext = lvlData;
            this.lvlData = lvlData;
            this.lblTitle.Text = "EDIT LEVEL";
        }

        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            lvlData.BGType = (BackgroundType)Enum.Parse(typeof(BackgroundType), cboBakcground.SelectedItem.ToString());
            OnSaveLevel(lvlData);
            this.Close();
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void txtWidth_LostFocus(object sender, RoutedEventArgs e)
        {
            int Columns = 0;
            if (Int32.TryParse(txtWidth.Text.Trim(), out Columns))
            {
                lblColumns.Text = ((int)(Columns / 32)).ToString();
                txtWidth.Text = (((int)(Columns / 32)) * 32).ToString();
            }
        }

        private void cboBakcground_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            lvlData.BGType = (BackgroundType)Enum.Parse(typeof(BackgroundType), cboBakcground.SelectedItem.ToString());
        }
    }
}

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
CEO Veloxcore
India India
Love Programming... and games. You can find latest about me over http://www.veloxcore.com/

Comments and Discussions