public Tile(Room room, Enumeration.TileType tileType, Enumeration.StateTile state, Enumeration.Items eitem, Enumeration.TileType NextTileType) { tileAnimation = new AnimationSequence(this); this.room = room; nextTileType = NextTileType; System.Xml.Serialization.XmlSerializer ax = new System.Xml.Serialization.XmlSerializer(tileSequence.GetType()); Stream txtReader = Microsoft.Xna.Framework.TitleContainer.OpenStream(PoP.CONFIG_PATH_CONTENT + PoP.CONFIG_PATH_SEQUENCES + tileType.ToString() + "_sequence.xml"); //TextReader txtReader = File.OpenText(PrinceOfPersiaGame.CONFIG_PATH_CONTENT + PrinceOfPersiaGame.CONFIG_PATH_SEQUENCES + tileType.ToString() + "_sequence.xml"); tileSequence = (List <Sequence>)ax.Deserialize(txtReader); foreach (Sequence s in tileSequence) { s.Initialize(); } //Search in the sequence the right type Sequence result = tileSequence.Find(delegate(Sequence s) { return(s.name.ToUpper() == state.ToString().ToUpper()); }); if (result != null) { //AMF to be adjust.... result.frames[0].SetTexture((Texture2D)Maze.Content[PoP.CONFIG_TILES + result.frames[0].value]); //result.frames[0].SetTexture(Content.Load<Texture2D>(PrinceOfPersiaGame.CONFIG_TILES + result.frames[0].value)); collision = result.collision; Texture = result.frames[0].texture; } Type = tileType; //change statetile element StateTileElement stateTileElement = new StateTileElement(); stateTileElement.state = state; tileState.Add(stateTileElement); tileAnimation.PlayAnimation(tileSequence, tileState); //load item switch (eitem) { case Enumeration.Items.flask: item = new Flask(); break; case Enumeration.Items.sword: item = new Sword(); break; } }
public Tile(RoomNew room, ContentManager Content, Enumeration.TileType tileType, Enumeration.StateTile state, Enumeration.Items eitem, Enumeration.TileType NextTileType__1) { this.room = room; nextTileType = NextTileType__1; System.Xml.Serialization.XmlSerializer ax = new System.Xml.Serialization.XmlSerializer(m_tileSequence.GetType()); Stream txtReader = Microsoft.Xna.Framework.TitleContainer.OpenStream(PrinceOfPersiaGame.CONFIG_PATH_CONTENT + PrinceOfPersiaGame.CONFIG_PATH_SEQUENCES + tileType.ToString().ToUpper() + "_sequence.xml"); //TextReader txtReader = File.OpenText(PrinceOfPersiaGame.CONFIG_PATH_CONTENT + PrinceOfPersiaGame.CONFIG_PATH_SEQUENCES + tileType.ToString().ToUpper() + "_sequence.xml"); m_tileSequence = (List <Sequence>)ax.Deserialize(txtReader); foreach (Sequence s in m_tileSequence) { s.Initialize(Content); } //Search in the sequence the right type Sequence result = m_tileSequence.Find((Sequence s) => s.name == state.ToString().ToUpper()); if (result != null) { //AMF to be adjust.... result.frames[0].SetTexture(Content.Load <Texture2D>(PrinceOfPersiaGame.CONFIG_TILES[0] + result.frames[0].value)); collision = result.collision; Texture = result.frames[0].texture; } Type = tileType; //change statetile element StateTileElement stateTileElement = new StateTileElement(); stateTileElement.state = state; tileState.Add(stateTileElement); tileAnimation.PlayAnimation(m_tileSequence, tileState.Value()); //load item switch (eitem) { case Enumeration.Items.flask: item = new Flask(Content); break; // TODO: might not be correct. Was : Exit Select case Enumeration.Items.flaskbig: item = new FlaskBig(Content); break; // TODO: might not be correct. Was : Exit Select case Enumeration.Items.sword: item = new Sword(Content); break; // TODO: might not be correct. Was : Exit Select } }
public void HandleCollision() { if (this.Type == Enumeration.TileType.loose) { if (this.tileState.Value().state != Enumeration.StateTile.loosefall) { return; } Rectangle r = new Rectangle((int)Position.X, (int)Position.Y, Tile.WIDTH, Tile.HEIGHT); Vector4 v = room.getBoundTiles(r); Tile myTile = room.GetTile((int)v.X, (int)v.W); //Rectangle tileBounds = room.GetBounds((int)v.X, (int)v.W); Vector2 depth = RectangleExtensions.GetIntersectionDepth(myTile.Position.Bounding, r); Enumeration.TileType tileType = room.GetType((int)v.X, (int)v.W); Enumeration.TileCollision tileCollision = room.GetCollision((int)v.X, (int)v.W); //Tile tile = room.GetTile(new Vector2((int)v.X, (int)v.W)); if (tileCollision == Enumeration.TileCollision.Platform) //if (tileType == Enumeration.TileType.floor) { if (depth.Y >= Tile.HEIGHT - Tile.PERSPECTIVE) { lock (room.tilesTemporaney) { room.tilesTemporaney.Remove(this); } //THE LOOSE FALL INTO FLOOR if (tileType == Enumeration.TileType.loose) { Loose l = (Loose)room.GetTile((int)v.X, (int)v.W); l.Fall(true); } else if (tileType == Enumeration.TileType.pressplate) { ((SoundEffect)Maze.Content[PoP.CONFIG_SOUNDS + "tile crashing into the floor"]).Play(); PressPlate pressPlate = (PressPlate)room.GetTile((int)v.X, (int)v.Y); pressPlate.Press(); } else { ((SoundEffect)Maze.Content[PoP.CONFIG_SOUNDS + "tile crashing into the floor"]).Play(); room.SubsTile(Coordinates, Enumeration.TileType.rubble); } } } //if (_position.Y >= RoomNew.BOTTOM_LIMIT - Tile.HEIGHT - Tile.PERSPECTIVE) if (_position.Y >= Room.BOTTOM_LIMIT - Tile.PERSPECTIVE) { //remove tiles from tilesTemporaney lock (room.tilesTemporaney) { room.tilesTemporaney.Remove(this); } //exit from DOWN room room = room.Down; _position.Y = Room.TOP_LIMIT - 10; lock (room.tilesTemporaney) { room.tilesTemporaney.Add(this); } } } }
private void DrawDebug(Room room) { if (CONFIG_DEBUG == false) { return; } Rectangle titleSafeArea = GraphicsDevice.Viewport.TitleSafeArea; Vector2 hudLocation = new Vector2(titleSafeArea.X, titleSafeArea.Y); DrawShadowedString(fontPrinceOfPersia_bigger, "LEVEL NAME=" + maze.player.MyLevel.levelName, hudLocation, Color.White); hudLocation.Y = hudLocation.Y + 10; DrawShadowedString(fontPrinceOfPersia_bigger, "ROOM NAME=" + maze.player.MyRoom.roomName, hudLocation, Color.White); hudLocation.Y = hudLocation.Y + 10; DrawShadowedString(fontPrinceOfPersia_bigger, "POSTION X=" + maze.player.Position.X.ToString() + " Y=" + maze.player.Position.Y.ToString(), hudLocation, Color.White); hudLocation.Y = hudLocation.Y + 10; DrawShadowedString(fontPrinceOfPersia_bigger, "FRAME RATE=" + AnimationSequence.frameRate.ToString(), hudLocation, Color.White); hudLocation.Y = hudLocation.Y + 10; DrawShadowedString(fontPrinceOfPersia_bigger, "PLAYER STATE=" + maze.player.spriteState.Value().state + " SEQUENCE CountOffset=" + maze.player.sprite.sequence.CountOffSet, hudLocation, Color.White); hudLocation.Y = hudLocation.Y + 10; DrawShadowedString(fontPrinceOfPersia_bigger, "PLAYER FRAME=" + maze.player.spriteState.Value().Frame + " NAME=" + maze.player.spriteState.Value().Name, hudLocation, Color.White); hudLocation.Y = hudLocation.Y + 10; DrawShadowedString(fontPrinceOfPersia_bigger, "PLAYER SWORD=" + maze.player.Sword.ToString(), hudLocation, Color.White); TouchCollection touchState = TouchPanel.GetState(); for (int x = 0; x < touchState.Count; x++) { hudLocation.Y = hudLocation.Y + 10; DrawShadowedString(fontPrinceOfPersia_bigger, "TOUCH_STATE=" + touchState[x].State.ToString(), hudLocation, Color.White); hudLocation.Y = hudLocation.Y + 10; DrawShadowedString(fontPrinceOfPersia_bigger, "TOUCH_LOCATION=" + touchState[x].Position.ToString(), hudLocation, Color.White); } hudLocation.Y = hudLocation.Y + 10; DrawShadowedString(fontPrinceOfPersia_bigger, "-SHIFTZONE=" + CntShiftZone.ToString(), hudLocation, Color.White); // Get the player's bounding rectangle and find neighboring tiles. Rectangle playerBounds = maze.player.Position.Bounding; Vector4 v4 = room.getBoundTiles(playerBounds); // For each potentially colliding Tile, warning the for check only the player row ground..W for (int y = (int)v4.Z; y <= (int)v4.W; ++y) { for (int x = (int)v4.X; x <= (int)v4.Y; ++x) { //Rectangle tileBounds = room.GetBounds(x, y); Tile myTile = room.GetTile(x, y); Vector2 depth = RectangleExtensions.GetIntersectionDepth(playerBounds, myTile.Position.Bounding); Enumeration.TileCollision tileCollision = room.GetCollision(x, y); Enumeration.TileType tileType = room.GetType(x, y); hudLocation.Y = hudLocation.Y + 10; DrawShadowedString(fontPrinceOfPersia_bigger, "GRID X=" + x + " Y=" + y + " TILETYPE=" + tileType.ToString() + " BOUND X=" + myTile.Position.Bounding.X + " Y=" + myTile.Position.Bounding.Y + " DEPTH X=" + depth.X + " Y=" + depth.Y, hudLocation, Color.White); } } }
public void HandleCollisionsNew() { isGround(); Rectangle playerBounds = _position.Bounding; //Find how many tiles are near on the left Vector4 v4 = SpriteRoom.getBoundTiles(playerBounds); // For each potentially colliding Tile, warning the for check only the player row ground..W for (int y = Convert.ToInt32(Math.Truncate(v4.Z)); y <= Convert.ToInt32(Math.Truncate(v4.W)); y++) { for (int x = Convert.ToInt32(Math.Truncate(v4.X)); x <= Convert.ToInt32(Math.Truncate(v4.Y)); x++) { Rectangle tileBounds = SpriteRoom.GetBounds(x, y); Vector2 depth = RectangleExtensions.GetIntersectionDepth(playerBounds, tileBounds); Enumeration.TileCollision tileCollision = SpriteRoom.GetCollision(x, y); Enumeration.TileType tileType = SpriteRoom.GetType(x, y); switch (tileType) { case Enumeration.TileType.spikes: if (IsAlive == false) { ((Spikes)SpriteRoom.GetTile(x, y)).Open(); return; } if (flip == SpriteEffects.FlipHorizontally) { if (depth.X < 10 & depth.Y >= Player.SPRITE_SIZE_Y) { ((Spikes)SpriteRoom.GetTile(x, y)).Open(); // if (depth.X <= -30 & depth.Y >= Player.SPRITE_SIZE_Y & ((Spikes)SpriteRoom.GetTile(x, y)).State == Enumeration.StateTile.open) // Impale(); } } else { if (depth.X > -10 & depth.Y >= Player.SPRITE_SIZE_Y) { ((Spikes)SpriteRoom.GetTile(x, y)).Open(); //if (depth.X >= 60 & depth.Y >= Player.SPRITE_SIZE_Y & ((Spikes)SpriteRoom.GetTile(x, y)).State == Enumeration.StateTile.open) // Impale(); } } break; // TODO: might not be correct. Was : Exit Select case Enumeration.TileType.lava: if (IsAlive == false) { ((Lava)SpriteRoom.GetTile(x, y)).Open(); return; } if (flip == SpriteEffects.FlipHorizontally) { if (depth.X < 10 & depth.Y >= Skeleton.SPRITE_SIZE_Y) { ((Lava)SpriteRoom.GetTile(x, y)).Open(); // if (depth.X <= -30 & depth.Y >= Player.SPRITE_SIZE_Y & ((Spikes)SpriteRoom.GetTile(x, y)).State == Enumeration.StateTile.open) // Impale(); } } else { if (depth.X > -10 & depth.Y >= Skeleton.SPRITE_SIZE_Y) { ((Lava)SpriteRoom.GetTile(x, y)).Open(); //if (depth.X >= 60 & depth.Y >= Player.SPRITE_SIZE_Y & ((Spikes)SpriteRoom.GetTile(x, y)).State == Enumeration.StateTile.open) // Impale(); } } break; // TODO: might not be correct. Was : Exit Select case Enumeration.TileType.loose: if (flip == SpriteEffects.FlipHorizontally) { if (depth.X < (-Tile.PERSPECTIVE - PLAYER_R_PENETRATION)) { ((Loose)SpriteRoom.GetTile(x, y)).Press(); //else //isLoosable(); } } else { if (depth.X > (Tile.PERSPECTIVE + PLAYER_L_PENETRATION)) { //45 ((Loose)SpriteRoom.GetTile(x, y)).Press(); //else //isLoosable(); } } break; // TODO: might not be correct. Was : Exit Select case Enumeration.TileType.pressplate: ((PressPlate)SpriteRoom.GetTile(x, y)).Press(); break; // TODO: might not be correct. Was : Exit Select case Enumeration.TileType.gate: case Enumeration.TileType.block: if (tileType == Enumeration.TileType.gate) { if (((Gate)SpriteRoom.GetTile(x, y)).State == Enumeration.StateTile.opened) { break; // TODO: might not be correct. Was : Exit Select } } //if player are raised then not collide.. //if sx wall i will penetrate..for perspective design if (flip == SpriteEffects.FlipHorizontally) { //only for x pixel if (depth.X < (-Tile.PERSPECTIVE - PLAYER_R_PENETRATION)) { if (spriteState.Value().state != Enumeration.State.freefall & spriteState.Value().state != Enumeration.State.highjump & spriteState.Value().state != Enumeration.State.hang & spriteState.Value().state != Enumeration.State.hangstraight & spriteState.Value().state != Enumeration.State.hangdrop & spriteState.Value().state != Enumeration.State.hangfall & spriteState.Value().state != Enumeration.State.jumphangMed & spriteState.Value().state != Enumeration.State.jumphangLong & spriteState.Value().state != Enumeration.State.climbup & spriteState.Value().state != Enumeration.State.climbdown) { //if (sprite.sequence.raised == false) // Bump(Enumeration.PriorityState.Force); //else // RJumpFall(Enumeration.PriorityState.Force); //return; _position.Value = new Vector2(_position.X + (depth.X - (-Tile.PERSPECTIVE - PLAYER_R_PENETRATION)), _position.Y); } } else { if (sprite.sequence.raised == true) { _position.Value = new Vector2(_position.X, _position.Y); } else { _position.Value = new Vector2(_position.X, _position.Y); } } } else { if (depth.X > (Tile.PERSPECTIVE + PLAYER_L_PENETRATION)) { //45 //if(sprite.sequence.raised == false) if (spriteState.Value().state != Enumeration.State.freefall & spriteState.Value().state != Enumeration.State.highjump & spriteState.Value().state != Enumeration.State.hang & spriteState.Value().state != Enumeration.State.hangstraight & spriteState.Value().state != Enumeration.State.hangdrop & spriteState.Value().state != Enumeration.State.hangfall & spriteState.Value().state != Enumeration.State.jumphangMed & spriteState.Value().state != Enumeration.State.jumphangLong & spriteState.Value().state != Enumeration.State.climbup & spriteState.Value().state != Enumeration.State.climbdown) { _position.Value = new Vector2(_position.X + (depth.X - (Tile.PERSPECTIVE + PLAYER_L_PENETRATION)), _position.Y); //Bump(Enumeration.PriorityState.Force); return; } } else if (sprite.sequence.raised == true) { _position.Value = new Vector2(_position.X, _position.Y); } else { _position.Value = new Vector2(_position.X, _position.Y); } } playerBounds = BoundingRectangle; break; // TODO: might not be correct. Was : Exit Select default: _position.Value = new Vector2(_position.X, tileBounds.Bottom); playerBounds = BoundingRectangle; break; } } } //??? //previousBottom = playerBounds.Bottom; //check if out room if (_position.Y > RoomNew.BOTTOM_LIMIT + 10) { RoomNew room = Maze.DownRoom(SpriteRoom); SpriteRoom = room; _position.Y = RoomNew.TOP_LIMIT + 27; // Y=77 //For calculate height fall from damage points calculations.. PositionFall = new Vector2(Position.X, (PrinceOfPersiaGame.CONFIG_SCREEN_HEIGHT - RoomNew.BOTTOM_LIMIT - PositionFall.Y)); } else if (_position.X >= RoomNew.RIGHT_LIMIT) { RoomNew room = Maze.RightRoom(SpriteRoom); SpriteRoom = room; _position.X = RoomNew.LEFT_LIMIT + 10; } else if (_position.X <= RoomNew.LEFT_LIMIT) { RoomNew room = Maze.LeftRoom(SpriteRoom); SpriteRoom = room; _position.X = RoomNew.RIGHT_LIMIT - 10; } else if (_position.Y < RoomNew.TOP_LIMIT - 10) { RoomNew room = Maze.UpRoom(SpriteRoom); SpriteRoom = room; //Y=270 _position.Y = RoomNew.BOTTOM_LIMIT - 24; } }
public void HandleCollision() { if (this.Type == Enumeration.TileType.loose) { if (this.tileState.Value().state != Enumeration.StateTile.loosefall) { return; } Rectangle r = new Rectangle(Convert.ToInt32(Math.Truncate(Position.X)), Convert.ToInt32(Math.Truncate(Position.Y)), Tile.WIDTH, Tile.HEIGHT); Vector4 v = room.getBoundTiles(r); Rectangle tileBounds = room.GetBounds(Convert.ToInt32(Math.Truncate(v.X)), Convert.ToInt32(Math.Truncate(v.W))); Vector2 depth = RectangleExtensions.GetIntersectionDepth(tileBounds, r); Enumeration.TileType tileType = room.GetType(Convert.ToInt32(Math.Truncate(v.X)), Convert.ToInt32(Math.Truncate(v.W))); Enumeration.TileCollision tileCollision = room.GetCollision(Convert.ToInt32(Math.Truncate(v.X)), Convert.ToInt32(Math.Truncate(v.W))); //Tile tile = room.GetTile(new Vector2((int)v.X, (int)v.W)); if (tileCollision == Enumeration.TileCollision.Platform) { //if (tileType == Enumeration.TileType.floor) if (depth.Y >= Tile.HEIGHT - Tile.PERSPECTIVE) { lock (room.tilesTemporaney) { room.tilesTemporaney.Remove(this); } //Vector2 vs = new Vector2(this.Position.X, this.Position.Y); if (tileType == Enumeration.TileType.loose) { Loose l = (Loose)room.GetTile(Convert.ToInt32(Math.Truncate(v.X)), Convert.ToInt32(Math.Truncate(v.W))); l.Fall(true); } else { ((SoundEffect)Maze.dContentRes[PrinceOfPersiaGame.CONFIG_SOUNDS + "tile crashing into the floor".ToUpper()]).Play(); room.SubsTile(Coordinates, Enumeration.TileType.rubble); } } } //if (_position.Y >= RoomNew.BOTTOM_LIMIT - Tile.HEIGHT - Tile.PERSPECTIVE) if (_position.Y >= RoomNew.BOTTOM_LIMIT - Tile.PERSPECTIVE) { //remove tiles from tilesTemporaney lock (room.tilesTemporaney) { room.tilesTemporaney.Remove(this); } //exit from DOWN room RoomNew roomDown = room.maze.DownRoom(room); room = roomDown; _position.Y = RoomNew.TOP_LIMIT - 10; lock (room.tilesTemporaney) { room.tilesTemporaney.Add(this); } } } }
public Tile(RoomNew room, ContentManager Content, Enumeration.TileType tileType, Enumeration.StateTile state, Enumeration.Items eitem, Enumeration.TileType NextTileType__1) { this.room = room; nextTileType = NextTileType__1; System.Xml.Serialization.XmlSerializer ax = new System.Xml.Serialization.XmlSerializer(m_tileSequence.GetType()); Stream txtReader = Microsoft.Xna.Framework.TitleContainer.OpenStream(PrinceOfPersiaGame.CONFIG_PATH_CONTENT + PrinceOfPersiaGame.CONFIG_PATH_SEQUENCES + tileType.ToString().ToUpper() + "_sequence.xml"); //TextReader txtReader = File.OpenText(PrinceOfPersiaGame.CONFIG_PATH_CONTENT + PrinceOfPersiaGame.CONFIG_PATH_SEQUENCES + tileType.ToString().ToUpper() + "_sequence.xml"); m_tileSequence = (List<Sequence>)ax.Deserialize(txtReader); foreach (Sequence s in m_tileSequence) { s.Initialize(Content); } //Search in the sequence the right type Sequence result = m_tileSequence.Find((Sequence s) => s.name == state.ToString().ToUpper()); if (result != null) { //AMF to be adjust.... result.frames[0].SetTexture(Content.Load<Texture2D>(PrinceOfPersiaGame.CONFIG_TILES[0] + result.frames[0].value)); collision = result.collision; Texture = result.frames[0].texture; } Type = tileType; //change statetile element StateTileElement stateTileElement = new StateTileElement(); stateTileElement.state = state; tileState.Add(stateTileElement); tileAnimation.PlayAnimation(m_tileSequence, tileState.Value()); //load item switch (eitem) { case Enumeration.Items.flask: item = new Flask(Content); break; // TODO: might not be correct. Was : Exit Select case Enumeration.Items.flaskbig: item = new FlaskBig(Content); break; // TODO: might not be correct. Was : Exit Select case Enumeration.Items.sword: item = new Sword(Content); break; // TODO: might not be correct. Was : Exit Select } }