Example #1
0
        //---------------------------------------------------------------------------

        public ItemPool(EItemPool type)
        {
            Type = type;

            Types  = new Dictionary <EItemType, float>();
            m_Rand = new Random(SeedManager.Get().NextSeed());
        }
Example #2
0
        public static Particle Create(EParticles particleType, Vector3 location, Vector3 force)
        {
            Particle particle = EntityFactory.Create <Particle>(string.Format("{0}Particle", particleType.ToString()));

            particle.AddComponent <TransformComponent>().Init(location);

            PhysicsComponent physics = particle.AddComponent <PhysicsComponent>();

            physics.Init(BodyType.Dynamic, 0.94f, 0.5f);
            physics.ApplyForce(force, true);

            SpriteComponent   sprite  = particle.AddComponent <SpriteComponent>();
            LightingComponent light   = particle.AddComponent <LightingComponent>();
            DespawnComponent  despawn = particle.AddComponent <DespawnComponent>();

            switch (particleType)
            {
            case EParticles.Spark:
                float lifeTime = SeedManager.Get().NextRandF(2.0f, 5.0f);

                sprite.Init(CollisionManager.Get().PointTexture);
                sprite.Scale = new Vector2(SeedManager.Get().NextRandF(5, 15), SeedManager.Get().NextRandF(5, 15));
                sprite.AddColorFunction(x => { return(Color.Lerp(new Color(0.99f, 1.0f, 0.78f), new Color(1.0f, 0.0f, 0.0f), x)); });
                sprite.AddOpacityFunction(x => { return(1.0f - x / lifeTime); });

                light.Init(AssetManager.Get().Find <Texture2D>(ELightAssets.CircleLight), Vector2.Zero, new Vector2(0.4f, 0.4f));
                light.AddColorFunction(x => { return(Color.Lerp(new Color(0.99f, 1.0f, 0.78f), new Color(1.0f, 0.0f, 0.0f), x)); });
                light.AddBrightnessFunction(x => { return(1.0f - x / lifeTime); });

                despawn.AddTimeTrigger(x => x > lifeTime);
                break;
            }

            return(particle);
        }
        //---------------------------------------------------------------------------

        public void Spawn(EItemType item)
        {
            TransformComponent transform = GetComponent <TransformComponent>();

            if (transform != null)
            {
                float   rot   = (SeedManager.Get().NextRandF() * (float)Math.PI * 2.0f);
                float   dist  = (SeedManager.Get().NextRandF() * 120.0f + 400.0f);
                Vector3 force = new Vector3((float)Math.Sin(rot) * dist, (float)Math.Cos(rot) * dist, SeedManager.Get().NextRandF(20, 40));
                PickupFactory.Create(item, transform.Location, force);
            }
        }
Example #4
0
        //---------------------------------------------------------------------------

        public byte[,] CreateMap(int size = 1)
        {
            byte[,] map = new byte[Bounds.Width / size, Bounds.Height / size];

            for (int x = 0; x < Bounds.Width / size; x++)
            {
                for (int y = 0; y < Bounds.Height / size; y++)
                {
                    map[x, y] = SeedManager.Get().NextRand(0, 2) == 0 ? (byte)0 : (byte)2;
                }
            }

            foreach (Room room in Rooms)
            {
                for (int x = room.Bounds.X; x < room.Bounds.X + room.Bounds.Width; x++)
                {
                    for (int y = room.Bounds.Y; y < room.Bounds.Y + room.Bounds.Height; y++)
                    {
                        map[x / size, y / size] = 255;
                    }
                }
            }
            foreach (Corridor corridor in Corridors)
            {
                foreach (CorridorSegment segment in corridor.Segments)
                {
                    int thickness = (segment.Thickness - 1) / 2;
                    for (int x = Math.Min(segment.Start.X, segment.End.X) - thickness; x <= Math.Max(segment.Start.X, segment.End.X) + thickness; x++)
                    {
                        for (int y = Math.Min(segment.Start.Y, segment.End.Y) - thickness; y <= Math.Max(segment.Start.Y, segment.End.Y) + thickness; y++)
                        {
                            if (x >= 0 && x < map.GetLength(0) && y >= 0 && y < map.GetLength(1))
                            {
                                map[x, y] = 255;
                            }
                        }
                    }
                }
            }
            return(map);
        }
Example #5
0
        //---------------------------------------------------------------------------

        protected override void Initialize()
        {
            base.Initialize();
            Window.AllowUserResizing = true;
            GameWindowSettings.SetWindowSettings(graphics, Window, 1680, 1050);

            oldKeyboardState = Keyboard.GetState();

            int width  = GraphicsDevice.PresentationParameters.BackBufferWidth;
            int height = GraphicsDevice.PresentationParameters.BackBufferHeight;

            GraphicsDevice.SamplerStates[0] = SamplerState.PointClamp;

            LightingManager.Get().Device = GraphicsDevice;

            SeedManager.Get().ResetBaseSeed(1234);

            /*--------------------------------------------------------------------------
            *          Items
            *  --------------------------------------------------------------------------*/

            ItemManager.Get().LoadItems();
            ItemManager.Get().LoadItemPools();

            /*--------------------------------------------------------------------------
            *          Stage
            *  --------------------------------------------------------------------------*/

            Stage stage = new Stage(SeedManager.Get().NextSeed());

            StageManager.Get().Create(stage.CreateMap());
            StageManager.Get().Stage = stage;

            foreach (Room room in stage.Rooms)
            {
                int max = SeedManager.Get().NextSeed(3, 7);
                for (int i = 0; i < max; i++)
                {
                    Vector2 position = new Vector2(room.Bounds.Center.X * 64 + (float)Math.Sin((i / (max / 2.0f)) * Math.PI) * 360, room.Bounds.Center.Y * 64 + (float)Math.Cos((i / (max / 2.0f)) * Math.PI) * 360);
                    EntityFactory.Create <Chest>("Chest").Init(position);
                }
                EntityFactory.Create <SimpleTestEnemy>("Enemy").Init(new Vector2(room.Bounds.Center.X * 64, room.Bounds.Center.Y * 64));

                for (int x = 0; x < room.Bounds.Width; x += 3)
                {
                    IEntity torch = EntityFactory.Create <Entity>("Torch");
                    torch.AddComponent <TransformComponent>().Init(new Vector3(room.Bounds.X * 64 + x * 64 + 32, room.Bounds.Y * 64 + 32, 110));
                    torch.AddComponent <ParticleSpawnerComponent>().Emitter.Description = ParticleDesc.Fire;
                    torch.AddComponent <LightingComponent>().Init(AssetManager.Get().Find <Texture2D>(ELightAssets.CircleLight), new Vector2(0, 6), new Vector2(1, 1), Color.Orange, 0.6f);
                }
            }

            stage.SaveStageAsImage(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Map.png"));

            /*--------------------------------------------------------------------------
            *          Player 1
            *  --------------------------------------------------------------------------*/

            Player player = EntityFactory.Create <Player>("Player1");

            /*--------------------------------------------------------------------------
            *           Player 2
            *  --------------------------------------------------------------------------*/

            Player player2 = EntityFactory.Create <Player>("Player2");

            /*--------------------------------------------------------------------------
            *           Camera
            *  --------------------------------------------------------------------------*/

            CameraManager.Get().Init(width, height);

            Camera cam1 = EntityFactory.Create <Camera>("Cam1");

            cam1.Properties.Init(GraphicsDevice, width / 2, height, AssetManager.Get().Find <Texture2D>(ESpriteAssets.CameraBackground1), AssetManager.Get().Find <Effect>(EEffectAssets.DeferredLighting));
            cam1.Properties.Viewport           = new Rectangle(0, 0, width / 2, height);
            cam1.Properties.BloomExtractEffect = AssetManager.Get().Find <Effect>(EEffectAssets.BloomExtract);
            cam1.Properties.BloomCombineEffect = AssetManager.Get().Find <Effect>(EEffectAssets.BloomCombine);
            cam1.Properties.BlurEffect         = AssetManager.Get().Find <Effect>(EEffectAssets.Blur);
            cam1.Properties.Tileset            = AssetManager.Get().Find <Texture2D>(ETilesetAssets.DungeonTileset2);
            cam1.Properties.AddTarget(player);
            //cam1.Properties.IsAmbientOcclusionEnabled = true;

            Camera cam2 = EntityFactory.Create <Camera>("Cam2");

            cam2.Properties.Init(GraphicsDevice, width / 2, height, AssetManager.Get().Find <Texture2D>(ESpriteAssets.CameraBackground1), AssetManager.Get().Find <Effect>(EEffectAssets.DeferredLighting));
            cam2.Properties.Viewport           = new Rectangle(width / 2, 0, width / 2, height);
            cam2.Properties.BloomExtractEffect = AssetManager.Get().Find <Effect>(EEffectAssets.BloomExtract);
            cam2.Properties.BloomCombineEffect = AssetManager.Get().Find <Effect>(EEffectAssets.BloomCombine);
            cam2.Properties.BlurEffect         = AssetManager.Get().Find <Effect>(EEffectAssets.Blur);
            cam2.Properties.Tileset            = AssetManager.Get().Find <Texture2D>(ETilesetAssets.DungeonTileset2);
            cam2.Properties.AddTarget(player2);
            //cam2.Properties.IsAmbientOcclusionEnabled = true;

            CameraManager.Get().FuseCameras(cam1, cam2, width / 2);


            /*--------------------------------------------------------------------------
            *           UI
            *  --------------------------------------------------------------------------*/

            UIManager.Get().Init(GraphicsDevice, width, height);
            SpriteFont debug_font = AssetManager.Get().Find <SpriteFont>(EFontAssets.DebugFont);

            UIEntity           healthbar1          = EntityFactory.CreateUI <UIEntity>("HealthbarPlayer1");
            HealthbarComponent healthbarcomponent1 = healthbar1.AddComponent <HealthbarComponent>();

            healthbar1.VerticalAlignment   = EVerticalAlignment.Top;
            healthbar1.HorizontalAlignment = EHorizontalAlignment.Left;
            healthbar1.Margin = new Rectangle(15, 25, 0, 0);
            healthbarcomponent1.BindPlayer(player, EHorizontalAlignment.Left);

            UIEntity           healthbar2          = EntityFactory.CreateUI <UIEntity>("HealthbarPlayer2");
            HealthbarComponent healthbarcomponent2 = healthbar2.AddComponent <HealthbarComponent>();

            healthbar2.VerticalAlignment   = EVerticalAlignment.Top;
            healthbar2.HorizontalAlignment = EHorizontalAlignment.Right;
            healthbar2.Margin = new Rectangle(0, 25, 15, 0);
            healthbarcomponent2.BindPlayer(player2, EHorizontalAlignment.Right);

            UIEntity coins = EntityFactory.CreateUI <UIEntity>("CollectedCoins");
            CoinCollectionComponent coincollectioncomponent = coins.AddComponent <CoinCollectionComponent>();

            coins.VerticalAlignment   = EVerticalAlignment.Top;
            coins.HorizontalAlignment = EHorizontalAlignment.Center;
            coins.Margin = new Rectangle(0, 25, 0, 0);
            coincollectioncomponent.Bind(player, player2);

#if DEBUG
            ConsoleManager.Get().RegisterCommand("SpawnChestAtPosition", null, (Func <int, int, string>)Chest.SpawnChest);
            ConsoleManager.Get().RegisterCommand("SpawnChestAtCamera", null, (Func <int, string>)Chest.SpawnChest);
            ConsoleManager.Get().RegisterCommand("SpawnPickup", null, (Func <string, int, Pickup>)PickupFactory.Create);
#endif
        }
Example #6
0
        //---------------------------------------------------------------------------

        public SpawnerComponent(Guid entity) : base(entity)
        {
            m_Rand = new Random(SeedManager.Get().NextSeed());
        }