public override void step() { sprite = Sprites.PlayerHuman; var w = Keyboard.GetState().IsKeyDown(Keys.W) ? 1 : 0; var a = Keyboard.GetState().IsKeyDown(Keys.A) ? 1 : 0; var s = Keyboard.GetState().IsKeyDown(Keys.S) ? 1 : 0; var d = Keyboard.GetState().IsKeyDown(Keys.D) ? 1 : 0; position += new Vector2(d - a, s - w); var scroll = _oldScroll - Mouse.GetState().ScrollWheelValue; _oldScroll = Mouse.GetState().ScrollWheelValue; if (scroll > 0) { Camera.zoom *= 0.9f; } if ((d - a) < 0) { FacingRight = false; } if ((d - a) > 0) { FacingRight = true; } if (scroll < 0) { Camera.zoom /= 0.9f; } var click = Mouse.GetState().LeftButton.Equals(ButtonState.Pressed); if (click) { var pos = Mouse.GetState().Position.ToVector2(); pos = Vector2.Transform(pos, Matrix.Invert(Camera.CameraMatrix)); var clampedpos = pos; clampedpos -= position; var len = Math.Clamp(clampedpos.Length(), 8, 96); clampedpos.Normalize(); clampedpos *= len; new Tile(EnumTiles.Fresh, ChunkedWorld.LoadChunk(new ChunkIdentifier((int)((pos.X / 8) / 256), (int)((pos.Y / 8) / 256))), Tile.SnapToGrid(position + clampedpos)); } var save = Keyboard.GetState().IsKeyDown(Keys.K); if (save) { ChunkedWorld.Save(); } Camera.zoom = Math.Clamp(Camera.zoom, 0.5f, 4f); }
public static bool IsTileAt(Vector2 position) { var(x, y) = (position / 8) / 256; var foundchunk = ChunkedWorld.LoadChunk(new ChunkIdentifier((int)x, (int)y)); if (foundchunk == null) { return(false); } var tile = foundchunk.GetTileFrom(foundchunk.WorldToChunk(position)); return(tile.TileType != EnumTiles.Air); }