public override void Update() { GetNodes(); var interfaceTargets = new Dictionary <Name, string>(); foreach (InterfaceNode target in interfaceNodes) { interfaceTargets.Add(target.Entity.Name, target.Interface.Text); } foreach (RenderNode target in renderNodes) { target.Display.DisplayObject.Position = new SFML.System.Vector2f(target.Position.X, target.Position.Y); target.Display.DisplayObject.Rotation = target.Position.Rotation; if (interfaceTargets.ContainsKey(target.Entity.Name)) { ((Text)target.Display.DisplayObject).DisplayedString = interfaceTargets[target.Entity.Name]; } CollisionComponent collision = (CollisionComponent)target.Entity.GetComponent("CollisionComponent"); if (collision != null) { Shape shape = (Shape)(target.Display.DisplayObject); if (target.Entity.Name.BaseName == BaseNames.Gem || target.Entity.Name.BaseName == BaseNames.Destroyer ) { target.Display.DisplayObject.Position = new SFML.System.Vector2f( target.Position.X + shape.GetLocalBounds().Width / 2.0f, target.Position.Y + shape.GetLocalBounds().Height / 2.0f ); if (engine.CheckClicked(target.Entity.Name)) { shape.OutlineColor = Colors.GemSelectedOutlineColor; } else { shape.OutlineColor = Colors.GemOutlineColor; } } collision.BoundingBox = shape.GetGlobalBounds(); } engine.Renderer.Draw(target.Display.DisplayObject); } }
public static Entity CreateGem( GemView gem, int x, int y ) { var gemEntity = new Entity(Registrator.GenerateName(BaseNames.Gem)); var gDisplayComponent = new DisplayComponent(); gem.GemShape.Origin = new SFML.System.Vector2f( gem.GemShape.GetLocalBounds().Width / 2.0f, gem.GemShape.GetLocalBounds().Height / 2.0f ); gDisplayComponent.DisplayObject = gem.GemShape; var gPositionComponent = new PositionComponent(); gPositionComponent.X = x; gPositionComponent.Y = y; var gCollisionComponent = new CollisionComponent(); gCollisionComponent.BoundingBox = new FloatRect(x, y, Layout.GemSize, Layout.GemSize); var gAnimationComponent = new AnimationComponent(); gAnimationComponent.X = x; gAnimationComponent.Y = y; gAnimationComponent.Speed = Engine.GameSpeed; gAnimationComponent.Scale = gDisplayComponent.DisplayObject.Scale; var gGemComponent = new GemComponent(); gGemComponent.GemType = gem.GemType; gGemComponent.GemSubType = gem.GemSubType; gemEntity.AddComponent(gDisplayComponent); gemEntity.AddComponent(gPositionComponent); gemEntity.AddComponent(gCollisionComponent); gemEntity.AddComponent(gAnimationComponent); gemEntity.AddComponent(gGemComponent); return(gemEntity); }
public static Entity CreateBackground( int width, int height, int x, int y, Color color, bool isGlobalBackground, int outline = 0, Color outlineColor = new Color(), Name name = null ) { var background = new Entity(name == null ? Registrator.GenerateName(BaseNames.Background) : name); var bgDisplayComponent = new DisplayComponent(); var bgShape = new RectangleShape(new SFML.System.Vector2f(width, height)); bgShape.FillColor = color; if (outline > 0) { bgShape.OutlineThickness = outline; bgShape.OutlineColor = outlineColor; } bgDisplayComponent.DisplayObject = bgShape; var bgPositionComponent = new PositionComponent(); bgPositionComponent.X = x; bgPositionComponent.Y = y; background.AddComponent(bgDisplayComponent); background.AddComponent(bgPositionComponent); if (!isGlobalBackground) { var bgCollisionComponent = new CollisionComponent(); bgCollisionComponent.BoundingBox = new FloatRect(x, y, width, height); background.AddComponent(bgCollisionComponent); } return(background); }
public static List <Entity> CreateChooseFrame( int width, int height, int x, int y, int textX, int textY, string textString, int labelX, int labelY, string labelText, int leftX, int leftY, int rightX, int rightY, Name bgName = null, Name textName = null, Name leftName = null, Name rightName = null ) { var chooseFrame = new List <Entity>(); var textLabel = new Entity(Registrator.GenerateName(BaseNames.Text)); var tlDisplayComponent = new DisplayComponent(); var tlText = new Text(labelText, new Font(Assets.Font), (uint)Layout.FontSize); tlDisplayComponent.DisplayObject = tlText; var tlPositionComponent = new PositionComponent(); tlPositionComponent.X = labelX; tlPositionComponent.Y = labelY; textLabel.AddComponent(tlDisplayComponent); textLabel.AddComponent(tlPositionComponent); var textFrame = CreateTextFrame(width, height, x, y, textX, textY, textString, bgName, textName); var optionLeftButton = new Entity(leftName); var lDisplayComponent = new DisplayComponent(); var lShape = new CircleShape(Layout.OptionEntryButtonSize, 3); lShape.Origin = new SFML.System.Vector2f( lShape.GetLocalBounds().Width / 2, lShape.GetLocalBounds().Height / 2 ); lShape.FillColor = Color.Transparent; lShape.OutlineThickness = 3; lShape.OutlineColor = Color.White; lDisplayComponent.DisplayObject = lShape; var lPositionComponent = new PositionComponent(); lPositionComponent.X = leftX; lPositionComponent.Y = leftY; lPositionComponent.Rotation = -90; var lCollisionComponent = new CollisionComponent(); lCollisionComponent.BoundingBox = new FloatRect( leftX, leftY, Layout.OptionEntryButtonSize, Layout.OptionEntryButtonSize ); optionLeftButton.AddComponent(lDisplayComponent); optionLeftButton.AddComponent(lPositionComponent); optionLeftButton.AddComponent(lCollisionComponent); var optionRightButton = new Entity(rightName); var rDisplayComponent = new DisplayComponent(); var rShape = new CircleShape(Layout.OptionEntryButtonSize, 3); rShape.Origin = new SFML.System.Vector2f( rShape.GetLocalBounds().Width / 2, rShape.GetLocalBounds().Height / 2 ); rShape.FillColor = Color.Transparent; rShape.OutlineThickness = 3; rShape.OutlineColor = Color.White; rDisplayComponent.DisplayObject = rShape; var rPositionComponent = new PositionComponent(); rPositionComponent.X = rightX; rPositionComponent.Y = rightY; rPositionComponent.Rotation = 90; var rCollisionComponent = new CollisionComponent(); rCollisionComponent.BoundingBox = new FloatRect( rightX, rightY, Layout.OptionEntryButtonSize, Layout.OptionEntryButtonSize ); optionRightButton.AddComponent(rDisplayComponent); optionRightButton.AddComponent(rPositionComponent); optionRightButton.AddComponent(rCollisionComponent); chooseFrame.Add(textLabel); chooseFrame.Add(optionLeftButton); chooseFrame.Add(optionRightButton); chooseFrame.AddRange(textFrame); return(chooseFrame); }