public void TestSpawnWithPositionAndRotationAndPriorityAndLifetime() { GameObject gameObject = new GameObject(); Assert.IsNotNull(gameObject); gameObject.name = "LifetimeObject"; gameObject.AddComponent <LifetimeComponent>(); LifetimeComponent component = gameObject.GetComponent <LifetimeComponent>(); Assert.IsNotNull(component); component.SetLifetime(1f); gameObject.AddComponent <PriorityComponent>(); PriorityComponent component2 = gameObject.GetComponent <PriorityComponent>(); Assert.IsNotNull(component2); component2.Priority = 1; m_objectPool.PrefabToInstance = Object.Instantiate(gameObject); Assert.IsNotNull(m_objectPool.PrefabToInstance); m_objectPool.OnEnable(); Vector3 position = new Vector3(0f, 0f, 0f); Quaternion rotation = Quaternion.Euler(new Vector3(0f, 0f, 0f)); for (int i = 0; i < InitialPoolSize; i++) { Assert.IsNotNull(m_objectPool.Spawn(position, rotation, 4, 1f)); } Object.DestroyImmediate(m_objectPool.PrefabToInstance); Object.DestroyImmediate(gameObject); }
public void SetCharacteristics(float velocity, ProjectileDirection direction, float lifeTime) { this.velocity = velocity; this.direction = direction; lifetimeComponent = new LifetimeComponent(lifeTime); }
public void TestSpawnWithTrandformAndPriorityAndLifetime() { GameObject gameObject = new GameObject(); Assert.IsNotNull(gameObject); gameObject.name = "LifetimeObject"; gameObject.AddComponent <LifetimeComponent>(); LifetimeComponent component = gameObject.GetComponent <LifetimeComponent>(); Assert.IsNotNull(component); component.SetLifetime(1f); gameObject.AddComponent <PriorityComponent>(); PriorityComponent component2 = gameObject.GetComponent <PriorityComponent>(); Assert.IsNotNull(component2); component2.Priority = 1; m_objectPool.PrefabToInstance = Object.Instantiate(gameObject); Assert.IsNotNull(m_objectPool.PrefabToInstance); m_objectPool.OnEnable(); for (int i = 0; i < InitialPoolSize; i++) { Assert.IsNotNull(m_objectPool.Spawn(m_objectPool.transform, 4, 1f)); } Object.DestroyImmediate(m_objectPool.PrefabToInstance); Object.DestroyImmediate(gameObject); }
public GameObject SpawnFuel(float positionX, float positionY) { int type = (int)PyroGameObjectTypes.Fuel; GameObject result = mGameObjectPool.Allocate(); result.SetPosition(positionX, positionY); result.ActivationRadius = mActivationRadiusTight; result.width = 32; result.height = 32; result.PositionLocked = true; result.DestroyOnDeactivation = false; result.life = 1; result.team = GameObject.Team.NONE; FixedSizeArray <BaseObject> staticData = GetStaticData(type); if (staticData == null) { ContentManager content = sSystemRegistry.Game.Content; GraphicsDevice device = sSystemRegistry.Game.GraphicsDevice; int staticObjectCount = 1; staticData = new FixedSizeArray <BaseObject>(staticObjectCount); const int fileImageSize = 64; Rectangle crop = new Rectangle(0, 0, fileImageSize, fileImageSize); Texture2D texture = content.Load <Texture2D>(@"pics\fuel"); DrawableTexture2D textureDrawable = new DrawableTexture2D(texture, (int)result.width, (int)result.height); textureDrawable.SetCrop(crop); RenderComponent render = (RenderComponent)AllocateComponent(typeof(RenderComponent)); render.Priority = PyroSortConstants.FUEL; render.setDrawable(textureDrawable); staticData.Add(render); SetStaticData(type, staticData); } LifetimeComponent lifetime = AllocateComponent <LifetimeComponent>(); lifetime.SetDeathSound(fuelSound); result.Add(lifetime); AddStaticData(type, result, null); return(result); }
public void Execute(int i) { LifetimeComponent lifetime = Lifetimes[i]; lifetime.TimeAlive += DeltaTime; if (lifetime.TimeAlive > lifetime.MaxTimeAlive) { CommandBuffer.SetComponent(i, Entities[i], DestroyComponentTrue); return; } Lifetimes[i] = lifetime; }
public void OnDespawned() { gameObject.SetActive(false); lifetimeComponent = null; }
public GameObject SpawnFire(float positionX, float positionY, int life) { int thisGameObjectType = (int)PyroGameObjectTypes.Fire; GameObject result = mGameObjectPool.Allocate(); result.SetPosition(positionX, positionY); result.ActivationRadius = mActivationRadius_AlwaysActive; result.width = 32; result.height = 32; result.life = life; result.team = GameObject.Team.NONE; FixedSizeArray <BaseObject> staticData = GetStaticData(thisGameObjectType); if (staticData == null) { ContentManager content = sSystemRegistry.Game.Content; int staticObjectCount = 10; staticData = new FixedSizeArray <BaseObject>(staticObjectCount); // Animation Data float animationDelay = 0.16f; const int fileImageSize = 64; Rectangle crop = new Rectangle(0, 0, fileImageSize, fileImageSize); SpriteAnimation fire100 = new SpriteAnimation((int)FireAnimation.Fire100, 2); fire100.Loop = true; fire100.AddFrame(new AnimationFrame(content.Load <Texture2D>(@"pics\fire1"), animationDelay, crop)); fire100.AddFrame(new AnimationFrame(content.Load <Texture2D>(@"pics\fire1"), animationDelay, crop, SpriteEffects.FlipHorizontally)); SpriteAnimation fire80 = new SpriteAnimation((int)FireAnimation.Fire80, 2); fire80.Loop = true; fire80.AddFrame(new AnimationFrame(content.Load <Texture2D>(@"pics\fire2"), animationDelay, crop)); fire80.AddFrame(new AnimationFrame(content.Load <Texture2D>(@"pics\fire2"), animationDelay, crop, SpriteEffects.FlipHorizontally)); SpriteAnimation fire60 = new SpriteAnimation((int)FireAnimation.Fire60, 2); fire60.Loop = true; fire60.AddFrame(new AnimationFrame(content.Load <Texture2D>(@"pics\fire3"), animationDelay, crop)); fire60.AddFrame(new AnimationFrame(content.Load <Texture2D>(@"pics\fire3"), animationDelay, crop, SpriteEffects.FlipHorizontally)); SpriteAnimation fire40 = new SpriteAnimation((int)FireAnimation.Fire40, 2); fire40.Loop = true; fire40.AddFrame(new AnimationFrame(content.Load <Texture2D>(@"pics\fire4"), animationDelay, crop)); fire40.AddFrame(new AnimationFrame(content.Load <Texture2D>(@"pics\fire4"), animationDelay, crop, SpriteEffects.FlipHorizontally)); SpriteAnimation fire20 = new SpriteAnimation((int)FireAnimation.Fire20, 2); fire20.Loop = true; fire20.AddFrame(new AnimationFrame(content.Load <Texture2D>(@"pics\fire5"), animationDelay, crop)); fire20.AddFrame(new AnimationFrame(content.Load <Texture2D>(@"pics\fire5"), animationDelay, crop, SpriteEffects.FlipHorizontally)); SpriteAnimation fire0 = new SpriteAnimation((int)FireAnimation.Fire0, 2); fire0.Loop = true; fire0.AddFrame(new AnimationFrame(content.Load <Texture2D>(@"pics\fire6"), animationDelay, crop)); fire0.AddFrame(new AnimationFrame(content.Load <Texture2D>(@"pics\fire6"), animationDelay, crop, SpriteEffects.FlipHorizontally)); //animations staticData.Add(fire100); staticData.Add(fire80); staticData.Add(fire60); staticData.Add(fire40); staticData.Add(fire20); staticData.Add(fire0); SetStaticData(thisGameObjectType, staticData); } RenderComponent render = (RenderComponent)AllocateComponent(typeof(RenderComponent)); render.Priority = PyroSortConstants.FIRE; render.CameraRelative = true; SpriteComponent sprite = (SpriteComponent)AllocateComponent(typeof(SpriteComponent)); sprite.SetSize((int)result.width, (int)result.height); sprite.SetRenderComponent(render); sprite.SetRenderMode(SpriteComponent.RenderMode.RotateToFacingDirection); LifetimeComponent lifetime = AllocateComponent <LifetimeComponent>(); result.Add(render); result.Add(lifetime); result.Add(sprite); AddStaticData(thisGameObjectType, result, sprite); sprite.PlayAnimation((int)FireAnimation.Fire100); return(result); }
public GameObject SpawnPlayerDead(float positionX, float positionY, Vector2 facingDir) { int thisGameObjectType = (int)PyroGameObjectTypes.PlayerDead; GameObject result = mGameObjectPool.Allocate(); result.SetPosition(positionX, positionY); result.ActivationRadius = mActivationRadius_AlwaysActive; result.width = 32; result.height = 32; result.facingDirection = facingDir; result.life = 1; result.team = GameObject.Team.NONE; FixedSizeArray <BaseObject> staticData = GetStaticData(thisGameObjectType); if (staticData == null) { ContentManager content = sSystemRegistry.Game.Content; int staticObjectCount = 1; staticData = new FixedSizeArray <BaseObject>(staticObjectCount); // Animation Data float animationDelay = 0.16f; Rectangle crop32 = new Rectangle(0, 0, 32, 32); //Idle SpriteAnimation idle = new SpriteAnimation((int)Animations.Idle, 2); idle.Loop = true; idle.AddFrame(new AnimationFrame(content.Load <Texture2D>(@"pics\player\001_Death"), animationDelay, crop32)); idle.AddFrame(new AnimationFrame(content.Load <Texture2D>(@"pics\player\001_Death"), animationDelay, crop32, SpriteEffects.FlipHorizontally)); //animations staticData.Add(idle); SetStaticData(thisGameObjectType, staticData); } RenderComponent render = (RenderComponent)AllocateComponent(typeof(RenderComponent)); render.Priority = PyroSortConstants.PLAYER; render.CameraRelative = true; SpriteComponent sprite = (SpriteComponent)AllocateComponent(typeof(SpriteComponent)); sprite.SetSize((int)result.width, (int)result.height); sprite.SetRenderComponent(render); sprite.SetRenderMode(SpriteComponent.RenderMode.RotateToFacingDirection); LifetimeComponent lifetime = AllocateComponent <LifetimeComponent>(); result.Add(render); result.Add(lifetime); result.Add(sprite); AddStaticData(thisGameObjectType, result, sprite); sprite.PlayAnimation((int)Animations.Idle); return(result); }