示例#1
0
文件: Map.cs 项目: psykano/STFU-xna
 public Map(World world, LevelMap levelMap, EntityManager entityManager, RepresentationManager representationManager, ControllerManager controllerManager)
 {
     this.world = world;
     this.LevelMap = levelMap;
     this.entityManager = entityManager;
     this.representationManager = representationManager;
     this.controllerManager = controllerManager;
     this.WallTiles = new List<WallTile>();
     this.Tiles = new List<Entity>();
     this.random = new Random();
 }
示例#2
0
        // Constructor
        public CheckpointTile(World world, Vector2 position, float width, float height, EntityManager entityManager)
            : base(world)
        {
            this.Width = ConvertUnits.ToSimUnits(width);
            this.Height = ConvertUnits.ToSimUnits(height);
            this.Activated = false;
            this.entityManager = entityManager;

            // Make the checkpoint in the physics world only as a sensor
            physicsObj = new StaticPhysicsObject(this, this.world, position, width, height);
            physicsObj.body.IsSensor = true;
            physicsObj.body.OnCollision += new OnCollisionEventHandler(onCollision);
        }
示例#3
0
文件: Game1.cs 项目: psykano/STFU-xna
        /// <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");
        }
示例#4
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");
        }