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); } }
private void ClearSlots(FixedSizeArray <GameSlot> slots) { foreach (GameSlot slot in slots) { if (slot.Child != null) { slot.KillImedietly(); slot.Child = null; } slot.EmptySlot(); } }
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 GameObject SpawnBackgroundPlate(float positionX, float positionY) { const int width = 1280; const int height = 720; int type = (int)PyroGameObjectTypes.Background_Plate; GameObject result = mGameObjectPool.Allocate(); result.SetPosition(positionX, positionY); result.ActivationRadius = mActivationRadiusExtraWide; result.width = width; result.height = height; ContentManager content = sSystemRegistry.Game.Content; FixedSizeArray <BaseObject> staticData = GetStaticData(type); if (staticData == null) { const int staticObjectCount = 1; staticData = new FixedSizeArray <BaseObject>(staticObjectCount); //InventoryRecord addWin = new InventoryRecord(); //addWin.winCount = 1; //staticData.Add(addWin); SetStaticData(type, staticData); } Rectangle crop = new Rectangle(0, 0, width, height); DrawableTexture2D textureDrawable = new DrawableTexture2D(content.Load <Texture2D>(@"pics\background"), (int)result.width, (int)result.height); textureDrawable.SetCrop(crop); RenderComponent render = (RenderComponent)AllocateComponent(typeof(RenderComponent)); render.Priority = PyroSortConstants.BACKGROUND; render.setDrawable(textureDrawable); result.Add(render); //AddStaticData(type, result, null); return(result); }
public PyroGameManager() : base() { random = new Random(); #if TestEnvironment random = new Random(2); #endif Score = 0; tileSlots = GenerateSlots(); playerSlot = new GameSlot(0, 0); //center tiles BoardXOffset = BoardXOffset + sSystemRegistry.ContextParameters.GameWidth / 2 - (GameWidthInSlots * SlotSize) / 2; BoardYOffset = BoardYOffset + sSystemRegistry.ContextParameters.GameHeight / 2 - (GameHeightInSlots * SlotSize) / 2; gameState = GameState.Loading; }
private void GenFireReport() { int fires = 0; for (int xx = 0; xx < 16; xx++) { fires = 0; foreach (GameSlot s in tileSlots) { if (s.Contents == GameSlotStatus.Fire && s.Child.life == xx) { fires++; } } if (fires > 1) { Console.WriteLine("{0} fires at {1} life", fires, xx); } } }
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); }
/// <summary> /// Create Log file with rolling logs - move log to next log file up (1 to 2) up to the limit /// </summary> /// <param name="logFileFullName">full path to destination log file</param> public static void Init(string logFileFullName, int logMemoryCount = LOG_MEMORY_DEFAULT_COUNT) { //setup local variables Log.logMemoryCount = logMemoryCount; logCount = 0; exceptionCount = 0; logRecords = new FixedSizeArray<LogRecord>(logMemoryCount); //setup log file(s) logFileName = logFileFullName; int logStorageMax = logFileCount;//single digits int logIndex = logStorageMax; while (logIndex >= 1) { string logOlder = logFileName.Replace(".txt", "_" + logIndex + ".txt"); string logNewer; if (logIndex > 1) logNewer = logFileName.Replace(".txt", "_" + (logIndex - 1) + ".txt"); else logNewer = logFileName; FreshArchives.MoveFileOverwrite(logNewer, logOlder); logIndex--; } //create any necisarry directories for logs Directory.CreateDirectory(Path.GetDirectoryName(logFileName)); //create first log record I(Assembly.GetExecutingAssembly().GetName().Name + " (v" + FreshArchives.TrimVersionNumber(Assembly.GetExecutingAssembly().GetName().Version) + ")"); }