/// <summary> /// Builds a bullet entity. /// </summary> /// <param name="e">The entity to build.</param> /// <param name="args">[0] = ITransform; [1] = IVelocity; [2] = Sprite; [3] = Bullet </param> /// <returns></returns> public Entity BuildEntity(Entity e, params object[] args) { e.Group = "Bullets"; //Set up defaults IVelocity velocity = _DefaultVelocity; Sprite sprite = _DefaultSprite; ITransform transform = new Transform(Vector2.Zero, 0.0f); Bullet bullet = _DefaultBullet; //Check arguments. if (args != null) { if (args.Length > 0) transform = (args[0] as ITransform); if (args.Length > 1) velocity = (args[1] as IVelocity); if (args.Length > 2) sprite = (Sprite)args[2]; if (args.Length > 3) bullet = (Bullet)args[3]; } //Make the velocity proportional to the default velocity and the target rotation e.AddComponent<Particle>(new Particle(e, transform.Position, transform.Rotation, velocity.LinearVelocity * new Vector2((float)Math.Cos(transform.Rotation), (float)Math.Sin(transform.Rotation)), velocity.AngularVelocity)); e.AddComponent<Sprite>(sprite); e.AddComponent<Bullet>(bullet); return e; }
private Entity LoadModel(string model, string texture, Entity parent, bool isAdditive) { Entity entity = new Entity(model) .AddComponent(new Model(string.Format(PATHMODELS, model))) .AddComponent(new Transform3D()) .AddComponent(new ModelRenderer()); if (!isAdditive) { entity.AddComponent(new MaterialsMap(new BasicMaterial(string.Format(PATHMATERIAL, texture), typeof(CustomLayer) ))); } else { entity.AddComponent(new MaterialsMap(new BasicMaterial(string.Format(PATHMATERIAL, texture), DefaultLayers.Additive) { DiffuseColor = new Color(0.6f, 0.6f, 0.6f) })); } if (parent == null) { EntityManager.Add(entity); } else { parent.AddChild(entity); } return entity; }
/// <summary> /// /// </summary> /// <param name="e"></param> /// <param name="args">args[0] = bool bigStar</param> /// <returns></returns> public Entity BuildEntity(Entity e, params object[] args) { e.Group = "Stars"; e.Tag = "Star" + stars.ToString(); ++stars; #region Sprite if (args.Length == 0) { Vector2 loc = new Vector2(rbitch.Next(-ScreenHelper.Viewport.Width / 2, ScreenHelper.Viewport.Width / 2), rbitch.Next(-ScreenHelper.Viewport.Width / 2, ScreenHelper.Viewport.Width / 2)); Sprite s = new Sprite(spriteSheet, "redstar", 0f); s.FrameIndex = rbitch.Next(0, 3); s.Scale = (float)rbitch.NextDouble(); e.AddComponent<Sprite>(s); Animation a = e.AddComponent<Animation>(new Animation(AnimationType.Bounce, 5)); Particle p = e.AddComponent<Particle>(new Particle(e, ConvertUnits.ToSimUnits(loc), (float)Math.Atan2(loc.Y, loc.X), Vector2.Zero, (float)rbitch.Next(-3, 3) * 0.01f)); } else { Vector2 loc = Vector2.Zero; Sprite s = new Sprite(spriteSheet, "nebula", 0f); e.AddComponent<Sprite>(s); Particle p = e.AddComponent<Particle>(new Particle(e, ConvertUnits.ToSimUnits(loc), 0f, Vector2.Zero, 0f)); } #endregion Sprite return e; }
protected override void CreateScene() { //WaveServices.ScreenLayers.AddScene<GameScene>() // .Apply("FromMultiplayer"); var Map_Bitmaps = new Entity("Whole_Map_global"); RenderManager.BackgroundColor = Color.CornflowerBlue; Level_Classes.LevelManager Level1 = new Level_Classes.LevelManager(); var Mob_set = new Entity("juest_Player"); Map_Bitmaps.AddComponent(Level1); Map_Bitmaps.AddComponent(Level1.Level); EntityManager.Add(Level1.BaseMobEntity); EntityManager.Add(Level1.BaseTowerEntity); EntityManager.Add(Mob_set); EntityManager.Add(Level1.Level.Map_Bitmaps); EntityManager.Add(Map_Bitmaps); EntityManager.Add(Level1.TowersBar); EntityManager.Add(Level1.MonsterCounter); EntityManager.Add(Level1.MoneyCounter); EntityManager.Add(Level1.TimerCounter); EntityManager.Add(Level1.ScreenLayout); }
public Entity BuildEntity(Entity entity, params object[] args) { entity.AddComponent<TransformComponent>(); entity.AddComponent<PaddleComponent>(); entity.AddComponent<PlayerInputComponent>(); return entity; }
public Body(EntityWorld world, Entity e) : base(world, e) { //Add transform and velocity e.AddComponent<ITransform>(this); e.AddComponent<IVelocity>(this); e.AddComponent<IDamping>(this); }
public Entity BuildEntity(Entity entity, params object[] args) { entity.AddComponent<TransformComponent>(); entity.AddComponent<BallComponent>(); entity.AddComponent<BallMovementComponent>(); return entity; }
public void AllComponentsAreAddedWhenEntityIsAdded() { var entity0 = new Entity(new VariableCollection()); entity0.AddComponent<FakeComp>(); entity0.AddComponent<FakeBehaviour>(); collection.Add(entity0); }
public void CreatePointer(Entity myStartingNode, Vector2 myOffset,Texture2D myTexture) { SpriteComponent sprite = myStartingNode.GetDrawable("SpriteComponent") as SpriteComponent; pointerEntity = new Entity(1, State.ScreenState.WORLD_MAP); pointerEntity.AddComponent(new SpriteComponent(true, sprite.position + myOffset, myTexture)); pointerEntity.AddComponent(new PointerComponent(myOffset)); EntityManager.AddEntity(pointerEntity); }
public void CreateNode(string myLevelName, string myLevelID, Vector2 myPosition, List<string> myConnectedTo, NodeState myNodeState, Texture2D myTexture) { Entity nodeEntity = new Entity(5, State.ScreenState.WORLD_MAP); nodeEntity.AddComponent(new SpriteComponent(true, myPosition, myTexture)); nodeEntity.AddComponent(new ClickableComponent(myPosition,myTexture.Width,myTexture.Height)); nodeEntity.AddComponent(new NodeComponent(myLevelName, myLevelID, myNodeState, myConnectedTo)); AddNode(nodeEntity); EntityManager.AddEntity(nodeEntity); }
public static Entity MakeCard(int cardID, string statsName) { Entity ret = new Entity(); ret.AddComponent(new Position(0,0,1)); ret.AddComponent(new BoundingRectangle(-cardSize.x / 2, -cardSize.y / 2, cardSize.x / 2, cardSize.y / 2)); ret.AddComponent(new CardType(ret, cardID, statsName)); return ret; }
private Entity createBulletTemplate(Game game) { Entity bullet = new Entity(); //Component: Damage entities. DamageOnContactComponent damage = new DamageOnContactComponent(); damage.Damage = 1; bullet.AddComponent(damage); //Component: Has health. Used to simulate destruction on contact with an entity HealthComponent health = new HealthComponent(); health.Health = 1; bullet.AddComponent(health); //Component: Has a texture TextureComponent tex = new TextureComponent(); tex.Texture = game.Content.Load<Texture2D>("spaceArt/png/laserGreen"); tex.SourceRect = tex.Texture.Bounds; bullet.AddComponent(tex); //Component: Moves linearly LinearMovementComponent movement = new LinearMovementComponent(); bullet.AddComponent(movement); //Component: Moves at constant speed MoveSpeedComponent speed = new MoveSpeedComponent(); speed.MoveSpeed = 18; bullet.AddComponent(speed); //Component: Has a bounding box AABBComponent aabb = new AABBComponent(); aabb.Height = tex.SourceRect.Height; aabb.Width = tex.SourceRect.Width; bullet.AddComponent(aabb); //Component: Is rendered at a specific layer - just above the enemies RenderLayerComponent layer = new RenderLayerComponent(); layer.LayerID = 12; bullet.AddComponent(layer); //Component: Is destroyed when it ventures off the (right side of the) screen DestroyedWhenOffScreenComponent destroyer = new DestroyedWhenOffScreenComponent(); bullet.AddComponent(destroyer); //Component: Is destroyed when it runs out of health DestroyedWhenNoHealthComponent destroyer2 = new DestroyedWhenNoHealthComponent(); bullet.AddComponent(destroyer2); //Component: Plays a laser sound SoundEffectComponent soundEffect = new SoundEffectComponent(); soundEffect.effect = game.Content.Load<SoundEffect>("sound/39459__the-bizniss__laser"); bullet.AddComponent(soundEffect); return bullet; }
public Particle(Entity e, Vector2 position, float rotation, Vector2 linearVelocity, float angularVelocity) { e.AddComponent<ITransform>(this); e.AddComponent<IVelocity>(this); e.AddComponent<IDamping>(this); this.Position = position; this.Rotation = rotation; this.LinearVelocity = linearVelocity; this.AngularVelocity = angularVelocity; this.LinearDamping = 0.0f; this.AngularDamping = 0.0f; }
public static Entity LevelEnd(int x, int y) { var entity = new Entity(); entity.Transform.Origin = new Vector2f(TILE_SIZE / 2f, TILE_SIZE / 2f); entity.Transform.Position = new Vector2f(x * TILE_SIZE, y * TILE_SIZE); var hitbox = new FloatRect(0, 0, TILE_SIZE, TILE_SIZE); var colider = new ColiderComponent(hitbox); var end = new LevelEnd(); entity.AddComponent(colider); entity.AddComponent(end); return entity; }
/// <summary> /// /// </summary> /// <param name="e"></param> /// <param name="args">args[0] = Entity smasher, args[1] = Smasher loc</param> /// <returns></returns> public Entity BuildEntity(Entity e, params object[] args) { string spriteKey = "smasherball"; #region Body Body bitch = e.AddComponent<Body>(new Body(_World, e)); FixtureFactory.AttachEllipse(ConvertUnits.ToSimUnits(_SpriteSheet[spriteKey][0].Width / 2), ConvertUnits.ToSimUnits(_SpriteSheet[spriteKey][0].Height / 2), 20, 1f, bitch); Sprite s = new Sprite(_SpriteSheet, spriteKey, bitch, 1f, Color.White, 0.5f); e.AddComponent<Sprite>(s); bitch.BodyType = GameLibrary.Dependencies.Physics.Dynamics.BodyType.Dynamic; bitch.CollisionCategories = GameLibrary.Dependencies.Physics.Dynamics.Category.Cat2 | GameLibrary.Dependencies.Physics.Dynamics.Category.Cat1; bitch.CollidesWith = GameLibrary.Dependencies.Physics.Dynamics.Category.Cat6 | GameLibrary.Dependencies.Physics.Dynamics.Category.Cat1; bitch.OnCollision += LambdaComplex.BossCollision(); ++bitch.Mass; Entity smasher = (args[0] as Entity); float dist = ConvertUnits.ToSimUnits(20f); Vector2 pos = smasher.GetComponent<Body>().Position + new Vector2(0, dist); bitch.Position = pos; #endregion Body #region Animation if (s.Source.Count() > 1) e.AddComponent<Animation>(new Animation(AnimationType.Bounce, 10)); #endregion Animation #region Health e.AddComponent<Health>(new Health(1000000)).OnDeath += ent => { Vector2 poss = e.GetComponent<ITransform>().Position; _World.CreateEntityGroup("BigExplosion", "Explosions", poss, 10, e, e.GetComponent<IVelocity>().LinearVelocity); int splodeSound = rbitch.Next(1, 5); SoundManager.Play("Explosion" + splodeSound.ToString()); }; #endregion Health e.AddComponent<Origin>(new Origin(smasher)); e.Group = "Enemies"; e.Tag = "SmasherBall"; return e; }
public Entity BuildEntity(Entity e, params object[] args) { e.Tag = "Player"; Rectangle source = (Rectangle)args[1]; FixtureFactory.AttachCircle(ConvertUnits.ToSimUnits(source.Height/2),1f,e.AddComponent<Body>(new Body(_World, e))); e.GetComponent<Body>().BodyType = GameLibrary.Dependencies.Physics.Dynamics.BodyType.Dynamic; e.GetComponent<Body>().FixedRotation = true; e.AddComponent<Sprite>(new Sprite(args[0] as Texture2D, source, new Vector2(30,16),1f,Color.White,0.1f)); //Sprite return e; }
private Entity CreatePlayer(Vector2 position) { var player = new Entity(); player.Transform.Position = position; player.AddComponent<TestComponent>(); player.AddComponent<Rotator>(); var collider = player.AddComponent<Collider>(); collider.SetBounds(64, 64); var sprite = player.AddComponent<Sprite>(); sprite.Texture = Content.Load<Texture2D>("spaceship"); return player; }
public void Attach(Entity newEntity) { ControlledEntity = newEntity; ControlledEntity.AddComponent(ComponentFamily.Input, IoCManager.Resolve<IEntityManagerContainer>().EntityManager.ComponentFactory. GetComponent("KeyBindingInputComponent")); ControlledEntity.AddComponent(ComponentFamily.Mover, IoCManager.Resolve<IEntityManagerContainer>().EntityManager.ComponentFactory. GetComponent("PlayerInputMoverComponent")); ControlledEntity.AddComponent(ComponentFamily.Collider, IoCManager.Resolve<IEntityManagerContainer>().EntityManager.ComponentFactory. GetComponent("ColliderComponent")); ControlledEntity.GetComponent<TransformComponent>(ComponentFamily.Transform).OnMove += PlayerEntityMoved; }
public static Entity CreateCharacter(Character character, NetConnection connection) { var entity = new Entity(); var size = new Vector2(96, 96); var position = new Vector2(character.WorldX, character.WorldY); entity.AddComponent(new TransformComponent(position, size)); entity.AddComponent(new CharacterComponent(connection)); entity.AddComponent(new NameComponent(character.Name)); entity.AddComponent(new SkinComponent("HumanBase")); return entity; }
public static Entity Box(int x, int y) { var entity = new Entity(); var texture = ResourceManager.Instance.Get<Texture>("rock" + Randomizer.Generator.Next(1, 3) + ".png"); entity.Transform.Origin = new Vector2f(texture.Size.X / 2f, texture.Size.Y / 2f); entity.Transform.Position = new Vector2f(x * texture.Size.X, y * texture.Size.Y); var sprite = new SpriteComponent(texture); var hitbox = new FloatRect(0, 0, texture.Size.X, texture.Size.Y); var colider = new ColiderComponent(hitbox); var box = new Solid(); entity.AddComponent(sprite); entity.AddComponent(colider); entity.AddComponent(box); return entity; }
public static void AddTestComponent( Entity entity ) { OrbitComponent orbitComponent = new OrbitComponent( entity ); orbitComponent.Radius = 10f; orbitComponent.Period = 2000f; entity.AddComponent( orbitComponent ); }
/*DebugProc DebugCallbackInstance = DebugCallback; static void DebugCallback(DebugSource source, DebugType type, int id, DebugSeverity severity, int length, IntPtr message, IntPtr userParam) { string msg = Marshal.PtrToStringAnsi(message); Console.WriteLine("[GL] {0}; {1}; {2}; {3}; {4};", source, type, id, severity, msg); }*/ public override void Initialize(){ //ErrorOutput errorOutput = new ErrorOutput(); //Foundation foundation = new Foundation(errorOutput); //physEngine= new Physics(foundation, checkRuntimeFiles: true); //var sceneDesc = new SceneDesc (){Gravity = new System.Numerics.Vector3(0, -9.81f, 0) }; //physScene = physEngine.CreateScene (); var e = new Entity (); e.Rotation = new Vector3 ((float)Math.PI, 0f, 0f); var cam=e.AddComponent<Camera> (); cam.SetModelviewMatrix (); cam.SetProjectionMatrix (); e.name="Main Camera"; e.OnTransformChanged +=((sender, evnt) =>cam.SetModelviewMatrix()); Camera.main = cam; var eLight = new Entity (); eLight.name="Directional Light"; eLight.Position = cam.entityObject.Position; var light = eLight.AddComponent<Light> (); eLight.Instatiate (); if(OnSetupMatrices!=null) OnSetupMatrices (); base.Initialize (); }
public void Process(Entity toProcess, GameTime gameTime) { if (!IsApplicableTo(toProcess)) { return; } // TODO pass this in so it can be controlled Random rand = new Random(); RandomPositionOffsetComponent offset = (RandomPositionOffsetComponent)toProcess.components[typeof(RandomPositionOffsetComponent)]; int minX = (int)Math.Min(offset.Maximum.X, offset.Minimum.X); int maxX = (int)Math.Max(offset.Maximum.X, offset.Minimum.X); int minY = (int)Math.Min(offset.Maximum.Y, offset.Minimum.Y); int maxY = (int)Math.Max(offset.Maximum.Y, offset.Minimum.Y); int x = rand.Next(minX, maxX); int y = rand.Next(minY, maxY); PositionDeltaComponent delta = new PositionDeltaComponent(); if (toProcess.components.ContainsKey(typeof(PositionDeltaComponent))) { delta = (PositionDeltaComponent)toProcess.components[typeof(PositionDeltaComponent)]; delta.Delta += new Vector2(x, y); } else { delta.Delta = new Vector2(x, y); toProcess.AddComponent(delta); } toProcess.RemoveComponent(offset); }
// add doors to the rooms public void addDoors() { for (int x = 0; x < floor.Length; x++) { for (int y = 0; y < floor[x].Length; y++) { if (floor[x][y] == 1) { // door faces: (N or S = 1), (W = 2), (E = 3) int dir = isValidDoorPlacement(x, y); if (dir == 1) { Entity door = new Entity(); door.AddComponent(new Animation(SpriteDict["door_wood_ns"], 2, false, SpriteEffects.None)); door.AddAction(new NextFrameOfAnimation()); door.AddComponent(new Position(x, y)); door.AddComponent(new Openable()); door.AddAction(new ChangeStateOfOpenable()); manager.addDoor(door, new Vector2(x, y)); } else if (dir == 2) { Entity door = new Entity(); door.AddComponent(new Animation(SpriteDict["door_wood_we"], 2, false, SpriteEffects.FlipHorizontally)); door.AddAction(new NextFrameOfAnimation()); door.AddComponent(new Position(x, y)); door.AddComponent(new Openable()); door.AddAction(new ChangeStateOfOpenable()); manager.addDoor(door, new Vector2(x, y)); } else if (dir == 3) { Entity door = new Entity(); door.AddComponent(new Animation(SpriteDict["door_wood_we"], 2, false, SpriteEffects.None)); door.AddAction(new NextFrameOfAnimation()); door.AddComponent(new Position(x, y)); door.AddComponent(new Openable()); door.AddAction(new ChangeStateOfOpenable()); manager.addDoor(door, new Vector2(x, y)); } } } } }
public static Entity Camera(Entity target) { var entity = new Entity(); var camera = new Camera(); camera.Target = target; entity.AddComponent(camera); return entity; }
protected override void CreateScene() { Entity x = new Entity("ww"); test ob = new test(); x.AddComponent(ob); EntityManager.Add(ob.Colors); EntityManager.Add(x); }
public Inventory(World world) { _inventoryOverlay = world.EntitySystem.CreateEntity(true); _inventoryOverlay.AddComponent(new WorldUiOverlayEntityComponent(_inventoryOverlay, 512, 512)); _inventoryOverlay.Position = new Vector3(-1.0f, 0.0f, -5.0f); _inventoryOverlay.IsActive = false; }
public static Entity MakeSystem(int tileX, int tileY) { Entity ret = new Entity(); Vector2f offset = (systemSize + systemSpacing) * 0.5f; /* system at (0,0) should be place on (0,0) */ float x = (systemSpacing.x + systemSize.x) * ((float)tileX + 0.5f); float y = (systemSpacing.y + systemSize.y) * ((float)tileY - 0.5f); Vector2f position = offset + new Vector2f(-x, y); ret.AddComponent(new BoundingRectangle(-systemSize.x / 2, -systemSize.y / 2, systemSize.x / 2, systemSize.y / 2)); ret.AddComponent(new SystemType(ret ,tileX, tileY)); ret.AddComponent(new Position(position.x,position.y,0)); return ret; }
public override void Process(Entity e) { if (!e.HasComponent<Animation>()) return; Sprite sprite = e.GetComponent<Sprite>(); Animation anim = e.GetComponent<Animation>(); if (anim.Type != AnimationType.None) { anim._Tick += world.Delta; if (anim._Tick >= anim.FrameRate) { anim._Tick -= anim.FrameRate; switch (anim.Type) { case AnimationType.Loop: sprite.FrameIndex++; //Console.WriteLine("Animation happened"); break; case AnimationType.ReverseLoop: sprite.FrameIndex--; break; case AnimationType.Increment: sprite.FrameIndex++; anim.Type = AnimationType.None; break; case AnimationType.Decrement: sprite.FrameIndex--; anim.Type = AnimationType.None; break; case AnimationType.Bounce: sprite.FrameIndex += anim.FrameInc; if (sprite.FrameIndex == sprite.Source.Count() - 1) anim.FrameInc = -1; if (sprite.FrameIndex == 0) anim.FrameInc = 1; break; case AnimationType.Once: if (sprite.FrameIndex < sprite.Source.Count() - 1) sprite.FrameIndex++; else anim.Type = AnimationType.None; break; } e.RemoveComponent<Sprite>(e.GetComponent<Sprite>()); e.AddComponent<Sprite>(sprite); } } }
public void TestCoroutines() { var entity = new Entity(new VariableCollection()); var comp = entity.AddComponent<FakeBehaviour>(); comp.StartCoroutine(Coroutine()); comp.StepCoroutines(); Assert.IsTrue(corutineCalled); }