public void UpdateFrame(float elapsed, ref Position position, ref SpriteEffects spriteEffects__1, ref PlayerState playerState) { //Resetting Name float TimePerFrame = 0; playerState.Value().Name = string.Empty; //playerState.Value().Name = sequence.frames[frameIndex].name; //System.Console.WriteLine(playerState.Value().Name.ToUpper()); TimePerFrame = frameRate + sequence.frames[m_frameIndex].delay; //0.1 //TimePerFrame = 0.9f + sequence.frames[frameIndex].delay; //0.1 //TimePerFrame = 1.2f + sequence.frames[frameIndex].delay; //0.1 TotalElapsed += elapsed; if (TotalElapsed > TimePerFrame) { //Play Sound sequence.frames[m_frameIndex].PlaySound(); m_frameIndex = Math.Min(m_frameIndex + 1, Frames.Count - 1); TotalElapsed -= TimePerFrame; //Taking name of the frame usefull for hit combat.. playerState.Value().Name = sequence.frames[m_frameIndex].name; if (sequence.frames[m_frameIndex].type != Enumeration.TypeFrame.SPRITE) { //COMMAND string[] aCommand = sequence.frames[m_frameIndex].name.Split('|'); string[] aParameter = sequence.frames[m_frameIndex].parameter.Split('|'); for (int x = 0; x <= aCommand.Length - 1; x++) { if (aCommand[x] == Enumeration.TypeCommand.ABOUTFACE.ToString()) { if (spriteEffects__1 == SpriteEffects.FlipHorizontally) { spriteEffects__1 = SpriteEffects.None; } else { spriteEffects__1 = SpriteEffects.FlipHorizontally; } } else if (aCommand[x] == Enumeration.TypeCommand.GOTOFRAME.ToString()) { string par = aParameter[x]; int result = sequence.frames.FindIndex((Frame f) => f.name == par); m_frameIndex = result; } else if (aCommand[x] == Enumeration.TypeCommand.GOTOSEQUENCE.ToString()) { string[] par = aParameter[x].Split(':'); Sequence result = lsequence.Find((Sequence s) => s.name == par[0]); sequence = result; m_frameIndex = 0; if (par.Length > 1) { Vector2 v = new Vector2(float.Parse(par[1].Split(',')[0]), float.Parse(par[1].Split(',')[1])); playerState.Add(StatePlayerElement.Parse(par[0]), Enumeration.PriorityState.Normal, v); } else { playerState.Add(StatePlayerElement.Parse(par[0])); } } else if (aCommand[x] == Enumeration.TypeCommand.IFGOTOSEQUENCE.ToString()) { string par = string.Empty; if (playerState.Value().IfTrue == true) { par = aParameter[0]; } else { par = aParameter[1]; } Sequence result = lsequence.Find((Sequence s) => s.name == par); sequence = result; m_frameIndex = 0; playerState.Add(StatePlayerElement.Parse(par)); } else if (aCommand[x] == Enumeration.TypeCommand.DELETE.ToString()) { playerState.Add(Enumeration.State.delete, Enumeration.PriorityState.Force); } } } int flip = 0; if (spriteEffects__1 == SpriteEffects.FlipHorizontally) { //& TotalElapsed > TimePerFrame) skip first frame =!==!=?!?bug flip = 1; } else { flip = -1; } position.Value = new Vector2(position.X + (sequence.frames[m_frameIndex].xOffSet * flip), position.Y + sequence.frames[m_frameIndex].yOffSet); } else if (firstTime == true) { //Play Sound sequence.frames[m_frameIndex].PlaySound(); int flip = 0; if (spriteEffects__1 == SpriteEffects.FlipHorizontally) { flip = 1; } else { flip = -1; } position.Value = new Vector2(position.X + (sequence.frames[m_frameIndex].xOffSet * flip), position.Y + sequence.frames[m_frameIndex].yOffSet); firstTime = false; } }
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(); } }