Exemplo n.º 1
0
        public override void initialize()
        {
            base.initialize();
            this.addRenderer(new DefaultRenderer());
            SetupPostProcess();

            //var deferredRenderer = addRenderer(new DeferredLightingRenderer(
            //    0, 1, 10, 20));
            //deferredRenderer.setAmbientColor(new Color(10, 10, 10));

            _enemiesContainer = addEntity(new ContainerEntity
            {
                name = "container-enemies"
            });
            EnemyEntity.Container = _enemiesContainer;
            _bulletContainer      = addEntity(new ContainerEntity
            {
                name = "container-bullet"
            });
            BulletEntity.Container = _bulletContainer;
            _itemsContainer        = addEntity(new ContainerEntity()
            {
                name = "container-items"
            });

            _currentMap     = content.Load <TiledMap>(Content.Tilemaps.map1);
            _mapBoundsGroup = _currentMap.getObjectGroup("MapBounds");
            var startPos = _currentMap.getObjectGroup("Points").objectWithName("StartPos");

            _mapEnemies = _currentMap.getObjectGroup("Enemies");
            _mapItems   = _currentMap.getObjectGroup("Upgrades");
            Texture2D freePlayerTexture = content.Load <Texture2D>(Content.Textures.tempFlightSprite);

            Entity            map      = createEntity("map");
            TiledMapComponent tiledMap = map.addComponent(new TiledMapComponent(_currentMap, "Level"));

            // Vector2 halfMapDimensions = new Vector2(tiledMap.width, tiledMap.height) / 2.0f;
            // map.setPosition(-halfMapDimensions);
            tiledMap.setRenderLayer(10);
            var flyingPlayer = new FreemovePlayerEntity(freePlayerTexture)
            {
                name = "player-flying"
            };

            flyingPlayer.addComponent <PositionBoundsLimitComponent>();
            this.addEntity(flyingPlayer);
            EnemyEntity.Player = flyingPlayer;

            var platformPlayer = new PlatformPlayerEntity(freePlayerTexture)
            {
                name = "player-platform"
            };

            platformPlayer.transform.position = new Vector2(startPos.x, startPos.y);
            this.addEntity(platformPlayer);

            CameraFollowComponent cameraFollow = new CameraFollowComponent(platformPlayer.transform);

            camera.addComponent(cameraFollow);

            PlayerManagerComponent p = addSceneComponent <PlayerManagerComponent>();

            p.PlatformPlayer       = platformPlayer.getComponent <PlatformPlayerComponent>();
            p.FreemovePlayer       = flyingPlayer.getComponent <FreemovePlayerComponent>();
            p.CameraFollow         = cameraFollow;
            p.OnTogglePlatforming += OnPlatformToggle;
            p.TogglePlatforming();
            //var scanLines = content.loadEffect(@"nez\effects\Invert.mgfxo");

            _bulletTextures     = new Texture2D[1];
            _enemyTextures      = new Texture2D[1];
            _upgradeTextures    = new Texture2D[1];
            _bulletTextures[0]  = content.Load <Texture2D>(Content.Textures.Enemies.bullet);
            _enemyTextures[0]   = content.Load <Texture2D>(Content.Textures.Enemies.enemy1);
            _upgradeTextures[0] = content.Load <Texture2D>(Content.Textures.tempFlightSprite);
            //// EnemyEntity e = new EnemyEntity(enemyTexture, bullet);
            //e.getComponent<EnemyComponent>().Player = flyingPlayer;
            //addEntity(e);

            addEntityProcessor(new UpgradeTriggerProcessor(new Matcher().all(typeof(UpgradeComponent))));

            CreateUi();
            Time.timeScale = 0.0f;
            Core.startCoroutine(WaitToStart(0.5f));

            ChangeCameraPos();
        }
Exemplo n.º 2
0
        public override void initialize()
        {
            Debug.log("Scene initialized");

            clearColor = Color.CornflowerBlue;
            addRenderer(new DefaultRenderer());


            Entity           tiledEntity      = createEntity("tiled-map");
            PlayerController playerController = new PlayerController();
            Sprite           playerSprite     = new Sprite(content.Load <Texture2D>("Temp/TestPlayerAnimationFiles/Idle/Idle_1"));

            playerSprite.setRenderLayer(1);

            //Load map here************************************************************
            TiledMap          map          = content.Load <TiledMap>("Temp/TestingWorld");
            TiledObject       spawn        = map.getObjectGroup("SpawnPoint").objectWithName("Spawn");
            TiledMapComponent mapComponent = new TiledMapComponent(map, "Ground");

            mapComponent.setRenderLayer(2);
            tiledEntity.addComponent(mapComponent);

            #region SpawnPlayer
            //Create player Entity
            CookieCutterEntity player = new CookieCutterEntity("Player", spawn.position, ref playerSprite, playerController);

            //Add camera to player
            FollowCamera camera = new FollowCamera(player);
            camera.mapLockEnabled = true;
            camera.mapSize        = new Vector2(map.width * map.tileWidth, map.height * map.tileHeight);
            player.addComponent <FollowCamera>(camera);

            //Add collision layers here*******************************************************************
            BoxCollider collider = new BoxCollider(-playerSprite.width / 2, -playerSprite.height / 2, playerSprite.width, playerSprite.height);
            player.addComponent <TiledMapMover>(new TiledMapMover(map.getLayer <TiledTileLayer>("Ground")));
            player.addComponent <BoxCollider>(collider);
            player.addComponent <PhysicsHandler>(new PhysicsHandler(player, playerController.collisionState, 20f, .5f));
            Flags.setFlagExclusive(ref collider.collidesWithLayers, 0); //Prevent collisions with projectiles
            Flags.setFlagExclusive(ref collider.physicsLayer, 1);

            this.addEntity <Entity> (player);
            #endregion

            #region SpawnAI
            //Initialize EnemyController
            EnemyMeleeController enemy = new EnemyMeleeController(map.getLayer <TiledTileLayer>("Ground"));
            Sprite enemySprite         = new Sprite(content.Load <Texture2D>("Temp/TestPlayerAnimationFiles/Idle/Idle_1"));
            enemySprite.setRenderLayer(1);
            TiledObject        enemySpawn  = map.getObjectGroup("SpawnPoint").objectWithName("EnemySpawn");
            CookieCutterEntity enemyEntity = new CookieCutterEntity("Enemy", enemySpawn.position, ref enemySprite, enemy);

            //Add collision layers
            BoxCollider enemyCollider = new BoxCollider(-enemySprite.width / 2, -enemySprite.height / 2, enemySprite.width, enemySprite.height);
            enemy.addComponent <TiledMapMover>(new TiledMapMover(map.getLayer <TiledTileLayer>("Ground")));
            enemy.addComponent <BoxCollider>(enemyCollider);
            enemy.addComponent <PhysicsHandler>(new PhysicsHandler(enemyEntity, enemy.collisionState, 20f, .5f));
            Flags.setFlagExclusive(ref enemyCollider.collidesWithLayers, 0); //Prevent collisions with projectiles
            Flags.setFlagExclusive(ref enemyCollider.physicsLayer, 1);

            //Add target
            enemy.target = player;

            this.addEntity <Entity>(enemyEntity);
            #endregion
        }