Beispiel #1
0
        WorldPhysics worldPhysics = WorldPhysics.DefaultWorldPhysics; //Physics object used on this map. Attributes may be specified in the map file.

        #endregion Fields

        #region Constructors

        //Construct a levelstate object
        public LevelState(Game game, PlayerState player, string mapName)
            : base(game, player)
        {
            Activated += delegate {
                game.Display.Renderer.SetFont("verdana", 8);
            };

            playerInfo = player;

            this.game = game;
            this.display = game.Display;
            this.mapName = mapName;
            //			game.Display.CameraX = 50;
            //game.Display.CameraY = 100;

            //Load map
            MapDescriptor map = game.Resources.GetMapDescriptor(mapName);
            objectFactory = new ObjectFactory(game, this);

            tileMap = new TileMap(game.Display, game.Resources, map);

            //And set up the world physics attributes
            if (map.ExtraProperties.ContainsKey("gravity"))
                worldPhysics.Gravity = double.Parse(map.ExtraProperties["gravity"]);
            if (map.ExtraProperties.ContainsKey("ground-friction-factor"))
                worldPhysics.GroundFrictionFactor = double.Parse(map.ExtraProperties["ground-friction-factor"]);

            //Spawn all objects
            foreach (var o in map.Objects)
            {
                GameObject obj = objectFactory.Spawn(o.Name, new Vector(o.X, o.Y), new Vector(0,-100), worldPhysics);
                if (obj != null)
                {
                    objects.Add(obj);
                    if (o.Name == "mario")
                    {
                        this.player = (Player)objects[objects.Count-1];
                    }
                }
            }

            //Set the map background
            if (!string.IsNullOrEmpty(map.Background))
                background = new ParallaxBackground(game.Resources.GetTexture(map.Background), 0.5, 0.2, game.Display);

            camera = new Camera(display, 0, map.Width * map.TileSize, 0, map.Height * map.TileSize);

            game.Audio.PlayMusic("overworld-intro", "overworld");

            icons["coin"] = objectFactory.CreateIcon("coin", 0.7); //new Icon(game, Helpers.
            icons["mario"] = objectFactory.CreateIcon("mario-big", 0.5); //new Icon(game, marioIcon);
        }
Beispiel #2
0
        public Arena(int width, int height, Game game)
        {
            if (width < 1 || height < 1)
            {
                throw new InvalidOperationException("Cannot create an arena with width or height less than 1.");
            }

            this.width = width;
            this.height = height;
            gameref = game;

            //Create the arena grid, max grid size = 50
            grid = new SpatialGrid<Component>(width, height, 75);

            background = new ParallaxBackground(game.Resources.GetTexture("starscape1"), 0.3, game.Display);
        }
Beispiel #3
0
        /*public override void Initialize(Game game)
        {
            display = game.Display;
            renderer = display.Renderer;
            input = game.Input;

            model.Display = display;
            model.Zoom = display.Zoom;
        }*/
        public void ModelChanged(EditorModel.VariableName v, object oldValue, object newValue)
        {
            switch (v)
            {
            case EditorModel.VariableName.Background:
                if (!string.IsNullOrEmpty((string)newValue))
                    Schedule(delegate {background = new ParallaxBackground(model.ResourceManager.GetTexture((string)newValue), 1, 0.5, model.Display); });
                break;
            }
        }