public MainWindow() { InitializeComponent(); // load Jared's Procreate software ControlPoint = new ControlPoint(); // bind the level data to the application LevelElements.ItemsSource = ControlPoint.Level.Elements; // set the algorithm type values for the combo box MethodAlgorithm.ItemsSource = ControlPoint.Algorithms; // default focused method // bind the method name data to the application // default focused method and game object FocusedMethod = ControlPoint.MethodFactory.CreateMethod(); MethodName.DataContext = FocusedMethod; FocusedGameObject = ControlPoint.GameObjectFactory.CreateGameObject(); // bind game object attribute data to the application GameObjectName.DataContext = FocusedGameObject; GameObjectType.DataContext = FocusedGameObject; GameObjectImagePath.DataContext = FocusedGameObject; GameObjectAppearRate.DataContext = FocusedGameObject; GameObjectPreview.DataContext = FocusedGameObject; // bind the generator's lists GeneratorMethodList.ItemsSource = ControlPoint.Generator.Methods; }
public LevelElement(Generation.GameObject toConvert) { Name = toConvert.Name; Type = toConvert.Type; ImagePath = toConvert.ImagePath; Image = new Image(); BitmapImage bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.UriSource = new Uri(toConvert.ImagePath); bitmap.DecodePixelWidth = Procreate.ControlPoint.GridWidth / Procreate.ControlPoint.LevelWidth; bitmap.EndInit(); Image.Source = bitmap; }
public override void Generate() { // do all the pre-algorithms foreach (Algorithm algorithm in PreAlgorithms) { algorithm.Generate(); } Level.Level level = Procreate.MainWindow.ControlPoint.Level; Generation.GameObject wall = new Generation.GameObject(WallDummy, Level.Level.WallImagePath, 50); Generation.GameObject floor = new Generation.GameObject(FloorDummy, Level.Level.FloorImagePath, 50); // iterate for (int iteration = 0; iteration < IterationCount; ++iteration) { for (int i = 0; i < level.Elements.Count(); ++i) { for (int j = 0; j < level.Elements[i].Count(); ++j) { // set the element to a wall if most of its neighbours are walls // otherwise it's in a grass area, so make it grass int wallTally = 0; int requiredWalls = 5; for (int y = -1; y <= 1; ++y) { for (int x = -1; x <= 1; ++x) { int rowIndex = i + y; int colIndex = j + x; // require less neighbour walls if this element is a corner or border if (rowIndex < 0 || rowIndex >= level.Elements.Count() || colIndex < 0 || colIndex >= level.Elements[i].Count()) { --requiredWalls; } else { // the neighbour exists - so use it Level.LevelElement element = level.Elements[rowIndex][colIndex]; if (element.Name == WallDummy) { wallTally++; } } } } if (wallTally >= requiredWalls) { level.Elements[i][j] = wall; } else { level.Elements[i][j] = floor; } } } } }
private void NewGameObjectButton_Click(object sender, RoutedEventArgs e) { // create a new game object FocusedGameObject = ControlPoint.GameObjectFactory.CreateGameObject(); }