Esempio n. 1
0
        PlayerUnit(Gamestate oldState, GamestateBuilder newState)
        {
            Assert.Ref(oldState, newState);

            PlayerUnit oldUnit = oldState.PlayerUnit;

            texture = oldUnit.texture;

            InputDevice device = oldState.Input.Devices[oldUnit.inputDevice];
            RigidBody   body   = (RigidBody)(oldState.Physics.PhysicsBodies[oldUnit.rigidBody]);
            Sprite      spr    = (Sprite)(oldState.Video.Drawables[oldUnit.sprite]);

            float   x    = device.GetAxisFrac("Horizontal");
            float   y    = device.GetAxisFrac("Vertical");
            Vector2 move = new Vector2(x, y).ClampMagnitude(0, 1) * accel;

            body = body.AddImpulse(move);

            inputDevice = newState.Input.AddDevice(device);
            rigidBody   = newState.Physics.AddPhysicsObject(body);
            sprite      = newState.Video.AddDrawable(spr.Reposition(body.Position));
            newState.Audio.SetListenerPosition(body.Position);

            Window     window       = oldState.Video.Windows[0];
            Vector2    centerOffset = new Vector2(window.Rect.W / 2, window.Rect.H / 2);
            WorldPoint cameraPos    = body.Position.PixelTranslate(-centerOffset + new Vector2(16, 16));

            newState.Video.SetCamera(new Camera(cameraPos));
        }
Esempio n. 2
0
File: Game.cs Progetto: idafi/heng
        static bool Init()
        {
            CoreConfig config = new CoreConfig();

            config.Log.MinLevelConsole = LogLevel.Debug;
            config.Log.MinLevelFile    = LogLevel.Warning;

            config.Events.EvLogMode = EventLogMode.Input;

            config.Audio.Format                      = heng.Audio.AudioFormat.S16;
            config.Audio.SampleRate                  = 44100;
            config.Audio.Channels                    = 2;
            config.Audio.Sounds.MaxSounds            = 1024;
            config.Audio.Mixer.ChannelCount          = 32;
            config.Audio.Mixer.AttenuationThreshold  = 32;
            config.Audio.Mixer.StereoFalloffExponent = 0.15f;

            if (Engine.Init(config))
            {
                Log.AddLogger(new ConsoleLogger(), LogLevel.Debug);
                Log.AddLogger(new FileLogger(), LogLevel.Warning);

                builder   = new GamestateBuilder();
                gamestate = builder.Build(null);
                builder.Clear();

                return(true);
            }

            return(false);
        }
Esempio n. 3
0
File: Unit.cs Progetto: idafi/heng
        Unit(Gamestate oldState, GamestateBuilder newState)
        {
            Unit oldUnit = oldState.Unit;

            texture = oldUnit.texture;

            RigidBody body = (RigidBody)(oldState.Physics.PhysicsBodies[oldUnit.rigidBody]);
            Sprite    spr  = (Sprite)(oldState.Video.Drawables[oldUnit.sprite]);

            rigidBody = newState.Physics.AddPhysicsObject(body);
            sprite    = newState.Video.AddDrawable(spr.Reposition(body.Position));
        }
Esempio n. 4
0
File: Unit.cs Progetto: idafi/heng
        public Unit(GamestateBuilder newState)
        {
            Assert.Ref(newState);

            texture = new Texture("../../data/textest.bmp");

            WorldPoint pos = new WorldPoint((116, 200 - 16));

            Polygon   collider = new Polygon(new Vector2(0, 0), new Vector2(32, 0), new Vector2(32, 32), new Vector2(0, 32));
            RigidBody body     = new RigidBody(pos, new ConvexCollider(collider), 1f, PhysicsMaterialLibrary.Steel);
            Sprite    spr      = new Sprite(texture, pos, 0);

            rigidBody = newState.Physics.AddPhysicsObject(body);
            sprite    = newState.Video.AddDrawable(spr);
        }
Esempio n. 5
0
        Scenery(Gamestate oldState, GamestateBuilder newState)
        {
            Assert.Ref(oldState, newState);

            Scenery oldScenery = oldState.Scenery;

            sound = oldScenery.sound;

            InputDevice  device = oldState.Input.Devices[oldScenery.inputDevice];
            StaticBody   body   = (StaticBody)(oldState.Physics.PhysicsBodies[oldScenery.staticBody]);
            RectDrawable drw    = (RectDrawable)(oldState.Video.Drawables[oldScenery.rectDrawable]);
            SoundSource  src    = oldState.Audio.SoundSources[oldScenery.soundSource];

            if (device.GetButtonPressed("SoundTest"))
            {
                src = src.PlaySound(sound);
            }

            inputDevice  = newState.Input.AddDevice(device);
            staticBody   = newState.Physics.AddPhysicsObject(body);
            rectDrawable = newState.Video.AddDrawable(drw);
            soundSource  = newState.Audio.AddSoundSource(src);
        }
Esempio n. 6
0
        public Scenery(GamestateBuilder newState)
        {
            Assert.Ref(newState);

            sound = new Sound("../../data/sto.ogg");

            InputDevice device = new InputDevice();

            device.RemapButton("SoundTest", new Key(KeyCode.Space));

            WorldPoint pos  = new WorldPoint(new Vector2(276, 140));
            Rect       rect = new Rect(Vector2.Zero, new Vector2(256, 16));

            Polygon      collider = new Polygon(new Vector2(-256, -16), new Vector2(256, -16), new Vector2(256, 16), new Vector2(-256, 16));
            StaticBody   body     = new StaticBody(pos, new ConvexCollider(collider), PhysicsMaterialLibrary.Concrete);
            RectDrawable drw      = new RectDrawable(rect, pos, true, Color.Black);
            SoundSource  src      = new SoundSource(body.Position);

            inputDevice  = newState.Input.AddDevice(device);
            staticBody   = newState.Physics.AddPhysicsObject(body);
            rectDrawable = newState.Video.AddDrawable(drw);
            soundSource  = newState.Audio.AddSoundSource(src);
        }
Esempio n. 7
0
        public PlayerUnit(GamestateBuilder newState)
        {
            Assert.Ref(newState);

            texture = new Texture("../../data/textest.bmp");

            InputDevice device = new InputDevice();

            device.RemapAxis("Horizontal", new ButtonAxis(new Key(KeyCode.Left), new Key(KeyCode.Right)));
            device.RemapAxis("Vertical", new ButtonAxis(new Key(KeyCode.Down), new Key(KeyCode.Up)));

            WorldPoint pos = new WorldPoint(new Vector2(280 - 16, 200 - 16));

            Polygon   collider = new Polygon(new Vector2(0, 0), new Vector2(32, 0), new Vector2(32, 32), new Vector2(0, 32));
            RigidBody body     = new RigidBody(pos, new ConvexCollider(collider), 1f, PhysicsMaterialLibrary.Steel);
            Sprite    spr      = new Sprite(texture, pos, 0);

            inputDevice = newState.Input.AddDevice(device);
            rigidBody   = newState.Physics.AddPhysicsObject(body);
            sprite      = newState.Video.AddDrawable(spr);
            newState.Audio.SetListenerPosition(body.Position);

            newState.Video.SetCamera(new Camera(body.Position));
        }
Esempio n. 8
0
File: Unit.cs Progetto: idafi/heng
 public Unit Update(Gamestate oldState, GamestateBuilder newState)
 {
     return(new Unit(oldState, newState));
 }
Esempio n. 9
0
 public Scenery Update(Gamestate oldState, GamestateBuilder newState)
 {
     return(new Scenery(oldState, newState));
 }