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; } }
/// <summary> /// Handles input, performs physics, and animates the player sprite. /// </summary> /// <remarks> /// We pass in all of the input states so that our game is only polling the hardware /// once per frame. We also pass the game's orientation because when using the accelerometer, /// we need to reverse our motion when the orientation is in the LandscapeRight orientation. /// </remarks> public void Update(GameTime gameTime, KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation) { float elapsed = Convert.ToSingle(gameTime.ElapsedGameTime.TotalSeconds); // TODO: Add your game logic here. sprite.UpdateFrame(elapsed, ref _position, ref flip, ref spriteState); if (IsAlive == false) { DropDead(); return; } //bool thereIsKid = false; foreach (Sprite s in SpriteRoom.SpritesInRoom()) { switch (s.GetType().Name) { case "Player": if (true) { if (s.IsAlive == false) { break; // TODO: might not be correct. Was : Exit Select } //thereIsKid = true; if (s.Position.CheckOnRow(Position)) { if (s.Position.CheckOnRowDistancePixel(Position) >= 0 & s.Position.CheckOnRowDistancePixel(Position) <= 70 & Alert == true & spriteState.Value().state == Enumeration.State.strike) { if (spriteState.Value().Name == Enumeration.State.strike.ToString().ToUpper()) { //check if block if (s.spriteState.Value().Name != Enumeration.State.readyblock.ToString().ToUpper()) { spriteState.Value().Name = string.Empty; s.Splash(true, gameTime); //Splash splash = new Splash(SpriteRoom, Position.Value, graphicsDevice, SpriteEffects.None, true); //Maze.sprites.Add(splash); s.Energy = s.Energy - 1; s.StrikeRetreat(); } else { System.Console.WriteLine("P->" + Enumeration.State.readyblock.ToString().ToUpper()); //blocked } } if (s.Energy == 0) { Fastheathe(); } } Alert = true; //Chenge Flip player.. if (Position.X < s.Position.X) { flip = SpriteEffects.None; } else { flip = SpriteEffects.FlipHorizontally; } Advance(s.Position, flip); } else { Alert = false; } break; // TODO: might not be correct. Was : Exit Select } default: break; // TODO: might not be correct. Was : Exit Select } } if (Alert == false) { Stand(); } //Ready(); else { Stand(); } }
public void isGround() { if (IsAlive == false) { return; } m_isOnGround = false; RoomNew room = null; Rectangle playerBounds = _position.Bounding; Vector2 v2 = SpriteRoom.getCenterTile(playerBounds); Rectangle tileBounds = SpriteRoom.GetBounds(Convert.ToInt32(Math.Truncate(v2.X)), Convert.ToInt32(Math.Truncate(v2.Y))); //Check if kid outside Room if (v2.X < 0) { room = Maze.LeftRoom(SpriteRoom); } else { room = SpriteRoom; } if (v2.Y > 2) { m_isOnGround = false; } else if (v2.Y < 0) { m_isOnGround = false; } else { if (room.GetCollision(Convert.ToInt32(Math.Truncate(v2.X)), Convert.ToInt32(Math.Truncate(v2.Y))) != Enumeration.TileCollision.Passable) { if (playerBounds.Bottom >= tileBounds.Bottom) { m_isOnGround = true; } } } if (m_isOnGround == false) { if (sprite.sequence.raised == false) { if (spriteState.Value().state == Enumeration.State.runjump) { spriteState.Add(Enumeration.State.rjumpfall, Enumeration.PriorityState.Force); sprite.PlayAnimation(spriteSequence, spriteState.Value()); } else { if (spriteState.Previous().state == Enumeration.State.runjump) { spriteState.Add(Enumeration.State.stepfall, Enumeration.PriorityState.Force, new Vector2(20, 15)); } else if (spriteState.Value().state != Enumeration.State.freefall) { spriteState.Add(Enumeration.State.stepfall, Enumeration.PriorityState.Force); } } //SpriteRoom.LooseShake(); //and for upper room... SpriteRoom.maze.UpRoom(SpriteRoom).LooseShake(); } return; } //IS ON GROUND! if (spriteState.Value().state == Enumeration.State.freefall) { //Align to tile x _position.Y = tileBounds.Bottom - _position._spriteRealSize.Y; //CHECK IF LOOSE ENERGY... int Rem = 0; Rem = Convert.ToInt32(Math.Truncate(Math.Abs(Position.Y - PositionFall.Y))) / Tile.REALHEIGHT; if (Rem == 0) { ((SoundEffect)Maze.dContentRes["Sounds/dos/falling echo".ToUpper()]).Play(); } else if (Rem >= 1 & Rem < 3) { ((SoundEffect)Maze.dContentRes["Sounds/dos/loosing a life falling".ToUpper()]).Play(); } else { ((SoundEffect)Maze.dContentRes["Sounds/dos/falling".ToUpper()]).Play(); //you should dead!!! DeadFall(); } Energy = Energy - Rem; spriteState.Add(Enumeration.State.crouch, Enumeration.PriorityState.Force, false); SpriteRoom.LooseShake(); } }