protected override void Init() { // Create a character controller that allows us to walk around. character = new CharacterController(camera, ContainingWorld); // For now, attach this entity to a simple sphere physics object. character.Body.SetTransformation(mat4.Translate(new vec3(0, 10f, 0))); thisEntity.AddComponent(new PhysicsComponent( character.Body, mat4.Translate(new vec3(0, character.EyeOffset, 0)))); // Add Torso mesh. thisEntity.AddComponent(rcTorsoShadow = new RenderComponent(new MeshRenderJob(Renderer.Shadow.Mesh, Resources.UseMaterial("::Shadow", UpvoidMiner.ModDomain), Resources.UseMesh("Miner/Torso", UpvoidMiner.ModDomain), mat4.Identity), torsoTransform, true)); /*psTorsoSteam = CpuParticleSystem.Create2D(new vec3(), ContainingWorld); * LocalScript.ParticleEntity.AddComponent(new CpuParticleComponent(psTorsoSteam, mat4.Identity));*/ // Add camera component. thisEntity.AddComponent(cameraComponent = new CameraComponent(camera, mat4.Identity)); // This digging controller will perform digging and handle digging constraints for us. digging = new DiggingController(ContainingWorld, this); Gui = new PlayerGui(this); AddTriggerSlot("AddItem"); Inventory.InitCraftingRules(); generateInitialItems(); }
private static void CreatePlayer() { int entityId = EntitySystem.GetInstance().CreateEntity(); //Initialisation du component de physique PhysicsComponent physics = new PhysicsComponent(); float xDirection = (float)rnd.Next(250, 750) / 1000; float yDirection = 1f - xDirection; physics.xPosition = rnd.Next(Console.WindowLeft, Console.WindowWidth); physics.yPosition = rnd.Next(Console.WindowTop, Console.WindowHeight); physics.xDirection = rnd.Next(0, 2) == 1 ? xDirection : -xDirection; physics.yDirection = rnd.Next(0, 2) == 1 ? yDirection : -yDirection; physics.speed = CHARACTER_SPEED; EntitySystem.GetInstance().AddComponent(entityId, physics); //Initialisation du component de rendu RenderComponent render = new RenderComponent(); render.character = currentChar; EntitySystem.GetInstance().AddComponent(entityId, render); currentChar++; }
public EntityPlayer(Texture2D playerTexture, int spriteId, Texture2D shadowTexture, int shadowOffset) : base() { PositionComponent = new PositionComponent(new Vector2(200, 200)); RenderComponent = new RenderComponent(playerTexture, new Vector2(0, spriteId), shadowTexture, shadowOffset, Color.White); ShooterComponent = new ShooterComponent(); ControlComponent = new ControlComponent(this); }
public void UpdateComponents() { Console.Clear(); foreach (Entity ent in EntitySystem.GetInstance().entities) { PhysicsComponent physics = null; RenderComponent render = null; for (int i = 0; i < ent.components.Count; i++) { if (typeof(PhysicsComponent) == ent.components.ElementAt(i).GetType()) { physics = (PhysicsComponent)ent.components.ElementAt(i); } if (typeof(RenderComponent) == ent.components.ElementAt(i).GetType()) { render = (RenderComponent)ent.components.ElementAt(i); } } //On peut dessiner un objet seulement s'il possède le component de physique et de rendu if (render != null && physics != null) { //Afficher le caracter à la bonne position Console.SetCursorPosition( (int)physics.xPosition, (int)physics.yPosition); Console.Write(render.character); } } }
void RenderText(string text, TextComponent textComponent, RenderComponent renderComponent) { Font font = textComponent.Font; float x = renderComponent.DisplayX; float y = renderComponent.DisplayY; if (textComponent.Align == Alignment.Right) { Vector2 size = textComponent.Font.MeasureString(text); x -= size.X; } if (textComponent.Align == Alignment.Center) { Vector2 size = textComponent.Font.MeasureString(text); x -= size.X / 2; } if (textComponent.Border > 0f) { Color borderAlpha = new Color(0f, 0f, 0f, textComponent.Border); float width = 2f; font.Render(text, x + width, y, borderAlpha); font.Render(text, x - width, y, borderAlpha); font.Render(text, x, y + width, borderAlpha); font.Render(text, x, y - width, borderAlpha); } font.Render(text, x, y, textComponent.Color); }
public override void Initialize() { base.Initialize(); renderComponent = Entity.GetComponent<RenderComponent>(); renderComponent.IsCustomRendered = true; renderComponent.Render += HandleRender; }
private void InitComponent(EnemyData data, EnemyType type, Sprite sprite, ITrajectoryData trajectoryData) { //更新飞机图片 Renderer = gameObject.AddOrGet <RenderComponent>(); Renderer.Init(); Renderer.SetSprite(sprite); //路径初始化 _path = new PathMgr(); _path.Init(transform, data, trajectoryData); gameObject.AddOrGet <CameraMove>().enabled = _path.NeedMoveWithCamera(); gameObject.AddOrGet <AutoDespawnComponent>(); gameObject.AddOrGet <EnemyTypeComponent>().Init(type); var lifeC = gameObject.AddOrGet <LifeComponent>(); lifeC.Init(data.life); gameObject.AddOrGet <EnemyBehaviour>().Init(data); _moveComponent = gameObject.AddOrGet <MoveComponent>(); _moveComponent.Init((float)data.speed); gameObject.AddOrGet <ColliderComponent>(); gameObject.AddOrGet <PlaneCollideMsgComponent>(); var bulletMgr = transform.Find("BulletRoot").AddOrGet <EnemyBulletMgr>(); bulletMgr.Init(data); if (_lifeView == null) { var lifeGo = LoadMgr.Single.LoadPrefabAndInstantiate(Paths.PREFAB_ENEMY_LIFE, transform); _lifeView = lifeGo.AddComponent <EnemyLifeView>(); } _lifeView.Init(); }
public void Render(Graphics g) { RenderComponent renderComponent = ((RenderComponent)GetComponent(typeof(RenderComponent))); //g.DrawImage(renderComponent.sprite, (float)renderComponent.view.x, (float)renderComponent.view.y); g.DrawImage(renderComponent.sprite, (float)renderComponent.view.x, (float)renderComponent.view.y, (float)renderComponent.sprite.Width, (float)renderComponent.sprite.Height); }
public override void OnAwake() { base.OnAwake(); m_renderComponent = gameObject.GetComponent <RenderComponent>(); chargeTimeMax = 0.5f; colliderObject = null; }
private void SetupVisual() { var renderComponent = Object.Components.FirstOrDefault( c => c.ComponentType == ReplicaComponentsId.RenderComponent ); if (renderComponent == default) { return; } try { var managed = new RenderComponent(renderComponent.ComponentRow); var nifPath = Path.Combine(FdbEditor.RecurseFolder, managed.render_asset.Replace('\\', '/').ToLower()); Debug.Log(nifPath); if (nifPath.EndsWith("kfm")) { return; } var nifRuntime = NifRuntime.FromFile(nifPath, out var gm); } catch (Exception e) { Debug.LogError(e); } }
public static bool ManagePixelCollisionsBunker(RenderComponent renderComponent, Box rectToColor, CollisionNode missileCollisionNode) { Color actualColor; MissileAbs missileEntity = missileCollisionNode.HitBoxComponent.entity as MissileAbs; for (int i = (int)rectToColor.X; i < (int)rectToColor.XPlusWidth; i++) { for (int j = (int)rectToColor.Y; j < (int)rectToColor.YPlusHeight; j++) { actualColor = ((Bitmap)renderComponent.sprite).GetPixel(i, j); if (missileEntity.NbPixelToDestroy > 0) { if (actualColor.A == 255 && actualColor.R == 0 && actualColor.B == 0 && actualColor.G == 0) { ((Bitmap)renderComponent.sprite).SetPixel(i, j, Color.FromArgb(0, 0, 0, 0)); missileEntity.NbPixelToDestroy--; } } else { return(true); } } } return(false); }
public TriggerEntity(string tileName, Vector2 position, Tags type, bool isAnimation = false) : base() { this._isAnimation = isAnimation; if (isAnimation) { animationComponent = new AnimationComponent(tileName, this, new int[] { 6 }, new int[] { 60 }, new string[] { tileName }, 32 , 32 , new Vector2(1, 1)); animationComponent.LoadContent(); } else { renderComponent = new RenderComponent(tileName, this); this.renderComponent.LoadContent(); } this.Position = position; Width = 32; Height = 32; _isAnimation = isAnimation; _alreadyTriggered = false; this.CollisionComponent = new BoxColliderComponent(this, Width, Height, Layers.Static, type); }
public void SetupBackgroundTiles(int width, int height) { for (var x = 0; x < width; x++) { for (var y = 0; y < height; y++) { var entityId3 = EntityManager.GetEntityManager().NewEntity(); //var renderComponent3 = new RenderComponentBuilder() // .Position(x * 1000, y * 1000, 1) // .Dimensions(1000, 1000).Build(); // ComponentManager.Instance.AddComponentToEntity(renderComponent3, entityId3); var renderComponent3 = new RenderComponent() { DimensionsComponent = new DimensionsComponent() { Height = 1000, Width = 1000 } }; var positionComponent3 = new PositionComponent() { Position = new Vector2(x * 1000, y * 1000), ZIndex = 1 }; var spriteComponent3 = new SpriteComponent() { SpriteName = "Grass" }; ComponentManager.Instance.AddComponentToEntity(positionComponent3, entityId3); ComponentManager.Instance.AddComponentToEntity(renderComponent3, entityId3); ComponentManager.Instance.AddComponentToEntity(spriteComponent3, entityId3); } } }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here startMenu = new StartMenu(this); firstPlayer = new PlayerInput(this); firstPlayer.TESTBINDING(); EntityManager = new EntityManager(this); SystemManager = new SystemManager(this); ComponentManager = new ComponentManager(this); TestSelect = new SelectionRectange(this); targetSelection = new TargetSelection(this); RenderSystem = new RenderSystem(this); RenderComponent = new RenderComponent(this); testWorld = new TestWorld(this); EntityCleaner = new DeadParrotCollector(this); //DEBUG mouseClick = Content.Load <Texture2D>(@"Graphics\Mouse0"); mouseClickRectangle = new Rectangle((int)(Mouse.GetState().X) - mouseClick.Width / 2, (int)(Mouse.GetState().Y) - mouseClick.Height / 2, mouseClick.Width, mouseClick.Height); base.Initialize(); }
public async Task AddToastAsync <TComponent>(string title, string subTitle, RenderComponent <TComponent> component, ToastOptions options = null) where TComponent : IComponent { var toast = new ToastModel(title, subTitle, component?.Contents, options); toasts.Add(toast); await Changed(); }
public Task <ModalResult> ShowAsync(string title, RenderComponent component, ModalOptions modalOptions = null) { modalModel = new ModalModel(component, title, modalOptions); modals.Push(modalModel); OnChanged?.Invoke(); return(modalModel.Task); }
public Entity Clone() { Entity entity = new Entity(); foreach (Entity child in Children) { entity.AddChild(child.Clone()); } entity.X = X; entity.Y = Y; entity.Active = Active; entity.Visible = Visible; if (UpdateComponent != null) { entity.AddUpdateComponent((IUpdateComponent)UpdateComponent.Clone()); } if (RenderComponent != null) { entity.AddRenderComponent((IRenderComponent)RenderComponent.Clone()); } foreach (KeyValuePair <Type, Component> entry in ComponentList) { entity.AddComponent(entry.Value.Clone()); } foreach (KeyValuePair <string, UpdateChain> chain in UpdateChains) { foreach (IUpdateComponent component in chain.Value) { entity.AddChainComponent(chain.Key, (IUpdateComponent)component.Clone()); } } return(entity); }
public Task <ModalResult> ShowAsync <TComponent>(string title, RenderComponent <TComponent> component, ModalOptions modalOptions = null) where TComponent : IComponent { modalModel = new ModalModel(component.Contents, title, modalOptions); modals.Push(modalModel); OnChanged?.Invoke(); return(modalModel.Task); }
public static void MakePlayer(Scene scene, float x, float y) { Entity entity = scene.NewEntity(); RenderComponent renderComponent = new RenderComponent(20, 0, true); entity.AddComponent(renderComponent); SpriteComponent sc = new SpriteComponent(scene.GS, "player"); /* * Frame frame = sc.Sprite.DefaultAnimationObject.Frames[0]; * sc.Width = frame.Width / 2; * sc.Height = frame.Height / 2; * sc.Stretched = true; */ entity.AddComponent(sc); entity.AddComponent(new PlayerComponent() { Lives = 5, Bombs = 2 }); BodyComponent body = new BodyComponent(x, y); body.Pen = new Vector4(0, 0, 1, 1); entity.AddComponent(body); entity.Enable(); entity.AddToGroup("player"); entity = scene.NewEntity(); entity.AddComponent(new RenderComponent(2, 0, true) { Leader = renderComponent }); entity.AddComponent(new SpriteComponent(scene.GS, "s_hitbox")); entity.Enable(); entity.AddToGroup("hitbox"); }
public EndTile() { render = new RenderComponent("", "", "Level/signExit"); var dimensions = render.GetDimensions(); this.CollisionRectangle = new Rectangle((int)Position.X, (int)Position.Y, (int)dimensions.X, (int)dimensions.Y); }
public void SetupBackground() { var entityId3 = EntityManager.GetEntityManager().NewEntity(); //var renderComponent3 = new RenderComponentBuilder() // .Position(0, 0, 1) // .Dimensions(1000, 1000).Build(); //ComponentManager.Instance.AddComponentToEntity(renderComponent3, entityId3); var renderComponent3 = new RenderComponent() { DimensionsComponent = new DimensionsComponent() { Height = 1000, Width = 1000 } }; var positionComponent3 = new PositionComponent() { Position = new Vector2(0, 0), ZIndex = 1 }; var spriteComponent3 = new SpriteComponent() { SpriteName = "Grass" }; ComponentManager.Instance.AddComponentToEntity(spriteComponent3, entityId3); ComponentManager.Instance.AddComponentToEntity(positionComponent3, entityId3); ComponentManager.Instance.AddComponentToEntity(renderComponent3, entityId3); }
public void SetExPlore(Entity entity, CinemachineVirtualCamera virtualCamera) { RenderComponent rc = entity.GetComponent <RenderComponent>(); virtualCamera.Follow = rc.GameObject.transform; virtualCamera.LookAt = rc.GameObject.transform; }
/// <summary> /// Assigns the values and settings as specified by this initializer, to the input entity /// </summary> public void ApplyToPlayer(Entity player) { if (player == null) { return; } RenderComponent renderer = player.Get <RenderComponent>(); renderer.displayName = name; // for each stat, assign the value from the initializers component, to the player entities component AttributesComponent playerAttr = player.Get <AttributesComponent>(); foreach (FieldInfo attrField in attributes.AttributeFields()) { attrField.SetValue(playerAttr, attrField.GetValue(attributes)); } // give the player all of the skills and items they selected var playerSkills = player.Get <SkillUserComponent>(); foreach (Entity e in startingSkills) { playerSkills.AddNewSkill(e); } foreach (Entity e in startingItems) { player.FireEvent(new EAquireItem() { item = e }); } }
// This method will render all the entities that are associated // with the render component. 1. we use our Component manager instance // to get all the entities with RenderComponent and then we render them. // we use the spritebach to draw all the entities. private void DrawEntities(SpriteBatch spriteBatch) { Dictionary <int, IComponent> renderableEntities = ComponentManager.Instance.GetEntitiesWithComponent(typeof(RenderComponent)); foreach (var entity in renderableEntities) { PositionComponent positionComponent = ComponentManager.GetEntityComponentOrDefault <PositionComponent>(entity.Key); if (positionComponent == null) { continue; } SpriteComponent sprite = ComponentManager.GetEntityComponentOrDefault <SpriteComponent>(entity.Key); if (sprite == null) { continue; } RenderComponent renderComponent = entity.Value as RenderComponent; RenderOffsetComponent offsetComponent = ComponentManager.GetEntityComponentOrDefault <RenderOffsetComponent>(entity.Key); MoveComponent moveComponent = ComponentManager.GetEntityComponentOrDefault <MoveComponent>(entity.Key); int zIndex = positionComponent.ZIndex; Vector2 offset = offsetComponent?.Offset ?? default(Vector2); float angle = moveComponent?.Direction ?? 0; Rectangle destinationRectangle = new Rectangle( (int)(positionComponent.Position.X + offset.X), (int)(positionComponent.Position.Y + offset.Y), (int)(RenderComponentHelper.GetDimensions(renderComponent).Width *sprite.Scale), (int)(RenderComponentHelper.GetDimensions(renderComponent).Height *sprite.Scale) ); // render the sprite only if it's visible (sourceRectangle) intersects // with the viewport. KeyValuePair <int, IComponent> camera = ComponentManager.Instance.GetEntitiesWithComponent(typeof(CameraViewComponent)).First(); CameraViewComponent cameraViewComponent = camera.Value as CameraViewComponent; if (cameraViewComponent.View.Intersects(destinationRectangle)) { var spriteCrop = new Rectangle( sprite.Position, new Point(sprite.TileWidth, sprite.TileHeight) ); spriteBatch.Draw( texture: sprite.Sprite, destinationRectangle: destinationRectangle, sourceRectangle: spriteCrop, color: Color.White * sprite.Alpha, rotation: (float)angle, origin: new Vector2(x: sprite.TileWidth / 2, y: sprite.TileHeight / 2), effects: SpriteEffects.None, layerDepth: (float)zIndex / SystemConstants.LayerDepthMaxLimit //layerDepth is a float between 0-1, as a result ZIndex will have a dividend (i.e. limit) ); } } }
private async Task OpenComponentModal() { if (ComponentType != null) { var component = new RenderComponent <TypeBrowser>().Set(e => e.Type, ComponentType); var result = await modalService.ShowAsync("Component API", component, new ModalOptions { Size = ModalSize.Large }); } }
public WanderingEnemy(Vector2 position, int wanderDistance, int wanderSpeed) { render = new RenderComponent("", "", "Enemies/snailWalk1"); this.Position = position; UpdateRect(); this.wanderDistance = wanderDistance; Velocity = new Vector2(wanderSpeed, 0); }
public void RemoveComponent(RenderComponent cmp) { components.Remove(cmp); if (cmp != null) { cmp.renderManager = null; } }
public async Task <bool> ShowDialogAsync(DialogOptions options) { var component = new RenderComponent <DialogModal>(). Set(e => e.Options, options); var result = await ShowAsync("", component, new ModalOptions { Size = ModalSize.Small, ShowHeader = false, StatusColor = options.StatusColor }); return(!result.Cancelled); }
private BaseEntity GetDoubleJump() { var doubleJump1 = new BaseEntity(Scene.SceneManager, "DoubleJump1", 1660, 480 - 80 - 64); var doubleJump1render = new RenderComponent(doubleJump1, "atpSolid", 32, 32); var doubleJump1physics = new PhysicsComponent(doubleJump1, 32, 32); return(doubleJump1); }
public ChainEntity(Vector2 position, float angle) { this.Position = position; this.MyrenderComponent = new RenderComponent("Chain", this); this.MyrenderComponent.Scale = new Vector2(1.0f, 1.0f); //this.MyrenderComponent.Rotation = angle; this.MyrenderComponent.LoadContent(); }
public SpawnSystem(Game1 myGame) { SpawnLocation = new List <Vector2>(); EntityManager = myGame.EntityManager; RenderComponent = myGame.RenderComponent; mouse = Mouse.GetState(); Subscribtions = new List <int>(); }
/// <summary> /// Renders a renderable components and applies its required renderstate if necessary. /// </summary> void Render(ICamera camera, RenderComponent renderable) { RenderState desiredState = renderable.RenderState; if (desiredState != null) { if (_currentlyEnabledState != desiredState) { if (_currentlyEnabledState != null) { _currentlyEnabledState(false); } desiredState(true); _currentlyEnabledState = desiredState; } } renderable.Render(camera); }
public static RenderComponent CreateComponent() { RenderComponent component = new RenderComponent(); return component; }
public void RenderEntity(Entity entity, RenderComponent renderComponent) { if (!renderComponent.IsVisible) { return; } if (renderComponent.IsCustomRendered) { renderComponent.HandleOnRender( new RenderEventArgs { Renderer = this, GraphicsDevice = graphicsDevice, BasicEffect = basicEffect } ); } else { var positionComponent = entity.GetComponent<PositionComponent>(); var sizeComponent = entity.GetComponent<SizeComponent>(); var orientationComponent = entity.GetComponent<OrientationComponent>(); var boundsComponent = entity.GetComponent<BoundsComponent>(); var colorComponent = entity.GetComponent<ColorComponent>(); var commandQueueComponent = entity.GetComponentOrNull<CommandQueueComponent>(); var zNudge = Vector3.Zero; if (sizeComponent.PositioningMode == VerticalPositioningMode.PositionBottom) { zNudge.Z = 0.5f; } var worldMatrix = Matrix.Translation(zNudge) * Matrix.Scaling(sizeComponent.Size) * Matrix.RotationQuaternion(orientationComponent.Orientation) * Matrix.Translation(positionComponent.Position); DrawCube(worldMatrix, colorComponent.Color, false); DrawOrientedBoundingBox(boundsComponent.Bounds, new Vector4(1, 1, 1, 1)); if (commandQueueComponent != null) { var pathingCommand = commandQueueComponent.CurrentCommand as PathingCommand; if (pathingCommand != null) { var points = pathingCommand.Path.Points; for (var i = 0 ; i < points.Length - 1; i++) { DrawDebugLine(points[i], points[i + 1], Color.Cyan); } } } } }