public override void Update(double deltaTime) { colliderRect.Position = position; for (var i = 0; i < targets.Count; i++) { var box = targets[i]; if (!box.parent.disposed && !disposed) { if (colliderRect.GetGlobalBounds().Intersects(box.colliderRect.GetGlobalBounds()) && !hasEntered) { hasEntered = true; OnColliderEnter(box); } else if (!colliderRect.GetGlobalBounds().Intersects(box.colliderRect.GetGlobalBounds()) && hasEntered) { hasEntered = false; OnColliderExit(box); } } } targets.Clear(); display = FarBeyond.showHitboxes; }
public void Draw() { var rs = new RectangleShape(); //Draw Roads foreach (Factory factory in gameState.Factories) { rs.Size = factory.Size * scale; rs.Position = (factory.Position - cameraPosition) * scale - rs.Size / 2; if (screenRect.Intersects(ToIntRect(rs.GetGlobalBounds()))) { rs.Texture = TextureManager.GetTexture(factory.Type); rs.TextureRect = new IntRect(0, 0, (int)rs.Texture.Size.X, (int)rs.Texture.Size.Y); win.Draw(rs); } } foreach (Truck truck in gameState.Trucks) { rs.Size = truck.Size * scale; rs.Position = (truck.Position - cameraPosition) * scale - rs.Size / 2; if (screenRect.Intersects(ToIntRect(rs.GetGlobalBounds()))) { rs.Texture = TextureManager.GetTexture(truck.Type); rs.TextureRect = new IntRect(0, 0, (int)rs.Texture.Size.X, (int)rs.Texture.Size.Y); win.Draw(rs); } } //Draw UI }
private void UpdateDisp() { var sprite = new Sprite(img); var rect = new RectangleShape() { OutlineColor = SFML.Graphics.Color.White, FillColor = SFML.Graphics.Color.Black }; while (!Finished) { Disp.Target.SetActive(); { Disp.Target.Size = new Vector2u((uint)Disp.Size.Width, (uint)Disp.Size.Height); FloatRect max; { List <Vector2f> outlines = new List <Vector2f>(); outlines.Add(rect.GetGlobalBounds().TopLeft()); outlines.Add(rect.GetGlobalBounds().TopRight()); outlines.Add(rect.GetGlobalBounds().BotLeft()); outlines.Add(rect.GetGlobalBounds().BotRight()); outlines.Add(sprite.GetGlobalBounds().TopLeft()); outlines.Add(sprite.GetGlobalBounds().TopRight()); outlines.Add(sprite.GetGlobalBounds().BotLeft()); outlines.Add(sprite.GetGlobalBounds().BotRight()); max = Utilities.CreateRect(outlines); } Vector2f HalfSize = new Vector2f(Disp.Size.Width, Disp.Size.Height) / 2; Vector2f HalfImgSize = (Vector2f)img.Size / 2; float facX = Utilities.Max(Utilities.Max(-max.Left + HalfImgSize.X, max.Right() - HalfImgSize.X) / HalfSize.X, 1) * 1.03f; float facY = Utilities.Max(Utilities.Max(-max.Top + HalfImgSize.Y, max.Bot() - HalfImgSize.Y) / HalfSize.Y, 1) * 1.03f; FloatRect rectView = new FloatRect(default, new Vector2f(Disp.Size.Width * Utilities.Max(facX, facY), Disp.Size.Height * Utilities.Max(facX, facY)));
static public Vector2f GetRandomVector2fInRect(RectangleShape shape) { Vector2f ret = GetRandomVector2f( new Vector2f(shape.GetGlobalBounds().Left, shape.GetGlobalBounds().Left + shape.GetGlobalBounds().Width), new Vector2f(shape.GetGlobalBounds().Top, shape.GetGlobalBounds().Top + shape.GetGlobalBounds().Height)); return(ret); }
private void Init() { _screenCenter = new Vector2(_width / 2, _height / 2); _world = new World(new Vector2(0, 20)); _circleSprite = new CircleShape { Radius = _diameter / 2f, FillColor = new Color(Color.Blue) }; _groundSprite = new RectangleShape(new Vector2f(512f, 32f)) { FillColor = new Color(Color.Green) }; /* Circle */ // Convert screen center from pixels to meters Vector2 circlePosition = (_screenCenter / MeterInPixels) + new Vector2(0, -3.5f); // Create the circle fixture _circleBody = BodyFactory.CreateCircle(_world, _diameter / (2f * MeterInPixels), 1f, circlePosition); _circleBody.BodyType = BodyType.Dynamic; // Give it some bounce and friction _circleBody.Restitution = 0.75f; _circleBody.Friction = 0.5f; /* Ground */ Vector2 groundPosition = (_screenCenter / MeterInPixels) + new Vector2(0, 3.25f); _groundSprite.Position = new Vector2f( groundPosition.X * MeterInPixels - (_groundSprite.GetGlobalBounds().Width / 2f), groundPosition.Y * MeterInPixels - (_groundSprite.GetGlobalBounds().Height / 2f)); // Create the ground fixture _groundBody = BodyFactory.CreateRectangle(_world, 512f / MeterInPixels, 32f / MeterInPixels, 1f, groundPosition); _groundBody.IsStatic = true; _groundBody.Restitution = 0.3f; _groundBody.Friction = 0.5f; try { // http://www.dafont.com/sansation.font _statsFont = new Font("Content/Font/Sansation.ttf"); } catch (Exception e) { Console.WriteLine("Unable to load font"); _window.Close(); } _text = new Text("Loading stats...", _statsFont) { Position = new Vector2f(5f, 5f), CharacterSize = 14 }; }
public IAppState Update(RenderWindow window) { _searchText.Position = new Vector2f(_searchBar.GetGlobalBounds().Left + (_searchBar.GetGlobalBounds().Width / 2) - (_searchText.GetGlobalBounds().Width / 2), _searchBar.GetGlobalBounds().Top + (_searchBar.GetGlobalBounds().Height / 2) - (_searchText.GetGlobalBounds().Height / 2)); MousePosition = new Vector2f(Mouse.GetPosition(window).X, Mouse.GetPosition(window).Y); //if ( Mouse.IsButtonPressed(Mouse.Button.Left) ) ClickOnSearchBar(window); //window.MouseButtonReleased += (sender, e) => ClickOnSearchBar(e); //if ( _inSearchBar == true ) WriteAdressIP(window); return(_nextState); }
/// <summary> /// Adds a collision trigger to a rectangle. /// </summary> public static void AddCollisionTriggerRect(RectangleShape rect, RectangleShape rect2) { if (rect.GetGlobalBounds().Intersects(rect2.GetGlobalBounds())) { Vector2f position = rect.Position; Vector2f obj = rect2.Position; if (position.Y > obj.Y) { position.Y += 1; rect.Position = position; } else if (position.Y < obj.Y) { position.Y -= 1; rect.Position = position; } else if (position.X > obj.X) { position.X += 1; rect.Position = position; } else if (position.X < obj.X) { position.X -= 1; rect.Position = position; } } }
virtual public void OnBound(RenderWindow window) { var bounds = _bound.GetGlobalBounds(); var pos = Mouse.GetPosition(window); if (bounds.Contains(pos.X, pos.Y)) { Active = true; } else { Active = false; } Fill(); }
public void CheckMouse(float mouseX, float mouseY) { List <SaveGameMetadata> list = Save.List(); int i = 1; if (_backButton.GetGlobalBounds().Contains(mouseX, mouseY)) { _ctx.MenuState = 0; } else { foreach (SaveGameMetadata metadata in list) { RectangleShape rec = new RectangleShape() { Size = new Vector2f(32 * 15, 32 * 3), Position = new Vector2f(_ctx.Resolution.X / 2 - (32 * 8), i * 32) }; if (rec.GetGlobalBounds().Contains(mouseX, mouseY)) { _chosenSave = metadata.Name; _saveSelected = true; _saveChoice = Save.LoadGame(_chosenSave); _ctx.LoadGame(_saveChoice); _ctx.MenuState = 1; } i += 4; } } }
public void UpdateInputString(string str) { var suggestions = _getSuggestions(str).Take(10).ToList(); if (!suggestions.Any()) { IsActive = false; return; } _suggestionTexts = suggestions.Select(a => new Text { Font = _font, CharacterSize = _charSize, DisplayedString = a, Color = Color.White }).Take(10).ToList(); var height = 0; foreach (var suggestionText in _suggestionTexts) { suggestionText.Position = _displayRegion.Position + new Vector2f(3, height); height += (int)_charSize; } _displayRegion.Size = new Vector2f(_suggestionTexts.Max(a => a.GetLocalBounds().Width + 6), height + _charSize * .5f); _renderView.Reset(_displayRegion.GetGlobalBounds()); IsActive = true; _selectionIndex = 0; ApplySelectionRect(); }
public override void Update(Time Elapsed) { if (!Active) { return; } if (shape.GetGlobalBounds().Intersects(Game.Input.Mouse.Position)) { shape.FillColor = Color.White; } else { shape.FillColor = normal; } }
public Tuple <PlayerType, FieldPosition> GetTarget(Vector2f mouse) { if (boundingBox.GetGlobalBounds().Contains(mouse.X, mouse.Y)) { return(new Tuple <PlayerType, FieldPosition>(PlayerType, null)); } return(null); }
private void bindEvents() { Window.MouseMoved += (sender, e) => { backButton.FillColor = backButton.GetGlobalBounds().Contains(Mouse.GetPosition(Window).X, Mouse.GetPosition(Window).Y) ? new Color(100, 100, 100) : new Color(150, 200, 150); }; Window.MouseButtonReleased += (sender, args) => { if (backButton.GetGlobalBounds().Contains(Mouse.GetPosition(Window).X, Mouse.GetPosition(Window).Y)) { WindowsStack.CloseLastWindow(); } }; }
public ConsolePanel(RenderWindow window, GameClient client) { this.client = client; Font font = new Font("Resources/arial.ttf"); text = new Text("", font, 18); text.Color = new Color(208, 208, 208); text.Position = new Vector2f(8, 8); input = new Text("", font, text.CharacterSize); input.Color = Color.White; input.Position = new Vector2f(8, window.Size.Y / 2 - text.CharacterSize - 4); maxDisplayedHeight = input.Position.Y - 4; background = new RectangleShape(); background.Position = new Vector2f(0, 0); background.Size = new Vector2f(window.Size.X, window.Size.Y / 2); background.FillColor = new Color(72, 72, 72, 220); scrollUp = new RectangleShape(); scrollUp.Position = new Vector2f(window.Size.X - scrollButtonSize, 0); scrollUp.Size = new Vector2f(scrollButtonSize, scrollButtonSize); scrollUp.FillColor = new Color(96, 96, 96); buttonUp = new CircleShape(scrollButtonIconRadius, 3); buttonUp.Position = new Vector2f(scrollUp.Position.X + scrollButtonIconOffset, scrollUp.Position.Y + scrollButtonIconOffset); buttonUp.FillColor = new Color(192, 192, 192); scrollDown = new RectangleShape(); scrollDown.Position = new Vector2f(window.Size.X - scrollButtonSize, window.Size.Y / 2 - scrollButtonSize); scrollDown.Size = scrollUp.Size; scrollDown.FillColor = scrollUp.FillColor; buttonDown = new CircleShape(scrollButtonIconRadius, 3); buttonDown.Position = new Vector2f(scrollDown.Position.X + scrollButtonIconOffset * 3, scrollDown.Position.Y + scrollButtonIconOffset * 3); buttonDown.FillColor = buttonUp.FillColor; buttonDown.Rotation = 180; scrollBar = new RectangleShape(); scrollBar.Position = new Vector2f(scrollUp.Position.X, scrollButtonSize); scrollBar.Size = new Vector2f(scrollButtonSize, window.Size.Y / 2 - scrollButtonSize - scrollButtonSize); scrollBar.FillColor = new Color(32, 32, 32, 128); upButtonBounds = scrollUp.GetGlobalBounds(); downButtonBounds = scrollDown.GetGlobalBounds(); view = new View(new FloatRect(0, 0, window.Size.X, window.Size.Y / 2)); view.Viewport = new FloatRect(0, 0, 1, 0.5f); scrollX = view.Center.X; maxScroll = view.Center.Y; Console.SetOut(this); Console.SetError(this); }
private void bindEvents() { Window.MouseMoved += (sender, e) => { backButton.FillColor = backButton.GetGlobalBounds().Contains(Mouse.GetPosition(Window).X, Mouse.GetPosition(Window).Y) ? new Color(100, 100, 100) : new Color(150, 200, 150); easyButton.FillColor = easyButton.GetGlobalBounds().Contains(Mouse.GetPosition(Window).X, Mouse.GetPosition(Window).Y) ? new Color(100, 100, 100) : new Color(150, 200, 150); mediumButton.FillColor = mediumButton.GetGlobalBounds().Contains(Mouse.GetPosition(Window).X, Mouse.GetPosition(Window).Y) ? new Color(100, 100, 100) : new Color(150, 200, 150); hardButton.FillColor = hardButton.GetGlobalBounds().Contains(Mouse.GetPosition(Window).X, Mouse.GetPosition(Window).Y) ? new Color(100, 100, 100) : new Color(150, 200, 150); }; Window.MouseButtonReleased += (sender, args) => { if (backButton.GetGlobalBounds().Contains(Mouse.GetPosition(Window).X, Mouse.GetPosition(Window).Y)) { WindowsStack.CloseLastWindow(); } else if (easyButton.GetGlobalBounds().Contains(Mouse.GetPosition(Window).X, Mouse.GetPosition(Window).Y)) { GameLogic.difficulty = 2; WindowsStack.CloseLastWindow(); } else if (mediumButton.GetGlobalBounds().Contains(Mouse.GetPosition(Window).X, Mouse.GetPosition(Window).Y)) { GameLogic.difficulty = 4; WindowsStack.CloseLastWindow(); } else if (hardButton.GetGlobalBounds().Contains(Mouse.GetPosition(Window).X, Mouse.GetPosition(Window).Y)) { GameLogic.difficulty = 5; WindowsStack.CloseLastWindow(); } }; }
public void TrackProjectile(ref List <Projectile> projectile) { for (int i = 0; i < projectile.Count; i++) { if (projectile[i].projectileRect.GetGlobalBounds().Intersects(barrierRect.GetGlobalBounds())) // checks if the projectile is within the bounds { //isDead = true; projectile[i].isDead = true; } } }
public void TrackInvaderProjectile(ref List <Projectile> invaderProjectile) { for (int i = 0; i < invaderProjectile.Count; i++) { if (invaderProjectile[i].projectileRect.GetGlobalBounds().Intersects(playerRect.GetGlobalBounds())) // checks if the projectile is within the bounds { isDead = true; invaderProjectile[i].isDead = true; } } }
/// <summary> /// Gets a collision trigger to a rectangle. /// </summary> public static bool CollisionTriggerRect(RectangleShape rect, RectangleShape rect2) { if (rect.GetGlobalBounds().Intersects(rect2.GetGlobalBounds())) { return(true); } else { return(false); } }
private void ColisionadorxZona() { if (c1.GetGlobalBounds().Intersects(c2.GetGlobalBounds())) { c1.FillColor = Color.Green; //c1.Position.X = } else { c1.FillColor = Color.Blue; } }
public void Contains(Vector2f mouse) { if (box.GetGlobalBounds().Contains(mouse.X, mouse.Y)) { Console.WriteLine("get input"); TakeInput = true; } else { TakeInput = false; } }
public bool Contains(int mouseX, int mouseY, double sx, double sy) { FloatRect bounds = timerBG.GetGlobalBounds(); mouseX = (int)(mouseX * sx); mouseY = (int)(mouseY * sy); if (mouseX >= bounds.Left && mouseX <= bounds.Left + bounds.Width && mouseY >= bounds.Top && mouseY <= bounds.Top + bounds.Height) { return(true); } return(false); }
static bool IsPlayerOverEnemy(RectangleShape player, RectangleShape enemy) { bool result = false; if (player.GetGlobalBounds().Intersects(enemy.GetGlobalBounds()) == true) { result = true; Console.WriteLine("You Go Die-Die!!"); } return(result); }
static bool IsPlayerOverFood(RectangleShape player, RectangleShape food) { bool result = false; if (player.GetGlobalBounds().Intersects(food.GetGlobalBounds()) == true) { result = true; Console.WriteLine("YUM-YUM!"); } return(result); }
public UITextBox(float x, float y, string dialogue, int cluster) { UITextBoxText = new Text(dialogue, UITextBoxFont, getFontSize()); box = new RectangleShape(new Vector2f(UITextBoxText.GetGlobalBounds().Width + 30, (float)(UITextBoxText.GetGlobalBounds().Height * 1.5) + 10)); box.Position = new Vector2f(x, y + 17); UITextBoxText.Position = new Vector2f((box.GetGlobalBounds().Width / 2 - UITextBoxText.GetGlobalBounds().Width / 2) + box.GetGlobalBounds().Left, (box.GetGlobalBounds().Height / 2 - (float)(UITextBoxText.GetGlobalBounds().Height / 1.1)) + box.GetGlobalBounds().Top); box.FillColor = buttonTonalColors["Default"]; prevColor = buttonTonalColors["Default"]; UITextBoxText.Color = new Color(67, 65, 69); this.affected = false; this.cluster = cluster; }
private List <Text> OptionMenu() { List <Text> OptionMenu = new List <Text>(); Font font = new Font("../../../../Ui/Resources/Fonts/GrizzlyAttack/GrizzlyAttack.ttf"); OptionMenu.Add(new Text("Lancer une partie", font, 50)); OptionMenu[0].Position = new Vector2f((_blackBackMenu.GetGlobalBounds().Width / 2f) - (OptionMenu[0].GetGlobalBounds().Width / 2f), 400f); OptionMenu[0].Style = Text.Styles.Bold; OptionMenu.Add(new Text("Option", font, 50)); OptionMenu[1].Position = new Vector2f((_blackBackMenu.GetGlobalBounds().Width / 2f) - (OptionMenu[1].GetGlobalBounds().Width / 2f), 485f); OptionMenu[1].Style = Text.Styles.Bold; OptionMenu.Add(new Text("Statistiques", font, 50)); OptionMenu[2].Position = new Vector2f((_blackBackMenu.GetGlobalBounds().Width / 2f) - (OptionMenu[2].GetGlobalBounds().Width / 2f), 570f); OptionMenu[2].Style = Text.Styles.Bold; OptionMenu.Add(new Text("Coup Speciaux", font, 50)); OptionMenu[3].Position = new Vector2f((_blackBackMenu.GetGlobalBounds().Width / 2f) - (OptionMenu[3].GetGlobalBounds().Width / 2f), 655f); OptionMenu[3].Style = Text.Styles.Bold; OptionMenu.Add(new Text("Credit", font, 50)); OptionMenu[4].Position = new Vector2f((_blackBackMenu.GetGlobalBounds().Width / 2f) - (OptionMenu[4].GetGlobalBounds().Width / 2f), /*485f*/ 740f); OptionMenu[4].Style = Text.Styles.Bold; OptionMenu.Add(new Text("Quitter", font, 50)); OptionMenu[5].Position = new Vector2f((_blackBackMenu.GetGlobalBounds().Width / 2f) - (OptionMenu[5].GetGlobalBounds().Width / 2f), /*570f*/ 825f); OptionMenu[5].Style = Text.Styles.Bold; return(OptionMenu); }
public void TestTapped(float x, float y) { var oldPosition = _rectangleShape.Position; _rectangleShape.Position = Position; var contains = _rectangleShape.GetGlobalBounds().Contains(x, y); _rectangleShape.Position = oldPosition; if (contains) { OnTapped(this); } }
public Button(HostileSpace Game, String Text, Int32 X, Int32 Y) : base(Game) { shape = new RectangleShape(new Vector2f(192, 64)); shape.Texture = Game.ContentManager.GetTexture("Button02"); shape.Position = new Vector2f(X, Y); shape.FillColor = Color.White; text = new Text(Text, Game.ContentManager.GetFont("Arial")); text.CharacterSize = 24; text.Origin = new Vector2f(text.GetGlobalBounds().Width / 2, 0); text.Position = shape.Position + new Vector2f(shape.GetGlobalBounds().Width / 2, 18); }
public CheckBox(HostileSpace Game, Int32 X, Int32 Y) : base(Game) { shape = new RectangleShape(new Vector2f(64, 64)); shape.Texture = Game.ContentManager.GetTexture("Checkbox"); shape.Position = new Vector2f(X, Y); shape.FillColor = Color.White; check = new Text("X", Game.ContentManager.GetFont("Arial")); check.CharacterSize = 34; check.Origin = new Vector2f(check.GetGlobalBounds().Width / 2, 0); check.Position = shape.Position + new Vector2f(shape.GetGlobalBounds().Width / 2, 10); }
/// <summary> /// the origin of the rectangles need to be set on left upper corner, as it is ad default /// </summary> public static float CheckColision(RectangleShape rect1, MyTile rect2) { // Vector2f CenterReact1 = rect1.Position + new Vector2f(rect1.Size.X / 2, rect1.Size.Y / 2); // Vector2f CenterReact2 = rect2.Position + new Vector2f(rect2.Size.X / 2, rect2.Size.Y / 2); if (rect1.GetGlobalBounds().Intersects(rect2.GetGlobalBounds()) == true) // this need to be simpliied { return(rect2.SpeedPunish); } else { return(0); } }
private void bindEvents() { Window.MouseMoved += (sender, e) => { newGameButton.FillColor = newGameButton.GetGlobalBounds().Contains(Mouse.GetPosition(Window).X, Mouse.GetPosition(Window).Y) ? new Color(100, 100, 100) : new Color(150, 200, 150); topButton.FillColor = topButton.GetGlobalBounds().Contains(Mouse.GetPosition(Window).X, Mouse.GetPosition(Window).Y) ? new Color(100, 100, 100) : new Color(150, 200, 150); settingsButton.FillColor = settingsButton.GetGlobalBounds().Contains(Mouse.GetPosition(Window).X, Mouse.GetPosition(Window).Y) ? new Color(100, 100, 100) : new Color(150, 200, 150); exitButton.FillColor = exitButton.GetGlobalBounds().Contains(Mouse.GetPosition(Window).X, Mouse.GetPosition(Window).Y) ? new Color(100, 100, 100) : new Color(150, 200, 150); }; Window.MouseButtonReleased += (sender, args) => { if (newGameButton.GetGlobalBounds().Contains(Mouse.GetPosition(Window).X, Mouse.GetPosition(Window).Y)) { new Game(); } else if (topButton.GetGlobalBounds().Contains(Mouse.GetPosition(Window).X, Mouse.GetPosition(Window).Y)) { new Top(); } else if (settingsButton.GetGlobalBounds().Contains(Mouse.GetPosition(Window).X, Mouse.GetPosition(Window).Y)) { //MessageBox.Show("Not implemented yet"); new Settings(); } else if (exitButton.GetGlobalBounds().Contains(Mouse.GetPosition(Window).X, Mouse.GetPosition(Window).Y)) { WindowsStack.CloseLastWindow(); } }; }