Esempio n. 1
0
        private void SetupScene()
        {
            // Game objects which will exist in our game
            GameObject background, player;

            // Components
            KeyReaderComponent krc;

            // Create the background game object and add it a Background
            // component
            background = new GameObject("Background");
            background.AddComponent(
                new BackgroundComponent(buffer2D, worldDimX, worldDimY));

            // Create the player game object and add it a key reader
            // component (to capture input) and a move component, for moving
            // the player according to the input
            player = new GameObject("PlayerX");

            // Create the key reader (to capture input)
            krc = new KeyReaderComponent();
            // Set action to perform when escape is pressed
            krc.EscapePressed += () => running = false;
            // Add the key reader component to the player game object
            player.AddComponent(krc);

            // Add a move component, for moving the player
            player.AddComponent(new MoveComponent(
                                    worldDimX / 2, worldDimY / 2, worldDimX, worldDimY, buffer2D));

            // Add both game objects to the game object list
            gameObjects.Add(background);
            gameObjects.Add(player);

            // Important notes:
            // 1 - The key reader component approach used here is not usable
            //     when different game objects require input. Input processing
            //     should be done before game object updates().
            // 2 - The rendering depends on the order in which game objects are
            //     added to the game object list. This might work for simple
            //     games, but soon becomes unmanageable when the games starts
            //     becoming a bit more complex
            // ->  See https://github.com/fakenmc/CoreGameEngine/ for a more
            //     versatile (and more complex) solutions
        }
 // Start is called immediately before the game loop starts
 public override void Start()
 {
     // Get a reference to the key reader component
     keyReader = ParentGameObject.GetComponent <KeyReaderComponent>();
 }