public GameInteractionsSystem(BallSystem ballSystem, KeysSystem keysSystem, StageSystem stageSystem)
    {
        this.ballSystem = ballSystem;
        stageSystem.AddFinishTrigger(this);
        ballSystem.AddBallDestroyer(this);
        keysSystem.AddKeyCollector(this);

        var gamezone = Object.FindObjectOfType <GameZone>();

        finishCollider  = gamezone.FinishTrigger;
        destroyCollider = gamezone.DestroyTrigger;

        handleTriggerEnter += (ball, trigger) =>
        {
            bool isMainTrigger = TestMainTriggers(ball, trigger);
            if (!isMainTrigger)
            {
                onTriggerEnterChain.Handle(ball, trigger);
            }
        };

        handleTriggerExit += (ball, trigger) =>
        {
            onTriggerExitChain.Handle(ball, trigger);
        };
    }
        public void Ball_WallBounceTest()
        {
            // Create ball and systems.
            BallSystem system = CreateSystem();
            Ball       ball   = CreatePlayer(system.World, "Test_1_Ball_1");

            // Set ball offscreen.
            ball.Parent.Position = new Vector2(-100, 300);
            ball.Direction       = new Vector2(80, 120);
            system.Update(0.5f);                                                                                     // Check position.
            Assert.AreEqual(ball.Direction.x, 120, 0.001, "Ball left bounce not resorting to correct direction.");   // Check bouce occured.

            // Set ball offscreen.
            ball.Parent.Position = new Vector2(1300, 300);
            system.Update(0.5f);                                                                                     // Check position.
            Assert.AreEqual(ball.Direction.x, 80, 0.001, "Ball right bounce not resorting to correct direction.");   // Check bouce occured.

            // Set ball offscreen.
            ball.Parent.Position = new Vector2(400, -5);
            system.Update(0.5f);                                                                                     // Check position.
            Assert.AreEqual(ball.Direction.y, 80, 0.001, "Ball top bounce not resorting to correct direction.");     // Check bouce occured.

            // Set ball offscreen.
            ball.Parent.Position = new Vector2(400, 800);
            system.Update(0.5f);                                                                                      // Check position.
            Assert.AreEqual(ball.Direction.y, 120, 0.001, "Ball bottom bounce not resorting to correct direction.");  // Check bouce occured.
        }
Пример #3
0
    private static void AfterSceneLoad()
    {
        // Initialize basic game systems.
        var userInterfaceSystem = new UserInterfaceSystem();
        var controlSystem       = new ControlSystem(resourcesData.gameplaySettings);
        var keysSystem          = new KeysSystem(resourcesData.stagePrefabs);
        var stageSystem         = new StageSystem(resourcesData.stagePrefabs, keysSystem);
        var ballSystem          = new BallSystem(resourcesData.ballPrefabs, stageSystem);
        var gameCurrencySystem  = new GameCurrencySystem(userInterfaceSystem);
        var monetizationSystem  = new MonetizationSystem(resourcesData.monetizationSettings, gameCurrencySystem);
        var shopSystem          = new ShopSystem(resourcesData.shopModel, ballSystem, gameCurrencySystem, monetizationSystem);

        // Initialize gameplay systems.
        var gameInteractionsSystem = new GameInteractionsSystem(ballSystem, keysSystem, stageSystem);
        var gameInterfaceSystem    = new GameInterfaceSystem(stageSystem, gameInteractionsSystem);

        // Register a proxy service for gameplay systems.
        var gameplaySystemsProxy = new GameplaySystemsProxy();

        gameplaySystemsProxy.Add(
            gameInteractionsSystem,
            gameInterfaceSystem);

        // Initialize the state machine system with all dependencies.
        var gameStateMachine = new GameStateMachine(
            gameplaySystemsProxy,
            userInterfaceSystem,
            controlSystem,
            stageSystem,
            ballSystem,
            keysSystem,
            gameCurrencySystem,
            monetizationSystem);

        // Preserve links to game services.
        var storage = new GameObject("[Game Services]").AddComponent <GameServices>();

        storage.Add(
            userInterfaceSystem,
            controlSystem,
            keysSystem,
            stageSystem,
            ballSystem,
            gameCurrencySystem,
            monetizationSystem,
            shopSystem);
        storage.Add(
            gameplaySystemsProxy,
            gameStateMachine);

        // Free the static reference to resources data - it's held by services from now.
        resourcesData = null;

        // Since there is only one scene in the project, we just link this very bootstrap script to the event of reloading scene.
        SceneManager.sceneLoaded += RebootOnNextSceneLoaded;
    }
Пример #4
0
        public GameDev()
        {
            InitializeComponent();

            var radius = 8;

            system    = new BallSystem(500, radius, pictureBox1.Width - radius, pictureBox1.Height - radius);
            canvas    = new Bitmap(pictureBox1.Width, pictureBox1.Height);
            KeyPress += Form1_KeyPress;
        }
        // Create player system and accompanying components.
        private BallSystem CreateSystem()
        {
            SubWorld       world          = new BreakoutWorld(0);
            BallSystem     ballSystem     = new BallSystem(world);
            ColliderSystem colliderSystem = new ColliderSystem(world);

            world.AddSystem(new PowerUpSystem(world));
            world.AddSystem(colliderSystem);
            world.AddSystem(ballSystem);

            return(ballSystem);
        }
        public void Ball_BrickBounceTest()
        {
            // Create ball and systems.
            BallSystem system = CreateSystem();

            system.World.AddSystem(new BrickSystem(system.World));
            Ball     ball     = CreatePlayer(system.World, "Test_3_Ball_1");
            Brick    brick    = CreateBrick(system.World, "Test_3_Brick_1");
            Collider collider = system.World.GetSystem <ColliderSystem>().Get(ball.Parent);

            // Update position for left bounce.
            brick.Parent.Position.x  = 100;
            ball.Parent.Position     = brick.Parent.Position;
            brick.Parent.Position.x -= 32;

            // Add ball-brick collision.
            collider.Colliding = true;
            collider.CollidingWith.Add("Brick");
            collider.CollidedComponents.Add(system.World.GetSystem <ColliderSystem>().Get(brick.Parent));
            system.World.GetSystem <BrickSystem>().Add(brick);

            // Perform collision.
            ball.Direction = new Vector2(120, 80);
            system.Update(0.5f);
            Assert.AreEqual(ball.Direction.x, 80, 0.001, "Ball not left bouncing off brick correctly.");        // Assert bounce occured.

            // Update position for right bounce.
            system.World.GetSystem <BallSystem>().Get(ball.Parent).Parent.Position.x += 100;
            ball.WasCollidingWithBrick = false;

            // Perform collision.
            system.Update(0.5f);
            Assert.AreEqual(ball.Direction.x, 120, 0.001, "Ball not right bouncing off brick correctly.");        // Assert bounce occured.

            // Update position for top bounce.
            system.World.GetSystem <BallSystem>().Get(ball.Parent).Parent.Position.y -= 8;
            system.World.GetSystem <BallSystem>().Get(ball.Parent).Parent.Position.x  = (short)(brick.Parent.Position.x + 24);
            ball.WasCollidingWithBrick = false;

            // Perform collision.
            system.Update(0.5f);
            Assert.AreEqual(ball.Direction.y, 80, 0.001, "Ball not top bouncing off brick correctly.");            // Assert bounce occured.

            // Update position for bottom bounce.
            system.World.GetSystem <BallSystem>().Get(ball.Parent).Parent.Position.y += 24;
            ball.WasCollidingWithBrick = false;

            // Perform collision.
            system.Update(0.5f);
            Assert.AreEqual(ball.Direction.y, 120, 0.001, "Ball not bottom bouncing off brick correctly.");        // Assert bounce occured.
        }
        public void Ball_PlayerBounceTest()
        {
            // Create ball and systems.
            BallSystem system = CreateSystem();
            Ball       ball   = CreatePlayer(system.World, "Test_2_Ball_1");

            // Set up ball-player bounce.
            system.World.GetSystem <ColliderSystem>().Get(ball.Parent).Colliding = true;
            system.World.GetSystem <ColliderSystem>().Get(ball.Parent).CollidingWith.Add("Player");
            system.World.GetSystem <ColliderSystem>().Get(ball.Parent).CollidedComponents.Add(new Collider(new GameEntity("Player", ball.Parent.Position), 128, 16, true));

            // Process bounce.
            ball.Direction = new Vector2(80, 120);
            system.Update(0.5f);

            // Assert bounce sucessfully occured.
            Assert.AreEqual(ball.Direction.y, 120, 0.001, "Ball not bouncing correctly off player.");
        }
Пример #8
0
        /// <summary>
        /// Create the initial Ball.
        /// </summary>
        private void CreateBall()
        {
            // Get Ball and Collider systems.
            BallSystem     ballSystem     = GetSystem <BallSystem>();
            ColliderSystem colliderSystem = GetSystem <ColliderSystem>();

            // Create Ball Entity and Components.
            GameEntity entity = new GameEntity("Ball", new Vector2(300, 600), "Ball");
            Ball       ball   = new Ball(entity)
            {
                Direction = new Vector2(133, 34)
            };
            Collider collider = new Collider(entity, 32, 32, true);

            // Add them to the systems.
            ballSystem.Add(ball);
            colliderSystem.Add(collider);
        }
Пример #9
0
    public void Initialize(ShopModel model, BallSystem ballSystem, GameCurrencySystem gameCurrencySystem, MonetizationSystem monetization)
    {
        this.model              = model;
        this.ballSystem         = ballSystem;
        this.gameCurrencySystem = gameCurrencySystem;
        this.monetization       = monetization;

        int screensCount = model.CatalogScreens.Length;

        scrollIndicatorDisabledColor = scrollIndicatorImage.color;
        scrollIndicators             = new Image[screensCount];
        scrollIndicators[0]          = scrollIndicatorImage;
        for (int i = 1; i < screensCount; i++)
        {
            scrollIndicators[i] = Instantiate(scrollIndicatorImage.gameObject, scrollIndicatorImage.transform.parent).GetComponent <Image>();
        }

        scroller.Initialize(screensCount, DisplayCategory);
    }
Пример #10
0
    public ShopSystem(ShopModel shopModel, BallSystem ballSystem, GameCurrencySystem gameCurrencySystem, MonetizationSystem monetization)
    {
        var shopInterface = Object.FindObjectOfType <ScreensOperator>().GetComponentInChildren <ShopUI>(true);

        shopInterface.Initialize(shopModel, ballSystem, gameCurrencySystem, monetization);
    }
    public GameStateMachine(
        IGameplaySystem gameplayProxy,
        UserInterfaceSystem ui,
        ControlSystem control,
        StageSystem stage,
        BallSystem ball,
        KeysSystem keys,
        GameCurrencySystem currencies,
        MonetizationSystem monetization) : base()
    {
        // Iterate through all states and link UI (and other capable systems) to every state events.
        var allStates = (GameState[])System.Enum.GetValues(typeof(GameState));

        foreach (var state in allStates)
        {
            AddCallbackOnEnter(state, () => ui.OnEnterState(state));
        }

        // Define gameplay initialization callbacks.
        System.Action initFirstSubstageAction   = stage.CreateFirstSubstage;
        System.Action initCurrentSubstageAction = stage.CreateCurrentSubstage;

        initFirstSubstageAction   += ball.SpawnFirstBall;
        initCurrentSubstageAction += ball.SpawnFirstBall;

        // Link gameplay initialization systems to the correct callbacks.
        AddCallbackOnEnter(GameState.StartScreen, initFirstSubstageAction);
        AddCallbackOnEnter(GameState.PreStage, initFirstSubstageAction);
        AddCallbackOnEnter(GameState.Gameplay, control.Reset);

        AddCallbackOnTransition(GameState.NoMoreBalls, GameState.Gameplay, initCurrentSubstageAction);
        AddCallbackOnTransition(GameState.GetExtraBall, GameState.Gameplay, ball.SpawnFirstBall);
        AddCallbackOnTransition(GameState.NextSubstage, GameState.Gameplay, initCurrentSubstageAction);

        // Link currency gain system to the correct callbacks.
        AddCallbackOnEnter(GameState.StageFinished, () =>
        {
            int coinsAmount = monetization.GetCoinsForVictory();
            currencies.SetBuffer(GameCurrency.Coins, coinsAmount);
            ball.SpawnBallsInCollector(coinsAmount);
        });
        AddCallbackOnExit(GameState.BallsSold, () =>
        {
            currencies.AddFromBuffer(GameCurrency.Coins);
            ball.ClearCollector();
        });

        // Link resolutions to the "instant pass" states.
        AddCallbackOnEnter(GameState.GetExtraBall, () => Advance(GameState.Gameplay));
        AddCallbackOnEnter(GameState.NextSubstage, () =>
        {
            bool didPassLastSubstage;
            stage.PassCurrentSubstage(out didPassLastSubstage);

            if (didPassLastSubstage)
            {
                Advance(GameState.StageFinished);
            }
            else
            {
                Advance(GameState.Gameplay);
            }
        });
        AddCallbackOnEnter(GameState.Chests, () =>
        {
            if (!keys.IsEnough(3))
            {
                Advance(GameState.PreStage);
            }
        });
        AddCallbackOnExit(GameState.Chests, () =>
        {
            if (keys.IsEnough(3))
            {
                keys.Spend(3);
            }
        });
        AddCallbackOnEnter(GameState.PreStage, () => Advance(GameState.Gameplay));

        // Link gameplay proxy to the gameplay state callbacks.
        AddCallbackOnEnter(GameState.Gameplay, gameplayProxy.OnGameplayStarted);
        AddCallbackOnExit(GameState.Gameplay, gameplayProxy.OnGameplayStopped);

        // Link the state machine operations to UI (and other capable systems).
        ui.RegisterAdvanceToStateAction(Advance);
        control.AddCallbackOnBeginPull(() => Advance(GameState.Gameplay));
        stage.SetSubstageFailedAction(() => Advance(GameState.NoMoreBalls));
        stage.SetNextSubstageAction(() => Advance(GameState.NextSubstage));
        monetization.SetAdvanceToStateCallbackForVideoRewardButton(rewardType =>
        {
            switch (rewardType)
            {
            case VideoRewardType.ExtraBall:
                Advance(GameState.GetExtraBall);
                break;

            case VideoRewardType.SellBalls:
                Advance(GameState.BallsSold);
                break;
            }
        });

        // Register every possible transition.
        AddTransition(GameState.StartScreen, GameState.Gameplay);
        AddTransition(GameState.StartScreen, GameState.BallShop);

        AddTransition(GameState.BallShop, GameState.StartScreen);

        AddTransition(GameState.Gameplay, GameState.NoMoreBalls);
        AddTransition(GameState.Gameplay, GameState.NextSubstage);

        AddTransition(GameState.NoMoreBalls, GameState.GetExtraBall);
        AddTransition(GameState.NoMoreBalls, GameState.Gameplay);
        AddTransition(GameState.GetExtraBall, GameState.Gameplay);

        AddTransition(GameState.NextSubstage, GameState.Gameplay);
        AddTransition(GameState.NextSubstage, GameState.StageFinished);

        AddTransition(GameState.StageFinished, GameState.BallsSold);

        AddTransition(GameState.BallsSold, GameState.Chests);

        AddTransition(GameState.Chests, GameState.PreStage);

        AddTransition(GameState.PreStage, GameState.Gameplay);

        // Finally, enter the initial state...
        Enter(GameState.StartScreen);
    }