private void SpawnFire(GameSlot fireSlot) { if (fireDurration > 0) { if (fireSlot.Contents == GameSlotStatus.Fire) { fireSlot.Child.facingDirection = playerSlot.Child.facingDirection; fireSlot.Child.life = fireDurration; } else { GameObjectManager manager = sSystemRegistry.GameObjectManager; PyroGameObjectFactory factory = (PyroGameObjectFactory)sSystemRegistry.GameObjectFactory; GameObject fireGameObject = factory.SpawnFire(0, 0, fireDurration); manager.Add(fireGameObject); fireSlot.Setup(GameSlotStatus.Fire, fireGameObject); fireGameObject.SetPosition(GetSlotLocation(fireSlot.Position)); fireGameObject.facingDirection = playerSlot.Child.facingDirection; fires.Add(fireSlot); } } }
protected override void InitializeStaticData() { //instanciate static data int objectTypeCount = Enum.GetValues(typeof(PyroGameObjectTypes)).Length; mStaticData = new FixedSizeArray <FixedSizeArray <BaseObject> >(objectTypeCount); for (int x = 0; x < objectTypeCount; x++) { mStaticData.Add(null); } }
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); }
private void ClearDeadFires() { foreach (GameSlot fire in fires) { if (fire.Child != null) {//in case this fire is already dead somehome... cuz collision is turned off and only one fire per tile if (fire.Child.life <= 0) { deadFires.Add(fire); } } } foreach (GameSlot fire in deadFires) { fires.Remove(fire, true); //clear slot fire.Child = null; fire.Contents = GameSlotStatus.Empty; } deadFires.Clear(); }
public FixedSizeArray <GameSlot> GenerateSlots() { int slotCount = GameWidthInSlots * (GameHeightInSlots); FixedSizeArray <GameSlot> result = new FixedSizeArray <GameSlot>(slotCount); GameObjectManager manager = sSystemRegistry.GameObjectManager; PyroGameObjectFactory factory = (PyroGameObjectFactory)sSystemRegistry.GameObjectFactory; for (int xx = 0; xx < slotCount; xx++) { int xPos = xx / GameWidthInSlots; int yPos = xx % GameWidthInSlots; GameObject emptyTile = factory.SpawnTileEmpty(xPos, yPos); manager.Add(emptyTile); GameSlot slot = new GameSlot(xPos, yPos); result.Add(slot); } return(result); }
protected override void InitializeComponentPools() { MaxGameObjects = 10000; mGameObjectPool = new GameObjectPool(MaxGameObjects); int renderedObjects = MaxGameObjects;//what game objects are inportant but not rendered? int particals = 1000; int collectables = 1500; int projectiles = 200; //int simplePhysicsEntities = 15; int players = 1; int enemies = 1500; //int wanderEnemies = 1500; //int patrolEnemies = 200; //int circularEnemies = 200; //int ninjas = 200; //int staticSets = 15; ComponentClass[] componentTypes = { //new ComponentClass(AnimationComponent.class, 384), //new ComponentClass(AttackAtDistanceComponent.class, 16), //new ComponentClass(enemies+players+particals+projectiles, typeof(BackgroundCollisionComponent)), //new ComponentClass(ButtonAnimationComponent.class, 32), //new ComponentClass(CameraBiasComponent.class, 8), //new ComponentClass(circularEnemies, typeof(CircularAIComponent)), //new ComponentClass(ChangeComponentsComponent.class, 256), //new ComponentClass(DoorAnimationComponent.class, 256), //! //new ComponentClass(enemies+players+projectiles, typeof(DynamicCollisionComponent)), //new ComponentClass(EnemyAnimationComponent.class, 256), //new ComponentClass(FadeDrawableComponent.class, 32), //new ComponentClass(FixedAnimationComponent.class, 8), //new ComponentClass(FrameRateWatcherComponent.class, 1), //new ComponentClass(GenericAnimationComponent.class, 32), //new ComponentClass(staticSets, typeof(GravityComponent)), //new ComponentClass(collectables+enemies, typeof(HitPlayerComponent)), //new ComponentClass(collectables+enemies+players, typeof(HitReactionComponent)), //new ComponentClass(players, typeof(InventoryComponent)), //new ComponentClass(players+ninjas, typeof(LaunchProjectileComponent)), new ComponentClass(enemies + players + particals + collectables + projectiles, typeof(LifetimeComponent)), //new ComponentClass(staticSets, typeof(MovementComponent)), //new ComponentClass(NPCAnimationComponent.class, 8), //new ComponentClass(NPCComponent.class, 8), //new ComponentClass(OrbitalMagnetComponent.class, 1), //new ComponentClass(patrolEnemies,typeof(PatrolAIComponent)), //new ComponentClass(staticSets, typeof(PhysicsComponent)), //new ComponentClass(players, typeof(PlayerComponent)), //new ComponentClass(wanderEnemies,typeof(PursuitAIComponent)), new ComponentClass(renderedObjects, typeof(RenderComponent)), //new ComponentClass(SimpleCollisionComponent.class, 32), //new ComponentClass(simplePhysicsEntities, typeof(SimplePhysicsComponent)), //new ComponentClass(enemies, typeof(SolidSurfaceComponent)), new ComponentClass(collectables + enemies + players, typeof(SpriteComponent)), //new ComponentClass(wanderEnemies,typeof(WanderAIComponent)), }; mComponentPools = new FixedSizeArray <FreshGameComponentPool>(componentTypes.Length, sComponentPoolComparator); for (int x = 0; x < componentTypes.Length; x++) { ComponentClass component = componentTypes[x]; mComponentPools.Add(new FreshGameComponentPool(component.type, component.poolSize)); } mComponentPools.Sort(true); mPoolSearchDummy = new FreshGameComponentPool(typeof(object), 1); }
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); }