Пример #1
0
        /// <summary>
        /// Call this in LoadContent after all the level is set up
        /// </summary>
        public void ExtablishDebugView(GraphicsDevice graphicsDevice, ContentManager content)
        {
            //Give your world to debugView
            DebugView = new DebugViewXNA(LevelWorld);
            //DebugView have many Property you can add
            DebugView.RemoveFlags(DebugViewFlags.Shape);
            DebugView.RemoveFlags(DebugViewFlags.Joint);
            DebugView.DefaultShapeColor  = Color.LightPink;
            DebugView.SleepingShapeColor = Color.MediumPurple;
            //add your GraphicsDevice & your ContentManager

            DebugView.AppendFlags(DebugViewFlags.CenterOfMass);
            DebugView.AppendFlags(DebugViewFlags.PerformanceGraph);
            DebugView.AppendFlags(DebugViewFlags.Shape);
            DebugView.AppendFlags(DebugViewFlags.ContactPoints);
            DebugView.AppendFlags(DebugViewFlags.PolygonPoints);
            DebugView.AppendFlags(DebugViewFlags.ContactNormals);

            DebugView.DefaultShapeColor  = Color.White;
            DebugView.SleepingShapeColor = Color.LightGray;

            DebugView.DebugPanelPosition     = Vector2.Zero;
            DebugView.PerformancePanelBounds = graphicsDevice.ScissorRectangle;

            DebugView.LoadContent(graphicsDevice, content);
        }
Пример #2
0
        public override void LoadContent()
        {
            base.LoadContent();
            if (World == null)
                return;

            DebugView = new DebugViewXNA(World);
            DebugView.AppendFlags(DebugViewFlags.TexturedShape);
            DebugView.RemoveFlags(DebugViewFlags.Shape);
            DebugView.RemoveFlags(DebugViewFlags.Joint);

            DebugView.DefaultShapeColor = Color.White;
            DebugView.SleepingShapeColor = Color.LightGray;

            DebugView.LoadContent(ScreenManager.GraphicsDevice, ScreenManager.ContentManager);
            Vector2 gameWorld =
                Camera2D.ConvertScreenToWorld(new Vector2(ScreenManager.Camera.ScreenWidth,
                                                          ScreenManager.Camera.ScreenHeight));
            _border = new Border(World, gameWorld.X, gameWorld.Y, 1f);

            ScreenManager.Camera.ProjectionUpdated += UpdateScreen;

            // Loading may take a while... so prevent the game from "catching up" once we finished loading
            ScreenManager.Game.ResetElapsedTime();
        }
Пример #3
0
        public override void LoadContent()
        {
            base.LoadContent();
            if (World == null)
            {
                return;
            }

            DebugView = new DebugViewXNA(World);
            DebugView.AppendFlags(DebugViewFlags.TexturedShape);
            DebugView.RemoveFlags(DebugViewFlags.Shape);
            DebugView.RemoveFlags(DebugViewFlags.Joint);

            DebugView.DefaultShapeColor  = Color.White;
            DebugView.SleepingShapeColor = Color.LightGray;

            DebugView.LoadContent(ScreenManager.GraphicsDevice, ScreenManager.ContentManager);
            Vector2 gameWorld =
                Camera2D.ConvertScreenToWorld(new Vector2(ScreenManager.Camera.ScreenWidth,
                                                          ScreenManager.Camera.ScreenHeight));

            _border = new Border(World, gameWorld.X, gameWorld.Y, 1f);

            ScreenManager.Camera.ProjectionUpdated += UpdateScreen;

            // Loading may take a while... so prevent the game from "catching up" once we finished loading
            ScreenManager.Game.ResetElapsedTime();
        }
        public void InitializePhysics(GraphicsDevice graphics, ContentManager Content)
        {
            // Catching Viewport dimensions
            ViewportWidth  = graphics.Viewport.Width;
            ViewportHeight = graphics.Viewport.Height;

            if (Penumbra == null)
            {
                Penumbra = new PenumbraComponent(graphics, Content);
            }

            // Our world for the physics body
            _World = new World(Vector2.Zero);

            // Unit conversion rule to get the right position data between simulation space and display space
            ConvertUnits.SetDisplayUnitToSimUnitRatio(MeterInPixels);

            // Initialize the physics debug view
            PhysicsDebugView = new DebugViewXNA(_World);
            PhysicsDebugView.LoadContent(graphics, Content);
            PhysicsDebugView.RemoveFlags(DebugViewFlags.Controllers);
            PhysicsDebugView.RemoveFlags(DebugViewFlags.Joint);
            PhysicsDebugView.RemoveFlags(DebugViewFlags.Shape);
            PhysicsDebugView.DefaultShapeColor = new Color(255, 255, 0);
        }
Пример #5
0
 private void InitDebug()
 {
     _debugView = new DebugViewXNA(World);
     _debugView.RemoveFlags(DebugViewFlags.Shape);
     _debugView.RemoveFlags(DebugViewFlags.Joint);
     _debugView.DefaultShapeColor  = Color.White;
     _debugView.SleepingShapeColor = Color.LightGray;
     _debugView.LoadContent(GraphicsDevice, Game1.contentManager);
 }
Пример #6
0
 public Scene(SpriteBatch sb, GraphicsDeviceManager graphicsDeviceManager, GraphicsDevice gd, GameWindow window,
              ContentManager content, int FOVWidth, int FOVHeight, IDrawSystem system = null)
 {
     buffer                 = new RenderTarget2D(gd, graphicsDeviceManager.PreferredBackBufferWidth, graphicsDeviceManager.PreferredBackBufferHeight);
     GraphicsDevice         = gd;
     SpriteBatch            = sb;
     _graphicsDeviceManager = graphicsDeviceManager;
     Content                = content;
     GameWindow             = window;
     Camera                 = new Camera(this, gd.Viewport)
     {
         FOV = new Vector2(FOVWidth, FOVHeight)
     };
     Input.Instance              = new Input(this);
     GameObjects                 = new GameObjectManager(this);
     TiledPrefabs                = new Dictionary <string, Type>();
     World                       = new World(Vector2.Zero);
     Settings.AllowSleep         = true;
     Settings.VelocityIterations = 2;
     Settings.ContinuousPhysics  = true;
     DebugView                   = new DebugViewXNA(World);
     DebugView.RemoveFlags(DebugViewFlags.Shape);
     DebugView.RemoveFlags(DebugViewFlags.Joint);
     DebugView.DefaultShapeColor  = Color.LightPink;
     DebugView.SleepingShapeColor = Color.MediumPurple;
     DebugView.LoadContent(GraphicsDevice, content);
     DebugView.AppendFlags(DebugViewFlags.DebugPanel);
     DebugView.AppendFlags(DebugViewFlags.PerformanceGraph);
     Debug = true;
     LoadedTiledPrefabs = new List <TiledPrefab>();
     Pipeline           = new CludoContentPipeline(gd);
     Vector             = Pipeline.LoadContent <Texture2D>("Vector", content, true);
     Line = new Texture2D(GraphicsDevice, 1, 1);
     Line.SetData(new[] { Color.White });
     GameWindow.ClientSizeChanged +=
         (sender, args) => {
         VirtualResolutionScaler = new VirtualResolutionScaler(this,
                                                               graphicsDeviceManager.PreferredBackBufferWidth, graphicsDeviceManager.PreferredBackBufferHeight,
                                                               gd, true);
     };
     VirtualResolutionScaler = new VirtualResolutionScaler(this,
                                                           graphicsDeviceManager.PreferredBackBufferWidth, graphicsDeviceManager.PreferredBackBufferHeight,
                                                           gd, true);
     Pipeline.LoadContent <SpriteFont>("Font", Content, true);
     if (system == null)
     {
         SetDrawSystem(new NormalDrawSystem(GraphicsDevice, this,
                                            new Vector2(graphicsDeviceManager.PreferredBackBufferWidth,
                                                        graphicsDeviceManager.PreferredBackBufferHeight)));
     }
     else
     {
         SetDrawSystem(system);
     }
     StartScene();
 }
Пример #7
0
 public PhysicsBase()
 {
     World     = new World(new Vector2(0, 0));
     DebugView = new DebugViewXNA(World);
     DebugView = new DebugViewXNA(World);
     DebugView.RemoveFlags(DebugViewFlags.Shape);
     DebugView.RemoveFlags(DebugViewFlags.Joint);
     DebugView.DefaultShapeColor  = Color.White;
     DebugView.SleepingShapeColor = Color.LightGray;
     DebugView.LoadContent(GraphicsExt.graphics.GraphicsDevice, ContentExt.Content);
 }
Пример #8
0
        //TODO: debugview in eiegene componente auslagern

        public WorldManager()
        {
            this.WorldStep = 30f;

            this.IsEnabled       = true;
            this.EntitiesInRange = new List <Entity>();
            this.World           = new World(Vector2.Zero);


#if DEBUG
            debug = new DebugViewXNA(this.World);
            debug.DefaultShapeColor  = Color.White;
            debug.SleepingShapeColor = Color.LightGray;


            //    debug.AppendFlags(DebugViewFlags.PerformanceGraph);

            //    debug.AppendFlags(DebugViewFlags.DebugPanel);

            debug.AppendFlags(DebugViewFlags.ContactPoints);
            //     debug.AppendFlags(DebugViewFlags.ContactNormals);


            //      debug.AppendFlags(DebugViewFlags.PolygonPoints);


            debug.AppendFlags(DebugViewFlags.Controllers);
            debug.AppendFlags(DebugViewFlags.CenterOfMass);
            debug.AppendFlags(DebugViewFlags.AABB);

            debug.RemoveFlags(DebugViewFlags.Joint);
#endif
        }
Пример #9
0
        private void TryInitPhysDbg()
        {
            if (Physics.World == null)
            {
                dbgv_?.Dispose();
                return;
            }

            if (dbgv_ != null)
            {
                return;
            }

            dbgv_ = new DebugViewXNA(Physics.World);
            dbgv_.LoadContent(Graphics.Device, Content.Manager);
            dbgv_.RemoveFlags((DebugViewFlags)Int32.MaxValue);
            //        dbgv_.AppendFlags(DebugViewFlags.AABB);
            dbgv_.AppendFlags(DebugViewFlags.CenterOfMass);
            //        dbgv_.AppendFlags(DebugViewFlags.ContactNormals);
            dbgv_.AppendFlags(DebugViewFlags.ContactPoints);
            //        dbgv_.AppendFlags(DebugViewFlags.Controllers);
            //        dbgv.AppendFlags(DebugViewFlags.DebugPanel);
            dbgv_.AppendFlags(DebugViewFlags.Joint);
            //        dbgv.AppendFlags(DebugViewFlags.PerformanceGraph);
            dbgv_.AppendFlags(DebugViewFlags.PolygonPoints);
            dbgv_.AppendFlags(DebugViewFlags.Shape);
        }
Пример #10
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            if (DebugView == null)
            {
                DebugView = new DebugViewXNA(World);
                DebugView.RemoveFlags(DebugViewFlags.Shape);
                DebugView.RemoveFlags(DebugViewFlags.Joint);
                DebugView.DefaultShapeColor  = Color.White;
                DebugView.SleepingShapeColor = Color.LightGray;
                DebugView.LoadContent(GraphicsDevice, Content);
            }

            _gameState.LoadContent();
        }
Пример #11
0
        public override void LoadContent(ContentManager content)
        {
            this.Content    = content;
            player1.texture = content.Load <Texture2D>("dad_sat");
            player2.texture = content.Load <Texture2D>("mom_sat");
            table.texture   = content.Load <Texture2D>("table");
            ending          = content.Load <Song>("co");


            font = content.Load <SpriteFont>("SpriteFont1");
            for (int i = 0; i < N; i++)
            {
                ball[i].texture = content.Load <Texture2D>("ball");
            }
            ball[0].texture = content.Load <Texture2D>("ttukbaegi");
            ball[1].texture = content.Load <Texture2D>("rice_1");
            ball[2].texture = content.Load <Texture2D>("kimchi");
            ball[3].texture = content.Load <Texture2D>("kimchi");
            ball[4].texture = content.Load <Texture2D>("ttukbaegi");
            ball[5].texture = content.Load <Texture2D>("rice_1");
            ball[6].texture = content.Load <Texture2D>("rice_2");
            ball[7].texture = content.Load <Texture2D>("kimchi");
            ball[8].texture = content.Load <Texture2D>("ttukbaegi");
            ball[9].texture = content.Load <Texture2D>("kimchi");

            baby.texture = this.Content.Load <Texture2D>("baby");

            background = this.Content.Load <Texture2D>("background");



            view = new DebugViewXNA(world);
            view.AppendFlags(DebugViewFlags.Shape);
            view.RemoveFlags(DebugViewFlags.Joint);
            view.DefaultShapeColor  = Color.White;
            view.SleepingShapeColor = Color.LightGray;
            view.LoadContent(game.GraphicsDevice, Content);
            if (Camera == null)
            {
                Camera = new Camera2D(game.GraphicsDevice);
            }
            else
            {
                Camera.ResetCamera();
            }
            glass_sfx = content.Load <SoundEffect>("glass");

            hit1_sfx = content.Load <SoundEffect>("hit1");
            hit2_sfx = content.Load <SoundEffect>("hit2");
            bgm      = content.Load <Song>("bgm");
            MediaPlayer.Play(bgm);
            MediaPlayer.IsRepeating = true;

            help_font = content.Load <SpriteFont>("SpriteFont2");
        }
Пример #12
0
 private void EnableOrDisableFlag(DebugViewFlags flag)
 {
     if ((debugView.Flags & flag) == flag)
     {
         debugView.RemoveFlags(flag);
     }
     else
     {
         debugView.AppendFlags(flag);
     }
 }
Пример #13
0
 public void SwitchDebugViewFlag(DebugViewFlags flag)
 {
     if ((_debugView.Flags & flag) == flag)
     {
         _debugView.RemoveFlags(flag);
     }
     else
     {
         _debugView.AppendFlags(flag);
     }
 }
Пример #14
0
        public override void LoadContent()
        {
            base.LoadContent();

            //We enable diagnostics to show get values for our performance counters.
            Settings.EnableDiagnostics = true;

            if (World == null)
            {
                World = new World(Vector2.Zero);
            }
            else
            {
                World.Clear();
            }

            if (DebugView == null)
            {
                DebugView = new DebugViewXNA(World);
                DebugView.RemoveFlags(DebugViewFlags.Shape);
                DebugView.RemoveFlags(DebugViewFlags.Joint);
                DebugView.DefaultShapeColor  = Color.White;
                DebugView.SleepingShapeColor = Color.LightGray;
                DebugView.LoadContent(ScreenManager.GraphicsDevice, ScreenManager.Content);
            }

            frameRateCounter = new FrameRateCounter(this.ScreenManager);

            if (Camera == null)
            {
                Camera = new Camera2D(ScreenManager.GraphicsDevice);
            }
            else
            {
                Camera.ResetCamera();
            }

            // Loading may take a while... so prevent the game from "catching up" once we finished loading
            ScreenManager.Game.ResetElapsedTime();
        }
Пример #15
0
        public override void LoadContent()
        {
            base.LoadContent();

            //We enable diagnostics to show get values for our performance counters.
            Settings.EnableDiagnostics = true;

            if (World == null)
            {
                World = new World(Vector2.Zero);
            }
            else
            {
                World.Clear();
            }

            if (DebugView == null)
            {
                DebugView = new DebugViewXNA(World);
                DebugView.RemoveFlags(DebugViewFlags.Shape);
                DebugView.RemoveFlags(DebugViewFlags.Joint);
                DebugView.DefaultShapeColor = Color.White;
                DebugView.SleepingShapeColor = Color.LightGray;
                DebugView.LoadContent(ScreenManager.GraphicsDevice, ScreenManager.Content);
            }

            frameRateCounter = new FrameRateCounter(this.ScreenManager);

            if (Camera == null)
            {
                Camera = new Camera2D(ScreenManager.GraphicsDevice);
            }
            else
            {
                Camera.ResetCamera();
            }

            // Loading may take a while... so prevent the game from "catching up" once we finished loading
            ScreenManager.Game.ResetElapsedTime();
        }
Пример #16
0
        public override void OnEnter()
        {
            //Camera
            GameWorldManager.Instance.SpawnEntity("camera", "camera1", new Vector3(0, -1300, 600));
            GameWorldManager.Instance.SpawnEntity("robot", "robot1", new Vector3(-400f, -1000f, 0f), 2f);
            GameWorldManager.Instance.SpawnEntity("crate", "crate", new Vector3(-50f, -1200f, 0f), 3f);
            GameWorldManager.Instance.SpawnEntity("crate", "crate2", new Vector3(-50f, -1100f, 0f), 2.6f);
            GameWorldManager.Instance.SpawnEntity("crate", "crate3", new Vector3(-50f, -1000f, 0f), 2f);
            GameWorldManager.Instance.SpawnEntity("crate", "crate4", new Vector3(-50f, -900f, 0f), 1.5f);
            //GameWorldManager.Instance.SpawnEntity( "crate", "crate5", new Vector3( 500f, -850f, 0f ), 0.1f );

            Robot = GameWorldManager.Instance.GetEntity("robot1");
            //Quaternion rotation = new Quaternion( 1f, 2f, 1f, 2f );
            //rotation.Normalize();
            //Robot.SetRotation( rotation );
            Robot.PhysicsEntity.Enabled = true;

            Robot.RegisterComponent("force", new SentientForceComponent());
            Robot.RegisterComponent(
                "control",
                new CarControlComponent(new List <string> {
                "GearJoint1", "GearJoint2", "GearJoint3"
            }, new List <float> {
                5f, 5f, 5f
            })
                );

            CameraController camControl = new CameraController(GameWorldManager.Instance.GetEntity("robot1"), SceneManager.Instance.GetCurrentCamera());

            ControllerRepository.Instance.RegisterController("camcontrol", camControl);
            FrameUpdateManager.Instance.Register(camControl);

            Camera = GameWorldManager.Instance.GetEntity("camera1");

            _cameraMoving          = false;
            _actionFreeze          = false;
            _actionSpawn           = false;
            _actionReset           = false;
            _debugViewState        = false;
            _actionToggleDebugView = false;


            LoadPhysicsContent();
            _debugView = new DebugViewXNA(Platform.Instance.PhysicsWorld);

            _debugView.LoadContent(Platform.Instance.Device, Platform.Instance.Content);
            _debugView.RemoveFlags(DebugViewFlags.Joint);

            _debugView.TextColor = Color.Black;

            _view = Matrix.Identity;
        }
Пример #17
0
        public override void LoadContent()
        {
            base.LoadContent();

            if (World == null)
            {
                World = new World(Vector2.Zero);
            }
            else
            {
                World.Clear();
            }

			#if DEBUG_RENDER
            if (DebugView == null)
            {
                DebugView = new DebugViewXNA(World);
                DebugView.RemoveFlags(DebugViewFlags.Shape);
                DebugView.RemoveFlags(DebugViewFlags.Joint);
                DebugView.DefaultShapeColor = Color.White;
                DebugView.SleepingShapeColor = Color.LightGray;
				DebugView.LoadContent(ScreenManager.GraphicsDevice);

				EnableOrDisableFlag(DebugViewFlags.Shape);
				EnableOrDisableFlag(DebugViewFlags.DebugPanel);
				EnableOrDisableFlag(DebugViewFlags.PerformanceGraph);
				EnableOrDisableFlag(DebugViewFlags.Joint);
				EnableOrDisableFlag(DebugViewFlags.ContactPoints);
				EnableOrDisableFlag(DebugViewFlags.ContactNormals);
				EnableOrDisableFlag(DebugViewFlags.Controllers);
            }
			#endif

			WireUpCamera ();

            // Loading may take a while... so prevent the game from "catching up" once we finished loading
            ScreenManager.Game.ResetElapsedTime();
        }
Пример #18
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            aKeyboardState = Keyboard.GetState();
            if (aKeyboardState.IsKeyDown(Keys.F12) && previousKeyboardState != aKeyboardState)
            {
                if (debugView.Flags.HasFlag(FarseerPhysics.DebugViewFlags.DebugPanel))
                {
                    debugView.RemoveFlags(FarseerPhysics.DebugViewFlags.DebugPanel);
                }
                else
                {
                    debugView.AppendFlags(FarseerPhysics.DebugViewFlags.DebugPanel);
                    debugView.DebugPanelPosition = new Vector2(0, 0);
                }
            }
            else if (aKeyboardState.IsKeyDown(Keys.F11) && previousKeyboardState != aKeyboardState)
            {
                if (debugView.Enabled)
                {
                    debugView.Enabled = false;
                }
                else if (!debugView.Enabled)
                {
                    debugView.Enabled = true;
                }
            }
            else if (aKeyboardState.IsKeyDown(Keys.F5) && previousKeyboardState != aKeyboardState)
            {
                objectList.Clear();
                world.Clear();
                lvlBuilder.readLevel("level1.txt");
                objectList = lvlBuilder.getLevelObjects();
            }
            else if (aKeyboardState.IsKeyDown(Keys.Escape))
            {
                this.Exit();
            }
            world.Step(Math.Min((float)gameTime.ElapsedGameTime.TotalSeconds, (1f / 30f)));
            previousKeyboardState = aKeyboardState;
            // TODO: Add your update logic here

            foreach (GameObject currObject in objectList)
            {
                currObject.Update();
            }


            base.Update(gameTime);
        }
Пример #19
0
        public override void LoadContent()
        {
            base.LoadContent();

            if (World == null)
            {
                World = new World(Vector2.Zero);
            }
            else
            {
                World.Clear();
            }

            if (DebugView == null)
            {
                DebugView = new DebugViewXNA(World);
                DebugView.RemoveFlags(DebugViewFlags.Shape);
                DebugView.RemoveFlags(DebugViewFlags.Joint);
                DebugView.DefaultShapeColor  = Color.White;
                DebugView.SleepingShapeColor = Color.LightGray;
                DebugView.LoadContent(ScreenManager.GraphicsDevice, ScreenManager.Content);
            }

            if (Camera == null)
            {
                Camera = new Camera2D(ScreenManager.GraphicsDevice);
            }
            else
            {
                Camera.ResetCamera();
            }

            HiddenBody = BodyFactory.CreateBody(World, Vector2.Zero);

            // Loading may take a while... so prevent the game from "catching up" once we finished loading
            ScreenManager.Game.ResetElapsedTime();
        }
Пример #20
0
        private void CreateDebugView(ContentManager content)
        {
            _debugView = new DebugViewXNA(Platform.Instance.PhysicsWorld);

            _debugView.LoadContent(Platform.Instance.Device, content);
            _debugView.RemoveFlags(DebugViewFlags.Joint);

            _debugView.TextColor = Color.Black;
            _view       = Matrix.Identity;
            _projection = Matrix.CreateOrthographicOffCenter(
                UnitsConverter.ToSimUnits(-Platform.Instance.Device.Viewport.Width / 2f),
                UnitsConverter.ToSimUnits(Platform.Instance.Device.Viewport.Width / 2f),
                UnitsConverter.ToSimUnits(Platform.Instance.Device.Viewport.Height / 2f),
                UnitsConverter.ToSimUnits(-Platform.Instance.Device.Viewport.Height / 2f),
                0f,
                1f
                );
        }
Пример #21
0
        /// <summary>
        /// Metoda  wywolywana przed LoadContent
        /// </summary>
        public void Initialize()
        {
            // Get the content manager from the application
            contentManager = (Application.Current as App).Content;
            spriteBatch = new SpriteBatch(SharedGraphicsDeviceManager.Current.GraphicsDevice);
            LevelLines = new List<LevelLine>();

            // Dodanie linii levelu.
            LevelLines.Add(new LevelLine(250, SharedGraphicsDeviceManager.Current.GraphicsDevice));
            LevelLines.Add(new LevelLine(500, SharedGraphicsDeviceManager.Current.GraphicsDevice));

            // Inicjalizacja świata
            if (world == null)
            {
                world = new World(Settings.gravity);
            }
            else
            {
                world.Clear();
            }

            if (debugView == null)
            {
                debugView = new DebugViewXNA(world);
                debugView.RemoveFlags(FarseerPhysics.DebugViewFlags.Controllers);
                debugView.RemoveFlags(FarseerPhysics.DebugViewFlags.Joint);

                debugView.LoadContent(SharedGraphicsDeviceManager.Current.GraphicsDevice, contentManager);
            }

            // Tworzenie podlogi
            _floor = BodyFactory.CreateRectangle(world,
                                                ConvertUnits.ToSimUnits(480),
                                                ConvertUnits.ToSimUnits(50),
                                                10f);
            _floor.Position = ConvertUnits.ToSimUnits(240, 775);
            _floor.BodyType = BodyType.Static;
            _floor.IsStatic = true;
            _floor.Restitution = 0.0f;
            _floor.Friction = 2.5f;

            // Tworzenie platformy
            _platform = BodyFactory.CreateRectangle(world,
                                                ConvertUnits.ToSimUnits(250),
                                                ConvertUnits.ToSimUnits(50),
                                                10f);
            _platform.Position = ConvertUnits.ToSimUnits(240, 725);
            _platform.BodyType = BodyType.Static;
            _platform.IsStatic = true;
            _platform.Restitution = 0.0f;
            _platform.Friction = 5.0f;

            // Żaden blok nie spada
            blockOnHisWay = false;

            //Aktywacja gestów - vertical do obracania i horizontaldrag do ruszania klockiem
            TouchPanel.EnabledGestures = GestureType.HorizontalDrag | GestureType.VerticalDrag;

            LoadContent();
        }
Пример #22
0
        public EggGameScreen(Game1 game)
            : base(game, game.Camera.Clone())
        {
            ConvertUnits.SetDisplayUnitToSimUnitRatio(64f);

            _eggtastic = game;

            Clips             = new Dictionary <string, Clip>();
            Enemies           = new List <EnemyEntity>();
            Eggs              = new List <EggEntity>();
            QueuedForDisposal = new List <CharacterEntity>();
            QueuedForCreation = new List <CharacterEntity>();

            ScreenSizeDefault = new Vector2(1280, 720);

            GraphicsDevice = game.GraphicsDevice;
            Viewport       = GraphicsDevice.Viewport;
            ScreenCenter   = new Vector2(ScreenSizeDefault.X / 2f, ScreenSizeDefault.Y / 2f);
            Content        = game.Content;

            gameFont = Content.Load <SpriteFont>("GameFont");

#if !ANDROID
            BackgroundMusic =
                Content.Load <Song>("background-music");
            MediaPlayer.Play(BackgroundMusic);
            MediaPlayer.Volume = 0.5f;
#endif

            Corners = new Vertices(4);
            Corners.Add(new Vector2(0f));                                         // top-left
            Corners.Add(new Vector2(ScreenSizeDefault.X, 0f));                    // top-right
            Corners.Add(new Vector2(ScreenSizeDefault.X, ScreenSizeDefault.Y));   // bottom-right
            Corners.Add(new Vector2(0f, ScreenSizeDefault.Y));                    // bottom-left

            projection =
                Matrix.CreateOrthographicOffCenter(0f, ConvertUnits.ToSimUnits(ScreenSizeDefault.X),
                                                   ConvertUnits.ToSimUnits(ScreenSizeDefault.Y), 0f, 0f, 1f);

            World     = new World(new Vector2(0, 0));
            DebugView = new DebugViewXNA(World);
            DebugView.RemoveFlags(DebugViewFlags.Shape);
            DebugView.DefaultShapeColor  = Color.White;
            DebugView.SleepingShapeColor = Color.LightGray;
            DebugView.LoadContent(GraphicsDevice, Content);

            if (Tweak.SHOW_PHYSICS_ON_START)
            {
                EnableOrDisableFlag(DebugViewFlags.Shape);
            }
            Tweak.Init();

            InitialiseClips();

            _enemySpawner = new EnemySpawner(this, Clips["enemy"]);

            // World is 1 screen high, N screens wide
            _border = new Border(World, new Vector2(ScreenSizeDefault.X * PLAY_AREA_WIDTH_IN_SCREENS, ScreenSizeDefault.Y));

            InitialiseLevel();
        }
Пример #23
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // for debug view
            DebugView = new DebugViewXNA(physicsSystem.world);
            DebugView.DefaultShapeColor  = Color.White;
            DebugView.SleepingShapeColor = Color.LightGray;
            DebugView.AppendFlags(DebugViewFlags.ContactPoints);
            DebugView.AppendFlags(DebugViewFlags.DebugPanel);
            DebugView.RemoveFlags(DebugViewFlags.Joint);
            DebugView.LoadContent(GraphicsDevice, Content);

            // for splitscreen
            SetUpSplitScreen();

            entityManager         = new EntityManager();
            representationManager = new RepresentationManager(Content);
            controllerManager     = new ControllerManager();

            LevelMap levelMap = Content.Load <LevelMap>("simplelevelmap");

            map = new Map(physicsSystem.world, levelMap, entityManager, representationManager, controllerManager);
            mapRepresentation = new MapRepresentation(map);
            mapRepresentation.LoadContent(Content);
            representationManager.Add(mapRepresentation);

            GameVariables.LevelHeight       = map.LevelMap.Height;
            GameVariables.EnemyRespawnDelay = 10f;
            GameVariables.CamCulling        = new Vector2(640 * 0.5f, 360 * 0.5f);

            // create the players
            int numPlayers = GameVariables.NumPlayers;

            CreatePlayer((int)PlayerIndex.One);
            if (numPlayers > 1)
            {
                CreatePlayer((int)PlayerIndex.Two);
            }
            if (numPlayers > 2)
            {
                CreatePlayer((int)PlayerIndex.Three);
            }
            if (numPlayers > 3)
            {
                CreatePlayer((int)PlayerIndex.Four);
            }

            map.SetUpTiles();


            // test for a slanted platform

            /*
             * Vector2 position = new Vector2(180, 270);
             * Vertices vertices = new Vertices();
             * vertices.Add(ConvertUnits.ToSimUnits(new Vector2(290, 480)));
             * vertices.Add(ConvertUnits.ToSimUnits(new Vector2(578, 384)));
             * vertices.Add(ConvertUnits.ToSimUnits(new Vector2(578, 480)));
             * Body body = BodyFactory.CreatePolygon(physicsSystem.world, vertices, 1f);
             * body.BodyType = BodyType.Static;
             * body.Restitution = 0f;
             * body.Friction = 0.5f;
             * body.CollisionCategories = GameConstants.PlatformCollisionCategory;
             */

            // test for a thin platform
            //Vector2 position = new Vector2(300, 400);

            /*
             * Body body = BodyFactory.CreateEdge(physicsSystem.world, ConvertUnits.ToSimUnits(new Vector2(300, 400)), ConvertUnits.ToSimUnits(new Vector2(500, 400)));
             * //StaticPhysicsObject physicsObject = new StaticPhysicsObject(this, physicsSystem.world, position, 64, 1);
             * //Body body = physicsObject.body;
             * body.BodyType = BodyType.Static;
             * body.Restitution = 0f;
             * body.Friction = 0.5f;
             * body.CollisionCategories = GameConstants.PlatformCollisionCategory;
             */
            //oneWayTile = new OneWayGroundTile(physicsSystem.world, position, 64);

            /*
             * Vector2 startPosition = new Vector2(268, 400);
             * Vector2 endPosition = new Vector2(332, 400);
             * Body body = BodyFactory.CreateEdge(physicsSystem.world, ConvertUnits.ToSimUnits(startPosition), ConvertUnits.ToSimUnits(endPosition));
             * body.BodyType = BodyType.Static;
             * body.Restitution = 0f;
             * body.Friction = 0.5f;
             */

            // set player spawn positions from map
            List <Player> players = entityManager.Players;

            foreach (Player player in players)
            {
                player.SpawnPosition = map.PlayerSpawn;
            }

            // spawn the living entities
            entityManager.SpawnLivingEntities();

            tmpTex = Content.Load <Texture2D>("blank");
        }
Пример #24
0
        /// <summary>
        /// Initialization
        /// </summary>
        public override void Initialize()
        {
            base.Initialize();

            /**
             *
             * TUTAJ ODBYWA SIE PRZYPISANIE CONTROLSOW
             *
             * */

            GameInputManager = new InputManager();
            GameInputManager.AddAction("BackToMenu");
            GameInputManager.AddAction("RepeatLevel");
            GameInputManager.AddAction("Pause");
            GameInputManager.AddAction("CCW");
            GameInputManager.AddAction("CW");
            GameInputManager.AddAction("Left");
            GameInputManager.AddAction("Right");

            GameInputManager["RepeatLevel"].Add(Keys.Enter);
            GameInputManager["BackToMenu"].Add(Keys.Escape);
            GameInputManager["Pause"].Add(Keys.P);
            GameInputManager["CCW"].Add(Keys.Up);
            GameInputManager["CW"].Add(Keys.Down);
            GameInputManager["Left"].Add(Keys.Left);
            GameInputManager["Right"].Add(Keys.Right);

            // Wysokosci podlogi i platformy
            floorHeight = 15;
            platformHeight = 40;
            highestBodyPosition = 1000;

            // Ustawienie flag zwyciestwa lub przegranej
            failFlag                = false;
            lineReached             = false;
            winFlag                 = false;
            countDownStarted        = false;
            notStableFlag           = false;
            afterWinProcedureDone   = false;
            pauseFlag               = false;
            // Utworzenie timera ktory bedzie zliczał w doł w przypadku osiagniecia wysokosci,
            // Czas odliczania to 3 - arg. sec TimeSpan'a
            CountDownTimer = new TimerGtt(TimerGttModes.COUNTDOWN, new TimeSpan(0, 0, 0, 3, 0));

            // Ustawienie defaultowych danych, w calej grze dane są z tej zmiennej brane
            Settings = new GameSettings(OptionsHandler.blocksFriction, OptionsHandler.blocksBounciness, 0.12f, new Vector2(0.0f, 1.0f),
                                        new Vector2(this.GraphicsDevice.Viewport.Width / 2, 40));

            // Standardowy "Efekt" do rysowania prymitywów w XNA
            basicEffect = new BasicEffect(GraphicsDevice);
            basicEffect.VertexColorEnabled = true;
            basicEffect.Projection = Matrix.CreateOrthographicOffCenter
               (0, GraphicsDevice.Viewport.Width,     // left, right
                GraphicsDevice.Viewport.Height, 0,    // bottom, top
                0, 1);                                         // near, far plane

            // Stworzenie batchy do rysowania
            spriteBatch = new SpriteBatch(GraphicsDevice);
            hudBatch = new SpriteBatch(GraphicsDevice);
            endingBatch = new SpriteBatch(GraphicsDevice);

            // Stworzenie kontenera na linie levelu
            LevelLines = new List<LevelLine>();

            // Dodanie linii levelu.
            LevelLines.Add(new LevelLine(TargetHeight, GraphicsDevice));

            // Inicjalizacja świata
            if (world == null)
            {
                world = new World(Settings.gravity);
            }
            else
            {
                world.Clear();
            }

            if (debugView == null)
            {
                debugView = new DebugViewXNA(world);
                debugView.RemoveFlags(FarseerPhysics.DebugViewFlags.Controllers);
                debugView.RemoveFlags(FarseerPhysics.DebugViewFlags.Joint);

                debugView.LoadContent(GraphicsDevice, Game.Content);
            }

            // Tworzenie podlogi
            _floor = BodyFactory.CreateRectangle(world,
                                                ConvertUnits.ToSimUnits(GraphicsDevice.Viewport.Width),
                                                ConvertUnits.ToSimUnits(floorHeight),
                                                10f);
            //_floor.Position = ConvertUnits.ToSimUnits(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height - 50);
            Vector2 posi = new Vector2(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height - floorHeight/2);
            _floor.Position = ConvertUnits.ToSimUnits(posi);
            _floor.BodyType = BodyType.Static;
            _floor.IsStatic = true;
            _floor.Restitution = 0.1f;
            _floor.Friction = 2.5f;
            _floor.OnCollision += new OnCollisionEventHandler(CheckFloorCollision);
            // Tworzenie platformy
            _platform = BodyFactory.CreateRectangle(world,
                                                ConvertUnits.ToSimUnits(platformWidth),
                                                ConvertUnits.ToSimUnits(platformHeight),
                                                10f);
            //_platform.Position = ConvertUnits.ToSimUnits(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height - 100);
            Vector2 posi2 = new Vector2(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height - platformHeight/2 - floorHeight);
            _platform.Position = ConvertUnits.ToSimUnits(posi2);
            _platform.BodyType = BodyType.Static;
            _platform.IsStatic = true;
            _platform.Restitution = 0.1f;
            _platform.Friction = 5.0f;

            // Żaden blok nie spada
            blockOnHisWay = false;

            // lista bloków leżących na platformie
            yOfBlocksOnPlatform = new List<float>();

            timer = new Timer(1000);
            timer.Elapsed += new System.Timers.ElapsedEventHandler(timerCallback);
            timer.Start();
        }