public void Draw(SpriteBatch spriteBatch) { Vector2 topLeft = new Vector2(position.X - size.X / 2, position.Y - size.Y / 2); if(play) spriteBatch.Draw(pauseImage, new Rectangle(topLeft.ToPoint(), size.ToPoint()), Color.White); else if(pause) spriteBatch.Draw(image, new Rectangle(topLeft.ToPoint(), size.ToPoint()), Color.White); }
public void Draw(SpriteBatch spriteBatch, AngryBallsEnvironment.GameState gameState) { if (gameState != AngryBallsEnvironment.GameState.levelBuilder && gameState != AngryBallsEnvironment.GameState.initialize) { Vector2 topLeft = new Vector2(position.X - size.X / 2, position.Y - size.Y / 2); if (play) spriteBatch.Draw(pauseImage, new Rectangle(topLeft.ToPoint(), size.ToPoint()), Color.White); else if (pause) spriteBatch.Draw(image, new Rectangle(topLeft.ToPoint(), size.ToPoint()), Color.White); } }
public void draw(SpriteBatch spriteBatch) { if (isSelecting) { Vector2 secondCorner = Global.Camera.ScreenToWorld(Mouse.GetState().Position.ToVector2()); Vector2 topLeft = new Vector2(Math.Min(firstCorner.X, secondCorner.X), Math.Min(firstCorner.Y, secondCorner.Y)); Vector2 bottomRight = new Vector2(Math.Max(firstCorner.X, secondCorner.X), Math.Max(firstCorner.Y, secondCorner.Y)); Microsoft.Xna.Framework.Rectangle rect = new Microsoft.Xna.Framework.Rectangle(topLeft.ToPoint(), (bottomRight - topLeft).ToPoint()); DrawLine(spriteBatch, new Vector2(topLeft.X, topLeft.Y), //start of line new Vector2(bottomRight.X, topLeft.Y) //end of line ); DrawLine(spriteBatch, new Vector2(bottomRight.X, topLeft.Y), //start of line new Vector2(bottomRight.X, bottomRight.Y) //end of line ); DrawLine(spriteBatch, new Vector2(topLeft.X, bottomRight.Y), //start of line new Vector2(topLeft.X, topLeft.Y) //end of line ); DrawLine(spriteBatch, new Vector2(bottomRight.X, bottomRight.Y), //start of line new Vector2(topLeft.X, bottomRight.Y) //end of line ); } }
public Button(Texture2D texture, Vector2 topLeft, Vector2 scale, Action onClick, Color color) { this.texture = texture; drawRect = new Rectangle(topLeft.ToPoint(), scale.ToPoint()); this.OnClick = onClick; this.color = color; }
public override void Update(GameTime gameTime) { if (isHorizontal) { if (position.X >= 0) scrollDir = -1; else if (Bounds.Right <= CurrentGame.Window.ClientBounds.Width) scrollDir = 1; position += new Vector2((float)(scrollSpeed * gameTime.ElapsedGameTime.TotalSeconds * scrollDir), 0.0f); } else { if (position.Y >= 0) scrollDir = -1; else if (Bounds.Bottom <= CurrentGame.Window.ClientBounds.Height) scrollDir = 1; position += new Vector2(0.0f, (float)(scrollSpeed * gameTime.ElapsedGameTime.TotalSeconds * scrollDir)); } var clampedX = MathHelper.Clamp(position.X, CurrentGame.Window.ClientBounds.Width - Bounds.Width, 0.0f); var clampedY = MathHelper.Clamp(position.Y, CurrentGame.Window.ClientBounds.Height - Bounds.Height, 0.0f); position = new Vector2(clampedX, clampedY); Bounds.Location = position.ToPoint(); }
public void Draw(SpriteBatch spriteBatch, AngryBallsEnvironment.GameState gameState) { if (gameState == AngryBallsEnvironment.GameState.levelBuilder) { Vector2 topLeft = new Vector2(position.X - size.X / 2, position.Y - size.Y / 2); spriteBatch.Draw(image, new Rectangle(topLeft.ToPoint(), size.ToPoint()), Color.White); } }
public Actor(Point location, Color tint, int layer) { Rect = new Rectangle(location * Dimentions, Dimentions); m_virtualpos = location; m_position = new Vector2(Rect.X, Rect.Y); m_targetPos = m_position.ToPoint(); m_tint = tint; }
public SpringGrid( Rectangle gridSize, Vector2 spacing ) { _gridSize = gridSize; var springList = new List<Spring>(); // we offset the gridSize location by half-spacing so the padding is applied evenly all around gridSize.Location -= spacing.ToPoint(); gridSize.Width += (int)spacing.X; gridSize.Height += (int)spacing.Y; var numColumns = (int)( gridSize.Width / spacing.X ) + 1; var numRows = (int)( gridSize.Height / spacing.Y ) + 1; _points = new PointMass[numColumns, numRows]; // these fixed points will be used to anchor the grid to fixed positions on the screen var fixedPoints = new PointMass[numColumns, numRows]; // create the point masses int column = 0, row = 0; for( float y = gridSize.Top; y <= gridSize.Bottom; y += spacing.Y ) { for( float x = gridSize.Left; x <= gridSize.Right; x += spacing.X ) { _points[column, row] = new PointMass( new Vector3( x, y, 0 ), 1 ); fixedPoints[column, row] = new PointMass( new Vector3( x, y, 0 ), 0 ); column++; } row++; column = 0; } // link the point masses with springs for( var y = 0; y < numRows; y++ ) { for( var x = 0; x < numColumns; x++ ) { if( x == 0 || y == 0 || x == numColumns - 1 || y == numRows - 1 ) // anchor the border of the grid springList.Add( new Spring( fixedPoints[x, y], _points[x, y], 0.1f, 0.1f ) ); else if( x % 3 == 0 && y % 3 == 0 ) // loosely anchor 1/9th of the point masses springList.Add( new Spring( fixedPoints[x, y], _points[x, y], 0.002f, 0.02f ) ); const float stiffness = 0.28f; const float damping = 0.06f; if( x > 0 ) springList.Add( new Spring( _points[x - 1, y], _points[x, y], stiffness, damping ) ); if( y > 0 ) springList.Add( new Spring( _points[x, y - 1], _points[x, y], stiffness, damping ) ); } } _springs = springList.ToArray(); }
public Button(Texture2D texture, Vector2 topLeft, Vector2 scale, Action onClick, Color color, SpriteFont font, string text, Color textColor) { this.texture = texture; drawRect = new Rectangle(topLeft.ToPoint(), scale.ToPoint()); this.OnClick = onClick; this.color = color; this.font = font; this.text = text; textDraw = topLeft + scale / 2f - font.MeasureString(text) / 2f; this.textColor = textColor; }
//gör så att fotbollar har det de värdena och sånt de behöver public Football() { texture = Assets.Ball; position = new Vector2(500, 260); random = new Random(); float v = 1.3f; speed = new Vector2((float)Math.Cos(RandomFloat(-v, v)), (float)Math.Sin(RandomFloat(-v, v))); speed.Normalize(); size = new Vector2(20, 20); speed *= 10; part.Location = position.ToPoint(); part.Size = size.ToPoint(); }
public Goal(ContentManager c, string objektName, int updateDelay, Vector2 spawnPosition) : base(c, objektName, updateDelay, spawnPosition) { GameObjectState = GameObject_State.Flying; Position = spawnPosition; PositionRectangle.Location = Position.ToPoint(); LoadAnimation(c, objektName, 8); Animations[ActiveAnimation].AnimationScale = new Vector2(2, 2); CollectibleRequirement = 75; CurrentCollectibleAmount = 0; GoalpriteFont = c.Load <SpriteFont>("SuperMarioFont"); UpdateDelay = 15; }
internal void ClientUpdate(GameTime gameTime) { Vector2 centerVector2 = new Vector2(960f, 540f); float lerpAmount = (float)(gameTime.ElapsedGameTime.TotalMilliseconds / WorldPump.Interval); if (this.PlayerCharacter.Position != PlayerCharacter.DrawPosition) { Vector2 drawPosition = Vector2.Lerp(PlayerCharacter.DrawPosition.ToVector2(), this.PlayerCharacter.Position.ToVector2(), lerpAmount); PlayerCharacter.DrawPosition = drawPosition.ToPoint(); PlayerCharacter.OldDrawPosition = PlayerCharacter.DrawPosition.ToVector2(); } foreach (ushort clientId in Characters) { if (PlayerCharacter.Id == clientId) { continue; } ClientCharacter client = (ClientCharacter)this.GetCharacter(clientId); //Vector2 realClientPosition = centerVector2 - (this.PlayerCharacter.Position - client.Position).ToVector2(); //new Vector2(this.PlayerCharacter.Position.X - client.Position.X, this.PlayerCharacter.Position.Y - client.Position.Y); if (client.Position != client.DrawPosition) { Vector2 drawPosition = Vector2.Lerp(client.DrawPosition.ToVector2(), client.Position.ToVector2(), lerpAmount); client.DrawPosition = drawPosition.ToPoint(); client.OldDrawPosition = PlayerCharacter.DrawPosition.ToVector2(); //client.OldDrawPosition = Vector2.Lerp(client.OldDrawPosition, realClientPosition, lerpAmount); } } if (this.ChatMessages.Count > 0) { Queue <ChatMessage> expiredMessage = new Queue <ChatMessage>(this.ChatMessages.Count); foreach (ChatMessage message in this.ChatMessages) { message.Duration -= gameTime.ElapsedGameTime.TotalMilliseconds; if (message.Duration <= 0D) { expiredMessage.Enqueue(message); } } while (expiredMessage.Count > 0) { this.ChatMessages.Remove(expiredMessage.Dequeue()); } } }
public void AddSnow(Particle p, Vector2 position) { p.alive = false; if (!CheckPosition(p)) { return; } AddParticle(p); int numberOfSnow = (int)p.mass; Particle.SplitUpParticle(p, new Rectangle(position.ToPoint(), new Point(1, 1))); }
private Sprite(Texture2D texture, Vector2 frameSize, Vector2 anchor, Color?color = null) { Texture = texture; FrameSize = frameSize; Anchor = anchor; ColorMask = color ?? Color.White; DrawPosition = default; DrawLayer = 0; FrameX = 0; FrameY = 0; IsAnimated = frameSize.ToPoint() != texture.Bounds.Size; }
public override void Update(float deltaTime) { if (isOpen && showOn != null) { timer += deltaTime; offset.Y -= 100 * deltaTime; Position = camera.ToScreen(showOn.realPosition) + offset.ToPoint(); if (timer >= showTime) { Close(); } } base.Update(deltaTime); }
protected async void MoveTowardsTarget() { isMoving = true; currentLocation = position.Location.ToVector2(); while ((currentLocation - moveTowards).Length() > 3) { currentLocation = Vector2.Lerp(currentLocation, moveTowards, moveSpeed); this.position.Location = currentLocation.ToPoint(); await Task.Delay(frameRateMS); } this.position.Location = moveTowards.ToPoint(); isMoving = false; }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.DeepSkyBlue); spriteBatch.Begin(); spriteBatch.Draw(Mario, new Rectangle(Pos.ToPoint(), new Point(50, 50)), Color.White); spriteBatch.End(); // TODO: Add your drawing code here. base.Draw(gameTime); }
private void initGameObject(Vector2 position, Texture2D sprite, bool isVisible, PhysicsType type) { //this.position = position; this.position = position; this.drawSpace = new Rectangle(position.ToPoint().X, position.ToPoint().Y, sprite.Width, sprite.Height); this.isVisible = isVisible; this.rendComp = new RenderComponent(sprite); if(type != PhysicsType.MechanicsObject) { this.physComp = new PhysicsComponent(sprite.Width, sprite.Height, type); if (type == PhysicsType.StaticObject) PhysicsSystem.Instance.addStaticObject(this.physComp); else if (type == PhysicsType.Door) PhysicsSystem.Instance.addDoorObject(this.physComp); else if (type == PhysicsType.Player) { } else throw new NotSupportedException("The type [" + type.ToString() + "] is not supported by the Physics System yet"); this.physComp.UpdateHitBoxPosition(position); } }
/// <summary> /// セクション移動中の処理 /// </summary> private static void ChangeSectionCalc() { Vector2 Source = ScrollSourcePosition; Vector2 Destination = ScrollDestinationPosition; Position.X = (int)(Source.X + (Destination.X - Source.X) / Const.ChangeSectionDuration * ChangeSectionFrame); Position.Y = (int)(Source.Y + (Destination.Y - Source.Y) / Const.ChangeSectionDuration * ChangeSectionFrame); ChangeSectionFrame++; if (ChangeSectionFrame > Const.ChangeSectionDuration) { InChangeSection = false; Position = Destination.ToPoint(); } }
public Enemy(Texture2D enemyTexture, Vector2 enemyStartPos, float enemySpeed, Vector2 enemyScale, Color enemyColor, float enemyHealth, float enemyAttackRange, float enemyAttackSpeed) { texture = enemyTexture; speed = enemySpeed; moveDir.Y = 1; color = enemyColor; scale = new Vector2(0.2f, 0.2f); position = new Vector2(400, 0); enemyRectangle = new Rectangle(position.ToPoint(), (texture.Bounds.Size.ToVector2() * scale).ToPoint()); health = enemyHealth; alive = true; attackRange = enemyAttackRange; attackSpeed = enemyAttackSpeed; attackTimer = 0; }
internal TacticalTextPopUp(String s, BaseCharacter p, Vector2 offSet, Point textBoxSize, int steps, UpdateFunc uf = null, DrawFunc df = null) { if (bInitialize) { Inititialize(); } text = s; parent = p; location = p.trueMapSize().Location.ToVector2() + offSet; textBox = new Rectangle(location.ToPoint(), textBoxSize); timer = new TimingUtility(16, true, standardTimer); timer.SetStepTimer(steps, 0); updateFunction = uf; drawFunction = df; }
public void center_to_bounds_with_no_starting_offset() { var actor = new Actor("Sammy Square", null); var startingPosition = new Vector2(300, 300); actor.transform.Position = startingPosition; var boundingRect = new BoundingRect(actor, new Point(32, 32)); var startingCenter = boundingRect.Rect.Center; boundingRect.CenterToBounds(); boundingRect.Rect.Center.Should().BeEquivalentTo(startingCenter); // Center should not have moved new Point(boundingRect.Rect.Top, boundingRect.Rect.Left).Should() .BeEquivalentTo(startingPosition.ToPoint()); }
public void Update(float deltaTime) { position += dir * speed * deltaTime; rectangle.Location = position.ToPoint(); if (rectangle.Intersects(Enemies.rockRect)) { Enemies.ChangeRockColor(Color.Red); Game1.RemoveBullet(this); } else { Enemies.ChangeRockColor(Color.White); } }
public static Texture2D FromColor(Color color, Size size, Rectangle destinationRectangle, GraphicsDevice device) { Texture2D texture = new Texture2D(device, size.Width, size.Height); Color[] data = new Color[size.Width * size.Height]; for (int i = 0; i < data.Length; i++) { Vector2 pos = new Vector2(i % size.Width, (i - (i % size.Width)) / size.Width); if (destinationRectangle.Contains(pos.ToPoint())) data[i] = color; else data[i] = Color.Transparent; } texture.SetData(data); return texture; }
public override void Draw(GameTime gameTime, SpriteBatch spriteBatch, Camera camera) { base.Draw(gameTime, spriteBatch, camera); //Draw the contents of this textfield. spriteBatch.DrawString(spriteFont, content, GlobalPosition + offset.ToVector2(), color); //Draw cursor but only ever other half second. if (gameTime.TotalGameTime.Milliseconds % 1000 < 500 && hasFocus && Editable) { Texture2D tex = GameEnvironment.AssetManager.GetSingleColorPixel(color); float cursorX = spriteFont.MeasureString(content.Substring(0, cursorPosition)).X; Vector2 cursorPos = GlobalPosition + new Vector2(offset.X + cursorX, offset.Y); spriteBatch.Draw(tex, null, new Rectangle(cursorPos.ToPoint(), new Point(2, Height - offset.Y * 2))); } }
public bool ProvideCandidate(SmartInteractScanSettings settings, out ISmartInteractCandidate candidate) { candidate = null; if (!settings.FullInteraction) { return(false); } List <int> listOfProjectilesToInteractWithHack = settings.player.GetListOfProjectilesToInteractWithHack(); bool flag = false; Vector2 mousevec = settings.mousevec; mousevec.ToPoint(); int num = -1; float projectileDistanceFromCursor = -1f; for (int i = 0; i < listOfProjectilesToInteractWithHack.Count; i++) { int num2 = listOfProjectilesToInteractWithHack[i]; Projectile projectile = Main.projectile[num2]; if (projectile.active) { float num3 = projectile.Hitbox.Distance(mousevec); if (num == -1 || Main.projectile[num].Hitbox.Distance(mousevec) > num3) { num = num2; projectileDistanceFromCursor = num3; } if (num3 == 0f) { flag = true; num = num2; projectileDistanceFromCursor = num3; break; } } } if (settings.DemandOnlyZeroDistanceTargets && !flag) { return(false); } if (num != -1) { _candidate.Reuse(num, projectileDistanceFromCursor); candidate = _candidate; return(true); } return(false); }
private void ChangeSizeTo(Vector2 size) { if (Size == size && LastCategories == Categories.HasButtons) { return; } var wasAtBottom = ChatHistoryText.VerticalScrollPosition == ChatHistoryText.VerticalScrollMax; var delta = size.ToPoint().ToVector2() - Size; if (LastCategories != Categories.HasButtons) { var yDelta = Categories.HasButtons ? 10 : -10; foreach (var child in Children) { if (child != Categories && child != Background) { child.Y += yDelta; } } LastCategories = Categories.HasButtons; delta.Y -= yDelta; } this.SetSize((int)size.X, (int)size.Y); ChatHistoryBackground.SetSize(ChatHistoryBackground.Size.X + delta.X, ChatHistoryBackground.Size.Y + delta.Y); ChatHistoryText.SetSize(ChatHistoryBackground.Size.X - 19, ChatHistoryBackground.Size.Y - 16); ChatHistorySlider.Position = new Vector2(ChatHistorySlider.Position.X + delta.X, ChatHistorySlider.Position.Y); ChatHistorySlider.SetSize(ChatHistorySlider.Size.X, ChatHistoryBackground.Size.Y - 26); ChatHistoryScrollUpButton.Position = new Vector2(ChatHistoryScrollUpButton.Position.X + delta.X, ChatHistoryScrollUpButton.Position.Y); ChatHistoryScrollDownButton.Position = new Vector2(ChatHistoryScrollDownButton.Position.X + delta.X, ChatHistoryScrollDownButton.Position.Y + delta.Y); ChatEntryTextEdit.Position = new Vector2(ChatEntryTextEdit.Position.X, ChatEntryTextEdit.Position.Y + delta.Y); ChatEntryTextEdit.SetSize(ChatEntryTextEdit.Size.X + delta.X, ChatEntryTextEdit.Size.Y); ChatEntryBackground.Position = new Vector2(ChatEntryBackground.Position.X, ChatEntryBackground.Position.Y + delta.Y); ChatEntryBackground.SetSize(ChatEntryBackground.Size.X + delta.X, ChatEntryBackground.Size.Y); ChatEntryTextEdit.ComputeDrawingCommands(); ChatHistoryText.ComputeDrawingCommands(); if (wasAtBottom) { ChatHistoryText.VerticalScrollPosition = ChatHistoryText.VerticalScrollMax; } }
void MoveMouse(float x, float y) { //mousePos = Input.MousePositionMatrix(boardMatrix); mousePos = new Vector2(x, y); if (startPos != null) { Point p = mousePos.ToPoint(); possible = (startPos.Value.ToPoint() == p) || ((p.X == startPos.Value.X || p.Y == startPos.Value.Y) && (Math.Abs(p.X - startPos.Value.X) + Math.Abs(p.Y - startPos.Value.Y)) == 1) && GetLine((int)startPos.Value.X, p.X, (int)startPos.Value.Y, p.Y) == ColourType.NONE; } }
private void HoverSelectionMode(Vector2 gameFieldPosition) { var unit = GameState.Current.GetDamageableUnitAtPosition(gameFieldPosition.ToPoint(), Players.Player); if (unit != null) { unit.IsHit = true; } if (mLastSelectedUnit != null && mLastSelectedUnit != unit) { mLastSelectedUnit.IsHit = false; } mLastSelectedUnit = unit; }
public override void LoadContent(GameWindow window) { font = content.Load <SpriteFont>("spriteFont"); titlePos = new Vector2( (window.ClientBounds.Size.X - titleScale * font.MeasureString(titleText).X) / 2, window.ClientBounds.Size.Y / 4 ); buttonPos = new Vector2( (window.ClientBounds.Size.X - font.MeasureString(buttonText).X) / 2, 3 * window.ClientBounds.Size.Y / 4 ); buttonRect = new Rectangle(buttonPos.ToPoint(), font.MeasureString(buttonText).ToPoint()); }
public Player(Texture2D aSprite, Vector2 aPosition, Texture2D aBullet1Sprite, Texture2D aBullet2Sprite, GameWindow aWindow, float someSpeed = 0.6f, float someSize = 10f) { myBullet1sprite = aBullet1Sprite; myBullet2sprite = aBullet2Sprite; mySpeed = someSpeed; mySprite = aSprite; myPosition = aPosition; myStartPosition = aPosition; mySpriteOrigin = new Vector2(mySprite.Width / 2f, mySprite.Height / 2f); myBullet1List = new List <Bullet1>(); myBullet2List = new List <Bullet2>(); myWindow = aWindow; mySize = someSize; myCollisionBox = new Rectangle(myPosition.ToPoint(), new Point(aSprite.Width, aSprite.Height)); }
public void Update(GameTime gameTime, Player player, int windowHeight) { float deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds; float pixelsToMove = speed * deltaTime; moveDir.Y = 1; moveDir.Normalize(); position += moveDir * pixelsToMove; rectangle.Location = position.ToPoint(); rectangle.Offset(-offset); if (rectangle.Intersects(player.GetRectangle()) == true) { player.Damage(10f); } }
public Rectangle getBounds(Rectangle viewportBounds)// returns the bounds of the camera in world space { Rectangle bounds; int width = viewportBounds.Width; int height = -viewportBounds.Height; Point centre = mPosition.ToPoint(); Point size = new Point((int)(width / mZoom), (int)(height / mZoom)); Point location = centre - size / new Point(2); bounds = new Rectangle(location, size); return(bounds); }
public void Update(GraphicsDevice graphics) { position += velocity; if (position.X <= 0 || position.X >= graphics.Viewport.Width - texture.Width) { velocity.X = -velocity.X; } if (position.Y > graphics.Viewport.Height) { isVisible = false; } hitbox.Location = position.ToPoint(); }
public override bool?Colliding(Rectangle projHitbox, Rectangle targetHitbox) { if (projectile.localAI[0] < SpawnFrames) { return(false); } for (int i = 0; i < critters.Count; i++) { Vector2 critterCenter = projectile.Center + critters[i].offset; if (targetHitbox.Contains(critterCenter.ToPoint())) { return(true); } } return(false); }
public PatchButton(int charWidths, Vector2 position, NinePatch patch, int scale, string text, Action action = null) { Point charBounds = ScaleManager.LargeFont.charSize(); charBounds.X *= charWidths; this.patch = patch; Point wrapBounds = patch.wrap(charBounds, scale); Point pointPos = position.ToPoint(); this.hitbox = new Rectangle(pointPos.X - (wrapBounds.X / 2), pointPos.Y - (wrapBounds.Y / 2), wrapBounds.X, wrapBounds.Y); this.position = hitbox.Location.ToVector2(); this.scale = scale; this.text = text; this.action = action; calculateBounds(); }
public override void Update(float deltaTime, Entity parent) { //Math used: I multiply the SpriteCenter by LocalScale because (of course) the more i scale, the more the center moves. //We have to accout for extension differences as well. //Same goes for the buttonSprize's size, and that's more obvious Vector2 rectPosition = (parent.Transform.LocalPosition + Transform.Position - (Sprite.SpriteCenter * Transform.LocalScale) + (offset * Transform.LocalScale)); Rectangle rect = new Rectangle(rectPosition.ToPoint(), (Extension * Transform.LocalScale).ToPoint()); MouseState mouseState = Mouse.GetState(); //Pretty explanatory i hope. But i already know i will forget this stuff in one day if (rect.Contains(mouseState.Position)) { Sprite.SetSource(0, 1, Sprite.Width, Sprite.Height); if (mouseState.LeftButton == ButtonState.Pressed) { Sprite.SetSource(1, 0, Sprite.Width, Sprite.Height); if (!hadPrevClicked) { if (onClick != null) { onClick(); } hadPrevClicked = true; } } else if (hadPrevClicked) { hadPrevClicked = false; if (onRelease != null) { onRelease(); } } } else { //Reset the button without calling the onRelease callback. //Users tend to move the cursor outside the button if they clicked by mistake //or they don't want the onRelease action if (hadPrevClicked) { hadPrevClicked = false; } Sprite.SetSource(0, 0, Sprite.Width, Sprite.Height); } }
public bool ProvideCandidate(SmartInteractScanSettings settings, out ISmartInteractCandidate candidate) { candidate = null; if (!settings.FullInteraction) { return(false); } Rectangle value = Utils.CenteredRectangle(settings.player.Center, new Vector2(Player.tileRangeX, Player.tileRangeY) * 16f * 2f); Vector2 mousevec = settings.mousevec; mousevec.ToPoint(); bool flag = false; int num = -1; float npcDistanceFromCursor = -1f; for (int i = 0; i < 200; i++) { NPC nPC = Main.npc[i]; if (nPC.active && nPC.townNPC && nPC.Hitbox.Intersects(value) && !flag) { float num2 = nPC.Hitbox.Distance(mousevec); if (num == -1 || Main.npc[num].Hitbox.Distance(mousevec) > num2) { num = i; npcDistanceFromCursor = num2; } if (num2 == 0f) { flag = true; num = i; npcDistanceFromCursor = num2; break; } } } if (settings.DemandOnlyZeroDistanceTargets && !flag) { return(false); } if (num != -1) { _candidate.Reuse(num, npcDistanceFromCursor); candidate = _candidate; return(true); } return(false); }
// boolean to check if the player character can move public bool CanMove(Vector2 velocity) { Vector2 newPos = m_position + velocity; Rectangle newBounds = new Rectangle(newPos.ToPoint(), m_animation.FrameSize); if (newPos.X < 0 || newPos.Y < 0 || newPos.X + m_animation.FrameWidth > Game1.screenWidth || newPos.Y > Game1.screenHeight + m_animation.FrameHeight) { return(false); } foreach (var platform in collideableSprites.OfType <Platform>()) { if (newBounds.Intersects(platform.Hitbox)) { return(false); } } foreach (var movingPlatform in moveableSprites.OfType <MovingPlatform>()) { if (newBounds.Intersects(movingPlatform.Hitbox)) { return(false); } } foreach (var doubleCauldron in collideableSprites.OfType <DoubleCauldron>()) { if (newBounds.Intersects(doubleCauldron.Hitbox)) { return(false); } } foreach (var cauldron in collideableSprites.OfType <Cauldron>()) { if (newBounds.Intersects(cauldron.Hitbox)) { return(false); } } foreach (var door in collideableSprites.OfType <Door>()) { if (newBounds.Intersects(door.Hitbox)) { return(false); } } return(true); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.Black); // TODO: Add your drawing code here. spriteBatch.Begin(); spriteBatch.Draw(racer, new Rectangle(racerPos.ToPoint(), new Point(50, 100)), Color.White); spriteBatch.Draw(enemy, new Rectangle(enemyPos.ToPoint(), new Point(50, 100)), Color.White); spriteBatch.Draw(enemy, new Rectangle(enemyPos2.ToPoint(), new Point(50, 100)), Color.White); spriteBatch.Draw(enemy, new Rectangle(enemyPos3.ToPoint(), new Point(50, 100)), Color.White); spriteBatch.End(); base.Draw(gameTime); }
/// <summary> /// Draw Text on screen /// </summary> /// <param name="_spiteBatch">Reference to main SpriteBatch</param> /// <param name="_gameTime">Reference to current GameTime</param> public void Draw(SpriteBatch _spiteBatch, GameTime _gameTime) { // Recalculate position each draw loop mTextPos = new Vector2(Global.Camera.Position.X - 525, Global.Camera.Position.Y + 225); mArtPos = new Vector2(Global.Camera.Position.X - 725, Global.Camera.Position.Y + 225); if (mArt2 != null) { mArtPos2 = new Vector2(Global.Camera.Position.X + 475, Global.Camera.Position.Y + 225); } // Create rectangle to position the full character art mArtRect = new Rectangle(mArtPos.ToPoint(), new Point(mArt.Width, mArt.Height)); if (mArt2 != null) { mArtRect2 = new Rectangle(mArtPos2.ToPoint(), new Point(mArt2.Width, mArt2.Height)); } // While there are lines to display and the running variable is active if (mCurrLine < mLines.Length && mRunning) { // Update the internal timer mTimer += (float)_gameTime.ElapsedGameTime.TotalMilliseconds; // Pass the current line to the Dialogue Box mDialogueBox.Draw(_spiteBatch, mLines[mCurrLine], mTextPos); // Draw thefull character Art _spiteBatch.Draw(mArt, mArtRect, Color.White); if (mArt2 != null) { _spiteBatch.Draw(mArt2, mArtRect2, Color.White); } // If the timer is reached move to next line and update timer. if (mTimer >= mInterval) { mCurrLine++; mTimer = 0; } } else { // At end of dialogue reset the running bool to false; mRunning = false; // Unsubscribe from the Input Event mInputManager.Un_Space(OnSpace); mSpeaker.DialougeComplete(); } }
public virtual void draw(SpriteBatch spriteBatch) { Vector2 sourceTopLeft = new Vector2 ( 0, type * brickHeight + type); Vector2 sourceBottomRight = new Vector2 ( size.X, size.Y ); Rectangle sourceRectangle = new Rectangle(sourceTopLeft.ToPoint(), sourceBottomRight.ToPoint()); if(placed) { position.X = UnitConverter.toPixelSpace(brickBody.Position.X);// - size.X / 2; position.Y = UnitConverter.toPixelSpace(brickBody.Position.Y);// - size.Y / 2; spriteBatch.Draw(image, new Rectangle(new Point((int)(position.X - size.X / 2), (int)(position.Y - size.Y / 2)), size.ToPoint()), sourceRectangle, color); } else { spriteBatch.Draw(image, new Rectangle(new Point((int)(position.X - size.X / 2), (int)(position.Y - size.Y / 2)), size.ToPoint()), sourceRectangle, color); } }
/// <summary> /// Creates a line of colored cells on the grid. /// </summary> /// <param name="start">The window based location of the beginning of the line.</param> /// <param name="end">The window based location of the end of the line.</param> public void createLine(Vector2 start, Vector2 end) { //Grid grid = FrameManager.ActiveFrame.Grid.Peek().Clone(); for (int x = 0; x < FrameManager.ActiveFrame.Grid.Peek().GridSize.X; x++) { for (int y = 0; y < FrameManager.ActiveFrame.Grid.Peek().GridSize.Y; y++) { if (Physics.LineIntersectsRect(start.ToPoint(), end.ToPoint(), FrameManager.ActiveFrame.Grid.Peek().Cells[x, y].Bounds)) { FrameManager.ActiveFrame.Grid.Peek().Cells[x, y].Color = Globals.DrawingColor; //grid.Cells[x, y].Color = Globals.DrawingColor; } } } //FrameManager.ActiveFrame.Grid.Push(grid); }
public static void PreUpdate(GameTime gameTime) { // Update inputs KeyboardState = Keyboard.GetState(); MouseState = Mouse.GetState(); MousePosition = Vector2.Transform( new Vector2( MouseState.Position.X, MouseState.Position.Y ), Matrix.Invert(World.Scale)); MouseHitbox = new Rectangle(MousePosition.ToPoint(), new Point(1, 1)); PadState1 = GamePad.GetState(PlayerIndex.One); PadState1 = GamePad.GetState(PlayerIndex.Two); // This will help determine how the menu buttons are selected. // If there is no new mouse input but there is new keyboard/gamepad input, assume the user is using the keyboard. if (MouseState == OldMouseState) { if (KeyboardState != OldKeyboardState || PadState1 != OldPadState1) { Primary = InputType.Buttons; } } // Else, if there is no new keyboard/gamepad input but there is new mouse input, assume the user is using the mouse. else if (MouseState != OldMouseState) { if (KeyboardState == OldKeyboardState || PadState1 == OldPadState1) { Primary = InputType.Pointer; } } }
public void Draw(SpriteBatch spriteBatch, Renderer renderer) { Vector2 portOffset = renderer.RenderState.Camera.Offset; Vector2 screen = spriteBatch.GetScreenDimensions(); const int size = 200; float xyratio = screen.X / screen.Y; Vector2 dim = new Vector2(size * xyratio, size); if (!_initialized && _wait-- == 0) CreateMapTexture(renderer); if (_initialized) { const int offset = 120; Rectangle target = new Rectangle((screen - dim).ToPoint(), dim.ToPoint()); Rectangle source = new Rectangle((int)(offset * xyratio), offset, (int)(screen.X - offset * xyratio), (int)screen.Y - offset); spriteBatch.Draw(_renderTarget, target, source, Color.White); } Debug.WriteToScreen("wait", _wait); }
public override void draw(SpriteBatch spriteBatch) { strength = 6 - brickStrength; Vector2 sourceTopLeft = new Vector2(strength * brickWidth + strength, type * brickHeight + type); Vector2 sourceBottomRight = new Vector2(size.X, size.Y); Rectangle sourceRectangle = new Rectangle(sourceTopLeft.ToPoint(), sourceBottomRight.ToPoint()); if (placed && !exploded) { position.X = UnitConverter.toPixelSpace(brickBody.Position.X) - size.X / 2; position.Y = UnitConverter.toPixelSpace(brickBody.Position.Y) - size.Y / 2; spriteBatch.Draw(image, new Rectangle(position.ToPoint(), size.ToPoint()), sourceRectangle, color); } else if(!exploded) { spriteBatch.Draw(image, new Rectangle(new Point((int)(position.X - size.X / 2), (int)(position.Y - size.Y / 2)), size.ToPoint()), sourceRectangle, color); } if (exploded) { brickExplosion.Draw(spriteBatch); } }
public static bool RectCollision3x3(Vector2 pos, Vector2 size, bool isNPC, bool isItem, bool isProjectile) { // g = grid position d = amount of tiles to square Point g = pos.ToPoint() / Settings.Dimensions.Size; Rectangle ocr = new Rectangle((pos - size).ToPoint(), (size * 2).ToPoint()); int d = 3; Tile[][] t = Util.GetInitialized2DArray<Tile>(d, d, null); for (int i = Layers.Count - 1; i >= 0; i--) { if ((Layers[i].Options & LayerTraits.Collision) != LayerTraits.Collision && ((Layers[i].Options & LayerTraits.ProjectileCollision) != LayerTraits.ProjectileCollision || !isProjectile) && ((Layers[i].Options & LayerTraits.NPCCollision) != LayerTraits.NPCCollision || !isNPC) && ((Layers[i].Options & LayerTraits.ItemCollision) != LayerTraits.ItemCollision || !isItem)) continue; for (int x = 0; x < d; x++) for (int y = 0; y < d; y++) { if ((g.X + (x - d / 2) >= 0 && g.Y + (y - d / 2) >= 0 && g.X + (x - d / 2) < Settings.Dimensions.XCount && g.Y + (y - d / 2) < Settings.Dimensions.YCount) && Layers[i].Tiles[g.X + (x - d / 2)][g.Y + (y - d / 2)] != Settings.AccessibleTiles.PlaceholderTile) t[x][y] = Layers[i].Tiles[g.X + (x - d / 2)][g.Y + (y - d / 2)]; else continue; Rectangle tcr = new Rectangle((g + new Point((x - d / 2), (y - d / 2))) * Settings.Dimensions.Size + t[x][y].CollisionRect.Location, t[x][y].CollisionRect.Size); if (tcr.Intersects(ocr)) return true; } } return false; }
public virtual void DrawMap(SpriteBatch sb,Vector2 offset) { sb.Draw(Pixel, new Rectangle((m_virtualpos * new Point(4, 4)) + offset.ToPoint(), new Point(4, 4)), m_tint); }
public Button(Vector2 loc) : this(new Rectangle(loc.ToPoint(), Point.Zero)) {}
private void BuildPolys(Vector2 rCursor, KeyboardState keyb) { if (keyb.IsKeyDown(Keys.LeftControl)) { //did user clicked over a pre-existent polygon? foreach (Polygon p in polys) { if (p.GetBoundingBox().Contains(rCursor.ToPoint())) { activePolygon = p; break; } } } //are we building a polygon from scratch? else if (activePolygon == null) { activePolygon = new Polygon(new Vector2[1] { rCursor }); } else if (activePolygon != null) { //.. add another vertex to the polygon vertex list... Vector2[] vertexes = new Vector2[activePolygon.VertexCount + 1]; activePolygon.Vertexes.CopyTo(vertexes, 0); vertexes[vertexes.Length - 1] = rCursor; //.. and recreate it polys.Remove(activePolygon); activePolygon = Polygon.ConvexHull(vertexes); polys.Add(activePolygon); } }
/// <summary> /// This will draw a non-static line, so it can be moved by mouse position. /// </summary> private void drawLine(Vector2 start, Vector2 end) { //if (FrameManager.ActiveFrame.Grid.Bounds.Contains(Input.CurrentMousePosition)) //end = MouseDrawPoint(Input.CurrentMousePosition); for (int x = 0; x < FrameManager.ActiveFrame.Grid.Peek().GridSize.X; x++) { for (int y = 0; y < FrameManager.ActiveFrame.Grid.Peek().GridSize.Y; y++) { if (Physics.LineIntersectsRect(start.ToPoint(), end.ToPoint(), FrameManager.ActiveFrame.Grid.Peek().Cells[x, y].Bounds)) { Globals.SpriteBatch.Draw(Textures.texture, FrameManager.ActiveFrame.Grid.Peek().Cells[x, y].Bounds, Globals.DrawingColor); } } } }
public Rectangle GetStringRectangle(string text, Vector2 position) { var size = GetSize(text); var p = position.ToPoint(); return new Rectangle(p.X, p.Y, size.Width, size.Height); }
public void Vector2ToPointTest() { Vector2 vector = new Vector2(23, 42); Windows.Foundation.Point result = vector.ToPoint(); Assert.AreEqual(23.0, result.X); Assert.AreEqual(42.0, result.Y); }
/// <summary> /// Dibuja la entrada en una posición dada. /// </summary> /// <param name="bat">Batch de dibujo.</param> /// <param name="pos">Posición de dibujo.</param> public void Dibujar (SpriteBatch bat, Vector2 pos) { bat.Draw ( TexturaIcon, new Rectangle (pos.ToPoint (), Tamaño), ColorIcon); bat.DrawString (Font, Str, pos + new Vector2 (Tamaño.X, 0), ColorTexto); }
private bool UpdateButtons(Vector2 mouse) { this.HoveredMode = -1; bool flag = !Main.graphics.IsFullScreen; int num = 9; for (int i = 0; i < num; i++) { Rectangle rectangle = new Rectangle(24 + 46 * i, 24, 42, 42); if (rectangle.Contains(mouse.ToPoint())) { this.HoveredMode = i; bool flag2 = Main.mouseLeft && Main.mouseLeftRelease; int num2 = 0; if (i == num2++ && flag2) { CaptureSettings captureSettings = new CaptureSettings(); Point point = Main.screenPosition.ToTileCoordinates(); Point point2 = (Main.screenPosition + new Vector2((float)Main.screenWidth, (float)Main.screenHeight)).ToTileCoordinates(); captureSettings.Area = new Rectangle(point.X, point.Y, point2.X - point.X + 1, point2.Y - point.Y + 1); captureSettings.Biome = CaptureBiome.Biomes[CaptureInterface.Settings.BiomeChoice]; captureSettings.CaptureBackground = !CaptureInterface.Settings.TransparentBackground; captureSettings.CaptureEntities = CaptureInterface.Settings.IncludeEntities; captureSettings.UseScaling = CaptureInterface.Settings.PackImage; captureSettings.CaptureMech = Main.player[Main.myPlayer].inventory[Main.player[Main.myPlayer].selectedItem].mech; CaptureInterface.StartCamera(captureSettings); } if (i == num2++ && flag2 && CaptureInterface.EdgeAPinned && CaptureInterface.EdgeBPinned) { CaptureInterface.StartCamera(new CaptureSettings { Area = CaptureInterface.GetArea(), Biome = CaptureBiome.Biomes[CaptureInterface.Settings.BiomeChoice], CaptureBackground = !CaptureInterface.Settings.TransparentBackground, CaptureEntities = CaptureInterface.Settings.IncludeEntities, UseScaling = CaptureInterface.Settings.PackImage, CaptureMech = Main.player[Main.myPlayer].inventory[Main.player[Main.myPlayer].selectedItem].mech }); } if (i == num2++ && flag2 && this.SelectedMode != 0) { this.SelectedMode = 0; this.ToggleCamera(true); } if (i == num2++ && flag2 && this.SelectedMode != 1) { this.SelectedMode = 1; this.ToggleCamera(true); } if (i == num2++ && flag2) { CaptureInterface.ResetFocus(); } if (i == num2++ && flag2 && Main.mapEnabled) { Main.mapFullscreen = !Main.mapFullscreen; } if (i == num2++ && flag2 && this.SelectedMode != 2) { this.SelectedMode = 2; this.ToggleCamera(true); } if (i == num2++ && flag2 && flag) { string fileName = Path.Combine(Main.SavePath, "Captures"); Process.Start(fileName); } if (i == num2++ && flag2) { this.ToggleCamera(false); Main.blockMouse = true; Main.mouseLeftRelease = false; } return true; } } return false; }
public static void translate( ref Rectangle rect, Vector2 vec ) { rect.Location += vec.ToPoint(); }
private void DragBounds(Vector2 mouse) { if (!CaptureInterface.EdgeAPinned || !CaptureInterface.EdgeBPinned) { bool flag = false; if (Main.mouseLeft) { flag = true; } if (flag) { bool flag2 = true; Point point; if (!Main.mapFullscreen) { point = (Main.screenPosition + mouse).ToTileCoordinates(); } else { flag2 = CaptureInterface.GetMapCoords((int)mouse.X, (int)mouse.Y, 0, out point); } if (flag2) { if (!CaptureInterface.EdgeAPinned) { CaptureInterface.EdgeAPinned = true; CaptureInterface.EdgeA = point; } if (!CaptureInterface.EdgeBPinned) { CaptureInterface.EdgeBPinned = true; CaptureInterface.EdgeB = point; } } this.currentAim = 3; this.caughtEdge = 1; } } int num = Math.Min(CaptureInterface.EdgeA.X, CaptureInterface.EdgeB.X); int num2 = Math.Min(CaptureInterface.EdgeA.Y, CaptureInterface.EdgeB.Y); int num3 = Math.Abs(CaptureInterface.EdgeA.X - CaptureInterface.EdgeB.X); int num4 = Math.Abs(CaptureInterface.EdgeA.Y - CaptureInterface.EdgeB.Y); bool value = Main.player[Main.myPlayer].gravDir == -1f; int num5 = 1 - value.ToInt(); int num6 = value.ToInt(); Rectangle rectangle; Rectangle rectangle2; if (!Main.mapFullscreen) { rectangle = Main.ReverseGravitySupport(new Rectangle(num * 16, num2 * 16, (num3 + 1) * 16, (num4 + 1) * 16)); rectangle2 = Main.ReverseGravitySupport(new Rectangle((int)Main.screenPosition.X, (int)Main.screenPosition.Y, Main.screenWidth + 1, Main.screenHeight + 1)); Rectangle rectangle3; Rectangle.Intersect(ref rectangle2, ref rectangle, out rectangle3); if (rectangle3.Width == 0 || rectangle3.Height == 0) { return; } rectangle3.Offset(-rectangle2.X, -rectangle2.Y); } else { Point point2; CaptureInterface.GetMapCoords(num, num2, 1, out point2); Point point3; CaptureInterface.GetMapCoords(num + num3 + 1, num2 + num4 + 1, 1, out point3); rectangle = new Rectangle(point2.X, point2.Y, point3.X - point2.X, point3.Y - point2.Y); rectangle2 = new Rectangle(0, 0, Main.screenWidth + 1, Main.screenHeight + 1); Rectangle rectangle3; Rectangle.Intersect(ref rectangle2, ref rectangle, out rectangle3); if (rectangle3.Width == 0 || rectangle3.Height == 0) { return; } rectangle3.Offset(-rectangle2.X, -rectangle2.Y); } this.dragging = false; if (!Main.mouseLeft) { this.currentAim = -1; } if (this.currentAim != -1) { this.dragging = true; Point point4 = default(Point); if (!Main.mapFullscreen) { point4 = Main.MouseWorld.ToTileCoordinates(); } else { Point point5; if (!CaptureInterface.GetMapCoords((int)mouse.X, (int)mouse.Y, 0, out point5)) { return; } point4 = point5; } switch (this.currentAim) { case 0: case 1: if (this.caughtEdge == 0) { CaptureInterface.EdgeA.Y = point4.Y; } if (this.caughtEdge == 1) { CaptureInterface.EdgeB.Y = point4.Y; } break; case 2: case 3: if (this.caughtEdge == 0) { CaptureInterface.EdgeA.X = point4.X; } if (this.caughtEdge == 1) { CaptureInterface.EdgeB.X = point4.X; } break; } } else { this.caughtEdge = -1; Rectangle drawbox = rectangle; drawbox.Offset(-rectangle2.X, -rectangle2.Y); this.inMap = drawbox.Contains(mouse.ToPoint()); int i = 0; while (i < 4) { Rectangle bound = this.GetBound(drawbox, i); bound.Inflate(8, 8); if (bound.Contains(mouse.ToPoint())) { this.currentAim = i; if (i == 0) { if (CaptureInterface.EdgeA.Y < CaptureInterface.EdgeB.Y) { this.caughtEdge = num6; break; } this.caughtEdge = num5; break; } else if (i == 1) { if (CaptureInterface.EdgeA.Y >= CaptureInterface.EdgeB.Y) { this.caughtEdge = num6; break; } this.caughtEdge = num5; break; } else if (i == 2) { if (CaptureInterface.EdgeA.X < CaptureInterface.EdgeB.X) { this.caughtEdge = 0; break; } this.caughtEdge = 1; break; } else { if (i != 3) { break; } if (CaptureInterface.EdgeA.X >= CaptureInterface.EdgeB.X) { this.caughtEdge = 0; break; } this.caughtEdge = 1; break; } } else { i++; } } } CaptureInterface.ConstraintPoints(); }
public Ground(Vector2 position, Vector2 size) { Bounds = new Rectangle(position.ToPoint(), size.ToPoint()); }
public void Draw(SpriteBatch spriteBatch) { if (particleList.Count != 0) { foreach (Body element in particleList) { Vector2 topLeft = new Vector2(UnitConverter.toPixelSpace(element.Position.X), UnitConverter.toPixelSpace(element.Position.Y)); spriteBatch.Draw(particleImage, new Rectangle(topLeft.ToPoint(), size.ToPoint()), Color.White); } } }
private bool IsSliding(Vector2 mousePosition) { return SliderBarDimentions.Add(Position).Contains(mousePosition.ToPoint()); }