Exemplo n.º 1
0
        public Key(Rectangle pos, Map map)
            : base(map)
        {
            Body BodyDec = new Body(map.PhysicalWorld);

            BodyDec.BodyType = BodyType.Static;

            PolygonShape S = new PolygonShape(1f);

            S.SetAsBox(pos.Width / 2, pos.Height / 2);

            Fixture             = BodyDec.CreateFixture(S);
            Fixture.Restitution = 1f;
            Fixture.Friction    = 10f;

            this.Position = pos;

            SetName("Key");

            LightingEngine LE = (LightingEngine)Renderer.GetRenderEffect("LightingEngine");

            light = new PointLight()
            {
                IsEnabled  = true,
                Color      = new Vector4(0.95f, .7f, .05f, 1f),
                Power      = power,
                LightDecay = 350,
                Position   = new Vector3(Position.X, Position.Y, 20),
                Direction  = new Vector3(0, 0, 0)
            };

            LE.AddLight(light);
        }
Exemplo n.º 2
0
        public override void Draw(GameTime GameTime)
        {
            LightingEngine LE = (LightingEngine)Renderer.GetRenderEffect("LightingEngine");

            FanAnim.Draw(GameTime, 0.8f);
            FanNormalAnim.Draw(GameTime, 0.8f);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Remove ShadowHull
        /// </summary>
        public void RemoveHull()
        {
            LightingEngine LE = ((LightingEngine)Renderer.GetRenderEffect("LightingEngine"));

            LE.RemoveHull(Hull);
            this._Hull = null;
        }
Exemplo n.º 4
0
        public override void Draw(GameTime GameTime)
        {
            LightingEngine LE = (LightingEngine)Renderer.GetRenderEffect("LightingEngine");

            Renderer.Draw(GeneralManager.Textures["Entities/" + GetName()], Position, Color.White, Fixture.Body.Rotation, new Vector2(Position.Width / 2, Position.Height / 2));
            LE.DrawNormal(GeneralManager.Textures["Entities/" + GetName() + "_normal"], Position, null, Fixture.Body.Rotation, new Vector2(Position.Width / 2, Position.Height / 2));
        }
Exemplo n.º 5
0
        public override void PlayerUse(Player P)
        {
            pickedUp     = true;
            P.showEndMsg = true;
            LightingEngine LE = (LightingEngine)Renderer.GetRenderEffect("LightingEngine");

            LE.RemoveLight(light);
            base.PlayerUse(P);
        }
Exemplo n.º 6
0
        public WorldScreen(Game Game)
            : base(Game, GeneralManager.ScreenX, GeneralManager.ScreenY)
        {
            GeneralManager.LoadAnimation("TestAnim", Vector2.One * 64, 6, 80);
            GeneralManager.LoadAnimation("PlayerIdle", Vector2.One * 64, 1, 10000);

            DebugWindow.Visible = false;
            DebugWindow.AddGUI(FarseerDebugCheck, DebugWindow);
            AddGUI(DebugWindow);

            LE = new LightingEngine();
            Color a = new Color(ambient, ambient, ambient);

            LE.SetAmbient(a, a);
            //LE.SetAmbient(Color.Gray, Color.Gray);
            Renderer.AddRendererEffect(LE, "LightingEngine");

            LoadContent();

            Map = new Map(this, tileSize, mapSize);
            //Renderer.AddPostProcess(new BlurEffect(), "Blur");
            SE               = new BlurSwitchEffect();
            SE.MaxTime       = 1f;
            SE.TurnOffAction = delegate() { Renderer.RemovePostProcess("Switch"); };
            Renderer.AddPostProcess(SE, "Switch");

            Camera.Init(GeneralManager.GetPartialRect(0, 0, 1, 1), new Rectangle(0, 0, tileSize * mapSize, tileSize * mapSize));

            PlayerLight = new SpotLight()
            {
                IsEnabled         = true,
                Color             = new Vector4(0.9f, .7f, .7f, 1f),
                Power             = .6f,
                LightDecay        = 600,
                Position          = new Vector3(500, 400, 20),
                SpotAngle         = 1.5f,
                SpotDecayExponent = 3,
                Direction         = new Vector3(0.244402379f, 0.969673932f, 0)
            };
            LE.AddLight(PlayerLight);

            Debug = new FarseerPhysics.DebugViews.DebugViewXNA(Map.PhysicalWorld);
            Debug.AppendFlags(FarseerPhysics.DebugViewFlags.Shape);
            Debug.AppendFlags(FarseerPhysics.DebugViewFlags.AABB);
            Debug.AppendFlags(FarseerPhysics.DebugViewFlags.PerformanceGraph);
            Debug.AppendFlags(FarseerPhysics.DebugViewFlags.Joint);
            Debug.AppendFlags(FarseerPhysics.DebugViewFlags.ContactPoints);
            Debug.DefaultShapeColor  = Color.White;
            Debug.SleepingShapeColor = Color.LightGray;
            Debug.LoadContent(Parent.GraphicsDevice, Parent.Content);

            //Weapon w = new Weapon("test", "Gun", 100, 10, Hands.One, 10, 600, 10, 10, 10);
            //Serializer.Serialize<Weapon>("weapon.xml", w);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Draw method
        /// </summary>
        /// <param name="gameTime">Time that passed since last Update loop</param>
        public void Draw(GameTime gameTime)
        {
            if (!Isolated && IsVisible)
            {
                Rectangle r = new Rectangle(position.X, position.Y, position.Width, position.Height);

                Renderer.Draw(GeneralManager.Textures[texName], r, Color.White, Z);

                LightingEngine LE = (LightingEngine)Renderer.GetRenderEffect("LightingEngine");
                LE.DrawNormal(GeneralManager.Textures[normName], r);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Set ShadowHull of Tile
        /// </summary>
        /// <param name="Size">Size</param>
        /// <param name="Pos">Position</param>
        public void SetRectHull(Vector2 Size, Vector2 Pos)
        {
            ShadowHull H = ShadowHull.CreateRectangle(Size);

            H.Position = Pos;
            LightingEngine LE = ((LightingEngine)Renderer.GetRenderEffect("LightingEngine"));

            if (Hull != null)
            {
                LE.RemoveHull(Hull);
            }
            LE.AddHull(H);
            this._Hull = H;
        }
        private void TryLoadCourseDir(string folder)
        {
            if (System.IO.File.Exists($"{folder}\\course.bgenv"))
            {
                var archive = (IArchiveFile)STFileLoader.OpenFileFormat($"{folder}\\course.bgenv");

                LightingEngine lightingEngine = new LightingEngine();
                lightingEngine.LoadArchive(archive.Files.ToList());
                LightingEngine.LightSettings = lightingEngine;
                LightingEngine.LightSettings.UpdateColorCorrectionTable();
            }
            if (System.IO.File.Exists($"{folder}\\course_bglpbd.szs"))
            {
                //ProbeMapManager.Prepare(EveryFileExplorer.YAZ0.Decompress($"{dir}\\course_bglpbd.szs"));
                //  DataCache.ModelCache.Add(bfres.Renderer.Name, bfres.Renderer);
            }
        }
Exemplo n.º 10
0
        public FloorFan(Rectangle r, Map m)
            : base(m)
        {
            LightingEngine LE = (LightingEngine)Renderer.GetRenderEffect("LightingEngine");

            FanAnim       = new Animation();
            FanNormalAnim = new AnimationNormal();

            FanAnim.Load("FloorFan", Vector2.One * 128, 6, 50);
            FanNormalAnim.Load("FloorFan_normal", Vector2.One * 128, 6, 50, LE);


            Position               = r;
            FanAnim.Position       = Position;
            FanNormalAnim.Position = Position;

            SetName("FloorFan");
        }
Exemplo n.º 11
0
        public override void use(ItemInInventory item)
        {
            base.use(item);
            MainForm instance       = MainForm.getInstance();
            Point    cursorLocation = MainForm.getInstance().getCursorBlockLocation();

            if (cursorLocation.X < instance.world.blocks.Count() && cursorLocation.Y < instance.world.blocks[5].Count())
            {
                if (instance.world.getBlockAt(cursorLocation.X, cursorLocation.Y) != null && instance.world.getBlockAt(cursorLocation.X, cursorLocation.Y).prototype.breakableBy.Equals(toolType))
                {
                    if (Util.distanceBetween(MainForm.getInstance().getCursorWorldLocation(), MainForm.getInstance().player.location) > 200)
                    {
                        return;
                    }
                    if (instance.world.getBlockAt(cursorLocation.X, cursorLocation.Y).prototype.hardness > instance.world.getBlockAt(cursorLocation.X, cursorLocation.Y).brokenness)
                    {
                        instance.world.getBlockAt(cursorLocation.X, cursorLocation.Y).brokenness += type.hardness;
                        Particle.spawnParticlesAround(Util.addPoints(instance.world.blocks[cursorLocation.X][cursorLocation.Y].location, new Point(10, 10)), instance.world.blocks[cursorLocation.X][cursorLocation.Y].prototype.color, 1);
                        return;
                    }
                    instance.player.inventory.addItem(instance.world.blocks[cursorLocation.X][cursorLocation.Y].prototype, 1);
                    bool shouldDoFullUpdate = false;
                    shouldDoFullUpdate = true;
                    instance.world.blocks[cursorLocation.X][cursorLocation.Y].prepareForRemoval();
                    DamageIndicator indicator = new DamageIndicator(instance.world.blocks[cursorLocation.X][cursorLocation.Y].location, instance.world.blocks[cursorLocation.X][cursorLocation.Y].getName());
                    //DamageIndicator indicator2 = new DamageIndicator(instance.world.blocks[cursorLocation.X][cursorLocation.Y].location, "■", Color.Brown);
                    Particle.spawnParticlesAround(Util.addPoints(instance.world.blocks[cursorLocation.X][cursorLocation.Y].location, new Point(10, 10)), instance.world.blocks[cursorLocation.X][cursorLocation.Y].prototype.color, 30);
                    instance.world.blocks[cursorLocation.X][cursorLocation.Y] = Block.createNewBlock(BlockPrototype.air, new Point(cursorLocation.X * 20, cursorLocation.Y * 20));
                    if (shouldDoFullUpdate)
                    {
                        LightingEngine.doFullLightingUpdate(false);
                    }
                    else
                    {
                        instance.world.updateSkyLightForColumn(cursorLocation.X);
                    }
                }
            }
        }
Exemplo n.º 12
0
        public virtual void use(ItemInInventory item)
        {
            if (!(item.item is BlockPrototype))
            {
                throw new ArgumentException("The provided item is not a BlockPrototype.");
            }
            BlockPrototype b = (BlockPrototype)item.item;

            /*Point p = MainForm.getInstance().getCursorBlockLocation();
             * if (MainForm.getInstance().world.blocks[p.X][p.Y].prototype == BlockPrototype.air) {
             *  Point pos = MainForm.getInstance().getTotalCursorPos();
             *  MainForm.getInstance().world.blocks[p.X][p.Y] = Block.createNewBlock(this, pos);
             *  item.useUp(1);
             * }*/
            Player   player      = MainForm.getInstance().player;
            MainForm mainform    = MainForm.getInstance();
            World    w           = mainform.world;
            Point    cursorBlock = mainform.getCursorBlockLocation();//new Point(mainform.player.blockX, mainform.player.blockY);//getCursorBlockLocation();
            Block    block       = w.getBlockAt(cursorBlock.X, cursorBlock.Y);

            if (block == null)
            {
                return;
            }
            if (Util.distanceBetween(block.location, mainform.player.location) > 200)
            {
                return;
            }
            if (block.prototype.id == "OpenTerraria:Air")
            {
                w.blocks[cursorBlock.X][cursorBlock.Y].prepareForRemoval();
                w.blocks[cursorBlock.X][cursorBlock.Y] = Block.createNewBlock(this, new Point(cursorBlock.X * 20, cursorBlock.Y * 20));
                w.updateSkyLightForColumn(cursorBlock.X);
            }
            Inventory inventory = MainForm.getInstance().getParentInventory(item);

            inventory.removeAmount(this, 1);
            LightingEngine.doFullLightingUpdate(false);
        }
Exemplo n.º 13
0
        public RedAlarmLamp(Rectangle r, Map m)
            : base(m)
        {
            Body BodyDec = new Body(m.PhysicalWorld);

            BodyDec.BodyType = BodyType.Static;

            PolygonShape S = new PolygonShape(1f);

            S.SetAsBox(r.Width / 2, r.Height / 2);

            Fixture             = BodyDec.CreateFixture(S);
            Fixture.Restitution = 1f;
            Fixture.Friction    = 10f;

            Position = r;

            SetName("RedAlarmLamp");


            AlertLight = new SpotLight()
            {
                IsEnabled         = true,
                Color             = new Vector4(0.9f, .1f, .1f, 1f),
                Power             = .6f,
                LightDecay        = 600,
                Position          = new Vector3(r.X, r.Y, 20),
                SpotAngle         = 1.5f,
                SpotDecayExponent = 3,
                Direction         = new Vector3(0.244402379f, 0.969673932f, 0)
            };

            LightingEngine LE = (LightingEngine)Renderer.GetRenderEffect("LightingEngine");

            LE.AddLight(AlertLight);
        }
Exemplo n.º 14
0
        private void TryLoadCourseDir(string folder)
        {
            if (System.IO.File.Exists($"{folder}\\course_muunt.byaml") && MapLoader.HasValidPath)
            {
                MapLoader.LoadSkybox($"{folder}\\course_muunt.byaml");

                foreach (var render in MapLoader.Renders)
                {
                    AddDrawable(render);
                }
            }
            if (System.IO.File.Exists($"{folder}\\course.bgenv"))
            {
                var archive = (IArchiveFile)STFileLoader.OpenFileFormat($"{folder}\\course.bgenv");

                LightingEngine lightingEngine = new LightingEngine();
                lightingEngine.LoadArchive(archive.Files.ToList());
                LightingEngine.LightSettings = lightingEngine;
                LightingEngine.LightSettings.UpdateColorCorrectionTable();

                //Generate light maps (area based lighting from directional and hemi lighting)
                foreach (var lmap in lightingEngine.Resources.LightMapFiles.Values)
                {
                    foreach (var lightMapArea in lmap.LightAreas)
                    {
                        LightingEngine.LightSettings.UpdateLightmap(Pipeline._context, lightMapArea.Settings.Name);
                    }
                }

                if (MapLoader.HasValidPath)
                {
                    //Create a list of models that can render onto cubemaps
                    List <GenericRenderer> cubemapRenderModels = new List <GenericRenderer>();
                    foreach (BfresRender model in Pipeline.SceneObjects)
                    {
                        if (model.IsSkybox) //Only load skybox (VR) map objects. Todo this should be improved.
                        {
                            cubemapRenderModels.Add(model);
                        }
                    }

                    //Load the main models (which in this case would be the course model)
                    foreach (var model in Pipeline.Files)
                    {
                        cubemapRenderModels.Add(model.Renderer);
                    }

                    //Generate cubemaps in the scene.

                    //Todo need to fixup cubemap generation as it typically has bugs on certain hardware.
                    //Certain games are also missing cubemap array support atm.
                    LightingEngine.LightSettings.UpdateCubemap(cubemapRenderModels, false);
                }
            }
            if (System.IO.File.Exists($"{folder}\\course_bglpbd.szs"))
            {
                //Todo handle probe lighting (they alter lightmaps for map objects)
                ProbeMapManager.Prepare(Toolbox.Core.IO.YAZ0.Decompress($"{folder}\\course_bglpbd.szs"));
            }
            if (System.IO.File.Exists($"{folder}\\course.bglpbd"))
            {
                //Todo handle probe lighting (they alter lightmaps for map objects)
                ProbeMapManager.Prepare(File.ReadAllBytes($"{folder}\\course.bglpbd"));
            }
        }
Exemplo n.º 15
0
        public override void Generate(Chunk Chunk)
        {
            this.Chunk = Chunk;
            xmax       = (int)Chunk.Size.X;
            ymax       = (int)Chunk.Size.Y;

            LightList   = new List <Vector2>();
            AlarmLights = new List <KeyValuePair <Vector2, Direction> >();

            CreateDungeon((int)Chunk.Size.X, (int)Chunk.Size.Y, 100);
            ConvertDungeon(Chunk);

            LightingEngine LE = (LightingEngine)Renderer.GetRenderEffect("LightingEngine");

            foreach (Vector2 V in LightList)
            {
                PointLight L = new PointLight()
                {
                    IsEnabled  = true,
                    Color      = new Vector4(0.9f, .2f, .2f, 1f),
                    Power      = .85f,
                    LightDecay = 300,
                    Position   = new Vector3(V.X * Chunk.tileSize, V.Y * Chunk.tileSize, 1),
                };

                LE.AddLight(L);
            }

            foreach (KeyValuePair <Vector2, Direction> Alarm in AlarmLights)
            {
                switch (Alarm.Value)
                {
                case Direction.North:
                    for (int i = -2; i <= 2; i++)
                    {
                        if (!(GetCellType((int)Alarm.Key.X + i, (int)Alarm.Key.Y) == Tile.DirtFloor || GetCellType((int)Alarm.Key.X + i, (int)Alarm.Key.Y) == Tile.Corridor) ||
                            (GetCellType((int)Alarm.Key.X + i, (int)Alarm.Key.Y - 1) == Tile.DirtFloor || GetCellType((int)Alarm.Key.X + i, (int)Alarm.Key.Y - 1) == Tile.Corridor))
                        {
                            break;
                        }
                    }

                    new RedAlarmLamp(new Rectangle((int)Alarm.Key.X * 64 + 32, (int)Alarm.Key.Y * 64 + 4, 16, 8), Chunk.map);

                    break;

                case Direction.South:

                    for (int i = -2; i <= 2; i++)
                    {
                        if (!(GetCellType((int)Alarm.Key.X + i, (int)Alarm.Key.Y + 1) == Tile.DirtFloor || GetCellType((int)Alarm.Key.X + i, (int)Alarm.Key.Y + 1) == Tile.Corridor) ||
                            (GetCellType((int)Alarm.Key.X + i, (int)Alarm.Key.Y) == Tile.DirtFloor || GetCellType((int)Alarm.Key.X + i, (int)Alarm.Key.Y) == Tile.Corridor))
                        {
                            break;
                        }
                    }

                    RedAlarmLamp tmp = new RedAlarmLamp(new Rectangle((int)Alarm.Key.X * 64 + 32, (int)Alarm.Key.Y * 64 + 60, 16, 8), Chunk.map);
                    tmp.Fixture.Body.Rotation = (float)Math.PI;

                    break;

                case Direction.East:

                    break;

                case Direction.West:

                    break;
                }
            }
        }
Exemplo n.º 16
0
        public Player(Rectangle pos, Map m) : base(m)
        {
            Body BodyDec = new Body(m.PhysicalWorld);

            BodyDec.BodyType = BodyType.Dynamic;

            Fixture = BodyDec.CreateFixture(new CircleShape(15f, 1.0f));

            Body BodyDecSensor = new Body(m.PhysicalWorld);

            BodyDecSensor.BodyType = BodyType.Dynamic;

            PlayerSensor = BodyDecSensor.CreateFixture(new CircleShape(15f, .0f));
            PlayerSensor.Body.IsSensor = true;
            PlayerSensor.OnCollision  += OnSensorCollide;

            this.Name       = "player";
            this.texName    = "Mobs/" + Name;
            this.normalName = "Mobs/" + Name + "_normal";

            this.Position = pos;
            hp            = 100;
            def           = 10;
            damage        = 5;
            lucky         = 123135;
            this.map      = m;
            speed         = 15500f;

            weapon = new AK47();

            IdleAnim       = new Animation();
            IdleNormalAnim = new AnimationNormal();

            WalkAnim       = new Animation();
            WalkNormalAnim = new AnimationNormal();

            IdleAnim        = GeneralManager.Animations["PlayerIdle"];
            IdleAnim.Center = Vector2.One * 32;

            IdleNormalAnim.Load("PlayerIdle_normal", Vector2.One * 64, 1, 10000, (LightingEngine)Renderer.GetRenderEffect("LightingEngine"));
            IdleNormalAnim.Center = Vector2.One * 32;

            WalkAnim        = GeneralManager.Animations["TestAnim"];
            WalkAnim.Center = Vector2.One * 32;

            WalkNormalAnim.Load("TestAnim_normal", Vector2.One * 64, 6, 80, (LightingEngine)Renderer.GetRenderEffect("LightingEngine"));
            WalkNormalAnim.Center = Vector2.One * 32;

            LightingEngine LE = (LightingEngine)Renderer.GetRenderEffect("LightingEngine");

            ShootLight = new SpotLight()
            {
                IsEnabled         = true,
                Color             = new Vector4(0.95f, .7f, .05f, 1f),
                Power             = .6f,
                LightDecay        = 600,
                Position          = new Vector3(500, 400, 20),
                SpotAngle         = 2f * 3.1415f,
                SpotDecayExponent = 3,
                Direction         = new Vector3(0.244402379f, 0.969673932f, 0)
            };

            LE.AddLight(ShootLight);

            stoper = new Stopwatch();
            stoper.Start();
        }