public void Draw(RenderTarget target, RenderStates states) { if (!Active) { return; } BarText.Position = new Vector2f(Position.X, Position.Y - 4 - Size.Y); background.Position = Position; background.Size = Size; background.FillColor = new Color(128, 128, 128, 128); Bar.Position = BarPosition; Bar.Size = new Vector2f(MaxBarLength * Progress, BarHeight); Bar.FillColor = Color.White; if (Mouse.IsButtonPressed(Mouse.Button.Left) && BarColider.Contains(Mouse.GetPosition().X, Mouse.GetPosition().Y)) { onClick(); } background.Draw(target, states); Bar.Draw(target, states); BarText.Draw(target, states); }
private void ObjectsInRectSearch(FloatRect rect, ICollection <T> results) { if (m_Leaf) { for (int i = 0; i < m_Objects.Count; i++) { T obj = m_Objects[i]; if (!rect.Contains(obj.Position.X, obj.Position.Y)) { return; } results.Add(obj); } } if (m_NorthWest != null && m_NorthWest.m_Region.Intersects(rect)) { m_NorthWest.ObjectsInRectSearch(rect, results); } if (m_SouthEast != null && m_SouthEast.m_Region.Intersects(rect)) { m_SouthEast.ObjectsInRectSearch(rect, results); } if (m_NorthEast != null && m_NorthEast.m_Region.Intersects(rect)) { m_NorthEast.ObjectsInRectSearch(rect, results); } if (m_SouthWest != null && m_SouthWest.m_Region.Intersects(rect)) { m_SouthWest.ObjectsInRectSearch(rect, results); } }
public ServerListOverlay() { servers = new List <Server>(); refreshing = false; listOffset = 0; selectedIndex = -1; RefreshServerList(); Input.MouseWheel += args => { listOffset += args.Delta; if (listOffset >= servers.Count) { listOffset = servers.Count - 1; } if (listOffset < 0) { listOffset = 0; } return(true); }; Input.MouseButton[Mouse.Button.Left] = args => { if (!args.Pressed) { return(false); } float boundingY = GameOptions.Height * (PaddingVertical * 3.0f) + 64.0f; float boundingX = GameOptions.Width * (PaddingHorizontal * 2.5f); float width = GameOptions.Width - boundingX * 2.0f; const float height = 64.0f * 6; FloatRect area = new FloatRect(boundingX, boundingY, width, height); if (!area.Contains(args.Position.X, args.Position.Y)) { selectedIndex = -1; return(false); } selectedIndex = (int)(args.Position.Y - boundingY) / 64 + listOffset; if (selectedIndex >= servers.Count) { selectedIndex = -1; } if (SelectedServer != null) { JoinNext(SelectedServer.IpAddress); } return(false); }; }
protected virtual bool WasClicked(Vector2f worldPos) { if (sprite == null || !visible) { return(false); } Sprite spriteToCheck = sprite.GetCurrentSprite(); var bounds = spriteToCheck.GetLocalBounds(); var AABB = new FloatRect( Owner.GetComponent <TransformComponent>(ComponentFamily.Transform).Position.X - (bounds.Width / 2), Owner.GetComponent <TransformComponent>(ComponentFamily.Transform).Position.Y - (bounds.Height / 2), bounds.Width, bounds.Height); if (!AABB.Contains(worldPos.X, worldPos.Y)) { return(false); } // Get the sprite's position within the texture var texRect = spriteToCheck.TextureRect; // Get the clicked position relative to the texture var spritePosition = new Vector2i((int)(worldPos.X - AABB.Left + texRect.Left), (int)(worldPos.Y - AABB.Top + texRect.Top)); if (spritePosition.X < 0 || spritePosition.Y < 0) { return(false); } IResourceManager _resManager = IoCManager.Resolve <IResourceManager>(); Dictionary <Texture, string> tmp = _resManager.TextureToKey; if (!tmp.ContainsKey(spriteToCheck.Texture)) { return(false); } //if it doesn't exist, something's f****d string textureKey = tmp[spriteToCheck.Texture]; bool[,] opacityMap = TextureCache.Textures[textureKey].Opacity; //get our clickthrough 'map' if (!opacityMap[spritePosition.X, spritePosition.Y]) // Check if the clicked pixel is opaque { return(false); } return(true); }
public void MousePressed(MouseButtonEventArgs e) { if (e.Button == Mouse.Button.Left) { if (upButtonBounds.Contains(e.X, e.Y)) { Scroll(true); } else if (downButtonBounds.Contains(e.X, e.Y)) { Scroll(false); } } }
public ServerListOverlay() { servers = new List<Server>(); refreshing = false; listOffset = 0; selectedIndex = -1; RefreshServerList(); Input.MouseWheel += args => { listOffset += args.Delta; if (listOffset >= servers.Count) listOffset = servers.Count - 1; if (listOffset < 0) listOffset = 0; return true; }; Input.MouseButton[Mouse.Button.Left] = args => { if (!args.Pressed) return false; float boundingY = GameOptions.Height * (PaddingVertical * 3.0f) + 64.0f; float boundingX = GameOptions.Width * (PaddingHorizontal * 2.5f); float width = GameOptions.Width - boundingX * 2.0f; const float height = 64.0f * 6; FloatRect area = new FloatRect(boundingX, boundingY, width, height); if (!area.Contains(args.Position.X, args.Position.Y)) { selectedIndex = -1; return false; } selectedIndex = (int)(args.Position.Y - boundingY) / 64 + listOffset; if (selectedIndex >= servers.Count) selectedIndex = -1; if (SelectedServer != null) JoinNext(SelectedServer.IpAddress); return false; }; }
private void ObjectsInRectSearch(FloatRect rect, ICollection <T> results) { var idx = FindBucketIndex(rect.Center()); var range = (rect.Center() - rect.Min()).Length(); var bucketRangeX = (int)(range / m_BucketWidth) + 1; if (bucketRangeX < 0) { bucketRangeX = m_NumBucketsWidth / 2; } var bucketRangeY = (int)(range / m_BucketHeight) + 1; if (bucketRangeY < 0) { bucketRangeY = m_NumBucketsHeight / 2; } for (int i = -bucketRangeX; i <= bucketRangeX; i++) { for (int j = -bucketRangeY; j <= bucketRangeY; j++) { var nextIdx = idx + (i + (j * m_NumBucketsWidth)); // If index is out of range if (nextIdx < 0 || nextIdx >= m_Buckets.Length) { continue; } if (m_Buckets[nextIdx] == null) { continue; } var bucket = m_Buckets[nextIdx]; for (int n = 0; n < bucket.Count; n++) { if (!rect.Contains(bucket[n].Position.X, bucket[n].Position.Y)) { continue; } results.Add(bucket[n]); } } } }
protected virtual bool WasClicked(Vector2f worldPos) { if (sprite == null || !visible) { return(false); } Sprite spriteToCheck = sprite.GetCurrentSprite(); var bounds = spriteToCheck.GetLocalBounds(); var AABB = new FloatRect( Owner.GetComponent <TransformComponent>(ComponentFamily.Transform).Position.X - (bounds.Width / 2), Owner.GetComponent <TransformComponent>(ComponentFamily.Transform).Position.Y - (bounds.Height / 2), bounds.Width, bounds.Height); if (!AABB.Contains(worldPos.X, worldPos.Y)) { return(false); } // Get the sprite's position within the texture var texRect = spriteToCheck.TextureRect; // Get the clicked position relative to the texture var spritePosition = new Vector2i((int)(worldPos.X - AABB.Left + texRect.Left), (int)(worldPos.Y - AABB.Top + texRect.Top)); if (spritePosition.X < 0 || spritePosition.Y < 0) { return(false); } // Copy the texture to image var img = spriteToCheck.Texture.CopyToImage(); // Check if the clicked pixel is opaque if (img.GetPixel((uint)spritePosition.X, (uint)spritePosition.Y).A == 0) { return(false); } return(true); }
private void OnMouseButtonReleased(object sender, MouseButtonEventArgs arg) { // Check if within simulation box if (Constants.SimulationGFXIntRect.Contains(arg.X, arg.Y)) { // Check if within sprite box of any person object foreach (var p in scene.People) { FloatRect rect = new FloatRect(p.Sprite.Position.X - p.Sprite.Origin.X, p.Sprite.Position.Y - p.Sprite.Origin.X, p.Sprite.GetGlobalBounds().Width, p.Sprite.GetGlobalBounds().Height); if (rect.Contains(arg.X, arg.Y)) { infoPane.WatchedPerson = p; infoPane.Update(); return; } } infoPane.WatchedPerson = null; } }
public static bool MouseHitBase(Framework.Gwen.Control.Base obj) { if (obj.IsHidden == true) { return(false); } else { var rect = new FloatRect( obj.LocalPosToCanvas(new Point(0, 0)).X, obj.LocalPosToCanvas(new Point(0, 0)).Y, obj.Width, obj.Height ); if (rect.Contains(InputHandler.MousePosition.X, InputHandler.MousePosition.Y)) { return(true); } } return(false); }
//********************************************************** //** methods: //********************************************************** public bool Insert(Vector2f vector, T data) { if (!_boundary.Contains(vector.X, vector.Y)) { return(false); } if (_data.Count < BoundaryCapacity && _northWest == null) { _data.Add(new DataHolder { Point = vector, Data = data }); return(true); } if (_northWest == null) { Subdivide(); } if (_northEast.Insert(vector, data)) { return(true); } if (_northWest.Insert(vector, data)) { return(true); } if (_southEast.Insert(vector, data)) { return(true); } if (_southWest.Insert(vector, data)) { return(true); } return(false); }
public void Update() { _window.DispatchEvents(); Random random = new Random(); bool grow = false; if (tick > _tickAddBubbles) { int n = random.Next(0, 6 + Level); for (int i = 0; i < n && bubbles.Count < 24 + (2 * Level); i++) { int x = random.Next((int)(_window.Size.X * 0.2f), (int)(_window.Size.X * 0.8f)); int y = -10; int size = random.Next(4, 48); bubbles.Add(new Objects.Bubble(x, y)); bubbles[bubbles.Count - 1].Velocity *= 1 + (Level / (5f + (Level / 10f))); } _tickAddBubbles = tick + 1000; } if (tick > _tickGrowBubbles) { grow = true; _tickGrowBubbles = tick + 100; } Stack<int> removalStack = new Stack<int>(); for (int i = 0; i < bubbles.Count; i++) { Objects.Bubble bubble = bubbles[i]; if (grow) { //bubble.Radius += 1; } //int size = (int)(1.96f * bubble.Radius); bubble.Update((tick - lastTick) / 1000.0); //bubble.X += (Time.Ticks() % 250 * bubble.MoveX * random.NextDouble() / 1000.0f); //bubble.Y += (Time.Ticks() % 250 * bubble.MoveY * random.NextDouble() / 1000.0f); if (/*bubble.Radius >= 50*/bubble.SurfaceForce < 0) { Points -= (int)(bubble.Radius / 40); removalStack.Push(i); continue; } FloatRect rect = new FloatRect(0, -25, _viewWorld.Size.X, _viewWorld.Size.Y + 25); if (!rect.Contains(bubble.Position.X, bubble.Position.Y)) { Points -= 25 + Level + (int)(bubble.Radius / 10); removalStack.Push(i); continue; } /*if (tick > bubble.ChangeAnimation) { bubble.State = (bubble.State + 1) % 4; bubble.ChangeAnimation = tick + 150; }*/ } while (removalStack.Count > 0) { bubbles.RemoveAt(removalStack.Pop()); } }
public override void Draw() { //blue sky MainGame.window.SetView(MainGame.window.DefaultView); shader.Shader.SetParameter("offsetY", MainGame.Camera.Center.Y); RectangleShape rs = new RectangleShape { Size = new Vector2f(800, 600) }; MainGame.window.Draw(rs, shader); MainGame.window.SetView(MainGame.Camera); //background Render.Draw(Content.GetTexture("background1Far.png"), new Vector2f(-200, -100), Color.White, new Vector2f(0, 0), 1, 0f); Render.Draw(Content.GetTexture("background1Far.png"), new Vector2f(145, -100), Color.White, new Vector2f(0, 0), 1, 0f); Render.Draw(Content.GetTexture("background1.png"), new Vector2f(-200, -150), Color.White, new Vector2f(0, 0), 1, 0f); //tracks RectangleShape tracks = new RectangleShape(new Vector2f(800, .5f)); tracks.Position = new Vector2f(-400, -49); tracks.FillColor = new Color(10, 10, 10, 50); tracks.Draw(MainGame.window, RenderStates.Default); //train Render.Draw(Content.GetTexture("mapDecor.png"), new Vector2f(trainPosX, -55), new Color(255, 255, 255, 200), new Vector2f(0, 0), 1, 0f, .03f); //title Render.Draw(Content.GetTexture("title.png"), new Vector2f(-50, -190), new Color(255, 255, 255, 240), new Vector2f(0, 0), 1, 0f, .4f); if (stage == 0) { //menubox RectangleShape rectBG = new RectangleShape(new Vector2f(200, 110)); rectBG.Position = new Vector2f(-50, 0); rectBG.FillColor = new Color(10, 10, 10, 100); rectBG.Draw(MainGame.window, RenderStates.Default); if (!submitted) { //menu username rectUsername.FillColor = new Color(10, 10, 10, (byte)(composingUsername ? 150 : 50)); rectUsername.Draw(MainGame.window, RenderStates.Default); //menu ip rectIP.FillColor = new Color(10, 10, 10, (byte)(composingIP ? 150 : 50)); rectIP.Draw(MainGame.window, RenderStates.Default); //menu connect button rectConnect.FillColor = new Color(10, 255, 10, (byte)(rectConnect.GetGlobalBounds().Contains( (int)MainGame.worldMousePos.X, (int)MainGame.worldMousePos.Y) ? 150 : 70)); rectConnect.Draw(MainGame.window, RenderStates.Default); //text: username, ip, connect button Render.DrawString(Content.GetFont("OldNewspaperTypes.ttf"), usernameField, new Vector2f(50, 15), Color.White, .3f, true, 1); Render.DrawString(Content.GetFont("OldNewspaperTypes.ttf"), ipField, new Vector2f(50, 45), Color.White, .3f, true, 1); Render.DrawString(Content.GetFont("OldNewspaperTypes.ttf"), "Connect", new Vector2f(50, 77), Color.White, .4f, true, 1); } else { Render.DrawString(Content.GetFont("OldNewspaperTypes.ttf"), "Connecting...", new Vector2f(50, 15), Color.White, .3f, true, 1); submitTimer++; if (submitTimer > 300) { submitted = false; submitTimer = 0; ipField = "Failed to Connect"; } } } if (stage == 1) { RectangleShape rectBG = new RectangleShape(new Vector2f(200, 110)); rectBG.Position = new Vector2f(-50, 0); rectBG.FillColor = new Color(10, 10, 10, 100); rectBG.Draw(MainGame.window, RenderStates.Default); //char1.Update(); //char2.Update(); Render.DrawAnimation(char1.Texture, new Vector2f(-0, 5), Color.White, new Vector2f(0, 0), 1, char1.Count, char1.Frame); Render.DrawAnimation(char2.Texture, new Vector2f(100, 5), Color.White, new Vector2f(0, 0), -1, char2.Count, char2.Frame); //Render.Draw(Content.GetTexture("gibHead.png"), new Vector2f(40, 10), Color.White, new Vector2f(0, 0), 1, 0, 2); //Render.Draw(Content.GetTexture("char2_gibHead.png"), new Vector2f(0, 10), Color.White, new Vector2f(0, 0), 1, 0, 2); FloatRect leftRect = new FloatRect(new Vector2f(0, 5), new Vector2f(20, 55)); FloatRect rightRect = new FloatRect(new Vector2f(75, 5), new Vector2f(20, 55)); if (leftRect.Contains(MainGame.worldMousePos.X, MainGame.worldMousePos.Y)) { currentCursor = hoverCursor; if (Input.isMouseButtonTap(Mouse.Button.Left)) { stage = 2; MainGame.dm.player.model = MainGame.Char1Model; MainGame.dm.player.UpdateToCurrentModel(); return; } } if (rightRect.Contains(MainGame.worldMousePos.X, MainGame.worldMousePos.Y)) { currentCursor = hoverCursor; if (Input.isMouseButtonTap(Mouse.Button.Left)) { stage = 2; MainGame.dm.player.model = MainGame.Char2Model; MainGame.dm.player.UpdateToCurrentModel(); return; } } rectConnect.Draw(MainGame.window, RenderStates.Default); Render.DrawString(Content.GetFont("OldNewspaperTypes.ttf"), "Select Character", new Vector2f(50, 77), Color.White, .4f, true, 1); } if (stage == 2) { RectangleShape rectBG = new RectangleShape(new Vector2f(200, 110)); rectBG.Position = new Vector2f(-50, 0); rectBG.FillColor = new Color(10, 10, 10, 100); rectBG.Draw(MainGame.window, RenderStates.Default); Render.Draw(Content.GetTexture("generatorStand.png"), new Vector2f(-10, 5), Color.White, new Vector2f(0, 0), 1, 0f); Render.Draw(Content.GetTexture("genBlue.png"), new Vector2f(-10, 5), Color.White, new Vector2f(0, 0), 1, 0f); Render.DrawString(Content.GetFont("PixelSix.ttf"), " Shield\nGenerator", new Vector2f(0, 45), Color.White, .3f, true, 1); Render.Draw(Content.GetTexture("mine.png"), new Vector2f(40, 30), Color.White, new Vector2f(0, 0), 1, 0f); Render.Draw(Content.GetTexture("mine.png"), new Vector2f(40, 30), Color.White, new Vector2f(0, 0), 1, 0f); Render.DrawString(Content.GetFont("PixelSix.ttf"), "Land\nMine", new Vector2f(50, 45), Color.White, .3f, true, 1); Render.Draw(Content.GetTexture("generatorStand.png"), new Vector2f(90, 5), Color.White, new Vector2f(0, 0), 1, 0f); Render.Draw(Content.GetTexture("genGreen.png"), new Vector2f(90, 5), Color.White, new Vector2f(0, 0), 1, 0f); Render.DrawString(Content.GetFont("PixelSix.ttf"), " Health\nGenerator", new Vector2f(100, 45), Color.White, .3f, true, 1); FloatRect genShieldRect = new FloatRect(new Vector2f(-10, 5), new Vector2f(20, 55)); FloatRect genHealthRect = new FloatRect(new Vector2f(90, 5), new Vector2f(20, 55)); FloatRect MineRect = new FloatRect(new Vector2f(40, 5), new Vector2f(20, 55)); if (genShieldRect.Contains(MainGame.worldMousePos.X, MainGame.worldMousePos.Y)) { currentCursor = hoverCursor; if (Input.isMouseButtonTap(Mouse.Button.Left)) { MainGame.dm.player.ItemType = 3; // Shield Generator Submit(); } } if (genHealthRect.Contains(MainGame.worldMousePos.X, MainGame.worldMousePos.Y)) { currentCursor = hoverCursor; if (Input.isMouseButtonTap(Mouse.Button.Left)) { MainGame.dm.player.ItemType = 2; // Health Generator Submit(); } } if (MineRect.Contains(MainGame.worldMousePos.X, MainGame.worldMousePos.Y)) { currentCursor = hoverCursor; if (Input.isMouseButtonTap(Mouse.Button.Left)) { MainGame.dm.player.ItemType = 1; // Land Mines Submit(); } } rectConnect.Draw(MainGame.window, RenderStates.Default); Render.DrawString(Content.GetFont("OldNewspaperTypes.ttf"), "Select Item", new Vector2f(50, 77), Color.White, .4f, true, 1); } //cursor Render.Draw(currentCursor, MainGame.worldMousePos, Color.White, new Vector2f(0, 0), 1, 0f); }
protected override void Update() { var mousePos = (Vector2f)GetMousePosition(); if (Mouse.IsButtonPressed(Mouse.Button.Left)) { var floatRect = new FloatRect(_shape.Position - _shape.Size * .5f, _shape.Size); if (floatRect.Contains(mousePos.X, mousePos.Y)) { _angularVelocity = 0f; if (!_dragging) { _p1 = mousePos; } //_angularAcceleration = 10f * Timer.DeltaTimeSeconds; // var distanceFromCenter = _pointOnShape - _shape.Position; // var direction = (mousePos - _pointOnShape)?.ToPolarCoordinates(); // _angularAcceleration = direction?.Angle } _dragging = true; _p2 = mousePos; } else { if (_p1.HasValue && _p2.HasValue) { // torque = r * F * sin(theta) // torque = r * sin(theta) var lever = _p1.Value - (_shape.Position - _shape.Size / 2); var force = (_p2 - _p1).Value; var r = lever.Length(); var ll = lever.Length(); var fl = force.Length(); var llfl = ll * fl; var angle = llfl == 0 ? 0 : Math.Acos(lever.Dot(force) / (ll * fl)); Console.WriteLine($"{angle}, {ll}, {fl}"); var torque = r * Math.Sin(angle); _angularAcceleration += (float)torque; } _p1 = null; _p2 = null; _dragging = false; } _angularVelocity += _angularAcceleration; _angle += _angularVelocity * Timer.DeltaTimeSeconds; _shape.Rotation = _angle; _angularAcceleration = 0f; }
protected virtual bool WasClicked(Vector2f worldPos) { if (sprite == null || !visible) return false; Sprite spriteToCheck = sprite.GetCurrentSprite(); var bounds = spriteToCheck.GetLocalBounds(); var AABB = new FloatRect( Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.X - (bounds.Width / 2), Owner.GetComponent<TransformComponent>(ComponentFamily.Transform).Position.Y - (bounds.Height / 2), bounds.Width, bounds.Height); if (!AABB.Contains(worldPos.X, worldPos.Y)) return false; // Get the sprite's position within the texture var texRect = spriteToCheck.TextureRect; // Get the clicked position relative to the texture var spritePosition = new Vector2i((int)(worldPos.X - AABB.Left + texRect.Left), (int)(worldPos.Y - AABB.Top + texRect.Top)); if (spritePosition.X < 0 || spritePosition.Y < 0) return false; // Copy the texture to image var img = spriteToCheck.Texture.CopyToImage(); // Check if the clicked pixel is opaque if (img.GetPixel((uint)spritePosition.X, (uint)spritePosition.Y).A == 0) return false; return true; }
private void SetControlUnits(FloatRect floatRect) { var controlList = new List<EntityBase>(); foreach (EntityBase entity in entities.Values) { if (floatRect.Contains(entity.Position.X, entity.Position.Y)) { controlList.Add(entity); } } if (controlList.Count > 0) { selectedUnits = controlList.ToArray(); } }
/// <summary> /// Checks if it collides with ball and adjust ball forward and position /// </summary> public bool CheckBallCollision(Ball ball) { bool collision = false; FloatRect ballBounds = ball.GetGlobalBounds(); FloatRect myBounds = GetGlobalBounds(); Vector2f top = new Vector2f(ballBounds.Left + ballBounds.Width / 2.0f, ballBounds.Top); Vector2f bottom = new Vector2f(ballBounds.Left + ballBounds.Width / 2.0f, ballBounds.Top + ballBounds.Height); Vector2f left = new Vector2f(ballBounds.Left, ballBounds.Top + ballBounds.Height / 2.0f); Vector2f right = new Vector2f(ballBounds.Left + ballBounds.Width, ballBounds.Top + ballBounds.Height / 2.0f); if (myBounds.Contains(top.X, top.Y)) { // Brick bottom collision = true; ball.Forward = new Vector2f(ball.Forward.X, -ball.Forward.Y); ball.Position = new Vector2f(ball.Position.X, myBounds.Top + myBounds.Height + ballBounds.Height / 2.0f); } else if (myBounds.Contains(bottom.X, bottom.Y)) { // Brick top collision = true; ball.Forward = new Vector2f(ball.Forward.X, -ball.Forward.Y); ball.Position = new Vector2f(ball.Position.X, myBounds.Top - ballBounds.Height / 2.0f); } else if (myBounds.Contains(right.X, right.Y)) { // Brick left collision = true; ball.Forward = new Vector2f(-ball.Forward.X, ball.Forward.Y); ball.Position = new Vector2f(myBounds.Left - ballBounds.Width / 2.0f, ball.Position.Y); } else if (myBounds.Contains(left.X, left.Y)) { // Brick right collision = true; ball.Forward = new Vector2f(-ball.Forward.X, ball.Forward.Y); ball.Position = new Vector2f(myBounds.Left + myBounds.Width + ballBounds.Width / 2.0f, ball.Position.Y); } // SONIDO DE COLISION BOLA-LKADRILLO if (collision == true) { Random alea = new Random(); switch (alea.Next(1, 5)) { case 1: sfx = new Sound(sfxBrick_1); break; case 2: sfx = new Sound(sfxBrick_2); break; case 3: sfx = new Sound(sfxBrick_3); break; case 4: sfx = new Sound(sfxBrick_4); break; } sfx.Play(); } if (collision && material.CanBeDestroyed) { if (!broken && material.CanBeBroken) { broken = true; Sprite = new Sprite(material.BrokenTexture); Center(); } else { MyGame.Get.HUD.NumPoints += 5; // sumamos puntuacion Destroy(); } } return(collision); }
/// <summary> /// Détermine si un Movable est situé à l'intérieur de la surface de jeu /// Peut être utilisée pour déterminer si les projectiles sont sortis du jeu /// ou si le héros ou un ennemi s'apprête à sortir. /// </summary> /// <param name="m">Le Movable à tester</param> /// <returns>true si le Movable est à l'intérieur, false sinon</returns> public bool Contains(Movable m) { FloatRect r = new FloatRect(0, 0, GW.WIDTH, GW.HEIGHT); return(r.Contains(m.Position.X, m.Position.Y)); }
public bool Contains(int x, int y) { return(_rec.Contains(x, y)); }
public override void Update(Time delta) { CheckInput(); UpdateSelectScriptInfo(); if (!IsUiHovered()) { if (Mouse.IsButtonPressed(Mouse.Button.Left)) { if (_selectScript == null) { foreach (var script in Level.Scripts) { var scriptBounds = new FloatRect(new Vector2f(script.RectShape.Position.X - script.RectShape.Size.X / 2, script.RectShape.Position.Y - script.RectShape.Size.Y / 2), script.RectShape.Size); if (scriptBounds.Contains(_mousePositionInWorld.X, _mousePositionInWorld.Y)) { SetSelectScript(script); } } } else { if (!Keyboard.IsKeyPressed(Keyboard.Key.S)) { var selectScriptBounds = new FloatRect(new Vector2f(_selectScript.RectShape.Position.X - _selectScript.RectShape.Size.X / 2, _selectScript.RectShape.Position.Y - _selectScript.RectShape.Size.Y / 2), _selectScript.RectShape.Size); if (_moveSelectScript) { _selectScript.RectShape.Position = new Vector2f((int)_mousePositionInWorld.X, (int)_mousePositionInWorld.Y); } else { if (selectScriptBounds.Contains(_mousePositionInWorld.X, _mousePositionInWorld.Y)) _moveSelectScript = true; } } } } else _moveSelectScript = false; if (Mouse.IsButtonPressed(Mouse.Button.Right)) { if (_selectScript != null) UnSelect_SelectScript(); } } }
public static bool Contains(this FloatRect r, Vector2i v) { return(r.Contains(v.X, v.Y)); }
public static bool Contains(this FloatRect rect, Vector2f vector) => rect.Contains(vector.X, vector.Y);