本文整理汇总了C#中SFML.Graphics.RectangleShape类的典型用法代码示例。如果您正苦于以下问题:C# RectangleShape类的具体用法?C# RectangleShape怎么用?C# RectangleShape使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RectangleShape类属于SFML.Graphics命名空间,在下文中一共展示了RectangleShape类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Draw
public override void Draw(RenderTarget rt)
{
RectangleShape overylay = new RectangleShape(new Vector2f(GameOptions.Width, GameOptions.Height))
{
FillColor = new Color(0, 0, 0, 128)
};
rt.Draw(overylay);
RectangleShape window = new RectangleShape(new Vector2f(GameOptions.Width * (1.0f - PaddingHorizontal * 2.0f), GameOptions.Height * (1.0f - PaddingVertical * 2.0f)))
{
Position = new Vector2f(GameOptions.Width * PaddingHorizontal, GameOptions.Height * PaddingVertical),
FillColor = Color.White,
OutlineColor = Color.Black,
OutlineThickness = 2.0f
};
rt.Draw(window);
Text labelSettings = new Text("Join by IP", Assets.LoadFont(Program.DefaultFont))
{
Position = new Vector2f(GameOptions.Width / 2.0f, GameOptions.Height * PaddingVertical + 48.0f),
Color = Color.Black,
CharacterSize = 32
};
labelSettings.Center();
labelSettings.Round();
rt.Draw(labelSettings);
base.Draw(rt);
}
示例2: Rowboat
public Rowboat(Game game)
: base(game, game.GraphicsMode == Game.GRAPHICSMODE_NORMAL ? Graphics.GetAnimatedSprite(game, "assets/sprites/rowboat.xml") : Graphics.GetAnimatedSprite(game, "assets/sprites/blueprint/rowboat.xml"))
{
Collision = new RectangleShape(new Vector2f(82f, 38f));
Collision.Position = new Vector2f(-41f, -19f);
Model.Stop();
HealthMax = 8000;
Health = HealthMax;
SpeedMax = 50.0f + Math.Min(0.5f * Game.AIManager.Difficulty, 25.0f);
Acc = 200.0f;
// Add Infantry Passengers
AddInfantryman(new Vector2f(0, -10));
AddInfantryman(new Vector2f(0, 10));
AddInfantryman(new Vector2f(25, -10));
AddInfantryman(new Vector2f(25, 10));
AddInfantryman(new Vector2f(-25, -10));
AddInfantryman(new Vector2f(-25, 10));
SetAI(new RowboatAI(Game));
}
示例3: Draw
public override void Draw(RenderTarget rt)
{
RectangleShape bgOverlay = new RectangleShape(new Vector2f(GameOptions.Width, GameOptions.Height)) { FillColor = Color.Black };
rt.Draw(bgOverlay);
Text title = new Text("Game Over", Assets.LoadFont(Program.DefaultFont))
{
Position = new Vector2f(GameOptions.Width / 2.0f, 48.0f),
CharacterSize = 48,
Color = Color.White
};
title.Center();
title.Round();
rt.Draw(title);
Text winnerTitle = new Text(GetWinnerText(), Assets.LoadFont(Program.DefaultFont))
{
Position = new Vector2f(GameOptions.Width / 2.0f, GameOptions.Height / 2.0f),
CharacterSize = 48,
Color = Color.White
};
winnerTitle.Center();
winnerTitle.Round();
rt.Draw(winnerTitle);
base.Draw(rt);
}
示例4: loadContent
public override void loadContent()
{
float logoScale;
_logoTexture = ResourceManager.getResource<Texture>("logo_1");
_logoShape = new RectangleShape();
_logoShape.Texture = _logoTexture;
_logoShape.Size = new Vector2f(_logoTexture.Size.X, _logoTexture.Size.Y);
logoScale = Game.window.GetView().Size.X / (float)_logoTexture.Size.X;
_logoShape.Scale = new Vector2f(logoScale, logoScale);
_font = ResourceManager.getResource<Font>("immortal_font");
_options = new List<Text>();
_options.Add(new Text("New Game", _font, 48));
_options.Add(new Text("Continue", _font, 48));
_options.Add(new Text("Options", _font, 48));
_options.Add(new Text("Exit", _font, 48));
for (int i = 0; i < _options.Count; i++)
{
Text text = _options[i];
text.Position = new Vector2f(128, i * 48 + _logoShape.Size.Y * _logoShape.Scale.Y + 64);
}
}
示例5: PauseState
public PauseState(StateStack stack, Context context)
: base(stack, context)
{
RenderWindow window = mContext.window;
mBackgroundSprite = new Sprite();
mPausedText = new Text();
mInstructionText = new Text();
mPausedText.Font = mContext.fonts.get(FontID.Main);
mPausedText.DisplayedString = "Game Paused";
mPausedText.CharacterSize = 70;
mPausedText.centerOrigin();
mPausedText.Position = new Vector2f(0, 0);
mInstructionText.Font = mContext.fonts.get(FontID.Main);
mInstructionText.DisplayedString = "(Press Backspace to return to main menu)";
mInstructionText.centerOrigin();
mInstructionText.Position = new Vector2f(0, 0);
backgroundShape = new RectangleShape();
backgroundShape.FillColor = new Color(0, 0, 0, 150);
backgroundShape.Position = window.GetView().Center;
backgroundShape.centerOrigin();
backgroundShape.Size = window.GetView().Size;
}
示例6: ButtonControl
public ButtonControl(Font font, uint size, Texture button, Texture hover, Texture press)
{
left = new RectangleShape();
middle = new RectangleShape();
right = new RectangleShape();
left.Texture = button;
middle.Texture = button;
right.Texture = button;
left.TextureRect = new IntRect(0, 0, (int)button.Size.X / 2 - 1, (int)button.Size.Y);
middle.TextureRect = new IntRect((int)button.Size.X / 2 - 1, 0, 2, (int)button.Size.Y);
right.TextureRect = new IntRect((int)button.Size.X / 2 + 1, 0, (int)button.Size.X / 2, (int)button.Size.Y);
text = new TextControl(font, size) { TextAlignment = Alignment.MiddleCenter, Bold = true };
text.BackgroundColor = Color.Transparent;
IsHovered = false;
IsPressed = false;
ClickYOffset = 4.0f;
buttonTexture = button;
hoverTexture = hover;
pressedTexture = press;
}
示例7: CircleRectangleCollision
/// <summary>Checks collision between Circle and Rotated Rectangle.</summary>
/// <param name="rectAngle">In Degrees.</param>
public static bool CircleRectangleCollision(Vector2f circleCenter, float circleRadius, RectangleShape rect, float rectAngle = 0, Vector2f rectOffset = default(Vector2f))
{
Vector2f rectPos = new Vector2f(rect.Position.X + rectOffset.X, rect.Position.Y + rectOffset.Y);
Vector2f rectCenter = new Vector2f(rectPos.X + (rect.Size.X / 2), rectPos.Y + (rect.Size.Y / 2));
// Rotate circle's center point back
Vector2f unrotatedCircle = new Vector2f();
unrotatedCircle.X = (float)Math.Cos(rectAngle) * (circleCenter.X - rectCenter.X) - (float)Math.Sin(rectAngle) * (circleCenter.Y - rectCenter.Y) + rectCenter.X;
unrotatedCircle.Y = (float)Math.Sin(rectAngle) * (circleCenter.X - rectCenter.X) + (float)Math.Cos(rectAngle) * (circleCenter.Y - rectCenter.Y) + rectCenter.Y;
// Closest point in the rectangle to the center of circle rotated backwards(unrotated)
Vector2f closest = new Vector2f();
// Find the unrotated closest x point from center of unrotated circle
if (unrotatedCircle.X < rectPos.X)
closest.X = rectPos.X;
else if (unrotatedCircle.X > rectPos.X + rect.Size.X)
closest.X = rectPos.X + rect.Size.X;
else
closest.X = unrotatedCircle.X;
// Find the unrotated closest y point from center of unrotated circle
if (unrotatedCircle.Y < rectPos.Y)
closest.Y = rectPos.Y;
else if (unrotatedCircle.Y > rectPos.Y + rect.Size.Y)
closest.Y = rectPos.Y + rect.Size.Y;
else
closest.Y = unrotatedCircle.Y;
// Determine collision
return Distance(unrotatedCircle, closest) < circleRadius;
}
示例8: Hud
public Hud(GameBase state)
{
_state = state;
_selected = new Sprite(Assets.LoadTexture("wep_selected.png")).Center();
_statusBack = new RectangleShape(new Vector2f(BarWidth + Padding * 2, BarHeight * 2 + Padding * 3));
_statusBack.Position = new Vector2f(Padding, Padding);
_statusBack.FillColor = new Color(0, 0, 0);
_statusBack.OutlineThickness = 2;
_statusBack.OutlineColor = new Color(38, 38, 38);
_health = new RectangleShape(new Vector2f(BarWidth, BarHeight));
_health.Position = _statusBack.Position + new Vector2f(Padding, Padding);
_health.FillColor = new Color(0, 120, 0);
_healthText = new Text("", Program.Font, (int)(BarHeight - Padding));
_healthText.Position = _health.Position + new Vector2f(BarWidth / 2, BarHeight / 2);
_healthText.Color = new Color(225, 225, 225);
_energy = new RectangleShape(new Vector2f(BarWidth, BarHeight));
_energy.Position = _health.Position + new Vector2f(0, BarHeight + Padding);
_energy.FillColor = new Color(30, 30, 180);
_energyText = new Text("", Program.Font, (int)(BarHeight - Padding));
_energyText.Position = _energy.Position + new Vector2f(BarWidth / 2, BarHeight / 2);
_energyText.Color = new Color(225, 225, 225);
}
示例9: Draw
public override void Draw(RenderTarget target, Vector2f position)
{
_icon.Position = position;
target.Draw(_icon);
if (_amount == 0)
{
var darken = new RectangleShape(new Vector2f(Hud.IconSize - Hud.IconBorderTwice, Hud.IconSize - Hud.IconBorderTwice));
darken.Origin = new Vector2f(Hud.IconSizeHalf - Hud.IconBorder, Hud.IconSizeHalf - Hud.IconBorder);
darken.FillColor = new Color(0, 0, 0, 200);
darken.Position = position;
target.Draw(darken);
}
if (_time > 0)
{
var per = _time / BuildTime;
var box = new RectangleShape(new Vector2f(per * (Hud.IconSize - Hud.IconBorderTwice), 8));
box.FillColor = new Color(0, 180, 0, 128);
box.Position = position - new Vector2f(Hud.IconSizeHalf - Hud.IconBorder, Hud.IconSizeHalf - Hud.IconBorder);
target.Draw(box);
}
_amountText.DisplayedString = _amount.ToString("G");
_amountText.Position = position + new Vector2f(Hud.IconSizeHalf - Hud.Padding, Hud.IconSizeHalf - Hud.Padding);
var bounds = _amountText.GetLocalBounds();
_amountText.Origin = new Vector2f(bounds.Width + bounds.Left, bounds.Height + bounds.Top);
target.Draw(_amountText);
}
示例10: ClassSelectorComponent
public ClassSelectorComponent(Screen screen, Texture upArrowTexture, Texture downArrowTexture, Texture classSelectorTexture, List<Texture> classTextures, Vector2f position)
: base(screen)
{
_position = position;
_classTextures = classTextures;
_upArrow = new RectangleShape();
_upArrow.Position = position + new Vector2f(0f, -42f);
_upArrow.Origin = new Vector2f(8f, 8f);
_upArrow.Texture = upArrowTexture;
_upArrow.Size = new Vector2f(16f, 16f);
_classSelector = new RectangleShape();
_classSelector.Position = position;
_classSelector.Origin = new Vector2f(32f, 32f);
_classSelector.Texture = classSelectorTexture;
_classSelector.Size = new Vector2f(64f, 64f);
_classIcon = new RectangleShape();
_classIcon.Position = position;
_classIcon.Origin = new Vector2f(32f, 32f);
_classIcon.Texture = _classTextures[(int)_selectedClass];
_classIcon.Size = new Vector2f(64f, 64f);
_downArrow = new RectangleShape();
_downArrow.Position = position + new Vector2f(0f, 42f);
_downArrow.Origin = new Vector2f(8f, 8f);
_downArrow.Texture = downArrowTexture;
_downArrow.Size = new Vector2f(16f, 16f);
}
示例11: Menu
public Menu()
: base()
{
hoverCursor = Content.GetTexture("cursorHover.png");
defaultCursor = Content.GetTexture("cursorPointer.png");
currentCursor = defaultCursor;
char1 = new Animation(Content.GetTexture("idle.png"), 4, 0, 0, true);
char2 = new Animation(Content.GetTexture("char2_idle.png"), 4, 0, 0, true);
shader = new RenderStates(new Shader(null, "Content/bgPrlx.frag"));
rectConnect = new RectangleShape()
{
Size = new Vector2f(150, 30),
Position = new Vector2f(-25, 70)
};
rectIP = new RectangleShape()
{
Size = new Vector2f(150, 20),
Position = new Vector2f(-25, 40)
};
rectUsername = new RectangleShape()
{
Size = new Vector2f(150, 20),
Position = new Vector2f(-25, 10)
};
MainGame.window.TextEntered += TextEnteredEvent;
}
示例12: Ship
public Ship(Game game)
: base(game)
{
if (Game.GraphicsMode == Game.GRAPHICSMODE_NORMAL)
{
Model = Graphics.GetAnimatedSprite(game, "assets/sprites/ship.xml");
}
else
{
Model = Graphics.GetSprite("assets/sprites/blueprint/ship.png");
Model.Scale = new Vector2f(0.5f, 0.5f);
Model.Origin = new Vector2f(265, 244);
}
AddChild(Model);
Collision = new RectangleShape(new Vector2f(265, 105));
Collision.Position = new Vector2f(-132.5f, -52.5f);
SpeedMax = 50.0f + Math.Min(0.5f * Game.AIManager.Difficulty, 25.0f);
Acc = 200.0f;
AmountOfInfantry = Utils.RandomInt(12, 18);
SetAI(new ShipAI(Game));
}
示例13: Frame
public Frame(RectangleShape borderRect, Color fillColor)
{
BorderRect = borderRect;
BorderRect.FillColor = fillColor;
BoundingRect = borderRect.GetGlobalBounds();
}
示例14: BigLabeledButtonComponent
public BigLabeledButtonComponent(Screen screen, Texture buttonTexture, Vector2f position, string text, Color buttonColor, Action onClick)
: base(screen)
{
_buttonTexture = buttonTexture;
_position = position;
_buttonColor = buttonColor;
_selectedColor = new Color(
(byte)Math.Min(255, (int)_buttonColor.R + 50),
(byte)Math.Min(255, (int)_buttonColor.G + 50),
(byte)Math.Min(255, (int)_buttonColor.B + 50),
255);
_onClick = onClick;
_font = ResourceManager.getResource<Font>("immortal_font");
// Initialize button shape
_buttonShape = new RectangleShape();
_buttonShape.Texture = _buttonTexture;
_buttonShape.Position = position;
_buttonShape.Size = new Vector2f(_buttonShape.Texture.Size.X, _buttonShape.Texture.Size.Y);
_buttonShape.FillColor = _buttonColor;
// Initialize text
_firstLetter = new Text(text.Substring(0, 1), _font, 72);
_firstLetter.Position = position + new Vector2f(30, 0);
_firstLetter.Color = Color.White;
_firstLetterShadow = new Text(_firstLetter.DisplayedString, _font, 72);
_firstLetterShadow.Position = _firstLetter.Position + new Vector2f(3, 3);
_firstLetterShadow.Color = Color.Black;
_word = new Text(text.Substring(1, text.Length - 1), _font, 48);
_word.Position = _firstLetter.Position + new Vector2f(_firstLetter.GetLocalBounds().Width + 4, 13);
_word.Color = Color.White;
_wordShadow = new Text(_word.DisplayedString, _font, 48);
_wordShadow.Position = _word.Position + new Vector2f(3, 3);
_wordShadow.Color = Color.Black;
}
示例15: Tile
public Tile(Color color, Vector2f position, bool walkable, Vector2f size)
{
shape = new RectangleShape(size);
shape.FillColor = color;
shape.Position = position;
Walkable = walkable;
}