Example #1
0
        public UI()
        {
            // Sla de UI thread dispatcher op
            _dispatcher = Dispatcher.CurrentDispatcher;

            // Laad alle achtergronden in
            List<ImageBrush> backgrounds = new List<ImageBrush>();
            for (int i = 1; i <= 7; i++)
            {
                backgrounds.Add(new ImageBrush(new BitmapImage(new Uri(@"pack://application:,,,/Resources/Backgrounds/" + i + ".png"))));
            }
            _backgrounds = backgrounds.ToArray();

            // Maak de main window aan
            _mainWindow = new MainWindow();
            _mainWindow.MainCanvas.Width = CONSTANTS.CANVAS_WIDTH;
            _mainWindow.MainCanvas.Height = CONSTANTS.CANVAS_HEIGHT;
            _mainWindow.Show();

            // Registreer events
            _mainWindow.Closing += Window_Closing;
            _mainWindow.MainCanvas.MouseDown += MainCanvas_MouseDown;
            _mainWindow.NewGame.Click += NewGame_Click;
            _mainWindow.Exit.Click += Exit_Click;

            // Maak de gameController aan
            _game = new Game(this);

            _instance = this;
            setBackground(-1);
        }
Example #2
0
        // --------------------------------------------------------- CTOR --------------------------------------------------------- //
        public Game(UI ui)
        {
            _ui = ui;

            // Readonly velden instellen.
            _tickTime = 1.0 / Stopwatch.Frequency;

            // Bereken de minimale frame tijd
            if (CONSTANTS.UPDATES_PER_SECOND > 0)
                minTicksPerUpdate = Stopwatch.Frequency / CONSTANTS.UPDATES_PER_SECOND;

            if (CONSTANTS.DISPLAY_FPS > 0)
                minTicksPerDraw = Stopwatch.Frequency / CONSTANTS.DISPLAY_FPS;

            // Factory registraties
            #region Units
            UnitFactories.Units.Register("chicken", () => new Chicken("chicken"));
            UnitFactories.Units.Register("bunny", () => new Bunny("bunny"));
            #endregion

            #region UnitStates
            // Shared states
            UnitFactories.States.Register(default(string), "dead", () => new DeadUnitState("dead"));
            UnitFactories.States.Register(default(string), "endlevel", () => new DeadUnitState("endlevel", 0.5, 0.5));

            // Chicken states
            UnitFactories.States.Register("chicken", "alive", () => new AliveUnitState("alive"));
            UnitFactories.States.Register("chicken", "fleeing", () => new FleeingUnitState("fleeing"));

            // Bunny states
            UnitFactories.States.Register("bunny", "alive", () => new AliveBunnyState("alive"));
            UnitFactories.States.Register("bunny", "fleeing", () => new FleeingBunnyState("fleeing"));
            #endregion

            #region Unit Move Behaviors
            // Shared move behaviors
            UnitFactories.MoveBehaviors.Register(default(string), "dead", () => new DeadUnitMoveBehavior(900, 500));
            UnitFactories.MoveBehaviors.Register(default(string), "endlevel", () => new DeadUnitMoveBehavior(900, 500));

            // Chicken move behaviors
            UnitFactories.MoveBehaviors.Register("chicken","alive", () => new RandomFlightMoveBehavior(900, 900, 750, 750));
            UnitFactories.MoveBehaviors.Register("chicken","fleeing", () => new FlyingFleeMoveBehavior(1000, -100, 750, 500));

            // Bunny move behaviors
            UnitFactories.MoveBehaviors.Register("bunny", "alive", () =>
            {
                if (Random.Next(2) == 0) // 50% kans op jump over mouse behavior
                    return new JumpOverMouseMoveBehavior(0, 900, 1000, 500, 400, 0);
                return new GravityMoveBehavior(0, 900, 1000, 500, 400, 0, 100);
            });
            UnitFactories.MoveBehaviors.Register("bunny", "fleeing", () => new RunningFleeMoveBehavior(0, 900, 500, 500, 400, 0));
            #endregion

            #region Unit Draw Behaviors
            // Chicken draw behaviors
            UnitFactories.DrawBehaviors.Register("chicken", "alive", () => new SpriteSheetDrawBehavior("ChickenFly.png", 0.07, 0, true));
            UnitFactories.DrawBehaviors.Register("chicken", "fleeing", () => new SpriteSheetDrawBehavior("ChickenFly.png", 0.07, 0, true));
            UnitFactories.DrawBehaviors.Register("chicken", "dead", () => new SpriteSheetDrawBehavior("ChickenDead.png", 0.07, 12.5, true));
            UnitFactories.DrawBehaviors.Register("chicken", "endlevel", () => new SpriteSheetDrawBehavior("ChickenDead.png", 0.07, 12.5, true));

            // Bunny draw behaviors
            UnitFactories.DrawBehaviors.Register("bunny", "alive", () => new SpriteSheetDrawBehavior("BunnyRun.png", 0.075, 0, true));
            UnitFactories.DrawBehaviors.Register("bunny", "fleeing", () => new SpriteSheetDrawBehavior("BunnyRun.png", 0.075, 0, true));
            UnitFactories.DrawBehaviors.Register("bunny", "jumping", () => new SpriteSheetDrawBehavior("BunnyJump.png", 0.15, 0, false));
            UnitFactories.DrawBehaviors.Register("bunny", "dead", () => new SpriteSheetDrawBehavior("BunnyDead.png", 0.1, 0, false));
            UnitFactories.DrawBehaviors.Register("bunny", "endlevel", () => new SpriteSheetDrawBehavior("BunnyDead.png", 0.1, 0, false));
            #endregion
        }