Exemplo n.º 1
0
        public Game()
        {
            // window
            win = new Window("Space Taxi Game v0.1", 800, AspectRatio.R1X1);

            // level class
            level = new LevelParser();

            // event bus
            eventBus = new GameEventBus <object>();
            eventBus.InitializeEventBus(new List <GameEventType>()
            {
                GameEventType.InputEvent,  // key press / key release
                GameEventType.WindowEvent, // messages to the window, e.g. CloseWindow()
                GameEventType.PlayerEvent  // commands issued to the player object, e.g. move, destroy, receive health, etc.
            });
            win.RegisterEventBus(eventBus);

            // game timer
            gameTimer = new GameTimer(60); // 60 UPS, no FPS limit

            // game assets
            backGroundImage = new Entity(
                new StationaryShape(new Vec2F(0.0f, 0.0f), new Vec2F(1.0f, 1.0f)),
                new Image(Path.Combine("Assets", "Images", "SpaceBackground.png"))
                );

            // event delegation
            eventBus.Subscribe(GameEventType.InputEvent, this);
            eventBus.Subscribe(GameEventType.WindowEvent, this);
            eventBus.Subscribe(GameEventType.PlayerEvent, level.Player);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Constructor for Game class
        /// </summary>
        public Game()
        {
            win       = new Window("Galaga", 500, 500);
            gameTimer = new GameTimer(60, 60);

            player = new Player(this,
                                new DynamicShape(new Vec2F(0.45f, 0.1f), new Vec2F(0.1f, 0.1f)),
                                new Image(Path.Combine("Assets", "Images", "Player.png")));

            eventBus = new GameEventBus <object>();
            eventBus.InitializeEventBus(new List <GameEventType> {
                GameEventType.InputEvent, // key press / key release
                GameEventType.WindowEvent // messages to the window
            });
            win.RegisterEventBus(eventBus);
            eventBus.Subscribe(GameEventType.InputEvent, this);
            eventBus.Subscribe(GameEventType.WindowEvent, this);

            enemyStrides = ImageStride.CreateStrides(4,
                                                     Path.Combine("Assets", "Images", "BlueMonster.png"));
            enemies = new List <Enemy>();

            playerShots     = new List <PlayerShot>();
            playerShotImage = new Image(
                Path.Combine("Assets", "Images", "BulletRed2.png"));

            explosionStrides = ImageStride.CreateStrides(8,
                                                         Path.Combine("Assets", "Images", "Explosion.png"));
            explosions = new AnimationContainer(4);

            score = new Score(new Vec2F(0.01f, -0.25f), new Vec2F(0.3f, 0.3f));
        }
Exemplo n.º 3
0
        public Game()
        {
            gameTimer    = new GameTimer(60, 60);
            win          = new Window("Galaca", 500, AspectRatio.R1X1);
            backGround   = new Image(Path.Combine("Assets", "Images", "SpaceBackground.png"));
            player       = new Player();
            enemies      = new EntityContainer();
            enemyStrides = ImageStride.CreateStrides(4,
                                                     Path.Combine("Assets", "Images", "BlueMonster.png"));
            AddEnemies();
            playerShots = new EntityContainer();
            shotStride  = new Image(Path.Combine("Assets", "Images", "BulletRed2.png"));

            explosionStrides = ImageStride.CreateStrides(8,
                                                         Path.Combine("Assets", "Images", "Explosion.png"));
            explosions = new AnimationContainer(4);

            eventBus = new GameEventBus <object>();
            eventBus.InitializeEventBus(new List <GameEventType>()
            {
                GameEventType.InputEvent,
                GameEventType.WindowEvent,
                GameEventType.PlayerEvent
            });

            win.RegisterEventBus(eventBus);
            eventBus.Subscribe(GameEventType.InputEvent, this);
            eventBus.Subscribe(GameEventType.WindowEvent, this);
        }
Exemplo n.º 4
0
 public Game()
 {
     win          = new Window("test", 500, 500);
     score        = new Score(new Vec2F(0.0f, 0.0f), new Vec2F(0.2f, 0.2f));
     gameTimer    = new GameTimer(60, 60);
     enemyStrides = ImageStride.CreateStrides(4,
                                              Path.Combine("Assets", "Images", "BlueMonster.png"));
     enemies = new List <Enemy>();
     player  = new Player(this,
                          new DynamicShape(new Vec2F(0.45f, 0.1f), new Vec2F(0.1f, 0.1f)),
                          new Image(Path.Combine("Assets", "Images", "Player.png")));
     moveDown          = new MoveDown();
     noMove            = new NoMove();
     zigZagDown        = new ZigZagDown();
     createEnemiesLine = new CreateEnemiesLine(this, enemies);
     createEnemiesLine.CreateEnemies(enemyStrides);
     shotImages  = new Image(Path.Combine("Assets", "Images", "BulletRed2.png"));
     playerShots = new List <PlayerShot>();
     eventBus    = new GameEventBus <object>();
     eventBus.InitializeEventBus(new List <GameEventType>()
     {
         GameEventType.InputEvent,
         GameEventType.WindowEvent,
         GameEventType.PlayerEvent
     });
     win.RegisterEventBus(eventBus);
     eventBus.Subscribe(GameEventType.InputEvent, this);
     eventBus.Subscribe(GameEventType.WindowEvent, this);
     eventBus.Subscribe(GameEventType.PlayerEvent, player);
     explosionStrides = ImageStride.CreateStrides(8,
                                                  Path.Combine("Assets", "Images", "Explosion.png"));
     explosions = new AnimationContainer(20);
 }
Exemplo n.º 5
0
    public Game()
    {
        win       = new Window("galaga", 500, 500);
        gameTimer = new DIKUArcade.Timers.GameTimer(60, 60);
        player    = new Player(
            new DynamicShape(new Vec2F(0.45f, 0.1f), new Vec2F(0.1f, 0.1f)),
            new Image(Path.Combine("Assets", "Images", "Player.png")));

        eventBus = new GameEventBus <object>();
        eventBus.InitializeEventBus(new List <GameEventType>()
        {
            GameEventType.InputEvent,  // key press / key release
            GameEventType.WindowEvent, // messages to the window
        });

        win.RegisterEventBus(eventBus);
        eventBus.Subscribe(GameEventType.InputEvent, this);
        eventBus.Subscribe(GameEventType.WindowEvent, this);


        enemyStrides = ImageStride.CreateStrides(4,
                                                 Path.Combine("Assets", "Images", "BlueMonster.png"));
        enemies = new List <Enemy>();
        Enemy.addEnemies(new ImageStride(80, enemyStrides));

        PlayerShots = new List <PlayerShot>();

        score = new Score(new Vec2F(0.9f, 0.9f), new Vec2F(0.1f, 0.1f));
    }
Exemplo n.º 6
0
        public void InitializeGameState()
        {
            eventBus     = SpaceTaxiBus.GetBus();
            levelManager = LevelManager.GetInstance();
            levelInfos   = levelManager.LevelInfos;

            var levels = new List <string>();

            foreach (var levelInfo in levelInfos)
            {
                levels.Add(levelInfo.Name);
            }

            levelNames = levels.ToArray();
            levelManager.ActiveLevelIndex = 0;

            selectLevelText =
                new Text("Please select a level \n with the arrow keys. \n ENTER to confirm:",
                         new Vec2F(0.25f, 0.0f), new Vec2F(0.5f, 0.5f));
            selectLevelText.SetColor(Color.White);
            selectLevelText.SetFontSize(35);
            levelTextBox =
                new Text(levelNames.First(), new Vec2F(0.3f, -0.2f), new Vec2F(0.5f, 0.5f));
            levelTextBox.SetColor(Color.White);
            levelTextBox.SetFontSize(35);
            background = new Entity(
                new StationaryShape(new Vec2F(0f, 0f), new Vec2F(1f, 1f)),
                new Image(Path.Combine("Assets", "Images", "SpaceBackground.png")));
        }
        private void Initialize()
        {
            _checkItems = GetComponentsInChildren <CheckItem>().ToList();
            _pointClaim = GetComponentInChildren <PointClaim>();
            foreach (var checkItem in _checkItems)
            {
                checkItem.Initialize();
            }
            _pointClaim.Initialize();

            GameEventBus.SubscribeEvent(GameEventType.CHECKPOINT, ActiveCheckPointItem);
            GameEventBus.SubscribeEvent(GameEventType.FINISHED, () =>
            {
                DeActivateCheckPointItem();
                _pointClaim.ChangePoint(0);
                _point = 0;
            });
            GameEventBus.SubscribeEvent(GameEventType.FAIL, () =>
            {
                DeActivateCheckPointItem();
                _pointClaim.ChangePoint(0);
                _point = 0;
            });

            _pickerBase.OnPointGained += ChangePoint;
        }
Exemplo n.º 8
0
        public Game()
        {
            // window
            win = new Window("Space Taxi Game v0.1", 500, AspectRatio.R1X1);

            // event bus
            eventBus = new GameEventBus <object>();
            SpaceTaxiBus.GetBus().InitializeEventBus(new List <GameEventType>()
            {
                GameEventType.InputEvent,
                GameEventType.WindowEvent,
                GameEventType.GameStateEvent,
                GameEventType.PlayerEvent
            });
            win.RegisterEventBus(SpaceTaxiBus.GetBus());

            // game timer
            gameTimer = new GameTimer(60); // 60 UPS, no FPS limit

            // game assets
            backGroundImage = new Entity(
                new StationaryShape(new Vec2F(0.0f, 0.0f), new Vec2F(1.0f, 1.0f)),
                new Image(Path.Combine("Assets", "Images", "SpaceBackground.png"))
                );
            backGroundImage.RenderEntity();

            // event delegation
            SpaceTaxiBus.GetBus().Subscribe(GameEventType.InputEvent, this);
            SpaceTaxiBus.GetBus().Subscribe(GameEventType.WindowEvent, this);
            SpaceTaxiBus.GetBus().Subscribe(GameEventType.GameStateEvent, this);

            //make level

            stateMachine = new StateMachine(this);
        }
Exemplo n.º 9
0
 public StateMachine()
 {
     ActiveState = MainMenu.GetInstance();
     _eventBus   = SpaceTaxiBus.GetBus();
     _eventBus.Subscribe(GameEventType.InputEvent, this);
     _eventBus.Subscribe(GameEventType.GameStateEvent, this);
 }
Exemplo n.º 10
0
        public Game()
        {
            // window
            win = new Window("Space Taxi Game v0.1", 500, AspectRatio.R1X1);

            // event bus
            eventBus = EventBus.GetBus();
            eventBus.InitializeEventBus(new List <GameEventType> {
                GameEventType.GameStateEvent,
                GameEventType.InputEvent,  // key press / key release
                GameEventType.WindowEvent, // messages to the window, e.g. CloseWindow()
                GameEventType.PlayerEvent  // commands issued to the player object, e.g. move,
                                           // destroy, receive health, etc.
            });
            win.RegisterEventBus(eventBus);

            // game timer
            gameTimer = new GameTimer(60); // 60 UPS, no FPS limit


            stateMachine = new StateMachine();


            // event delegation
            eventBus.Subscribe(GameEventType.InputEvent, this);
            eventBus.Subscribe(GameEventType.WindowEvent, this);
            eventBus.Subscribe(GameEventType.PlayerEvent, this);
        }
Exemplo n.º 11
0
        public void InitializeGameState()
        {
            //Player
            player = new Player();

            //Enemies
            squadronContainer = new List <ISquadron>();

            //Squadrons
            squad = new Squad();
            squad.CreateEnemies(ImageStride.CreateStrides(4,
                                                          Path.Combine("Assets", "Images", "BlueMonster.png")));

            boss = new Boss();
            boss.CreateEnemies(ImageStride.CreateStrides(4,
                                                         Path.Combine("Assets", "Images", "BlueMonster.png")));


            //Add to enemies
            squadronContainer.Add(squad);
            squadronContainer.Add(boss);
//            squadronContainer.Add(invasion);

            explosionStrides = ImageStride.CreateStrides(8,
                                                         Path.Combine("Assets", "Images", "Explosion.png"));

            explosions = new AnimationContainer(10);

            //Movement
            down = new Down();

            eventBus = GalagaBus.GetBus();
            eventBus.Subscribe(GameEventType.PlayerEvent, player);
        }
Exemplo n.º 12
0
//
//        //Enemies
//        private  List<ISquadron> squadronContainer;
//        //Squadrons
//        private Squad squad;
//        private Boss boss;
//        private Invasion invasion;

//        //Movement
//        private Down down;
//
//
//        //Player
//        private Player player;
//
        //Timer

//        //Explosions
//        private List<Image> explosionStrides;
//        private AnimationContainer explosions;
//        private int explosionLength = 500;
//

        public Game()
        {
            win   = new Window("Galaga", 500, AspectRatio.R16X9);
            state = new StateMachine();

            //Player
//            player = new Player();
//

//            //Enemies
//            squadronContainer = new List<ISquadron>();
//
//              //Squadrons
//            squad = new Squad();
//            squad.CreateEnemies(ImageStride.CreateStrides(4,
//                Path.Combine("Assets", "Images", "BlueMonster.png")));
//
//            boss = new Boss();
//            boss.CreateEnemies(ImageStride.CreateStrides(4,
//                Path.Combine("Assets", "Images", "BlueMonster.png")));

//            invasion = new Invasion();
//            invasion.CreateEnemies(ImageStride.CreateStrides(4,
//                Path.Combine("Assets", "Images", "BlueMonster.png")));


//            //Add to enemies
//            squadronContainer.Add(squad);
//            squadronContainer.Add(boss);
////            squadronContainer.Add(invasion);


            //Explosiom
//            explosionStrides = ImageStride.CreateStrides(8,
//                Path.Combine("Assets","Images","Explosion.png"));
//
//            explosions = new AnimationContainer(10);
//
//            //Movement
//            down = new Down();

            //Eventbus


            eventBus = new GameEventBus <object>();
            eventBus.InitializeEventBus(new List <GameEventType>()
            {
                GameEventType.InputEvent,  // key press / key release
                GameEventType.WindowEvent, // messages to the window
                GameEventType.PlayerEvent  // commands issued to the player object,
            });                            // e.g. move, destroy, receive health, etc.
            win.RegisterEventBus(eventBus);
            eventBus.Subscribe(GameEventType.InputEvent, this);
            eventBus.Subscribe(GameEventType.WindowEvent, this);


            //Gametimer
            gameTimer = new GameTimer(60, 60);
        }
Exemplo n.º 13
0
        public override void Initialize()
        {
            base.Initialize();
            _checkPointCounterPlatform = GetComponentInChildren <CheckPointCounterPlatform>(true);
            _gate1 = transform.Find("Gate1");
            _gate2 = transform.Find("Gate2");

            GameEventBus.SubscribeEvent(GameEventType.FINISHED, Reset);
            GameEventBus.SubscribeEvent(GameEventType.FAIL, Reset);
        }
Exemplo n.º 14
0
        private void OnTriggerEnter(Collider other)
        {
            var picker = other.GetComponent <PickerPhysicsController>();

            if (picker != null)
            {
                Debug.Log("Finished!");

                Timer.Instance.TimerWait(2f, () => GameEventBus.InvokeEvent(GameEventType.FINISHED));
            }
        }
Exemplo n.º 15
0
        public void InitializeGameState()
        {
            bottomPanel = new BottomPanel();

            eventBus = SpaceTaxiBus.GetBus();

            backGroundImage = new Entity(
                new StationaryShape(new Vec2F(0.0f, 0.0f + Constants.BOTTOM), new Vec2F(1.0f, 1.0f - Constants.BOTTOM)),
                new Image(Path.Combine("Assets", "Images", "SpaceBackground.png"))
                );
        }
Exemplo n.º 16
0
        public TestTimedEvent(WindowArgs windowArgs) : base(windowArgs)
        {
            window.SetKeyEventHandler(KeyHandler);
            random = new Random();

            eventBus = new GameEventBus();
            eventBus.InitializeEventBus(new List <GameEventType> {
                GameEventType.TimedEvent
            });

            eventBus.Subscribe(GameEventType.TimedEvent, this);
        }
Exemplo n.º 17
0
        public void SendEvent(GameEventBus eventBus, IGameEventProcessor to, int intValue)
        {
            this.Value = intValue;
            var e = new GameEvent {
                EventType = GameEventType.GraphicsEvent,
                From      = this,
                To        = to,
                IntArg1   = intValue
            };

            eventBus.RegisterEvent(e);
        }
Exemplo n.º 18
0
        public TestTimedEvents()
        {
            _helper = new Helper();

            _eventBus = new GameEventBus();
            _eventBus.InitializeEventBus(new List <GameEventType> {
                GameEventType.TimedEvent,
                GameEventType.StatusEvent,
                GameEventType.MovementEvent
            });
            _eventBus.Subscribe(GameEventType.TimedEvent, _helper);
        }
        public void Initialize(int target)
        {
            _counter       = 0;
            _targetCounter = target;
            _textMesh      = GetComponentInChildren <TextMeshPro>(true);
            _meshRenderer  = GetComponent <MeshRenderer>();
            _textMesh.text = Mathf.RoundToInt(_counter) + "/" + _targetCounter;
            _firstPos      = new Vector3(transform.position.x, -3.43f, transform.position.z);

            GameEventBus.SubscribeEvent(GameEventType.FINISHED, Reset);
            GameEventBus.SubscribeEvent(GameEventType.FAIL, Reset);
        }
Exemplo n.º 20
0
        public TestTimedEventsT()
        {
            _helper = new Helper();

            _eventBus = new GameEventBus <TestTimedEventT>();
            _eventBus.InitializeEventBus(new List <TestTimedEventT> {
                TestTimedEventT.TimedEvent,
                TestTimedEventT.StatusEvent,
                TestTimedEventT.MovementEvent
            });
            _eventBus.Subscribe(TestTimedEventT.TimedEvent, _helper);
        }
 public ContainerTest()
 {
     bus = new GameEventBus <object>();
     bus.InitializeEventBus(new List <GameEventType>()
     {
         GameEventType.TimedEvent
     });
     container = new TimedEventContainer(5);
     container.AttachEventBus(bus);
     processor = new MockupEventProcessor();
     bus.Subscribe(GameEventType.TimedEvent, processor);
 }
Exemplo n.º 22
0
        public Player()
        {
            Entity = new Entity(
                new DynamicShape(new Vec2F(0.45f, 0.1f), new Vec2F(0.1f, 0.1f)),
                new Image(Path.Combine("Assets", "Images", "Player.png")));

            eventBus = new GameEventBus <object>();
            eventBus.InitializeEventBus(new List <GameEventType>()
            {
                GameEventType.PlayerEvent
            });
            eventBus.Subscribe(GameEventType.PlayerEvent, this);
        }
Exemplo n.º 23
0
 public void InitializeGameState()
 {
     eventBus       = SpaceTaxiBus.GetBus();
     imageContainer = ImageContainer.GetInstance();
     backgroundImg  = new Entity(new StationaryShape(0, 0, 1, 1),
                                 imageContainer.GetImageByName("SpaceBackground.png"));
     pausedText = new Text(
         "Game paused. \n\nPress P to continue \nPress ESC to quit",
         new Vec2F(0.23f, 0.1f),
         new Vec2F(0.6f, 0.6f));
     pausedText.SetColor(Color.White);
     pausedText.SetFontSize(40);
 }
Exemplo n.º 24
0
        public void InitiateStateMachine()
        {
            DIKUArcade.Window.CreateOpenGLContext();
            // Here you should:
            // (1) Initialize a GalagaBus with proper GameEventTypes
            // (2) Instantiate the StateMachine
            // (3) Subscribe the GalagaBus to proper GameEventTypes
            // and GameEventProcessors

            GameEventBus <object> GalagaBus    = GalagaBus.eventBus();
            StateMachine          stateMachine = new StateMachine();

            GalagaBus.GetBus().Subscribe(GameEventType.GameStateEvent, stateMachine);
        }
Exemplo n.º 25
0
        public TestGameEvent()
        {
            _sender            = new TestGameEventSender();
            _receiver1         = new TestGameEventReceiver();
            _receiver2         = new TestGameEventReceiver();
            _receiverGetSender = new TestGameEventReceiverGetSender();

            _eventBus = new GameEventBus();
            _eventBus.InitializeEventBus(new List <GameEventType> {
                GameEventType.GraphicsEvent
            });                                                                                    // arbitrary event type
            _eventBus.Subscribe(GameEventType.GraphicsEvent, _receiver1);
            _eventBus.Subscribe(GameEventType.GraphicsEvent, _receiver2);
        }
Exemplo n.º 26
0
 /// <summary>
 /// Register an event bus to this window instance. The specified
 /// bus will be used for capturing input events, such as keyboard presses.
 /// </summary>
 /// <param name="bus">A GameEventBus to register for this window</param>
 /// <returns>False if an event bus was already registered, true otherwise.</returns>
 public bool RegisterEventBus(GameEventBus <object> bus)
 {
     if (eventBus != null)
     {
         // an event bus was already registered!
         // TODO: Should it be possible to swap event bus?
         return(false);
     }
     eventBus = bus;
     window.Keyboard.KeyDown += RegisterEvent;
     window.Keyboard.KeyUp   += RegisterEvent;
     RemoveDefaultKeyEventHandler();
     return(true);
 }
Exemplo n.º 27
0
        public void InitializeGameState()
        {
            // level class
            LevelParser.NewGame();
            level = LevelParser.GetInstance();

            // event bus
            eventBus = TaxiBus.GetBus();

            // game assets
            backGroundImage = new Entity(
                new StationaryShape(new Vec2F(0.0f, 0.0f), new Vec2F(1.0f, 1.0f)),
                new Image(Path.Combine("Assets", "Images", "SpaceBackground.png"))
                );
        }
Exemplo n.º 28
0
        public TestEventBusInputEvents()
        {
            win = new Window("TestEventBusInputEvents", 500, AspectRatio.R1X1);
            win.SetClearColor(Color.ForestGreen);

            // just listen to input events for now
            bus = new GameEventBus <object>();
            bus.InitializeEventBus(new List <GameEventType>()
            {
                GameEventType.InputEvent
            });
            bus.Subscribe(GameEventType.InputEvent, this);

            win.RegisterEventBus(bus);
        }
Exemplo n.º 29
0
 public void InitializeGameState()
 {
     spaceTaxiBus    = SpaceTaxiBus.GetBus();
     imageContainer  = ImageContainer.GetInstance();
     backgroundImage =
         new Entity(
             new StationaryShape(0.0f, 0.0f, 1f, 1f),
             imageContainer.GetImageByName("SpaceBackground.png"));
     gameOverText = new Text("GAME OVER", new Vec2F(0.31f, 0.4f), new Vec2F(0.4f, 0.3f));
     gameOverText.SetColor(Color.White);
     tryAgainButton =
         new Text("Press ENTER to try again", new Vec2F(0.25f, 0.0f), new Vec2F(0.7f, 0.5f));
     tryAgainButton.SetColor(Color.White);
     tryAgainButton.SetFontSize(20);
 }
Exemplo n.º 30
0
        public void SetupEventBusForTests()
        {
            _eb = new GameEventBus <object>();
            _eb.InitializeEventBus(_registeredEvents);

            _simpleEventProcessor = new SimpleEventProcessor();

            _eb.Subscribe(GameEventType.ControlEvent, _simpleEventProcessor);
            _eb.Subscribe(GameEventType.SoundEvent, _simpleEventProcessor);

            _eventControl = GameEventFactory <object> .CreateGameEventForAllProcessors(
                GameEventType.ControlEvent, this, "Test1", "test", "test");

            _eventSound = GameEventFactory <object> .CreateGameEventForAllProcessors(
                GameEventType.SoundEvent, this, "Test2", "test", "test");
        }