Пример #1
0
 public PushBox( Ramp r, float x, float y, int width, int height, bool direction)
     : base("blank",x, y, width, height)
 {
     this.SpawnPoint = new Vector2(x, y);
     connectedRamp = r;
     this.direction = direction;
 }
Пример #2
0
 public PushBox(Ramp r, float x, float y, int width, int height, bool direction)
     : base("blank", x, y, width, height)
 {
     this.SpawnPoint = new Vector2(x, y);
     connectedRamp   = r;
     this.direction  = direction;
 }
Пример #3
0
        public Level(string mapFile, GraphicsDeviceManager graphicsManager)
        {
            this.isComplete = false;
            this.bunnydead  = false;
            this.graphics   = graphicsManager;
            this.map        = new TmxMap(mapFile);

            this.Bunny = new Bunny(
                Single.Parse(map.Properties["bunnySpawnX"]),
                Single.Parse(map.Properties["bunnySpawnY"]));
            this.Clyde = new Clyde(
                Single.Parse(map.Properties["clydeSpawnX"]),
                Single.Parse(map.Properties["clydeSpawnY"]));

            this.inventory    = new Inventory(0, 0, 55, 55);
            this.worldSprites = new List <Sprite>();
            this.platforms    = new List <Sprite>();
            this.items        = new List <Item>();
            this.sounds       = new List <SoundEffect>();
            this.keys         = new List <Item>();
            this.ramps        = new List <Item>();
            this.doors        = new List <Item>();
            this.buttons      = new List <Item>();
            this.waters       = new List <Item>();
            this.goal         = new List <Item>();
            this.gates        = new List <Item>();
            this.physics      = new Physics();
            this.physics.Add(this.Bunny);
            this.physics.Add(this.Clyde);
            this.collisions = new CollisionManager(platforms, items, new List <Sprite>());
            this.collisions.addMoving(this.Clyde);

            this.collisions.addMoving(this.Bunny);

            this.mapObjectsDrawable    = map.ObjectGroups["drawable"];
            this.mapObjectsNonDrawable = map.ObjectGroups["nondrawable"];

            // draw the nondrawable objects as Regions
            foreach (TmxObjectGroup.TmxObject o in mapObjectsNonDrawable.Objects)
            {
                Console.WriteLine("X:" + o.X);
                Console.WriteLine("Y:" + o.Y);
                Console.WriteLine("Width:" + o.Width);
                Console.WriteLine("Height:" + o.Height);

                Region currentRegion = new Region(o.X, o.Y, o.Width, o.Height);
                //Sprite currentRegion = new Sprite("ground", o.X, o.Y, o.Width, o.Height);
                this.worldSprites.Add(currentRegion);
                this.platforms.Add(currentRegion);
            }

            // draw the drawable objects
            foreach (TmxObjectGroup.TmxObject o in mapObjectsDrawable.Objects)
            {
                Item currentObject;
                Key  whiteKey = new Key(Color.AliceBlue, this, 0, 0, 0, 0);
                if (o.Properties["type"] == "water")
                {
                    currentObject = new Water(o.X, o.Y, o.Width, o.Height, this);
                    this.waters.Add(currentObject);
                }
                else if (o.Properties["type"] == "key")
                {
                    System.Drawing.Color drawColor = System.Drawing.Color.FromName(o.Properties["color"]);
                    Color c = new Color(drawColor.R, drawColor.G, drawColor.B, drawColor.A);
                    whiteKey      = new Key(c, this, o.X, o.Y, o.Width, o.Height);
                    currentObject = whiteKey;
                    this.keys.Add(currentObject);
                }
                else if (o.Properties["type"] == "goal_door")
                {
                    System.Drawing.Color drawColor = System.Drawing.Color.FromName(o.Properties["color"]);
                    Color c = new Color(drawColor.R, drawColor.G, drawColor.B, drawColor.A);
                    currentObject = new Goal(this, c, o.X, o.Y, o.Width, o.Height);
                    this.goal.Add(currentObject);
                }
                else if (o.Properties["type"] == "switch_button")
                {
                    System.Drawing.Color drawColor = System.Drawing.Color.FromName(o.Properties["color"]);
                    Color c = new Color(drawColor.R, drawColor.G, drawColor.B, drawColor.A);
                    currentObject = new Switch(c, this, o.X, o.Y, o.Width, o.Height, false);
                    this.buttons.Add(currentObject);
                }
                else if (o.Properties["type"] == "reverse_switch")
                {
                    System.Drawing.Color drawColor = System.Drawing.Color.FromName(o.Properties["color"]);
                    Color c = new Color(drawColor.R, drawColor.G, drawColor.B, drawColor.A);
                    currentObject = new Switch(c, this, o.X, o.Y, o.Width, o.Height, true);
                    this.buttons.Add(currentObject);
                }
                else if (o.Properties["type"] == "switch_gate")
                {
                    System.Drawing.Color drawColor = System.Drawing.Color.FromName(o.Properties["color"]);
                    Color c = new Color(drawColor.R, drawColor.G, drawColor.B, drawColor.A);
                    currentObject = new Gate(o.Properties["imageName"], c, o.X, o.Y, o.Width, o.Height);
                    this.platforms.Add(currentObject);
                    this.gates.Add(currentObject);
                }
                else if (o.Properties["type"] == "door")
                {
                    System.Drawing.Color drawColor = System.Drawing.Color.FromName(o.Properties["color"]);
                    Color c = new Color(drawColor.R, drawColor.G, drawColor.B, drawColor.A);
                    currentObject = new Door(this, c, o.X, o.Y, o.Width, o.Height);
                    this.platforms.Add(currentObject);
                    this.doors.Add(currentObject);
                }
                else if (o.Properties["type"] == "ramp")
                {
                    Ramp r = new Ramp(o.Properties["imageName"], o.X, o.Y, o.Width, o.Height, this);
                    currentObject = r;
                    this.items.Add(r.leftPushBox);
                    this.worldSprites.Add(r.leftPushBox);
                    this.items.Add(r.rightPushBox);
                    this.worldSprites.Add(r.rightPushBox);
                    this.physics.Add(r);
                    this.platforms.Add(currentObject);
                    this.ramps.Add(currentObject);
                    this.collisions.addMoving(currentObject);
                }
                else if (o.Properties["type"] == "cloud")
                {
                    currentObject = new Cloud(o.Properties["imageName"], o.X, o.Y, o.Width, o.Height);
                }
                else
                {
                    //this shouldn't happen
                    currentObject = new Water(o.X, o.Y, o.Width, o.Height, this);
                    Console.WriteLine(o.Properties["imageName"]);
                }
                this.worldSprites.Add(currentObject);
                this.items.Add(currentObject);
            }

            this.PlayerIcon = new PlayerIcon("BunnyCurrentsmall", "ClydeCurrentsmall");
            this.background = new Sprite(map.Properties["backgroundImage"], 0, 0,
                                         GameGlobals.WINDOW_WIDTH, GameGlobals.WINDOW_HEIGHT);
            this.worldSprites.Add(this.Bunny);
            this.worldSprites.Add(this.Clyde);
            this.worldSprites.Add(this.Clyde.back);
            this.items.Add(this.Clyde.back);
            this.platforms.Add(this.Clyde);
            this.inputManager = new InputManager(worldSprites, this.Bunny, this.Clyde, platforms, sounds, this);

            this.worldSprites.Add(inventory);
            this.imshow3 = new imageshow("win", 0, 0, 0, (map.TileHeight * map.Height));
            this.worldSprites.Add(imshow3);
            this.imshow2 = new imageshow("bunnydies", (map.TileWidth * map.Width) / 3, (map.TileHeight * map.Height) / 4, 0, (map.TileHeight * map.Height) / 2);
            this.worldSprites.Add(imshow2);
            this.Bunny.die      = imshow2;
            this.Bunny.mapwidth = (map.TileWidth * map.Width) / 3;
            String logoImage  = "mainlogo";
            String resetImage = "reset_keyboard.png";

            if (GamePad.GetState(PlayerIndex.One).IsConnected)
            {
                logoImage  = "mainlogo_controller";
                resetImage = "reset_controller";
            }
            this.imshow  = new imageshow(logoImage, (map.TileWidth * map.Width) / 4, (map.TileHeight * map.Height) / 4, 0, (map.TileHeight * map.Height) / 2);
            this.imshoww = (map.TileWidth * map.Width) / 2;
            this.worldSprites.Add(imshow);
        }
        public void moveSprite(Sprite sprite)
        {
            Vector2 velocity       = sprite.Velocity;
            bool    removed        = false;
            bool    removedProblem = false;

            if (solids.Contains(sprite))
            {
                removed = true;
                solids.Remove(sprite);
            }
            Sprite problem = getInitialCollision(sprite.testBox(0, 0));

            if (problem == null)
            {
            }
            else
            {
                solids.Remove(problem);
                removedProblem = true;
            }

            if (checkPlatformCollision(sprite.testBox(0, velocity.Y)))
            {
                resolveCollision(sprite, new Vector2(0, velocity.Y));

                sprite.Velocity = new Vector2(velocity.X, 0);

                Console.WriteLine(sprite.Velocity);
                if (velocity.Y > 0)
                {
                    //this is for ramp falling sound, fix later
                    if (velocity.Y == 0.6)
                    {
                        if (sprite.imageName == "gate_block")
                        {
                            Ramp r = (Ramp)sprite;
                            r.soundeffect.Play();
                        }
                    }
                    sprite.state = Sprite.State.Default;
                }
                else
                {
                }
            }
            else
            {
                sprite.Position += new Vector2(0, velocity.Y);
                sprite.Update(new GameTime());
            }
            if (checkPlatformCollision(sprite.testBox(velocity.X, 0)))
            {
                resolveCollision(sprite, new Vector2(velocity.X, 0));
            }
            else
            {
                sprite.Position += new Vector2(velocity.X, 0);
                sprite.Update(new GameTime());
            }
            if (removed)
            {
                solids.Add(sprite);
            }
            if (removedProblem)
            {
                solids.Add(problem);
            }
            //sprite.Update(new GameTime());
            // sprite.Velocity = new Vector2(0.5f * sprite .Velocity .X, sprite.Velocity.Y);
        }
Пример #5
0
        public Level(string mapFile, GraphicsDeviceManager graphicsManager)
        {
            this.isComplete = false;
            this.bunnydead = false;
            this.graphics = graphicsManager;
            this.map = new TmxMap(mapFile);

            this.Bunny = new Bunny(
                Single.Parse(map.Properties["bunnySpawnX"]),
                Single.Parse(map.Properties["bunnySpawnY"]));
            this.Clyde = new Clyde(
                Single.Parse(map.Properties["clydeSpawnX"]),
                Single.Parse(map.Properties["clydeSpawnY"]));

            this.inventory = new Inventory(0, 0, 55, 55);
            this.worldSprites = new List<Sprite>();
            this.platforms = new List<Sprite>();
            this.items = new List<Item>();
            this.sounds = new List<SoundEffect>();
            this.keys = new List<Item>();
            this.ramps = new List<Item>();
            this.doors = new List<Item>();
            this.buttons = new List<Item>();
            this.waters = new List<Item>();
            this.goal = new List<Item>();
            this.gates = new List<Item>();
            this.physics = new Physics();
            this.physics.Add(this.Bunny);
            this.physics.Add(this.Clyde);
            this.collisions = new CollisionManager(platforms, items, new List<Sprite>());
            this.collisions.addMoving(this.Clyde);

            this.collisions.addMoving(this.Bunny);

            this.mapObjectsDrawable = map.ObjectGroups["drawable"];
            this.mapObjectsNonDrawable = map.ObjectGroups["nondrawable"];

            // draw the nondrawable objects as Regions
            foreach (TmxObjectGroup.TmxObject o in mapObjectsNonDrawable.Objects)
            {
                Console.WriteLine("X:" + o.X);
                Console.WriteLine("Y:" + o.Y);
                Console.WriteLine("Width:" + o.Width);
                Console.WriteLine("Height:" + o.Height);

                Region currentRegion = new Region(o.X, o.Y, o.Width, o.Height);
                //Sprite currentRegion = new Sprite("ground", o.X, o.Y, o.Width, o.Height);
                this.worldSprites.Add(currentRegion);
                this.platforms.Add(currentRegion);
            }

            // draw the drawable objects
            foreach (TmxObjectGroup.TmxObject o in mapObjectsDrawable.Objects)
            {
                Item currentObject;
                Key whiteKey = new Key(Color.AliceBlue, this, 0, 0, 0, 0);
                if (o.Properties["type"] == "water")
                {
                    currentObject = new Water(o.X, o.Y, o.Width, o.Height, this);
                    this.waters.Add(currentObject);
                }
                else if (o.Properties["type"] == "key")
                {
                    System.Drawing.Color drawColor = System.Drawing.Color.FromName(o.Properties["color"]);
                    Color c = new Color(drawColor.R, drawColor.G, drawColor.B, drawColor.A);
                    whiteKey = new Key(c, this, o.X, o.Y, o.Width, o.Height);
                    currentObject = whiteKey;
                    this.keys.Add(currentObject);
                }
                else if (o.Properties["type"] == "goal_door")
                {
                    System.Drawing.Color drawColor = System.Drawing.Color.FromName(o.Properties["color"]);
                    Color c = new Color(drawColor.R, drawColor.G, drawColor.B, drawColor.A);
                    currentObject = new Goal(this, c, o.X, o.Y, o.Width, o.Height);
                    this.goal.Add(currentObject);
                }
                else if (o.Properties["type"] == "switch_button")
                {
                    System.Drawing.Color drawColor = System.Drawing.Color.FromName(o.Properties["color"]);
                    Color c = new Color(drawColor.R, drawColor.G, drawColor.B, drawColor.A);
                    currentObject = new Switch(c, this, o.X, o.Y, o.Width, o.Height, false);
                    this.buttons.Add(currentObject);
                }
                else if (o.Properties["type"] == "reverse_switch")
                {
                    System.Drawing.Color drawColor = System.Drawing.Color.FromName(o.Properties["color"]);
                    Color c = new Color(drawColor.R, drawColor.G, drawColor.B, drawColor.A);
                    currentObject = new Switch(c, this, o.X, o.Y, o.Width, o.Height, true);
                    this.buttons.Add(currentObject);
                }
                else if (o.Properties["type"] == "switch_gate")
                {
                    System.Drawing.Color drawColor = System.Drawing.Color.FromName(o.Properties["color"]);
                    Color c = new Color(drawColor.R, drawColor.G, drawColor.B, drawColor.A);
                    currentObject = new Gate(o.Properties["imageName"], c, o.X, o.Y, o.Width, o.Height);
                    this.platforms.Add(currentObject);
                    this.gates.Add(currentObject);
                }
                else if (o.Properties["type"] == "door")
                {
                    System.Drawing.Color drawColor = System.Drawing.Color.FromName(o.Properties["color"]);
                    Color c = new Color(drawColor.R, drawColor.G, drawColor.B, drawColor.A);
                    currentObject = new Door(this, c, o.X, o.Y, o.Width, o.Height);
                    this.platforms.Add(currentObject);
                    this.doors.Add(currentObject);
                }
                else if (o.Properties["type"] == "ramp")
                {
                    Ramp r = new Ramp(o.Properties["imageName"], o.X, o.Y, o.Width, o.Height, this);
                    currentObject = r;
                    this.items.Add(r.leftPushBox);
                    this.worldSprites.Add(r.leftPushBox);
                    this.items.Add(r.rightPushBox);
                    this.worldSprites.Add(r.rightPushBox);
                    this.physics.Add(r);
                    this.platforms.Add(currentObject);
                    this.ramps.Add(currentObject);
                    this.collisions.addMoving(currentObject);
                }
                else if (o.Properties["type"] == "cloud")
                {
                    currentObject = new Cloud(o.Properties["imageName"], o.X, o.Y, o.Width, o.Height);
                }
                else
                {
                    //this shouldn't happen
                    currentObject = new Water(o.X, o.Y, o.Width, o.Height, this);
                    Console.WriteLine(o.Properties["imageName"]);
                }
                this.worldSprites.Add(currentObject);
                this.items.Add(currentObject);
            }

            this.PlayerIcon = new PlayerIcon("BunnyCurrentsmall", "ClydeCurrentsmall");
            this.background = new Sprite(map.Properties["backgroundImage"], 0, 0,
                GameGlobals.WINDOW_WIDTH, GameGlobals.WINDOW_HEIGHT);
            this.worldSprites.Add(this.Bunny);
            this.worldSprites.Add(this.Clyde);
            this.worldSprites.Add(this.Clyde.back);
            this.items.Add(this.Clyde.back);
            this.platforms.Add(this.Clyde);
            this.inputManager = new InputManager(worldSprites, this.Bunny, this.Clyde, platforms, sounds, this);

            this.worldSprites.Add(inventory);
            this.imshow3 = new imageshow("win", 0, 0, 0, (map.TileHeight * map.Height));
            this.worldSprites.Add(imshow3);
            this.imshow2 = new imageshow("bunnydies", (map.TileWidth * map.Width) / 3, (map.TileHeight * map.Height) / 4, 0, (map.TileHeight * map.Height) / 2);
            this.worldSprites.Add(imshow2);
            this.Bunny.die = imshow2;
            this.Bunny.mapwidth = (map.TileWidth * map.Width) / 3;
            String logoImage = "mainlogo";
            String resetImage = "reset_keyboard.png";
            if (GamePad.GetState(PlayerIndex.One).IsConnected)
            {
                logoImage = "mainlogo_controller";
                resetImage = "reset_controller";
            }
            this.imshow = new imageshow(logoImage, (map.TileWidth * map.Width) / 4, (map.TileHeight * map.Height) / 4, 0, (map.TileHeight * map.Height) / 2);
            this.imshoww = (map.TileWidth * map.Width) / 2;
            this.worldSprites.Add(imshow);
        }