private void Reverse() { currentdirection = DirectionUtils.Reverse(currentdirection); currentrailblockprogress = 1 - currentrailblockprogress; lastdirection = currentdirection; //currentvehiclespeed = 0; }
VehicleDirection12?BestNewDirection(VehicleDirection12Flags dir, bool turnleft, bool turnright) { if (turnright) { if ((dir & VehicleDirection12Flags.DownRightRight) != 0) { return(VehicleDirection12.DownRightRight); } if ((dir & VehicleDirection12Flags.UpRightUp) != 0) { return(VehicleDirection12.UpRightUp); } if ((dir & VehicleDirection12Flags.UpLeftLeft) != 0) { return(VehicleDirection12.UpLeftLeft); } if ((dir & VehicleDirection12Flags.DownLeftDown) != 0) { return(VehicleDirection12.DownLeftDown); } } if (turnleft) { if ((dir & VehicleDirection12Flags.DownRightDown) != 0) { return(VehicleDirection12.DownRightDown); } if ((dir & VehicleDirection12Flags.UpRightRight) != 0) { return(VehicleDirection12.UpRightRight); } if ((dir & VehicleDirection12Flags.UpLeftUp) != 0) { return(VehicleDirection12.UpLeftUp); } if ((dir & VehicleDirection12Flags.DownLeftLeft) != 0) { return(VehicleDirection12.DownLeftLeft); } } foreach (var v in DirectionUtils.ToVehicleDirection12s(dir)) { return(v); } return(null); }
public VehicleDirection12Flags PossibleRails(TileEnterData enter) { Vector3 new_position = enter.BlockPosition; VehicleDirection12Flags possible_rails = VehicleDirection12Flags.None; if (MapUtil.IsValidPos(d_Map, (int)enter.BlockPosition.X, (int)enter.BlockPosition.Y, (int)enter.BlockPosition.Z)) { RailDirectionFlags newpositionrail = d_Data.Rail[ d_Map.GetBlock((int)enter.BlockPosition.X, (int)enter.BlockPosition.Y, (int)enter.BlockPosition.Z)]; List <VehicleDirection12> all_possible_rails = new List <VehicleDirection12>(); foreach (var z in DirectionUtils.PossibleNewRails(enter.EnterDirection)) { if ((newpositionrail & DirectionUtils.ToRailDirectionFlags(DirectionUtils.ToRailDirection(z))) != RailDirectionFlags.None) { all_possible_rails.Add(z); } } possible_rails = DirectionUtils.ToVehicleDirection12Flags(all_possible_rails); } return(possible_rails); }
public Item Stack(Item itemA, Item itemB) { if (itemA.ItemClass == ItemClass.Block && itemB.ItemClass == ItemClass.Block) { int railcountA = MyLinq.Count(DirectionUtils.ToRailDirections(d_Data.Rail[itemA.BlockId])); int railcountB = MyLinq.Count(DirectionUtils.ToRailDirections(d_Data.Rail[itemB.BlockId])); if ((itemA.BlockId != itemB.BlockId) && (!(railcountA > 0 && railcountB > 0))) { return(null); } //todo stack size limit Item ret = new Item(); ret.ItemClass = itemA.ItemClass; ret.BlockId = itemA.BlockId; ret.BlockCount = itemA.BlockCount + itemB.BlockCount; return(ret); } else { return(null); } }
public static Vector3 NextTile(VehicleDirection12 direction, Vector3 currentTile) { return(NextTile(DirectionUtils.ResultExit(direction), currentTile)); }
void RailOnNewFrame(float dt) { LocalPlayerAnimationHint.InVehicle = railriding; LocalPlayerAnimationHint.DrawFix = railriding ? new Vector3(0, -0.7f, 0) : new Vector3(); bool turnright = keyboardstate[GetKey(OpenTK.Input.Key.D)]; bool turnleft = keyboardstate[GetKey(OpenTK.Input.Key.A)]; RailSound(); if (railriding) { ENABLE_FREEMOVE = true; ENABLE_MOVE = false; LocalPlayerPosition = CurrentRailPos(); currentrailblockprogress += currentvehiclespeed * (float)dt; if (currentrailblockprogress >= 1) { lastdirection = currentdirection; currentrailblockprogress = 0; var newenter = new TileEnterData(); newenter.BlockPosition = NextTile(currentdirection, currentrailblock); //slope if (GetUpDownMove(currentrailblock, DirectionUtils.ResultEnter(DirectionUtils.ResultExit(currentdirection))) == UpDown.Up) { newenter.BlockPosition.Z++; } if (GetUpDownMove(newenter.BlockPosition + new Vector3(0, 0, -1), DirectionUtils.ResultEnter(DirectionUtils.ResultExit(currentdirection))) == UpDown.Down) { newenter.BlockPosition.Z--; } newenter.EnterDirection = DirectionUtils.ResultEnter(DirectionUtils.ResultExit(currentdirection)); var newdir = BestNewDirection(PossibleRails(newenter), turnleft, turnright); if (newdir == null) { //end of rail currentdirection = DirectionUtils.Reverse(currentdirection); } else { currentdirection = newdir.Value; currentrailblock = newenter.BlockPosition; } } } if (keyboardstate[GetKey(OpenTK.Input.Key.W)] && GuiTyping != TypingState.Typing) { currentvehiclespeed += 1f * (float)dt; } if (keyboardstate[GetKey(OpenTK.Input.Key.S)] && GuiTyping != TypingState.Typing) { currentvehiclespeed -= 5f * (float)dt; } if (currentvehiclespeed < 0) { currentvehiclespeed = 0; } //todo fix //if (viewport.keypressed != null && viewport.keypressed.Key == OpenTK.Input.Key.Q) if (!wasqpressed && keyboardstate[GetKey(OpenTK.Input.Key.Q)] && GuiTyping != TypingState.Typing) { Reverse(); } if (!wasepressed && keyboardstate[GetKey(OpenTK.Input.Key.E)] && !railriding && !ENABLE_FREEMOVE && GuiTyping != TypingState.Typing) { currentrailblock = new Vector3((int)LocalPlayerPosition.X, (int)LocalPlayerPosition.Z, (int)LocalPlayerPosition.Y - 1); if (!MapUtil.IsValidPos(d_Map, (int)currentrailblock.X, (int)currentrailblock.Y, (int)currentrailblock.Z)) { ExitVehicle(); } else { var railunderplayer = d_Data.Rail[d_Map.GetBlock((int)currentrailblock.X, (int)currentrailblock.Y, (int)currentrailblock.Z)]; railriding = true; CharacterHeight = minecartheight; currentvehiclespeed = 0; if ((railunderplayer & RailDirectionFlags.Horizontal) != 0) { currentdirection = VehicleDirection12.HorizontalRight; } else if ((railunderplayer & RailDirectionFlags.Vertical) != 0) { currentdirection = VehicleDirection12.VerticalUp; } else if ((railunderplayer & RailDirectionFlags.UpLeft) != 0) { currentdirection = VehicleDirection12.UpLeftUp; } else if ((railunderplayer & RailDirectionFlags.UpRight) != 0) { currentdirection = VehicleDirection12.UpRightUp; } else if ((railunderplayer & RailDirectionFlags.DownLeft) != 0) { currentdirection = VehicleDirection12.DownLeftLeft; } else if ((railunderplayer & RailDirectionFlags.DownRight) != 0) { currentdirection = VehicleDirection12.DownRightRight; } else { ExitVehicle(); } lastdirection = currentdirection; } } else if (!wasepressed && keyboardstate[GetKey(OpenTK.Input.Key.E)] && railriding && GuiTyping != TypingState.Typing) { ExitVehicle(); LocalPlayerPosition += new Vector3(0, 0.7f, 0); } wasqpressed = keyboardstate[GetKey(OpenTK.Input.Key.Q)] && GuiTyping != TypingState.Typing; wasepressed = keyboardstate[GetKey(OpenTK.Input.Key.E)] && GuiTyping != TypingState.Typing; }