public Vector CalculateX(double accelerationRatio, Engine.Direction d) { switch (d) { case Engine.Direction.None: movementVector.X = 0; return new Vector(0, 0); case Engine.Direction.Left: if (accelerationRatio >= 1) { if (movementVector.X > maxMoveSpeed_X * -1) { movementVector.X -= (Math.Abs(accelerationRatio)); } return new Vector(GetMaxMovement(Engine.Direction.Left, Convert.ToInt32(movementVector.X))*-1, 0); } return new Vector(0, 0); break; case Engine.Direction.Right: if (accelerationRatio >= 1) { if (movementVector.X < maxMoveSpeed_X) { movementVector.X += (Math.Abs(accelerationRatio)); } return new Vector(GetMaxMovement(Engine.Direction.Right, Convert.ToInt32(movementVector.X)), 0); } return new Vector(0, 0); } return new Vector(0, 0); }
//public void Jump(Engine.Direction d) { // if (isMoving != true) // { // int deltaY = GetMaxMovement(Engine.Direction.Up, 30); // switch (d) // { // case Engine.Direction.Left: // break; // case Engine.Direction.Right: // AddToQueue(new Movement(new Vector(0, deltaY * -1), deltaY * 10, 0, 0.999)); // AddToQueue(new Movement(new Vector(3,0), 1)); // ProcessEntireQueue(); // break; // case Engine.Direction.None: // //MessageBox.Show("jump"); // StartAnimation(new Movement(new Vector(0, deltaY * -1), deltaY * 10, 0, 0.999)); // break; // } // } //} private int GetMaxMovement(Engine.Direction dir, int maxDistance) { //returns the max number of pixels that the player can travel in a specific direction, with an upper limit of a specified number of pixels (maxDistance) int playerX = Convert.ToInt32(this.Margin.Left); int playerY = Convert.ToInt32(this.Margin.Top); maxDistance = Math.Abs(maxDistance); switch (dir) { case Engine.Direction.Up: int maxL_Up = maxDistance; int maxR_Up = maxDistance; try { for (int l = 0; l <= maxDistance; l++) { if (parentWorld.GetBlockAtLocation(playerX + 2, playerY - l).penetrable == false) { maxL_Up = l; break; } } for (int r = 0; r <= maxDistance; r++) { if (parentWorld.GetBlockAtLocation(Convert.ToInt32(playerX + this.Width - 2), playerY - r).penetrable == false) { maxR_Up = r; break; } } if (maxL_Up <= maxR_Up) { if (maxL_Up == 0) { return 0; } else { return maxL_Up - 1; } } else { if (maxR_Up == 0) { return 0; } else { return maxR_Up - 1; } } } catch { return 0; } case Engine.Direction.Down: int maxL_Down = maxDistance; int maxR_Down = maxDistance; try { for (int l = 0; l <= maxDistance; l++) { if (parentWorld.GetBlockAtLocation(playerX + 2, Convert.ToInt32(playerY + this.Height)).penetrable == false) { maxL_Down = l; break; } } for (int r = 0; r <= maxDistance; r++) { if (parentWorld.GetBlockAtLocation(Convert.ToInt32(playerX + this.Width - 2), Convert.ToInt32(playerY + this.Height) + r).penetrable == false) { maxR_Down = r; break; } } if (maxL_Down <= maxR_Down) { if (maxL_Down == 0) { return 0; } else { return maxL_Down - 1; } } else { if (maxR_Down == 0) { return 0; } else { return maxR_Down - 1; } } } catch { return 0; } case Engine.Direction.Left: int maxU_Left = maxDistance; int maxD_Left = maxDistance; try { for (int u = 0; u <= maxDistance; u++) { if (parentWorld.GetBlockAtLocation(playerX - u + 2, playerY).penetrable == false) { maxU_Left = u; break; } } for (int d = 0; d <= maxDistance; d++) { if (parentWorld.GetBlockAtLocation(playerX - d + 2, Convert.ToInt32((playerY - 1) + this.Height)).penetrable == false) { maxD_Left = d; break; } } if (maxU_Left <= maxD_Left) { if (maxU_Left == 0) { return 0; } else { return maxU_Left - 1; } } else { if (maxD_Left == 0) { return 0; } else { return maxD_Left - 1; } } } catch { return 0; } case Engine.Direction.Right: try { int maxU_Right = maxDistance; int maxD_Right = maxDistance; for (int u = 0; u <= maxDistance; u++) { if (parentWorld.GetBlockAtLocation(Convert.ToInt32((playerX - 2) + this.Width + u), playerY).penetrable == false) { maxU_Right = u; break; } } for (int d = 0; d <= maxDistance; d++) { if (parentWorld.GetBlockAtLocation(Convert.ToInt32((playerX - 2) + this.Width + d), Convert.ToInt32((playerY - 1) + this.Height)).penetrable == false) { maxD_Right = d; break; } } if (maxU_Right <= maxD_Right) { if (maxU_Right == 0) { return 0; } else { return maxU_Right - 1; } } else { if (maxD_Right == 0) { return 0; } else { return maxD_Right - 1; } } } catch { return 0; } } return 0; }
//private bool VerifyMovement(Movement m) //{ // int[] newLocL = Engine.GetArrayLocation(this.Margin.Left + m.Displacement.X, this.Margin.Top + m.Displacement.Y); // int[] newLocR = Engine.GetArrayLocation((this.Margin.Left + this.Width) + m.Displacement.X, this.Margin.Top + m.Displacement.Y); // try // { // if (parentWorld.blockArray[newLocL[0], newLocL[1]].penetrable && parentWorld.blockArray[newLocL[0], newLocL[1] + 1].penetrable) // { // if (parentWorld.blockArray[newLocR[0], newLocR[1]].penetrable && parentWorld.blockArray[newLocR[0], newLocR[1] + 1].penetrable) // { // return true; // } // } // } // catch { } // return false; //} //public void CheckGravity() //{ // int floor = parentWorld.GetFloor(this); //location in the array of the next lower solidblock // int[] playerFloor = Engine.GetArrayLocation(this.Margin.Left + 1, this.Margin.Top + this.Height); //location in the array of the bottom left corner of the world.player // if (playerFloor[1] < floor) // { // int deltaY = ((floor * 25) - Convert.ToInt32((this.Margin.Top + this.Height - 1)) - 1); // Movement m = new Movement(new Vector(0, deltaY), 3 * deltaY, mAcceleration: 0.999); // this.StartAnimation(m); // } //} public void Move(Engine.Direction d) { currentMoveDir = d; }