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 SpawnPlayer(float positionX, float positionY) { int thisGameObjectType = (int)PyroGameObjectTypes.Player; GameObject result = mGameObjectPool.Allocate(); result.SetPosition(positionX, positionY); result.ActivationRadius = mActivationRadius_AlwaysActive; result.width = 32; result.height = 32; result.life = 1; result.team = GameObject.Team.PLAYER; 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; //Idle SpriteAnimation idle = new SpriteAnimation((int)Animations.Idle, 3); idle.Loop = true; idle.AddFrame(new AnimationFrame(content.Load <Texture2D>(@"pics\player\001_attackNN_01"), animationDelay)); idle.AddFrame(new AnimationFrame(content.Load <Texture2D>(@"pics\player\001_attackNN_02"), animationDelay, new Rectangle(0, 0, 32, 32))); idle.AddFrame(new AnimationFrame(content.Load <Texture2D>(@"pics\player\001_attackNN_03"), animationDelay)); //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>(); lifetime.SetDeathSound(playerDeathSound); lifetime.SetObjectToSpawnOnDeath((int)PyroGameObjectTypes.PlayerDead, false); result.Add(render); result.Add(lifetime); result.Add(sprite); AddStaticData(thisGameObjectType, result, sprite); sprite.PlayAnimation((int)Animations.Idle); return(result); }