Example #1
0
        protected override void Initialize()
        {
            IsMouseVisible = true;

            // Initialize the lighting system
            penumbra.Initialize();
            penumbra.AmbientColor = new Color(new Vector3(0.7f));
            //penumbra.Debug = true;

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

            // Initialize the physics debug view
            PhysicsDebugView = new DebugViewXNA(world);
            PhysicsDebugView.LoadContent(GraphicsDevice, Content);
            PhysicsDebugView.RemoveFlags(DebugViewFlags.Controllers);
            PhysicsDebugView.RemoveFlags(DebugViewFlags.Joint);
            PhysicsDebugView.RemoveFlags(DebugViewFlags.Shape);
            PhysicsDebugView.DefaultShapeColor = new Color(255, 255, 0);

            graphics.PreferredBackBufferWidth  = 1280;
            graphics.PreferredBackBufferHeight = 720;

            graphics.SynchronizeWithVerticalRetrace = true;
            IsFixedTimeStep = false;
            base.Initialize();
        }
Example #2
0
        public Physics(Vector2 gravity, Vector2 min, Vector2 max)
        {
            m_World = new World(gravity, new FarseerPhysics.Collision.AABB(ref min, ref max));
            m_View = new DebugViewXNA(m_World);
            m_View.Flags |= DebugViewFlags.PerformanceGraph;
            m_View.AppendFlags(DebugViewFlags.Shape);
            m_View.AppendFlags(DebugViewFlags.DebugPanel);
            m_View.AppendFlags(DebugViewFlags.Joint);
            m_View.AppendFlags(DebugViewFlags.ContactPoints);
            m_View.AppendFlags(DebugViewFlags.ContactNormals);
            m_View.AppendFlags(DebugViewFlags.Controllers);
            m_View.AppendFlags(DebugViewFlags.CenterOfMass);
            m_View.AppendFlags(DebugViewFlags.AABB);

            m_View.DefaultShapeColor = Color.Green;
            m_View.SleepingShapeColor = Color.LightGray;

            //floor
            BodyFactory.CreateEdge(m_World, new Vector2(min.X, min.Y), new Vector2(max.X, min.Y));

            //right side
            BodyFactory.CreateEdge(m_World, new Vector2(max.X, min.Y), new Vector2(max.X, max.Y));

            //left side
            BodyFactory.CreateEdge(m_World, new Vector2(min.X, min.Y), new Vector2(min.X, max.Y));

            //top
            BodyFactory.CreateEdge(m_World, new Vector2(min.X, max.Y), new Vector2(max.X, max.Y));
        }
        public ControllerViewManager(GraphicsDevice graphicsDevice, ContentManager content)
        {
            controllers = new List<Controller>();
            views = new List<IView>();

            this.content = content;
            this.graphicsDevice = graphicsDevice;
            this.batch = new SpriteBatch(graphicsDevice);
            this.world = new World(new Vector2(0, Constants.GamePlayGravity));
            this.controllerQueue = new ConcurrentQueue<Tuple<Controller, QueueState>>();
            this.viewQueue = new ConcurrentQueue<Tuple<IView, QueueState>>();

            if (Constants.DebugMode && debugView == null)
            {
                debugView = new DebugViewXNA(world);
                debugView.AppendFlags(DebugViewFlags.DebugPanel);
                debugView.DefaultShapeColor = Color.Red;
                debugView.SleepingShapeColor = Color.Green;
                debugView.LoadContent(graphicsDevice, content);
            }

            if (camera == null)
            {
                Viewport v = graphicsDevice.Viewport;
                camera = new Camera2D(graphicsDevice);
                camera.Position = new Vector2(v.Width / 2, v.Height / 2);
            }
            else camera.ResetCamera();
        }
Example #4
0
        //SpriteFont debugfont;
        public Scene(Game game)
            : base(game)
        {
            World = new World(new Vector2(0, 18));
            PhysicsDebug = new DebugViewXNA(World);
            InputManager = new InputManager(Game);
            Transitioner = new Transitioner(Game, this);
            #if !FINAL_RELEASE
            SelectionManager = new SelectionManager(Game, this);
            #endif
            SceneLoader = new SceneLoader(Game);
            Camera = new Camera(Game, this);
            GarbageElements = new SortedList<Element>();
            RespawnElements = new SortedList<Element>();
            Elements = new SortedList<Element>();

            PhysicsDebug.Enabled = false;
            SelectionManager.ShowEmblems = false;
            Kinect.ColorStream.Enable();
            Kinect.DepthStream.Enable();
            Kinect.SkeletonStream.Enable();
            Kinect.Start();

            //SelectionManager.ShowForm = false;
        }
Example #5
0
        public PhysicsComponent(Scene aScene, Vector2 aGravity, bool aOptimised = false)
            : base(aScene)
        {
            ConvertUnits.SetDisplayUnitToSimUnitRatio(24f);

            mGravity = aGravity;
            mMultiplier = 1;
            mWorld = new World(mGravity);

            mDebugView = new DebugViewXNA(mWorld);
            mDebugView.DefaultShapeColor = Color.White;
            mDebugView.SleepingShapeColor = Color.LightGray;

            mDebugView.LoadContent(MilkShake.Graphics, MilkShake.ConentManager);

            // [Add Listeners]
            Scene.Listener.Update += new UpdateEvent(Update);
            Scene.Listener.PostDraw[DrawLayer.First] += new DrawEvent(Draw);
            Settings.AllowSleep = false;
            // Optimise
            if(aOptimised)
            {
             	   	Settings.AllowSleep = false;
             	   	Settings.EnableDiagnostics = false;
                Settings.VelocityIterations = 6;
               	     	Settings.PositionIterations = 4;
               	    	Settings.ContinuousPhysics = false;
            }
        }
Example #6
0
        public PhysicsGameScreen()
        {
            EnableCameraControl = true;

            this.mWorld = null;
            mCamera = null;
            this.mDebugViewXNA = null;
        }
Example #7
0
 public override void Awake()
 {
     activated = true;
     physicsDebugView = new DebugViewXNA(Physics.world);
     //physicsDebugView.DrawSolidShapes = false;
     physicsDebugView.LoadContent(Application.Instance.GraphicsDevice);
     material = new Material() { name = "Debug material", color = Color.white, renderQueue = 100000, shaderName = "Transparent" };
     base.Awake();
 }
 protected PhysicsGameScreen()
 {
     TransitionOnTime = TimeSpan.FromSeconds(0.75);
     TransitionOffTime = TimeSpan.FromSeconds(0.75);
     HasCursor = true;
     EnableCameraControl = true;
     _userAgent = null;
     World = null;
     Camera = null;
     DebugView = null;
 }
Example #9
0
        public Physics(Game game, Camera2D camera)
            : base(game)
        {
            World = new World(new Vector2(0f, 10f));
            debugView = new DebugViewXNA(World);
            debugView.AppendFlags(DebugViewFlags.Shape);
            debugView.AppendFlags(DebugViewFlags.ContactNormals);
            debugView.AppendFlags(DebugViewFlags.PolygonPoints);

            this.camera = camera;

            ShowDebug = false;
        }
        public void LoadContent(GraphicsDevice graphicsDevice, ContentManager content, SpriteFont font) {
            if (!FarseerEnabled)
                return;

            //_view.LoadContent(graphicsDevice, SceneManager.GlobalContent);
            if (DebugView == null) {
                DebugView = new DebugViewXNA(StaticWorld);
                DebugView.AppendFlags(DebugViewFlags.Shape);
                DebugView.AppendFlags(DebugViewFlags.PolygonPoints);
                DebugView.AppendFlags(DebugViewFlags.PerformanceGraph);
                DebugView.AppendFlags(DebugViewFlags.AABB);
                DebugView.DefaultShapeColor = Color.White;
                DebugView.SleepingShapeColor = Color.LightGray;
                DebugView.LoadContent(graphicsDevice, content, font);
            }
        }
        public PhysicsComponent(Vector2 aGravity)
        {
            ConvertUnits.SetDisplayUnitToSimUnitRatio(24f);

            //lucas smells
            mGravity = aGravity;
            Multiplier = 1;
            mWorld = new World(mGravity);

            mDebugView = new DebugViewXNA(mWorld);
            mDebugView.DefaultShapeColor = Color.White;
            mDebugView.SleepingShapeColor = Color.LightGray;

            mDebugView.LoadContent(MilkShake.Graphics, MilkShake.ConentManager);

            //
            Settings.AllowSleep = false;
        }
        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);
            }

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

            if (PauseMenu == null)
            {
                PauseMenu = new PauseScreen(this);
            }

            // Loading may take a while... so prevent the game from "catching up" once we finished loading
            ScreenManager.Game.ResetElapsedTime();
        }
Example #13
0
        public Physics(Vector2 gravity, Vector2 min, Vector2 max)
        {
            m_World = new World(gravity, new FarseerPhysics.Collision.AABB(ref min, ref max));
            m_View = new DebugViewXNA(m_World);
            m_View.Flags |= DebugViewFlags.PerformanceGraph;
            m_View.AppendFlags(DebugViewFlags.Shape);
            m_View.AppendFlags(DebugViewFlags.DebugPanel);
            m_View.AppendFlags(DebugViewFlags.Joint);
            m_View.AppendFlags(DebugViewFlags.ContactPoints);
            m_View.AppendFlags(DebugViewFlags.ContactNormals);
            m_View.AppendFlags(DebugViewFlags.Controllers);
            m_View.AppendFlags(DebugViewFlags.CenterOfMass);
            m_View.AppendFlags(DebugViewFlags.AABB);

            m_View.DefaultShapeColor = Color.Green;
            m_View.SleepingShapeColor = Color.LightGray;

            m_min = min;
            m_max = max;
        }
Example #14
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);
        }
Example #15
0
        public PhysicsSystem(GameScreen screen)
        {
            this.screen = screen;

            GnomicGame game = screen.ParentGame;

            // Todo: pass in a PhysicsSystemSetting with gravity, worldMin and worldMax
            world = new World(
                new Vector2(0.0f, 20.0f),
                new FarseerPhysics.Collision.AABB(Vector2.One * -500.0f, Vector2.One * 500.0f));

            debugView = new DebugViewXNA(world);
            debugView.AppendFlags(DebugViewFlags.Shape);
            debugView.DefaultShapeColor = Color.White;
            debugView.SleepingShapeColor = Color.LightGray;
            debugView.LoadContent(game.GraphicsDevice, game.Content, "GameFont");

            projection = Matrix.CreateOrthographicOffCenter(
                0f,
                ConvertUnits.ToSimUnits(game.ScreenWidth),
                ConvertUnits.ToSimUnits(game.ScreenHeight),
                0f, 0f, 1f);
        }
Example #16
0
        public Physics(Engine engine)
            : base(engine)
        {
            // this should probably never change
              PixelsPerMeter = Global.Configuration.GetFloatConfig("Physics", "PixelsPerMeter");

              World = new World(new Vector2(0.0f, 9.8f));

              DebugView = new DebugViewXNA(World);
              DebugView.LoadContent(Global.Game.GraphicsDevice, Engine.Content);
              uint flags = 0;
              flags += (uint)DebugViewFlags.AABB;
              flags += (uint)DebugViewFlags.CenterOfMass;
              flags += (uint)DebugViewFlags.ContactNormals;
              flags += (uint)DebugViewFlags.ContactPoints;
              flags += (uint)DebugViewFlags.DebugPanel;
              flags += (uint)DebugViewFlags.Joint;
              flags += (uint)DebugViewFlags.Pair;
              flags += (uint)DebugViewFlags.PolygonPoints;
              flags += (uint)DebugViewFlags.Shape;
              DebugView.Flags = (DebugViewFlags)flags;

              DrawOrder = int.MaxValue;
        }
Example #17
0
 /// <summary>
 /// Initialize the Debug System.
 /// </summary>
 public void Initialize(World world)
 {
     //Save the world reference.
     _World = world;
     _DebugView = new DebugViewXNA(world);
     _DebugViewEnabled = false;
 }
        /// <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);

            //Create New World with gravity of 10 units, downward.
            MyWorld = new World(Vector2.UnitY * 10);
            bird = Content.Load<Texture2D>("AngryRedBird");
            floor = Content.Load<Texture2D>("blank");

            //camera

            DebugView = new DebugViewXNA(MyWorld);
            DebugView.AppendFlags(DebugViewFlags.Shape);
            DebugView.RemoveFlags(DebugViewFlags.Joint);
            DebugView.DefaultShapeColor = Color.White;
            DebugView.SleepingShapeColor = Color.LightGray;
            DebugView.LoadContent(GraphicsDevice, Content);
            Camera = new Camera2D(GraphicsDevice);

            //Create Floor
            FloorBody = BodyFactory.CreateBody(MyWorld);
            Fixture floorFixture = FixtureFactory.AttachRectangle(ConvertUnits.ToSimUnits(480), ConvertUnits.ToSimUnits(10), 10, Vector2.Zero, FloorBody);
            floorFixture.Restitution = 0.5f;        //Bounceability
            floorFixture.Friction = 0.5f;           //Friction
            FloorBody = floorFixture.Body;          //Get Body from Fixture
            FloorBody.IsStatic = true;              //Floor must be stationary object

            //Create Box, (Note:Different way from above code, just to show it otherwise there is no difference)
            HeroBird = BodyFactory.CreateBody(MyWorld);
            FixtureFactory.AttachRectangle(ConvertUnits.ToSimUnits(50), ConvertUnits.ToSimUnits(50), 10, Vector2.Zero, HeroBird);
            foreach (Fixture fixture in HeroBird.FixtureList)
            {
                fixture.Restitution = 0.5f;
                fixture.Friction = 0.5f;
            }
            HeroBird.BodyType = BodyType.Dynamic;

            //Place floor object to bottom of the screen.
            FloorBody.Position = ConvertUnits.ToSimUnits(new Vector2(240, 700));

            //Place Box on screen, somewhere
            HeroBird.Position = ConvertUnits.ToSimUnits(new Vector2(240, 25));
        }
        /// <summary> 
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            Graphics.PreferredBackBufferWidth = 1280;
            Graphics.PreferredBackBufferHeight = 720;
            Graphics.ApplyChanges();
            
            Components.Add(new FrameRateCounter(this, "Content\\debugfont", 1f));
            Components.Add(new GameObjectInfoDisplay(this, 5, "Content\\debugfont", new Vector2(0f, 25f)));

            ComponentFactory componentFactory = new ComponentFactory();
            TiledGameObjectFactory gameObjectFactory = new TiledGameObjectFactory(this.Content);
            gameObjectFactory.PathToXML = "EntityDefinitions\\entity.xml";
            
            inputHandler = new InputHandler(false);
            playerManager = new PlayerManager();

            particleManager = new ParticleManager(Content, "ParticleEffects\\", "Textures\\");

            PhysicsManager physicsManager = new PhysicsManager();
            particleRenderer = new SpriteBatchRenderer();
            particleRenderer.GraphicsDeviceService = Graphics;

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

            renderer = new Renderer(Graphics, spriteBatch);
            renderer.SetInternalResolution(1280, 720);
            renderer.SetScreenResolution(1280, 720, false);

            GameServiceManager.AddService(typeof(IGameObjectFactory), gameObjectFactory);
            GameServiceManager.AddService(typeof(IComponentFactory), componentFactory);
            GameServiceManager.AddService(typeof(RenderableFactory), new RenderableFactory(this.Content));
            GameServiceManager.AddService(typeof(IInputHandler), inputHandler);
            GameServiceManager.AddService(typeof(PlayerManager), playerManager);
            GameServiceManager.AddService(typeof(IScoreManager), new ScoreManager());
            GameServiceManager.AddService(typeof(IGameObjectManager), new GameObjectManager());
            GameServiceManager.AddService(typeof(IPhysicsManager), physicsManager);
            GameServiceManager.AddService(typeof(IBehaviorFactory), new BehaviorFactory());
            GameServiceManager.AddService(typeof(IActionFactory), new ActionFactory());
            GameServiceManager.AddService(typeof(IActionManager), new ActionManager());
            GameServiceManager.AddService(typeof(ILevelLogicManager), new LevelLogicManager(this.Content));
            GameServiceManager.AddService(typeof(IRandomGenerator), new RandomGenerator());
            GameServiceManager.AddService(typeof(IParticleManager), particleManager);
            GameServiceManager.AddService(typeof(IRenderer), renderer);

            debugView = new DebugViewXNA(GameServiceManager.GetService<IPhysicsManager>().PhysicsWorld);

            //Initialize the GameServices
            GameServiceManager.Initialize();
            
            CameraController.Initialize(this);
            CameraController.MoveCamera(new Vector2(GraphicsDevice.Viewport.Width / 2f, GraphicsDevice.Viewport.Height / 2f));
            
            base.Initialize();
        }
Example #20
0
 public Debug(Game game, World world, Play play)
 {
     _physicsDebug = new DebugViewXNA(world);
     _physicsDebug.LoadContent(game.GraphicsDevice, game.Content);
     _physicsDebug.AppendFlags(DebugViewFlags.DebugPanel);
 }
Example #21
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);

            _world = new World(new Vector2(0,0));

            _debugView = new DebugViewXNA(_world);

               // default is shape, controller, joints
               // we just want shapes to display
               _debugView.RemoveFlags(DebugViewFlags.Controllers);
               _debugView.RemoveFlags(DebugViewFlags.Joint);

               _debugView.LoadContent(GraphicsDevice, Content);

               //_debugView.LoadContent(GraphicsDevice, Content);

             // Create and position our floor
               _floor = BodyFactory.CreateRectangle(
            _world,
            ConvertUnits.ToSimUnits(480),
            ConvertUnits.ToSimUnits(50),
            10f);
            _floor.Position = ConvertUnits.ToSimUnits(300,400);
            _floor.IsStatic = true;
            _floor.Restitution = 0.2f;
            _floor.Friction = 0.2f;

                          box = BodyFactory.CreateRectangle(
               _world,
               ConvertUnits.ToSimUnits(100),
               ConvertUnits.ToSimUnits(100),
               10f,
               new Vector2(ConvertUnits.ToSimUnits(300), ConvertUnits.ToSimUnits(0)));

               box.BodyType = BodyType.Dynamic;
               box.Restitution = 0.2f;
               box.Friction = 0.2f;
        }
Example #22
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");
        }
        /// <summary>
        /// Load graphics content for the game.
        /// </summary>
        public override void LoadContent(ContentManager _content)
        {
            base.LoadContent(_content);

            Camera.Score = 0;
            Camera.ScoreCombo = 1;

            //setup physics world
            ConvertUnits.SetDisplayUnitToSimUnitRatio((float)physicsScale);

            spriteBatch = ScreenManager.SpriteBatch;
            pp = ScreenManager.GraphicsDevice.PresentationParameters; //aa
            renderTarget = new RenderTarget2D(ScreenManager.GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight, false, pp.BackBufferFormat, pp.DepthStencilFormat, pp.MultiSampleCount, RenderTargetUsage.DiscardContents); //aa
            renderTarget2 = new RenderTarget2D(ScreenManager.GraphicsDevice, pp.BackBufferWidth/2, pp.BackBufferHeight/2, false, pp.BackBufferFormat, pp.DepthStencilFormat, pp.MultiSampleCount, RenderTargetUsage.DiscardContents); //aa

            parallaxEngine = new ParallaxManager();
            contactListener = new ContactListener(physicsWorld);
            contactSolver = new ContactSolver(physicsWorld, contactListener);
            contactListener.PowerUpActivated += new ContactListener.EffectEventHandler(contactListener_PowerUpActivated);

            //gameplay instances a new content manager for UI
            if (content == null)
                content = new ContentManager(ScreenManager.Game.Services, "Content");

            //level data manager instances its own content managers for level textures and effects
            LevelDataManager.Initialize(ScreenManager.Game, parallaxEngine, world, level);
            SoundManager.InitializeSoundEvents(contactListener);
            SoundManager.LoadMusic(LevelDataManager.levelContent, world);

            //xboxButtonFont = content.Load <SpriteFont>("GameUI\\xboxControllerSpriteFont");
            menuBackground = content.Load<Texture2D>("GameUI\\MenuBack");
            menuCorner = content.Load<Texture2D>("GameUI\\MenuCorner");
            menuTopSide = content.Load<Texture2D>("GameUI\\MenuSide");
            pellet = content.Load<Texture2D>("GameUI\\pellet");
            powerFrame = content.Load<Texture2D>("GameUI\\PowerFrame");
            powerBar = content.Load<Texture2D>("GameUI\\PowerBar");
            powerMarkerTarget = content.Load<Texture2D>("GameUI\\Power01");
            fruitBar = content.Load<Texture2D>("GameUI\\FruitBar");
            shotWindow = content.Load<Texture2D>("GameUI\\ShotWindow");
            smLock = content.Load<Texture2D>("GameUI\\Small_Lock");
            LevelDataManager.UItextures.TryGetValue("MedalBronze", out medalBronze);
            LevelDataManager.UItextures.TryGetValue("MedalSilver", out medalSilver);
            LevelDataManager.UItextures.TryGetValue("MedalGold", out medalGold);
            LevelDataManager.UItextures.TryGetValue("NoMedal", out noMedal);
            LevelDataManager.UItextures.TryGetValue("Cursor", out cursor);
            LevelDataManager.UItextures.TryGetValue("Pixel", out pixel);
            LevelDataManager.UItextures.TryGetValue("AppleJack", out appleJack);
            cursorOrigin = new Vector2(cursor.Width / 2, cursor.Height / 2);

            star = new Sprite(51, 0, Vector2.Zero, false);
            star.TintColor = new Color (0,0,0,0);
            star.Location = new Vector2(shotWindowLocation.X + (shotWindow.Width * 0.5f) - (star.SpriteRectWidth * 0.5f),
                                         shotWindowLocation.Y + (shotWindow.Height * 0.5f) - (star.SpriteRectHeight * 0.5f));

            terrainManager = new TerrainManager(physicsWorld);
            blockManager = new BlockManager(physicsWorld, contactListener);
            enemyManager = new EnemyManager(physicsWorld, contactListener);
            shotManager = new ShotManager(physicsWorld, contactListener);
            hazardManager = new HazardManager(physicsWorld, contactListener);
            explosiveManager = new ExplosiveManager(physicsWorld, contactListener);
            introManager = new IntroManager(ScreenManager.buxtonFont,ScreenManager.smallFont, world,level);

            #region  ACTIVE BARREL
            for (int i = 0; i < parallaxEngine.worldLayers.Count; i++)
            {
                for (int j = 0; j < parallaxEngine.worldLayers[i].SpriteCount; j++)
                {

                    if (parallaxEngine.worldLayers[i].layerSprites[j].SpriteType == Sprite.Type.PowerUp)
                    {
                        //find the barrel with variable set to -1
                        if (parallaxEngine.worldLayers[i].layerSprites[j].HitPoints == -1 )
                        {
                            shotManager.ShotStartBarrel = parallaxEngine.worldLayers[i].layerSprites[j];
                            shotManager.ActivePowerUpBarrel = shotManager.ShotStartBarrel;
                            interactLayer = i;
                        }

                    }
                }
            }
            #endregion

            //different objects are updated through their manager classes therefore the play area layer is set to not awake so that update is skipped for the layer
            for ( int i = 0 ; i < parallaxEngine.worldLayers.Count; i++)
            {
                parallaxEngine.worldLayers[i].IsAwake = false;
            }

            //create physical bodies for all objects, for parallax 1.o layers
            for (int j = 0; j < parallaxEngine.worldLayers.Count; j++)
            {
                if (parallaxEngine.worldLayers[j].LayerParallax == Vector2.One)
                {
                    for (int i = 0; i < parallaxEngine.worldLayers[j].SpriteCount; i++)
                    {
                        CreateBody(physicsWorld, parallaxEngine.worldLayers[j].layerSprites[i]);
                    }
                }
            }

            //UI setup
            levelName = "WORLD " + LevelDataManager.world.ToString() + "-" + LevelDataManager.level.ToString() + "  :  " + LevelDataManager.levelData[LevelDataManager.world, LevelDataManager.level].name;
            levelNameSize = ScreenManager.font.MeasureString(levelName);

            //create debug view
            oDebugView = new DebugViewXNA(physicsWorld)
            {
                DefaultShapeColor = Color.Magenta,
                SleepingShapeColor = Color.Pink,
                StaticShapeColor = Color.Yellow,
            };
            this.oDebugView.LoadContent(ScreenManager.GraphicsDevice, content, ScreenManager.smallFont);
            this.oDebugView.AppendFlags(DebugViewFlags.Shape);
            this.oDebugView.AppendFlags(DebugViewFlags.PolygonPoints);
            this.oDebugView.AppendFlags(DebugViewFlags.CenterOfMass);

            powerTargetLocation = new Vector2(powerBarLocation.X - 24, powerBarLocation.Y - 36);
            powerSlope = (GameSettings.MaxFiringPower - GameSettings.MinFiringPower) / 0.8f;
            powerMod = GameSettings.MaxFiringPower - powerSlope;

            PlayArea.AddSpriteToLayer(shotManager.shot);
            firingPower = (GameSettings.MaxFiringPower + GameSettings.MinFiringPower) * 0.5f;
            firingDirection = new Vector2(1, -1);
            firingAngle = 45f;
            firingForce = firingDirection * firingPower;
            firingLocation = shotManager.ActivePowerUpBarrel.SpriteCenterInWorld;
            shotLocation = shotManager.shot.SpriteCenterInWorld;

            shotManager.shot.spriteBody = BodyFactory.CreateCircle(physicsWorld, ConvertUnits.ToSimUnits(32f), 1f, shotManager.ShotStartBarrel.spriteBody.Position, shotManager.shot);
            shotManager.shot.spriteBody.Enabled = false;
            shotManager.shot.spriteBody.BodyType = BodyType.Dynamic;

            #region INITIALIZE DECO SPRITES TO MANAGER
            decoManager = new DecoManager(parallaxEngine, true);
            for (int i = 0; i < parallaxEngine.worldLayers.Count; i++)
            {
                for (int j = 0; j < parallaxEngine.worldLayers[i].SpriteCount; j++)
                {

                    if (parallaxEngine.worldLayers[i].layerSprites[j].SpriteType == Sprite.Type.Deco)
                    {
                        decoManager.InitializeDeco(parallaxEngine.worldLayers[i].layerSprites[j]);
                    }
                    if (parallaxEngine.worldLayers[i].layerSprites[j].SpriteType == Sprite.Type.Boss)
                    {
                        enemyManager.bossLayer = parallaxEngine.worldLayers[i];
                    }
                    if (parallaxEngine.worldLayers[i].layerSprites[j].TextureID == 3) //cage
                    {
                        enemyManager.cageLayer = parallaxEngine.worldLayers[i];
                    }
                }
            }
            #endregion

            effectManager = new EffectManager(physicsWorld, contactListener, decoManager.Tint);

            #region SETUP 5-15 boss level
            if (world == 5 && level == 15)
            {
                LevelDataManager.levelData[world, level].safety = true;
            }
            #endregion

            #region SETUP APPLEJACK LEVELS
            if (world == 6 && level == 3)
            {
                appleJackPos = new Vector2(2914, 1344);
                isAppleJack = true;
            }
            if (world == 6 && level == 5)
            {
                appleJackPos = new Vector2(2880, 1344);
                isAppleJack = true;
            }
            if (world == 6 && level == 7)
            {
                appleJackPos = new Vector2(3512, 1344);
                isAppleJack = true;
            }
            #endregion

            //set starting level state
            if (introManager.IntroFinished())
            {
                Camera.ScrollTo(firingLocation, 0);
                Camera.IsScrolling = true;
                if (!LevelDataManager.levelData[world, level].safety)
                {
                    shotManager.shot.spriteBody.Enabled = true;
                    shotManager.shot.spriteBody.IsSensor = true;
                    levelState = LevelState.Aim;
                }
                else levelState = LevelState.Countdown;
            }
            else levelState = LevelState.Intro;

            if (GameSettings.isBoss) Camera.ZoomTo(0.6f);

            #region APPLY CHEATS
            if (GameSettings.CheatTNTBarrel) shotManager.ShotStartBarrel.TextureIndex = 4;
            if (GameSettings.CheatFireBarrel) shotManager.ShotStartBarrel.TextureIndex = 1;
            if (GameSettings.CheatLightningBarrel) shotManager.ShotStartBarrel.TextureIndex = 3;
            if (GameSettings.CheatGrowthBarrel) shotManager.ShotStartBarrel.TextureIndex = 7;
            if (GameSettings.CheatCannonBarrel) shotManager.ShotStartBarrel.TextureIndex = 8;
            if (GameSettings.CheatSawBarrel) shotManager.ShotStartBarrel.TextureIndex = 9;

            #endregion

            // once the load has finished, we use ResetElapsedTime to tell the game's
            // timing mechanism that we have just finished a very long frame, and that
            // it should not try to catch up.

            ScreenManager.Game.ResetElapsedTime();
        }
Example #24
0
        /// <summary>
        /// Update the Environment each frame.
        /// </summary>
        /// <param name="elapsedTime">Time since last Update() call.</param>
        public override void Update(float elapsedTime)
        {
            // Toggle debug view = F1.
            if (Keyboard.GetState().IsKeyDown(Keys.F1) && !OldKeyboard.GetState().IsKeyDown(Keys.F1))
            {
                if (m_debugView != null)
                {
                    m_debugView = null;
                }
                else
                {
                    m_debugView = new Physics.DebugViewXNA(CollisionWorld);
                }
            }

            //Pause with Escape
            if (!paused)
            {
                if (Keyboard.GetState().IsKeyDown(Keys.Escape) && !OldKeyboard.GetState().IsKeyDown(Keys.Escape) ||
                    (GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.Start) && !OldGamePad.GetState().IsButtonDown(Buttons.Start))
                    )
                {
                    pause(new GamePauseMenu(Controller, this));
                    Sound.PlayCue("scroll");
                }
            }

            // Debug Menu = F10.
            if (Keyboard.GetState().IsKeyDown(Keys.F10) && !OldKeyboard.GetState().IsKeyDown(Keys.F10))
            {
                Controller.ChangeEnvironment(new Menus.DebugMenu(Controller));
            }

            // Exit game.
            if (Keyboard.GetState().IsKeyDown(Keys.F5) && !OldKeyboard.GetState().IsKeyDown(Keys.F5))
            {
                Controller.Exit();
            }

            if (!paused)
            {
                HUD.enabled = true;
                if (elapsedTime > 0.0f)
                {
                    // Update physics.
                    CollisionWorld.Step(elapsedTime);

                    if (SpawnController != null)
                    {
                        SpawnController.Update(elapsedTime);
                    }

                    // Update entities.
                    Camera.Update(elapsedTime);
                    base.Update(elapsedTime);

                    // Particle keepalive.  Update remaining and try to remove if they are done.
                    ParticleKeepalive.RemoveAll(ent => {
                        ent.Update(elapsedTime);
                        if (ent.Effect.ActiveParticlesCount == 0)
                        {
                            ent.Remove();
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    });
                }
            }
            else
            {
                Camera.Update(elapsedTime);
                m_popUp.Update(elapsedTime);
                HUD.enabled = false;
            }

            HUD.Update(elapsedTime);
            FadeOut.Update(elapsedTime);

            if (Balloon != null)
            {
                heatMultiplier = (this.ScreenVirtualSize.Y / 2 - Balloon.Position.Y) * 0.0007f;
            }
            else
            {
                heatMultiplier = 0;
            }
        }
Example #25
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();
        }
Example #26
0
        public void initializeLevel()
        {
            ConvertUnits.SetDisplayUnitToSimUnitRatio(64);
            if (_currentLevel == null)
                _currentLevel = new Level();
            if (_world == null)
            {
                _world = new World(new Vector2(0f, 12f));
            }
            if (_hero == null)
                _hero = new Player(_world);

            if (_camera == null)
            {
                _camera = new Camera2D(ScreenManager.GraphicsDevice);
                _camera.EnablePositionTracking = true;
                _camera.TrackingBody = _hero._body;
            }
            if (gameTimers == null)
            {
                gameTimers = new TimerManager(ref _world);
            }

            if (_debugView == null)
            {
                _debugView = new DebugViewXNA(_world);
                _debugView.AppendFlags(DebugViewFlags.DebugPanel);
                _debugView.DefaultShapeColor = Color.White;
                _debugView.SleepingShapeColor = Color.LightGray;
                _debugView.LoadContent(ScreenManager.GraphicsDevice, content);
            }
            completedLevel = false;
        }
Example #27
0
        public virtual void Draw(SpriteBatch theSpriteBatch, DebugViewXNA debugView, Matrix projection, Matrix view)
        {
            if (mSpriteBody != null)
            {
                mspritePos = mSpriteBody.Position * MeterInPixels;
                mspriteRotation = mSpriteBody.Rotation;
            }

            theSpriteBatch.Draw(mSpriteSheetTexture, mspritePos, Source,
                Color.White, mspriteRotation, spriteOrigin,
                new Vector2(mWidthScale, mHeightScale), SpriteEffects.None, 0f);
        }
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        public override void LoadContent()
        {
            //read write stream to the server
            readStream = new MemoryStream();
            writeStream = new MemoryStream();

            reader = new BinaryReader(readStream);
            writer = new BinaryWriter(writeStream);
            if (Content == null)
                Content = new ContentManager(ScreenManager.Game.Services, "Content");

            //DebugView Stuff
            Settings.EnableDiagnostics = true;
            DebugView = new DebugViewXNA(world);
            DebugView.LoadContent(ScreenManager.GraphicsDevice, Content);

            terrain.LoadContent(ScreenManager.GraphicsDevice);

            //Create camera using current viewport. Track a body without rotation.
            camera = new Camera2D(ScreenManager.GraphicsDevice);

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

            // Back ground stuff --------------------------------
            List<Texture2D> list = new List<Texture2D>();
            list.Add(ScreenManager.Game.Content.Load<Texture2D>("Sky"));
            list.Add(ScreenManager.Game.Content.Load<Texture2D>("trees"));
            list.Add(ScreenManager.Game.Content.Load<Texture2D>("Grass"));
            skyLayer = new GameBackground(list, camera.Position)
            {
                Height = ScreenManager.GraphicsDevice.Viewport.Height,
                Width = ScreenManager.GraphicsDevice.Viewport.Width,
                SpeedX = 0.3f
            };
            //---------------------------------------------------

            Texture2D terrainTex = Content.Load<Texture2D>("ground");

            font = Content.Load<SpriteFont>("font");

            //Create player
            player = new CompositeCharacter(world, new Vector2(ScreenManager.GraphicsDevice.Viewport.Width / 2.0f, ScreenManager.GraphicsDevice.Viewport.Height / 2.0f),
                Content.Load<Texture2D>("bean_ss1"), new Vector2(35.0f, 50.0f), ScreenManager.CharacterColor);

            //Create HUD
            playerHUD = new HUD(ScreenManager.Game, player, ScreenManager.Game.Content, ScreenManager.SpriteBatch);
            ScreenManager.Game.Components.Add(playerHUD);

            client = new TcpClient();
            client.NoDelay = true;
            IPAddress ipadd = System.Net.IPAddress.Parse("169.254.169.231");
            client.Connect(ipadd, PORT);
            readBuffer = new byte[BUFFER_SIZE];
            client.GetStream().BeginRead(readBuffer, 0, BUFFER_SIZE, StreamReceived, null);

            Thread.Sleep(2000);

            if (id == 0)
            {
                terrain.CreateRandomTerrain(new Vector2(0, 0));
            }
            // Set camera to track player
            camera.TrackingBody = player.body;

            //Create walls
            leftWall = new StaticPhysicsObject(world, new Vector2(ConvertUnits.ToDisplayUnits(-100.0f), 0), Content.Load<Texture2D>("platformTex"),
                new Vector2(100, ConvertUnits.ToDisplayUnits(100.0f)));
            rightWall = new StaticPhysicsObject(world, new Vector2(ConvertUnits.ToDisplayUnits(100.0f), 0), Content.Load<Texture2D>("platformTex"),
                new Vector2(100, ConvertUnits.ToDisplayUnits(100.0f)));

            ground = new StaticPhysicsObject(world, new Vector2(ScreenManager.GraphicsDevice.Viewport.Width / 4.0f, ScreenManager.GraphicsDevice.Viewport.Height / 2.0f + 100), Content.Load<Texture2D>("platformTex"), new Vector2(2000f, 20f));
            // Load projectile and explosion textures
            projectileTexRed = Content.Load<Texture2D>("projectile_fire_red");
            projectileTexBlue = Content.Load<Texture2D>("projectile_fire_blue");
            projectileTexYellow = Content.Load<Texture2D>("projectile_fire_yellow");
            explosionTex = Content.Load<Texture2D>("explosion");

            // ----------------------------------------------------------

            // once the load has finished, we use ResetElapsedTime to tell the game's
            // timing mechanism that we have just finished a very long frame, and that
            // it should not try to catch up.
            ScreenManager.Game.ResetElapsedTime();
        }
Example #29
0
       public void Initialize(RenderContext context)
       {
           //Create new savedata file if it doesn't exist yet
           if (!File.Exists(SaveDataFile))
           {
               SaveData data = new SaveData();
               data.HighestDistance = 0;

               XmlWriter.SaveScore(data, SaveDataFile);
           }
           SaveScore(); // actually loads the score

           isActive = true;

           m_ViewPort = context.GraphicsDevice.Viewport;

           //Load a font
           TextRenderer.SetFont(context.Content.Load<SpriteFont>("Font/Standard"));

           //Create player an set him at center of screen
           m_StartPos = new Vector2(context.ViewPortSize.X * 0.25f, context.ViewPortSize.Y * 0.25f);
           m_Player = new Player(context, m_StartPos);
           m_Player.Initialize(context);
           m_Player.Translate(m_StartPos);

           context.Player = m_Player;

           //Generate a random level
           m_LevelManager = new LevelManager();
           m_LevelManager.Initialize(context);

           //AddParalaxing backgrounds
           m_BgManager = new BackgroundManager(context);
           m_BgManager.AddBackgound(new Background("background", new Vector2(0, 0), 1.0f, false, context));
           m_BgManager.AddBackgound(new Background("1", new Vector2(60, 20), 1.0f, false, context));
           m_BgManager.AddBackgound(new Background("2", new Vector2(100, 70), 1, false, context));
           m_BgManager.AddBackgound(new Background("3", new Vector2(200, 40), 1, false, context));
           m_BgManager.AddBackgound(new Background("4", new Vector2(300, 50), 1, false, context));
           m_BgManager.AddBackgound(new Background("5", new Vector2(400, 200), 1, false, context));

           #if(DEBUG)
           m_MonoDebug = new DebugViewXNA(context.World);
           m_MonoDebug.AppendFlags(DebugViewFlags.DebugPanel);
           m_MonoDebug.DefaultShapeColor = Color.Red;
           m_MonoDebug.SleepingShapeColor = Color.LightGray;
           m_MonoDebug.LoadContent(context.GraphicsDevice, context.Content);
           #endif

           SoundManager.Play("Background", true);

           HitScreen = new GameSprite("Textures/GUI/hit", context);
           PickScreen = new GameSprite("Textures/GUI/pickupHit", context);
       }             
Example #30
0
        protected override void LoadContent()
        {
            // Initialize camera controls
            #region "etc"
            _view = Matrix.Identity;

            _screenCenter = new Vector2(graphics.GraphicsDevice.Viewport.Width / 2f,
                                                graphics.GraphicsDevice.Viewport.Height / 2f);

            backgroundRectangle = new Rectangle(0, 0, graphics.GraphicsDevice.Viewport.Width, graphics.GraphicsDevice.Viewport.Height);

            //_cameraPosition = new Vector2(0, -200);
            cam = new Camera2d();
            cam._pos = new Vector2(0, -200);
            _view = Matrix.CreateTranslation(new Vector3(cam._pos - _screenCenter, 0f)) *
                        Matrix.CreateTranslation(new Vector3(_screenCenter, 0f));
            batch = new SpriteBatch(graphics.GraphicsDevice);

            menuMusic = Content.Load<Song>("Audio/MenuMusic");  // Put the name of your song in instead of "song_title"
            MediaPlayer.IsRepeating = true;
            MediaPlayer.Volume = 0.6f;
            MediaPlayer.Play(menuMusic);

            menuBlip1 = Content.Load<SoundEffect>("Audio/Blip1");
            menuBlip2 = Content.Load<SoundEffect>("Audio/Blip2");

            font = Content.Load<SpriteFont>("font");

            minecraftia = Content.Load<SpriteFont>("Fonts/Minecraftia");
            bitWonder = Content.Load<SpriteFont>("Fonts/8BitWonder");

            fxaaEffect = Content.Load<Effect>("FXAA");

            // Load sprites
            circleSprite = Content.Load<Texture2D>("circleSprite"); //  96px x 96px => 1.5m x 1.5m
            //groundSprite = Content.Load<Texture2D>("groundSprite"); // 512px x 64px =>   8m x 1m
            blissSprite = Content.Load<Texture2D>("bliss");
            vignette = Content.Load<Texture2D>("textures/vignette");
            particleImage = Content.Load<Texture2D>("textures/metaparticle");

            walk = Content.Load<Texture2D>("textures/walk"); //  96px x 96px => 1.5m x 1.5m
            stand = Content.Load<Texture2D>("textures/stand"); // 512px x 64px =>   8m x 1m
            arm1 = Content.Load<Texture2D>("textures/arm"); // 512px x 64px =>   8m x 1m
            sword = Content.Load<Texture2D>("textures/sword");
            pick = Content.Load<Texture2D>("textures/pick");
            back = Content.Load<Texture2D>("textures/back");

            /* Circle */
            circleSprite = Content.Load<Texture2D>("circleSprite"); //  96px x 96px => 1.5m x 1.5m
            //groundSprite = Content.Load<Texture2D>("groundSprite"); // 512px x 64px =>   8m x 1m
            characterSprite = Content.Load<Texture2D>("textures/character"); // 512px x 64px =>   8m x 1m

            textures[1] = Content.Load<Texture2D>("textures/blocks/stone");
            textures[2] = Content.Load<Texture2D>("textures/blocks/dirt");
            textures[3] = Content.Load<Texture2D>("textures/blocks/iron");
            textures[4] = Content.Load<Texture2D>("textures/blocks/gold");
            textures[10] = Content.Load<Texture2D>("textures/blocks/cloud");
            textures[11] = Content.Load<Texture2D>("textures/blocks/grass");
            textures[12] = Content.Load<Texture2D>("textures/blocks/wood");
            textures[13] = Content.Load<Texture2D>("textures/blocks/brush");

            grass[1] = Content.Load<Texture2D>("textures/grass/grassleft");
            grass[2] = Content.Load<Texture2D>("textures/grass/grasstop");
            grass[3] = Content.Load<Texture2D>("textures/grass/grassright");
            grass[4] = Content.Load<Texture2D>("textures/grass/grasstopleft");
            grass[5] = Content.Load<Texture2D>("textures/grass/grasstopright");
            grass[6] = Content.Load<Texture2D>("textures/grass/grassleftright");
            grass[7] = Content.Load<Texture2D>("textures/grass/grasscovered");

            _fluidSimulation = new FluidSimulation(world, batch, font);
            water = new Water(GraphicsDevice, particleImage);
            #endregion
            #region "initTerrain"
            for (int x = 0; x < xD; x++)
            {
                for (int y = 0; y < yD; y++)
                {
                    terrain[x, y] = new Block();
                    terrain[x, y].setBlockType(Block.NO_BLOCK);
                }
            }
            int Seed = (int)DateTime.Now.Ticks;
            Console.Out.WriteLine(Seed);
            random = new Random(Seed);
            /*for (int xi = 1; xi < xD; xi++)
            {
                for (int yi = 1; yi < yD - 121; yi++)
                {
                    terrain[xi, yi + 121].setBlockType(2);
                }
            }*/
            Tree temp = new Tree(157, 121);
            terrain[159, 120].setBlockType(2);
            for (int xi = 163; xi < xD / 4; xi++)
            {
                terrain[xi, 117].setBlockType(2);
            }
            for (int xi = 162; xi < xD / 4; xi++)
            {
                terrain[xi, 118].setBlockType(2);
            }
            for (int xi = 161; xi < xD / 4; xi++)
            {
                terrain[xi, 119].setBlockType(2);
            }
            for (int xi = 161; xi < xD / 4; xi++)
            {
                terrain[xi, 120].setBlockType(2);
            }
            for (int xi = 150; xi < xD/4; xi++)
            {
                terrain[xi, 121].setBlockType(2);
            }
            for (int xi = 151; xi < xD / 4; xi++)
            {
                terrain[xi, 122].setBlockType(2);
            }
            for (int xi = 152; xi < xD / 4; xi++)
            {
                terrain[xi, 123].setBlockType(2);
            }
            for (int xi = 154; xi < xD / 4; xi++)
            {
                terrain[xi, 124].setBlockType(2);
            }
            for (int xi = 156; xi < xD / 4; xi++)
            {
                terrain[xi, 125].setBlockType(2);
            }
            for (int xi = 159; xi < xD / 4; xi++)
            {
                terrain[xi, 126].setBlockType(2);
            }
            for (int xi = 161; xi < xD / 4; xi++)
            {
                terrain[xi, 127].setBlockType(2);
            }
            for (int xi = 162; xi < xD / 4; xi++)
            {
                terrain[xi, 128].setBlockType(2);
            }
            //rock
            for (int xi = 163; xi < xD / 4; xi++)
            {
                terrain[xi, 119].setBlockType(1);
            }
            for (int xi = 162; xi < xD / 4; xi++)
            {
                terrain[xi, 120].setBlockType(1);
            }
            for (int xi = 162; xi < xD / 4; xi++)
            {
                terrain[xi, 121].setBlockType(1);
            }
            for (int xi = 153; xi < xD / 4; xi++)
            {
                terrain[xi, 122].setBlockType(1);
            }
            for (int xi = 155; xi < xD / 4; xi++)
            {
                terrain[xi, 123].setBlockType(1);
            }
            for (int xi = 157; xi < xD / 4; xi++)
            {
                terrain[xi, 124].setBlockType(1);
            }
            for (int xi = 160; xi < xD / 4; xi++)
            {
                terrain[xi, 125].setBlockType(1);
            }
            for (int xi = 162; xi < xD / 4; xi++)
            {
                terrain[xi, 126].setBlockType(1);
            }
            //dem checks
            for (int xi = 2; xi < xD - 1; xi++)
            {
                for (int yi = 1; yi < yD - 1; yi++)
                {
                    checkVariation(xi, yi);
                }
            }
            for (int xi = 4; xi < xD - 3; xi++)
            {
                for (int yi = 4; yi < yD - 3; yi++)
                {
                    if (terrain[xi, yi].getBlockType() != Block.DIRT_BLOCK)
                    {
                        terrain[xi, yi].setVariation(0);
                    }
                    //checkGrass(xi, yi);
                }
            }
            terrain[157, 121].setVariation(2);
            terrain[151, 120].setBlockType(Block.GRASS_BLOCK);
            terrain[153, 120].setBlockType(Block.GRASS_BLOCK);
            terrain[154, 120].setBlockType(Block.GRASS_BLOCK);
            terrain[155, 120].setBlockType(Block.GRASS_BLOCK);
            terrain[160, 120].setBlockType(Block.GRASS_BLOCK);
            terrain[162, 117].setBlockType(Block.GRASS_BLOCK);
            #endregion
            //generateTerrain();
            #region "physicssetup"
            // create and configure the debug view
            _debugView = new DebugViewXNA(world);
            _debugView.AppendFlags(DebugViewFlags.DebugPanel);
            _debugView.DefaultShapeColor = Color.White;
            _debugView.SleepingShapeColor = Color.LightGray;
            _debugView.LoadContent(GraphicsDevice, Content);

            Vector2 characterPosition = new Vector2(152.9f, 120);

            characterBody = CreateCapsule(world, 14f / scale, 7f / scale, 1f, null);

            characterBody.Position = characterPosition;
            characterBody.Mass = 10000;
            characterBody.SleepingAllowed = false;
            characterBody.IsStatic = false;
            characterBody.Restitution = 0.0f;
            characterBody.Friction = 0.0f;
            characterBody.FixedRotation = true;
            characterBody.OnCollision += CharacterOnCollision;
            characterBody.OnSeparation += CharacterOnSeparation;

            ////// arm stuff
            /*armBody = BodyFactory.CreateRectangle(world, 6f / scale, 29f / scale, 1f, characterPosition+new Vector2(0/scale,-14/scale));
            armBody.Mass = 1;
            armBody.IsStatic = false;
            armBody.IgnoreCollisionWith(characterBody);

            _joint = new RevoluteJoint(armBody, characterBody, armBody.GetLocalPoint(characterBody.Position), new Vector2(4 / scale, -4 / scale));
            world.AddJoint(_joint);

            //_joint.MotorSpeed = 1.0f * Settings.Pi;
            _joint.MaxMotorTorque = 1.0f;
            _joint.MotorEnabled = false;
            _joint.CollideConnected = false;*/

            characterBody.Mass = 1;
            //armBody.Mass = 0;

            /* Circle */
            // Convert screen center from pixels to meters
            Vector2 circlePosition = (_screenCenter / scale) + new Vector2(0, -40.5f);

            // Create the circle fixture
            circleBody = BodyFactory.CreateCircle(world, 96f / (2f * scale), 1f, circlePosition);
            circleBody.BodyType = BodyType.Dynamic;

            // Give it some bounce and friction
            circleBody.Restitution = 0.3f;
            circleBody.Friction = 0.5f;

            /* Ground */
            Vector2 groundPosition = (_screenCenter / scale) + new Vector2(0, -24.25f);

            // Create the ground fixture
            groundBody = BodyFactory.CreateRectangle(world, 512f / scale, 64f / scale, 1f, groundPosition);
            groundBody.IsStatic = true;
            groundBody.Restitution = 0.3f;
            groundBody.Friction = 0.5f;

            // create and configure the debug view
            _debugView = new DebugViewXNA(world);
            _debugView.AppendFlags(DebugViewFlags.DebugPanel);
            _debugView.DefaultShapeColor = Color.White;
            _debugView.SleepingShapeColor = Color.LightGray;
            _debugView.LoadContent(GraphicsDevice, Content);
            #endregion
            #region "blur"
            gaussianBlur = new GaussianBlur(this);
            gaussianBlur.ComputeKernel(BLUR_RADIUS, BLUR_AMOUNT);

            renderTargetWidth = 16;
            renderTargetHeight = 16;

            renderTarget1 = new RenderTarget2D(GraphicsDevice,
                renderTargetWidth, renderTargetHeight, false,
                GraphicsDevice.PresentationParameters.BackBufferFormat,
                DepthFormat.None);

            renderTarget2 = new RenderTarget2D(GraphicsDevice,
                renderTargetWidth, renderTargetHeight, false,
                GraphicsDevice.PresentationParameters.BackBufferFormat,
                DepthFormat.None);

            gaussianBlur.ComputeOffsets(renderTargetWidth, renderTargetHeight);
            #endregion
            #region "rays"
            Services.AddService(batch.GetType(), batch);

            rays.lightSource = rayStartingPos;
            rays.Exposure -= .15f;
            rays.LightSourceSize -= .5f;

            scene = new RenderTarget2D(graphics.GraphicsDevice, graphics.GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, false, SurfaceFormat.Color, DepthFormat.None);
            sceneReg = new RenderTarget2D(graphics.GraphicsDevice, graphics.GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, false, SurfaceFormat.Color, DepthFormat.None);
            sceneRegB = new RenderTarget2D(graphics.GraphicsDevice, graphics.GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, false, SurfaceFormat.Color, DepthFormat.None);
            sceneRegPre = new RenderTarget2D(graphics.GraphicsDevice, graphics.GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, false, SurfaceFormat.Color, DepthFormat.None);

            #endregion
        }
Example #31
0
        /// <summary>
        /// Unload graphics content used by the game.
        /// </summary>
        public override void Unload()
        {
            content.Unload();
            content = null;
            _hero = null;
            _world.Clear();
            //_world = null;
            _camera = null;
            _currentLevel = null;
            _debugView = null;

            #if WINDOWS_PHONE
            Microsoft.Phone.Shell.PhoneApplicationService.Current.State.Remove("PlayerPosition");
            Microsoft.Phone.Shell.PhoneApplicationService.Current.State.Remove("EnemyPosition");
            #endif
        }
Example #32
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            _debugView = new DebugViewXNA(_world);
            _debugView.LoadContent(GraphicsDevice, Content);
            _debugView.RemoveFlags(DebugViewFlags.Controllers);
               _debugView.RemoveFlags(DebugViewFlags.Joint);

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            _fpscounter = new FPScounter(this);
            Mouse.SetPosition(400, 400);
            _cursor = new Cursor(this);

            _introsong = Content.Load<Song>(".\\Audio\\INTRO");

            //--------------------------------------
            //Game STarts here!!!
            //--------------------------------------

            if (Globals.SkipIntro)
            {
               StartPlayingLevel();
            }
            else
            {
                StartTheGame();
            }
        }