示例#1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="World"/> class.
 /// </summary>
 /// <param name="parentGame">The Game in which the instance lives.</param>
 /// <param name="worldPerPixelRatio">The number of world units for each pixel.</param>
 /// <param name="gravity">The gravity that will be applied to world objects.</param>
 /// <param name="bounds">The world's bounds.</param>
 internal World(BaseGame parentGame, RectangleF bounds, float worldPerPixelRatio, Vector2 gravity)
     : base(parentGame)
 {
     this.Bounds                   = bounds;
     this.worldSpriteObjects       = new ThrottledCollection <QuadTree <SpriteBase, List <SpriteBase> >, SpriteBase>(new QuadTree <SpriteBase, List <SpriteBase> >(bounds, 4));
     this.worldSimObjects          = new ThrottledCollection <SortedSet <SimBase>, SimBase>(new SortedSet <SimBase>());
     this.screenDrawableComponents = new ThrottledCollection <SortedSet <ScreenDrawableComponent>, ScreenDrawableComponent>(new SortedSet <ScreenDrawableComponent>());
     this.physicsWorld             = new FarseerPhysics.Dynamics.World(gravity);
     this.worldPerPixelRatio       = worldPerPixelRatio;
     this.parentGame               = parentGame;
 }
示例#2
0
        public GameEnvironment(Controller ctrl)
            : base(ctrl)
        {
            Pressure = 0.0f;

            Sound.StopAll(true);

            // Camera.
            Camera = new Camera2D(this);
            //Camera.Position = new Vector2(1280.0f, k_idealScreenSize.Y * 0.5f);
            Camera.MoveSpeed = defaultCameraMoveSpeed;
            Camera.ResetEffectScale(1.0f);             // Set at slightly higher than 1.0 so we can do a zoom out pressure effect.

            // Window.
            Controller.Window.ClientSizeChanged += WindowSizeChanged;
            WindowSizeChanged(null, null);
            Controller.IsMouseVisible = true;

            // Collision.
            CollisionWorld = new Physics.Dynamics.World(Vector2.Zero);

            // Create a new SpriteBatch which can be used to draw textures.
            m_spriteBatch = new SpriteBatch(ctrl.GraphicsDevice);

            ParticleRenderer = new SpriteBatchRenderer {
                GraphicsDeviceService = ctrl.Graphics
            };

            ParticleRenderer.LoadContent(contentManager);

            // Create collision notification callbacks.
            CollisionWorld.ContactManager.PreSolve      += PreSolve;
            CollisionWorld.ContactManager.BeginContact  += BeginContact;
            CollisionWorld.ContactManager.EndContact    += EndContact;
            CollisionWorld.ContactManager.ContactFilter += ContactFilter;

            // HUD.
            HUD = new Menus.HUD(this);

            // Effects.
            m_tintEffect = contentManager.Load <Effect>("TintEffect");

            FadeOut = new FaderOuter(this);

            SpawnController = new SpawnController(this);

            // Farseer freaks out unless we call Update here when changing Environments.  FIXME: Why?
            Update(0.0f);
        }
示例#3
0
        /// <summary>
        /// Destroy the collision body attached to this body.
        /// </summary>
        public void DestroyCollisionBody()
        {
            if (CollisionBody == null)
            {
                return;
            }

            m_position = CollisionBody.Position * GameEnvironment.k_invPhysicsScale;
            if (!VisualRotationOnly)
            {
                m_rotation = CollisionBody.Rotation;
            }

            CollisionWorld.RemoveBody(CollisionBody);
            CollisionWorld = null;
            CollisionBody  = null;
        }
示例#4
0
        private void InitializeGame()
        {
            //Initialize game
            World             = new FarseerPhysics.Dynamics.World(Vector2.Zero);
            TimerFactory      = new Timer.Factory();
            AnimationEngine   = new Rendering.Animations.AnimationEngine();
            ParticleEngine    = new Rendering.Particles.ParticleEngine(this);
            EventEngine       = new Core.Events.EventEngine(this);
            SharedRandom      = new Random();
            Diagnostics       = new Diagnostics();
            RPCHelper         = new RPC.RemoteProcedureCallHelper(this);
            LightEngine       = new Rendering.Lighting.LightEngine();
            SoundEngine       = new Sound.SoundEngine(this);
            DiagnosticsParent = "Game Update";

            Gamemode.Create();
            Logger.Info(Strings.Engine.GameCreated + $" ({Gamemode.DisplayName})");
        }
示例#5
0
        public GameEnvironment(Controller ctrl)
            : base(ctrl)
        {
            //Frame rate variables initialize
            frameTime = 0;
            fps = 30;
            frameCounter = 0;

            // Create a new SpriteBatch, which can be used to draw textures.
            m_spriteBatch = new SpriteBatch(ctrl.GraphicsDevice);

            CollisionWorld = new Physics.Dynamics.World(Vector2.Zero);

            m_debugView = new Physics.DebugViewXNA(CollisionWorld);
            m_debugView.AppendFlags(Physics.DebugViewFlags.DebugPanel);

            // Create collision notification callbacks.
            CollisionWorld.ContactManager.PreSolve += PreSolve;

            // TODO: Scale to physics world.
            m_debugPhysicsMatrix = Matrix.CreateOrthographicOffCenter(0.0f, m_controller.GraphicsDevice.Viewport.Width * k_physicsScale, m_controller.GraphicsDevice.Viewport.Height * k_physicsScale, 0.0f, -1.0f, 1.0f);
        }
示例#6
0
        /// <summary>
        /// Create and attach a new collision body to this Entity.
        /// </summary>
        /// <param name="world">CollisionWorld instance.</param>
        /// <param name="type">Type of collision body.  Dynamic bodies receive responses, kinematic bodies do not.  Static bodies cannot move.</param>
        /// <param name="flags">Flags.</param>
        public void CreateCollisionBody(Physics.Dynamics.World world, Physics.Dynamics.BodyType type, CollisionFlags flags = CollisionFlags.Default)
        {
            if (CollisionBody != null)
            {
                throw new ArgumentException("CreateCollisionBody called on Entity where collision body already exists.");
            }
            CollisionWorld = world;

            Physics.Dynamics.Body body = world.CreateBody();

            body.BodyType = type;
            body.Position = m_position * GameEnvironment.k_physicsScale;
            if (!VisualRotationOnly)
            {
                body.Rotation = m_rotation;
            }
            body.LinearVelocity  = m_velocity * GameEnvironment.k_physicsScale;
            body.FixedRotation   = flags.HasFlag(CollisionFlags.FixedRotation);
            body.SleepingAllowed = !flags.HasFlag(CollisionFlags.DisableSleep);
            body.IsBullet        = flags.HasFlag(CollisionFlags.IsBullet);
            body.UserData        = this;

            CollisionBody = body;
        }
示例#7
0
        public GameEnvironment(Controller ctrl)
            : base(ctrl)
        {
            Sound.StopAll(true);

            CollisionWorld = new Physics.Dynamics.World(Vector2.Zero);
            Controller.Window.ClientSizeChanged += WindowSizeChanged;
            Camera = new Camera2D(this);
            WindowSizeChanged(null, null);

            // Create a new SpriteBatch which can be used to draw textures.
            m_spriteBatch = new SpriteBatch(ctrl.GraphicsDevice);

            ParticleRenderer = new SpriteBatchRenderer {
                GraphicsDeviceService = ctrl.Graphics
            };

            ExplosionEffect = contentManager.Load<ParticleEffect>("ExplosionEffect");
            ThrusterEffect = contentManager.Load<ParticleEffect>("ThrusterEffect");
            FrostThrusterEffect = contentManager.Load<ParticleEffect>("FrostThrusterEffect");
            AttachEffect = contentManager.Load<ParticleEffect>("AttachEffect");
            BlackHoleEffect = contentManager.Load<ParticleEffect>("BlackHoleEffect");
            AlertEffect = contentManager.Load<ParticleEffect>("AlertEffect");
            TractorBeamEffect = contentManager.Load<ParticleEffect>("TractorBeamEffect");

            EffectsBelowShip.Add(ThrusterEffect);
            EffectsBelowShip.Add(FrostThrusterEffect);
            EffectsBelowShip.Add(TractorBeamEffect);

            EffectsAboveShip.Add(ExplosionEffect);
            EffectsAboveShip.Add(AttachEffect);
            EffectsAboveShip.Add(BlackHoleEffect);
            EffectsAboveShip.Add(AlertEffect);

            ParticleRenderer.LoadContent(contentManager);

            foreach (var e in EffectsBelowShip) {
                e.Initialise();
                e.LoadContent(contentManager);
            }

            foreach (var e in EffectsAboveShip) {
                e.Initialise();
                e.LoadContent(contentManager);
            }

            // Create collision notification callbacks.
            CollisionWorld.ContactManager.PreSolve += PreSolve;
            CollisionWorld.ContactManager.BeginContact += BeginContact;
            CollisionWorld.ContactManager.EndContact += EndContact;
            CollisionWorld.ContactManager.ContactFilter += ContactFilter;

            // first parameter controls how strong the pull is; the second parameter controls the radius of the pull.
            BlackHoleController = new BlackHolePhysicsController(500.0f, 250.0f * k_physicsScale, 9.0f * k_physicsScale);
            CollisionWorld.AddController(BlackHoleController);

            ShipCollisionAvoidanceController shipAvoid = new ShipCollisionAvoidanceController(150.0f * k_physicsScale);
            shipAvoid.MaxRadius = 80.0f * k_physicsScale;
            CollisionWorld.AddController(shipAvoid);

            // HUD.
            HUD = new Menus.HUD(this);

            // Farseer freaks out unless we call Update here when changing Environments.  FIXME: Why?
            Update(0.0f);
        }
示例#8
0
 public override void Load(FarseerPhysics.Dynamics.World world)
 {
     base.Load(world);
 }
示例#9
0
 public override void Load(FarseerPhysics.Dynamics.World world)
 {
     Texture = TextureBank.GetTexture("Powerup");
 }
示例#10
0
 /// <summary>
 /// Creates a new <see cref="Playground"/> instance.
 /// </summary>
 /// <param name="state">The <see cref="Gamestate"/> the instance is tied to.</param>
 public Playground(Gamestate state)
 {
     State = state;
     World = new FarseerPhysics.Dynamics.World(new Vector2(0f, 0.9f));
 }
示例#11
0
        protected override void Initialize()
        {
            _inputState = new InputState();
            tileManager = new TileManager();
            tileMap = new TileMap(tileManager, new int2(Global.mapWidth, Global.mapHeight));
            entityWorld = new EntityWorld();
            entityTileMap = new EntityTileMap(entityWorld, new int2(Global.mapWidth, Global.mapHeight));
            disFieldMixer = new DisFieldMixer();
            textureManager = new TextureManager();
            animationManager = new AnimationManager();
            world = new FarseerPhysics.Dynamics.World(new Vector2(0f, 0f));
            generator = new Generator(tileMap);
            lord = new Lord("Obama", Color.Red, 0);
            enemyLord = new Lord("Justin Bieber", Color.Brown, 1);
            unitController = new UnitController(null, _inputState, entityWorld, disFieldMixer, lord);

            spriteBatch = new SpriteBatch(GraphicsDevice);

            graphics.PreferredBackBufferWidth = Global.ViewportWidth;
            graphics.PreferredBackBufferHeight = Global.ViewportHeight;
            graphics.ApplyChanges();

            EntitySystem.BlackBoard.SetEntry<SpriteBatch>("SpriteBatch", spriteBatch);
            EntitySystem.BlackBoard.SetEntry<TextureManager>("TextureManager", textureManager);
            EntitySystem.BlackBoard.SetEntry<TileMap>("TileMap", tileMap);
            EntitySystem.BlackBoard.SetEntry<EntityTileMap>("EntityTileMap", entityTileMap);
            EntitySystem.BlackBoard.SetEntry<DisFieldMixer>("DisFieldMixer", disFieldMixer);
            EntitySystem.BlackBoard.SetEntry<FarseerPhysics.Dynamics.World>("PhysicsWorld", world);
            EntitySystem.BlackBoard.SetEntry<Generator>("Generator", generator);
            EntitySystem.BlackBoard.SetEntry<AnimationManager>("AnimationManager", animationManager);

            this.entityWorld.InitializeAll(true);

            base.Initialize();
        }
示例#12
0
文件: Entity.cs 项目: jwmcglynn/TeamQ
        /// <summary>
        /// Destroy the collision body attached to this body.
        /// </summary>
        public void DestroyCollisionBody()
        {
            if (CollisionBody == null) return;

            m_position = CollisionBody.Position * GameEnvironment.k_invPhysicsScale;
            if (!VisualRotationOnly) m_rotation = CollisionBody.Rotation;

            CollisionWorld.RemoveBody(CollisionBody);
            CollisionWorld = null;
            CollisionBody = null;
        }
示例#13
0
文件: Entity.cs 项目: jwmcglynn/TeamQ
        /// <summary>
        /// Create and attach a new collision body to this Entity.
        /// </summary>
        /// <param name="world">CollisionWorld instance.</param>
        /// <param name="type">Type of collision body.  Dynamic bodies receive responses, kinematic bodies do not.  Static bodies cannot move.</param>
        /// <param name="flags">Flags.</param>
        public void CreateCollisionBody(Physics.Dynamics.World world, Physics.Dynamics.BodyType type, CollisionFlags flags = CollisionFlags.Default)
        {
            if (CollisionBody != null) throw new ArgumentException("CreateCollisionBody called on Entity where collision body already exists.");
            CollisionWorld = world;

            Physics.Dynamics.Body body = world.CreateBody();

            body.BodyType = type;
            body.Position = m_position * GameEnvironment.k_physicsScale;
            if (!VisualRotationOnly) body.Rotation = m_rotation;
            body.LinearVelocity = m_velocity * GameEnvironment.k_physicsScale;
            body.FixedRotation = flags.HasFlag(CollisionFlags.FixedRotation);
            body.SleepingAllowed = !flags.HasFlag(CollisionFlags.DisableSleep);
            body.IsBullet = flags.HasFlag(CollisionFlags.IsBullet);
            body.UserData = this;

            CollisionBody = body;
        }
示例#14
0
        /// <summary>
        /// Destroy the collision body attached to this body.
        /// </summary>
        public void DestroyCollisionBody()
        {
            if (CollisionBody == null) return;

            m_collisionWorld.RemoveBody(CollisionBody);
            m_collisionWorld = null;
            CollisionBody = null;
        }