public MapPixelToCoords ( Vector2i point ) : Vector2f | ||
point | Vector2i | Pixel to convert |
return | Vector2f |
static void Main(string[] args) { Window = new RenderWindow(new VideoMode(1280, 720), "Collapse"); Window.SetFramerateLimit(60); Window.Closed += (sender, eventArgs) => Window.Close(); Map = new TileMap(200, 90); for (var y = 85; y < 100; y++) { for (var x = 0; x < 200; x++) { Map[x, y] = Tile.Floor; } } Window.MouseMoved += (sender, eventArgs) => { var mousePosF = Window.MapPixelToCoords(new Vector2i(eventArgs.X, eventArgs.Y)); var mousePos = new Vector2i((int)mousePosF.X / TileSize, (int)mousePosF.Y / TileSize); if (Mouse.IsButtonPressed(Mouse.Button.Left)) { Map[mousePos.X, mousePos.Y] = Tile.Block; } if (Mouse.IsButtonPressed(Mouse.Button.Right)) { Map[mousePos.X, mousePos.Y] = Tile.None; } if (Mouse.IsButtonPressed(Mouse.Button.Middle)) { Map[mousePos.X, mousePos.Y] = Tile.Floor; } }; while (Window.IsOpen()) { Window.DispatchEvents(); Window.Clear(new Color(100, 149, 237)); Window.Draw(Map); Window.Display(); } }
public Vector2f GetMouseWorldPos() { return(w.MapPixelToCoords(Mouse.GetPosition(w))); }
public override void Draw(RenderWindow window) { window.SetView(Level.Camera); _mousePositionInWorld = window.MapPixelToCoords(Mouse.GetPosition(window), Level.Camera); Level.Draw(window); window.SetView(window.DefaultView); }
public override void input(RenderWindow _window) { if (Keyboard.IsKeyPressed(Keyboard.Key.A)) { if (mPosition.X > 0) mBody.ApplyLinearImpulse(new Vector2(-0.3f * Delta.mDelta, 0f)); else mBody.ApplyLinearImpulse(new Vector2(0.3f * Delta.mDelta, 0f)); } else if (Keyboard.IsKeyPressed(Keyboard.Key.D)) { if(mPosition.Y < 1280) mBody.ApplyLinearImpulse(new Vector2( 0.3f * Delta.mDelta, 0f)); else mBody.ApplyLinearImpulse(new Vector2(-0.3f * Delta.mDelta, 0f)); } if(Keyboard.IsKeyPressed(Keyboard.Key.Return)) { if(!mOnce) invincible(); } if (Keyboard.IsKeyPressed(Keyboard.Key.Space)) { if (mPosition.X > 0 && mPosition.X < 1280) mBody.ApplyLinearImpulse(new Vector2(0f, -0.9f * Delta.mDelta)); } if (Mouse.IsButtonPressed(Mouse.Button.Left)) { if (mShoot.ElapsedMilliseconds > 250) { Vector2i mousePos = Mouse.GetPosition(_window); Vector2f translated = _window.MapPixelToCoords(mousePos, _window.GetView()); Vector2f aim = new Vector2f(translated.X - mPosition.X, translated.Y - mPosition.Y); double angle = Math.Atan2(aim.Y, aim.X); mWorld.createBullet(mPosition, this, "resources/bullet.png", angle); mShoot.Restart(); } } }