// called when the transition waypoint is touched by the player public void movePlayer(Player player) { for (int i = 0; i < 3; i++) { if (layers[i].containsTransition(id)) { // move the player to the new layer, at the location of the transition block player.BoundingRectangle.Min = new Vector3(srcx * 60, srcy * 40, layers[i].depth); player.BoundingRectangle.Max = new Vector3(srcx * 60 + 60, srcy * 40 + 80, layers[i].depth); } } }
public Vehicle(Game game, Player p, VehicleType type, Vector2 pos, Level curr) { g = game; player = p; Type = type; switch (Type) { case VehicleType.Spinner: texture = g.Content.Load<Texture2D>("Vehicles/spinner"); break; case VehicleType.Jeep: texture = g.Content.Load<Texture2D>("Vehicles/jeep"); break; case VehicleType.Minecart: texture = g.Content.Load<Texture2D>("Vehicles/minecart"); break; case VehicleType.Rocket: texture = g.Content.Load<Texture2D>("Vehicles/rocket"); break; case VehicleType.Lift: texture = g.Content.Load<Texture2D>("Vehicles/lift"); break; } physics = new Physics(); physics.Velocity = 200.0f; // create the bounding rectangle in world space if (Type != VehicleType.Lift) { BoundingRectangle = new BoundingBox(new Vector3(pos.X, pos.Y, 0.0f), new Vector3(pos.X + 60, pos.Y + 40, 0.0f)); texRect = new Rectangle((int)pos.X, (int)pos.Y, 60, 40); } else { BoundingRectangle = new BoundingBox(new Vector3(pos.X, pos.Y - 40, 0.0f), new Vector3(pos.X + 300, pos.Y, 0.0f)); texRect = new Rectangle((int)pos.X, (int)pos.Y - 40, 300, 40); } level = curr; }
/// <summary> /// Load the current level from the text file /// </summary> /// <param name="reader">The level file stream (after width and height have been read in)</param> private void loadLevel(StreamReader reader) { int currentTile = 0; currentTile = reader.Read(); bool swap = true; int x = 0; int y = 0; player = new Player(Game, new Vector2(x * 60, y * 40), this); while (!reader.EndOfStream) { switch (currentTile) { case 'w': // waypoint tiles[x][y] = new Tile(new Vector2(x * 60.0f, y * 40), Tile.TileType.Waypoint, 0.0f); break; case 'p': // player tile. Spawn the player here tiles[x][y] = new Tile(new Vector2(x * 60, y * 40), Tile.TileType.Player, 0.0f); spawn = new Point(x, y); break; case 'P': // platform tiles[x][y] = new Tile(new Vector2(x * 60.0f, y * 40), Tile.TileType.Platform, 0.0f); break; case 'W': tiles[x][y] = new Tile(textures["sewerWall"], new Vector2(x * 60.0f, y * 40), Tile.TileType.SewerWall, 0.0f); break; case 'S': tiles[x][y] = new Tile(textures["sewerInterior"], new Vector2(x * 60.0f, y * 40), Tile.TileType.SewerInterior, 0.0f); break; case 'V': tiles[x][y] = new Tile(new Vector2(x * 60.0f, y * 40.0f), Tile.TileType.Waypoint, 0.0f); waypoints.Add("spinner", new Waypoint(Waypoint.WaypointType.Spinner, player, new Vector2(x * 60, y * 40), 0.0f)); vehicle = new Vehicle(Game, player, Vehicle.VehicleType.Spinner, new Vector2(x * 60, y * 40), this); vehicleSpawn = new Point(x, y); break; case '.': // air tiles[x][y] = new Tile(new Vector2(x * 60.0f, y * 40), Tile.TileType.Air, 0.0f); break; case 'x': // road // swap between the two different textures if (swap) tiles[x][y] = new Tile(textures["road0"], new Vector2(x * 60.0f, y * 40), Tile.TileType.Road, 0.0f); else tiles[x][y] = new Tile(textures["road1"], new Vector2(x * 60.0f, y * 40), Tile.TileType.Road, 0.0f); break; case 'X': tiles[x][y] = new Tile(new Vector2(x * 60.0f, y * 40), Tile.TileType.Waypoint, 0.0f); waypoints.Add("X", new Waypoint(Waypoint.WaypointType.EndRide, vehicle, new Vector2(x * 60, y * 40), 0.0f)); break; case 'c': tiles[x][y] = new Tile(textures["concrete"], new Vector2(x * 60.0f, y * 40), Tile.TileType.Concrete, 0.0f); break; case 's': tiles[x][y] = new Tile(new Vector2(x * 60.0f, y * 40), Tile.TileType.Waypoint, 0.0f); waypoints.Add("s", new Waypoint(Waypoint.WaypointType.SavePoint, this, new Vector2(x * 60, y * 40), 0.0f)); break; case 'e': tiles[x][y] = new Tile(new Vector2(x * 60.0f, y * 40), Tile.TileType.Waypoint, 0.0f); waypoints.Add("e", new Waypoint(Waypoint.WaypointType.EndLevel, this, new Vector2(x * 60, y * 40), 0.0f)); break; case 'E': tiles[x][y] = new Tile(new Vector2(x * 60, y * 40), Tile.TileType.Boss, 0.0f); boss = new Boss(Game, x * 60, y * 40, this); break; case 'B': tiles[x][y] = new Tile(textures["buildingInterior"], new Vector2(x * 60.0f, y * 40), Tile.TileType.BuildingInterior, 0.0f); break; case 'b': tiles[x][y] = new Tile(textures["buildingWall"], new Vector2(x * 60.0f, y * 40), Tile.TileType.BuildingWall, 0.0f); break; case '-': tiles[x][y] = new Tile(textures["buildingPlatform"], new Vector2(x * 60.0f, y * 40), Tile.TileType.Platform, 0.0f); break; case '|': tiles[x][y] = new Tile(textures["ladder"], new Vector2(x * 60.0f, y * 40), Tile.TileType.Ladder, 0.0f); break; case 'l': tiles[x][y] = new Tile(textures["powerline"], new Vector2(x * 60.0f, y * 40.0f), Tile.TileType.Powerline, 0.0f); break; case 'L': tiles[x][y] = new Tile(textures["buildingInterior"], new Vector2(x * 60.0f, y * 40.0f), Tile.TileType.Waypoint, 0.0f); vehicle = new Vehicle(Game, player, Vehicle.VehicleType.Lift, new Vector2(x * 60, (y + 1) * 40), this); waypoints.Add("lift", new Waypoint(Waypoint.WaypointType.Lift, player, new Vector2(x * 60, y * 40), 0.0f)); if (waypoints["X"] != null) waypoints["X"].handler = vehicle; vehicleSpawn = new Point(x, y); break; case '\n': // newline or EOF, reset the x value and increment the y value y++; x = -1; break; default: // carriage return, reset the x-value once more x = -1; break; } x++; swap = !swap; currentTile = reader.Read(); } player.resetRectangle(spawn); }