/// <summary> /// Get touch data (touch world position, direction...) ///<b>PS:</b> This is only to debug /// </summary> /// <param name="finger">The last touch touch information object</param> public virtual void TapIndicator(LeanFinger finger) { touchWorldPos = cam.ScreenToWorldPoint(finger.LastScreenPosition); touchedFinger = finger; lastTouchedDirection = GetDirection(touchWorldPos); }
public virtual Action <Vector3, LeanFinger> GetDirectionAction(Vector3 position) { SideDirection direction = GetDirection(position); // C# 7.0+ Syntax: Use "out" + "var" in the same sentence if (directionsActions.TryGetValue(direction, out var directionData)) { return(directionData.OnTapDirection); } return(default);
//Methods //---------------------------------------------------------- public virtual void LoadContent(ContentManager Content, string textura, SideDirection currentDirection) { this._Content = Content; flecha.LoadContent(Content, colorFlecha); abajo.LoadContent(Content, "azul"); medio.LoadContent(Content, "azul"); switch (currentDirection) { case SideDirection.MOVERIGHT: { moveRight.LoadContent(Content, textura); } break; case SideDirection.MOVELEFT: { moveLeft.LoadContent(Content, textura); } break; case SideDirection.FUSILEFT: { fusilLeft.LoadContent(Content, textura); } break; case SideDirection.FUSILRIGHT: { fusilRight.LoadContent(Content, textura); } break; case SideDirection.STANDRIGHT: { standRight.LoadContent(Content, textura); } break; case SideDirection.STANDLEFT: { standLeft.LoadContent(Content, textura); } break; } }
public void LoadMove(string filename, SideDirection direction) { switch (direction) { case (SideDirection.STAND_DOWN): standDown.LoadImage(filename); break; case (SideDirection.STAND_LEFT): standLeft.LoadImage(filename); break; case (SideDirection.STAND_RIGHT): standRight.LoadImage(filename); break; case (SideDirection.STAND_UP): standUp.LoadImage(filename); break; } }
public void Update(GameTime gameTime) { Rectangle currentPos = this.Pos; Rectangle col = abajo.Getpos; col.X = currentPos.X + 12; col.Y = currentPos.Y + currentPos.Height - 17; abajo.Getpos = col; col = medio.Getpos; col.X = currentPos.X - 10; col.Y = currentPos.Y + currentPos.Height - 37; medio.Getpos = col; Rectangle posFusil = fusilRight.GetPos; posFusil.X = currentPos.X + 41; posFusil.Y = currentPos.Y + 16; fusilRight.GetPos = posFusil; posFusil = fusilLeft.GetPos; posFusil.X = currentPos.X + 13; posFusil.Y = currentPos.Y + 16; fusilLeft.GetPos = posFusil; fusilLeft.Update(gameTime); fusilRight.Update(gameTime); posFusil = flecha.Getpos; posFusil.X = currentPos.X + (currentPos.Width / 2) - 14; posFusil.Y = currentPos.Y - 20; flecha.Getpos = posFusil; if (bajarVida) // if "bajarvida" is true the life of the tank will decrease 30 units { life -= 15; bajarVida = false; } if (subirVida) // if "subirVida" is true the life of the tank will increase 30 units { life += 30; subirVida = false; } if (life == 0) // if "life" is equals to 0 the alive attribute of the tank will be false { GetAlive = false; vidas -= 1; } if (Pos.Y > graphicsDevice.Viewport.Height) { life = 0; GetAlive = false; } if (currentState == SideDirection.MOVERIGHT) { currentState = SideDirection.STANDRIGHT; } if (currentState == SideDirection.MOVELEFT) { currentState = SideDirection.STANDLEFT; } if (Keyboard.GetState().IsKeyDown(up)) { if (grados < 75) { grados += 1; velocidad -= 3; fusilRight.GetDirection = 1; fusilLeft.GetDirection = 2; y--; } } if (Keyboard.GetState().IsKeyDown(down)) { if (grados > 40) { grados -= 1; velocidad += 3; fusilRight.GetDirection = 2; fusilLeft.GetDirection = 1; y++; } } if (!ColisionDerechaMedio && !ColisionIzquierdaMedio && Pos.X > 3 && (Pos.X + Pos.Width) < graphicsDevice.Viewport.Width - 3) { if (Keyboard.GetState().IsKeyDown(left)) { currentState = SideDirection.MOVELEFT; currentPos.X -= 5; moveLeft.Update(gameTime); } if (Keyboard.GetState().IsKeyDown(right)) { currentState = SideDirection.MOVERIGHT; currentPos.X += 5; moveRight.Update(gameTime); } } else if (ColisionDerechaMedio || (Pos.X + Pos.Width) > graphicsDevice.Viewport.Width - 4) { if (Keyboard.GetState().IsKeyDown(left)) { currentState = SideDirection.MOVELEFT; currentPos.X -= 5; moveLeft.Update(gameTime); } } else if (ColisionIzquierdaMedio || Pos.X < 4) { if (Keyboard.GetState().IsKeyDown(right)) { currentState = SideDirection.MOVERIGHT; currentPos.X += 5; moveRight.Update(gameTime); } } if (Keyboard.GetState().IsKeyDown(shoot) && retraso >= 40) { int x = fusilLeft.GetPos.X - 20; if (currentState == SideDirection.STANDRIGHT || currentState == SideDirection.MOVERIGHT) { x = fusilRight.GetPos.X + 10; angulo = grados; } if (currentState == SideDirection.STANDLEFT || currentState == SideDirection.MOVELEFT) { lado = false; angulo = 180 - grados; } disp = new Shot(x, currentPos.Y + y, lado, velocidad, angulo); disp.LoadContent(_Content); arregloBalas.Add(disp); retraso = 0; } for (int x = 0; x < arregloBalas.Count; x++) { ((Shot)arregloBalas[x]).Update(gameTime); } retraso++; if (ColisionAbajo) { currentPos.Y += 5; } else if (ColisionAbajo && (ColisionIzquierdaAbajo || ColisionDerechaAbajo || ColisionDerechaMedio || ColisionIzquierdaMedio)) { currentPos.Y += 5; } else if (ColisionIzquierdaAbajo || ColisionDerechaAbajo && !ColisionDerechaMedio && !ColisionIzquierdaMedio) { currentPos.Y -= 8; } ColisionAbajo = true; ColisionDerechaMedio = false; ColisionIzquierdaMedio = false; ColisionDerechaAbajo = false; ColisionIzquierdaAbajo = false; this.Pos = currentPos; }
/// <summary> /// Смена вида по горизонтали /// </summary> private void FlipSide() { sideDirection = (SideDirection)((int)sideDirection * -1f); //Смена лица/спины после добавления анимации }
public virtual void Update(GameTime gameTime) { //Poner los valores por default if (direccion == SideDirection.Move_Down) { direccion = SideDirection.Stand_Down; } if (direccion == SideDirection.Move_Up) { direccion = SideDirection.Stand_Up; } if (direccion == SideDirection.Move_Left) { direccion = SideDirection.Stand_Left; } if (direccion == SideDirection.Move_Right) { direccion = SideDirection.Stand_Right; } /*if (collision) { * PARA IMAGENES EN COLISIONES direccion = SideDirection.Collision; }*/ }
public virtual void LoadContent_WalkUp(ContentManager Content, string dirName, String name, int frameWidth, int frameHeight, int frameCount, float timePerFrame) { walkUp = new BasicAnimatedSprite(); direccion = SideDirection.Move_Up; walkUp.LoadContent(Content, dirName, name, frameWidth, frameHeight, frameCount, timePerFrame); }
public void LoadMove(string nameDir, string filename, int framecount, float timePerFrame, SideDirection direction) { switch (direction) { case (SideDirection.MOVE_DOWN): moveDown.MultipleFiles(nameDir, filename, framecount, timePerFrame); break; case (SideDirection.MOVE_UP): moveUp.MultipleFiles(nameDir, filename, framecount, timePerFrame); break; case (SideDirection.MOVE_LEFT): moveLeft.MultipleFiles(nameDir, filename, framecount, timePerFrame); break; case (SideDirection.MOVE_RIGHT): moveRight.MultipleFiles(nameDir, filename, framecount, timePerFrame); break; } }
// Methods //Load content para imagenes estáticas (BasicSprite) public virtual void LoadContent_Jump(ContentManager Content, string dirName, String name) { jump = new BasicSprite(); direccion = SideDirection.Jump; jump.LoadContent(Content, dirName, name); }
public virtual void Update(GameTime gameTime) { //Poner los valores por default if (direccion == SideDirection.Move_Right) direccion = SideDirection.Stand_Right; //PARA CACTUS if (direccion== SideDirection.cac) { for (int k = 0; k < Cactu.Count; k++) { ((BasicSprite)Cactu[k]).SetMove(true); ((BasicSprite)Cactu[k]).SetIncrement(new Vector2(-2, 0)); ((BasicSprite)Cactu[k]).Update(gameTime); } } }
public virtual void LoadContent_Crouch(ContentManager Content, string dirName, String name) { crouch = new BasicSprite(); direccion = SideDirection.Crouch; crouch.LoadContent(Content, dirName, name); }
/// <summary> /// Moves the left or right. /// </summary> /// <param name="navInfoParam">The nav information parameter.</param> /// <param name="moveDirection">The move direction.</param> /// <returns>NavigationInfo.</returns> private NavigationInfo MoveLeftOrRight(NavigationInfo navInfoParam, SideDirection moveDirection) { var navigationInfo = navInfoParam; if (CellSelectionInspector.CellHierarchyPath.Any()) { var coordinates = navigationInfo.InitialCell.GetCellCoordinates(moveDirection); var targetCell = NavigationHelper.FindAppropriateCellToMove(this, coordinates.CellBeginsAt, coordinates.CellEndsAt, moveDirection); CellSelectionInspector.CellHierarchyPath.Clear(); if (targetCell != null) navigationInfo = targetCell.ProcessSelectionCommand(navigationInfo); } else { if (moveDirection == SideDirection.Right) navigationInfo = SelectFirst(navigationInfo); else if (moveDirection == SideDirection.Left) { if (this is DetailCell) navigationInfo = SelectFirst(navigationInfo); else { if (ChildSpreadsheet != null && ChildSpreadsheet.Items.Any()) { var container = ChildSpreadsheet.GetContainerFromItem(ChildSpreadsheet.Items[0] as IWrap); if (container != null) navigationInfo = container.SelectLast(navigationInfo); else navigationInfo = SelectLast(navigationInfo); } else navigationInfo = SelectLast(navigationInfo); } } } return navigationInfo; }
/// <summary> /// Selects the column to move. /// </summary> /// <param name="navInfoParam">The nav information parameter.</param> /// <param name="moveDirection">The move direction.</param> /// <returns>NavigationInfo.</returns> protected virtual NavigationInfo SelectColumnToMove(NavigationInfo navInfoParam, SideDirection moveDirection) { var navigationInfo = navInfoParam ?? new NavigationInfo(); var minLevel = 1; IColumn theDeepestColumn = null; foreach (var column in CellSelectionInspector.CellsSelectedChain.Where(x => x.LevelOfInheritance > 0)) { if (minLevel < column.LevelOfInheritance) { minLevel = column.LevelOfInheritance; theDeepestColumn = column; } } if (theDeepestColumn == null || theDeepestColumn.LevelOfInheritance <= Column.LevelOfInheritance) { if (moveDirection == SideDirection.Up) navigationInfo = SelectFirstCellFromLastContainer(navigationInfo); else if (moveDirection == SideDirection.Down) navigationInfo = SelectFirst(navigationInfo); } else { CellSelectionInspector.CellsSelectedChain.RemoveAll(x => x != theDeepestColumn); if (ChildSpreadsheet != null && ChildSpreadsheet.IsVisible && ChildSpreadsheet.Items.Any()) { IColumn column; if (theDeepestColumn.LevelOfInheritance == Column.LevelOfInheritance + 1) column = theDeepestColumn; else column = theDeepestColumn.GetParentColumnOfLevel(Column.LevelOfInheritance + 1); IWrap item = null; if (moveDirection == SideDirection.Up) item = ChildSpreadsheet.Items.Last() as IWrap; else if (moveDirection == SideDirection.Down) item = ChildSpreadsheet.Items.First() as IWrap; var container = ChildSpreadsheet.GetContainerFromItem(item); if (column != null && container != null) { container.SelectByColumn(column, navigationInfo); } } if (navigationInfo.ActionState != MoveStates.Ok) { if (moveDirection == SideDirection.Up) navigationInfo = SelectFirstCellFromLastContainer(navigationInfo); else if (moveDirection == SideDirection.Down) navigationInfo = SelectFirst(navigationInfo); } } return navigationInfo; }
//Loading metodo para animaciones con multiples archivos (BasicAnimatedSprite) public virtual void LoadContent_WalkRight(ContentManager Content, String nameDir, String nameFile, int frameCount, float timePerFrame) { walkRigh = new BasicAnimatedSprite(); direccion = SideDirection.Move_Right; walkRigh.LoadContent(Content, nameDir, nameFile, frameCount, timePerFrame); }
// BasicMap map; // Methods //LoadContent para cargar los cactus public virtual void Cactus(ContentManager Content, string dirName, String name, String name2, String name3) { Cactu = new ArrayList(); myRandom = new Random(); for (int k = 0; k < 20; k++) { cactus1 = new BasicSprite(); cactus2 = new BasicSprite(); cactus3 = new BasicSprite(); cactus1.LoadContent(Content, dirName, name); cactus2.LoadContent(Content, dirName, name2); cactus3.LoadContent(Content, dirName, name3); nR = myRandom.Next(1, 4); if (nR == 1) { Rectangle tempo = cactus1.Pos; if (k == 0) tempo.X = 350; if (k >= 1) tempo.X = (myRandom.Next(360, 400)) + (((BasicSprite)Cactu[(k - 1)]).Pos.X); //Se separan los cactus tempo.Y = 330; cactus1.Pos = tempo; Cactu.Add(cactus1); } else if (nR== 2) { Rectangle tempo = cactus2.Pos; if (k == 0) tempo.X = 350; if (k >= 1) tempo.X = (myRandom.Next(360, 400)) + (((BasicSprite)Cactu[(k - 1)]).Pos.X); //Se separan los cactus tempo.Y = 330; cactus2.Pos = tempo; Cactu.Add(cactus2); } else if (nR >= 3) { Rectangle tempo = cactus3.Pos; if (k == 0) tempo.X = 350; if (k >= 1) tempo.X = (myRandom.Next(360, 400)) + (((BasicSprite)Cactu[(k - 1)]).Pos.X); //Se separan los cactus tempo.Y = 330; cactus3.Pos = tempo; Cactu.Add(cactus3); } direccion = SideDirection.cac; } }
public virtual void Update(GameTime gameTime) { //Poner los valores por default if (direccion == SideDirection.Move_Right) direccion = SideDirection.Stand_Right; }
/// <summary> /// Finds the appropriate cell to move. /// </summary> /// <param name="parentCell">The parent cell.</param> /// <param name="lowerLimit">The lower limit.</param> /// <param name="upperLimit">The upper limit.</param> /// <param name="moveDirection">The move direction.</param> /// <returns>CellBase.</returns> internal static CellBase FindAppropriateCellToMove(CellBase parentCell, double lowerLimit, double upperLimit, SideDirection moveDirection) { var parentCellBeginsAt = 0.0; var parentCellEndsAt = 0.0; Func<CellBase, CellBase> calculator = null; calculator = cell => { var currentCell = cell; var spreadsheet = currentCell.HasNested ? ((StackCell)currentCell).ChildSpreadsheet : null; var detailCell = currentCell as DetailCell; if (detailCell != null) { parentCellBeginsAt = parentCellEndsAt; parentCellEndsAt += currentCell.Container.ActualHeight; if (spreadsheet != null && spreadsheet.IsVisible) parentCellEndsAt -= spreadsheet.ActualHeight; if (CellSuites(parentCellBeginsAt, parentCellEndsAt, upperLimit, lowerLimit)) return currentCell; } if (spreadsheet != null && spreadsheet.Items.Any() && spreadsheet.IsVisible) { foreach (IWrap item in spreadsheet.Items) { var itemContainer = spreadsheet.GetContainerFromItem(item); currentCell = moveDirection == SideDirection.Right ? itemContainer.Cells[itemContainer.Owner.FirstRowIndex] : itemContainer.Cells.Last(); var expectant = calculator(currentCell); if (expectant != null) return expectant; } } else { parentCellBeginsAt = parentCellEndsAt; parentCellEndsAt += currentCell.Container.ActualHeight; } if (CellSuites(parentCellBeginsAt, parentCellEndsAt, upperLimit, lowerLimit)) return currentCell; return null; }; return calculator(parentCell); }
public virtual void LoadContent_StandRight(ContentManager Content, string dirName, String name) { standRight = new BasicSprite(); direccion = SideDirection.Stand_Right; standRight.LoadContent(Content, dirName, name); }
/// <summary> /// Gets the cell coordinates. /// </summary> /// <param name="moveDirection">The move direction.</param> /// <returns>CellCoordinates.</returns> protected internal CellCoordinates GetCellCoordinates(SideDirection moveDirection) { var containerAddress = CellSelectionInspector.CellHierarchyPath; var level = containerAddress.Count; var currentCell = this; var cellBeginsAt = 0.0; var cellEndsAt = 0.0; for (var i = 0; i < level; i++) currentCell = currentCell.Owner.ParentCell; for (var i = 0; i < level; i++) { var spreadsheet = currentCell.HasNested ? ((StackCell)currentCell).ChildSpreadsheet : null; if (spreadsheet != null) { var currentDetailCell = currentCell as DetailCell; if (currentDetailCell != null) cellBeginsAt += currentDetailCell.Container.ActualHeight - spreadsheet.ActualHeight; for (var j = 0; j < containerAddress[i]; j++) { var container = spreadsheet.GetContainerFromItem((IWrap)spreadsheet.Items[j]); if (container != null) cellBeginsAt += container.ActualHeight; } if (i + 1 < level) { var nextContainer = spreadsheet.GetContainerFromItem((IWrap)spreadsheet.Items[containerAddress[i]]); if (moveDirection == SideDirection.Right) currentCell = nextContainer.Cells.Last(); else if (moveDirection == SideDirection.Left) currentCell = nextContainer.Cells.First(); } } else break; } cellEndsAt = cellBeginsAt + Container.ActualHeight; var detailCell = this as DetailCell; if (detailCell != null) { if (detailCell.ChildSpreadsheet != null && detailCell.ChildSpreadsheet.IsVisible) { cellEndsAt -= detailCell.ChildSpreadsheet.ActualHeight; } } return new CellCoordinates(cellBeginsAt, cellEndsAt); }