public void initSprites(Player player) { this.type = player.FlowerType; this.aliveSprite.Texture = player.AliveTexture; this.aliveSprite.AnimationManager.State = AnimationState.PlayForwardOnce; this.activeSprite = this.aliveSprite; this.dyingSprite.Texture = player.DyingTexture; }
public Flower(ContentManager content, int index) { this.index = index; this.aliveSprite = FlowerBuilder.getFlowerSprite(content, index); this.dyingSprite = FlowerBuilder.getFlowerSprite(content, index); reset(); #if WINDOWS #if DEBUG #endif #endif }
public Wall(ContentManager content, Vector2 position) : base(content) { Texture2D texture = null; texture = LoadingUtils.load <Texture2D>(content, "Fence"); StaticDrawable2DParams wallParams = new StaticDrawable2DParams { Position = position, Texture = texture, Scale = new Vector2(.5f), Origin = new Vector2(Constants.TILE_SIZE) }; this.idleImage = new StaticDrawable2D(wallParams); Animated2DSpriteLoadSingleRowBasedOnTexture parms = new Animated2DSpriteLoadSingleRowBasedOnTexture(); BaseAnimationManagerParams animationParms = new BaseAnimationManagerParams(); animationParms.AnimationState = AnimationState.PlayForwardOnce; animationParms.FrameRate = 100f; animationParms.TotalFrameCount = 3; parms.Position = position; parms.Scale = new Vector2(.25f); parms.Texture = LoadingUtils.load <Texture2D>(content, "FenceOpening"); parms.Origin = new Vector2(Constants.TILE_SIZE); parms.AnimationParams = animationParms; this.spawnSprite = new Animated2DSprite(parms); base.init(spawnSprite); BaseParticle2DEmitterParams emitterParams = new BaseParticle2DEmitterParams() { ParticleTexture = LoadingUtils.load <Texture2D>(content, "Dust"), }; this.dustEmitter = new DustParticleEmitter(emitterParams, base.Position); for (int i = 0; i < 5; i++) { this.dustEmitter.createParticle(); } this.crumpleSFX = LoadingUtils.load <SoundEffect>(content, SFX_NAME_CRUMPLE); SoundEmitterParams sfxEmitterParms = new SoundEmitterParams { SFXEngine = SoundManager.getInstance().SFXEngine, EmittRadius = SFX_EMITT_RADIUS, Position = this.spawnSprite.Position }; this.sfxEmitter = new SoundEmitter(sfxEmitterParms); SoundManager.getInstance().addEmitter(this.sfxEmitter); SoundManager.getInstance().playSoundEffect(this.sfxEmitter, this.crumpleSFX); this.stage = Stage.Opening; }
public Food(ContentManager content, Random rand, int points, float speedMultiplier, List <string> dyingCharacterTextureNames, string deathParticleTextureName, string idleTextureName, string spawnTextureName, string spawnSFXName, string idleSFXName, string dyingSFXName, float spawnPositionYOffset = 0f) : base(content) { this.Points = points; this.SpeedMultiplier = speedMultiplier; this.LifeStage = Stage.Spawn; this.dyingCharacterTextures = new List <Texture2D>(); foreach (string texture in dyingCharacterTextureNames) { this.dyingCharacterTextures.Add(LoadingUtils.load <Texture2D>(content, texture)); } this.deathParticleTexture = LoadingUtils.load <Texture2D>(content, deathParticleTextureName); Animated2DSpriteLoadSingleRowBasedOnTexture parms = new Animated2DSpriteLoadSingleRowBasedOnTexture(); BaseAnimationManagerParams animationParms = new BaseAnimationManagerParams(); animationParms.AnimationState = AnimationState.PlayForward; animationParms.FrameRate = 100f; animationParms.TotalFrameCount = 4; parms.Position = PositionGenerator.getInstance().generateSpawn(); parms.Texture = LoadingUtils.load <Texture2D>(content, idleTextureName); parms.Scale = new Vector2(.5f); parms.Origin = new Vector2(Constants.TILE_SIZE); parms.AnimationParams = animationParms; this.idleSprite = new Animated2DSprite(parms); animationParms.AnimationState = AnimationState.PlayForwardOnce; parms.AnimationParams = animationParms; parms.Texture = LoadingUtils.load <Texture2D>(content, spawnTextureName); parms.Scale = new Vector2(1f); parms.Position = new Vector2(parms.Position.X, parms.Position.Y + spawnPositionYOffset); this.spawnSprite = new Animated2DSprite(parms); base.init(this.spawnSprite); this.spawnSFX = LoadingUtils.load <SoundEffect>(content, spawnSFXName); this.idleSFX = LoadingUtils.load <SoundEffect>(content, idleSFXName); this.dyingSFX = LoadingUtils.load <SoundEffect>(content, dyingSFXName); SoundEmitterParams sfxEmitterParms = new SoundEmitterParams { SFXEngine = SoundManager.getInstance().SFXEngine, EmittRadius = SFX_EMITT_RADIUS, Position = this.spawnSprite.Position }; this.sfxEmitter = new SoundEmitter(sfxEmitterParms); SoundManager.getInstance().addEmitter(this.sfxEmitter); }
public void update(float elapsed) { if (this.type != FlowerType.None) { if (StateManager.getInstance().CurrentState == StateManager.GameState.InitGameOver) { if (StateManager.getInstance().Winner.winningType != this.type || !StateManager.getInstance().Winner.winningIndexes.Contains(this.index)) { this.dyingSprite.AnimationManager.State = AnimationState.PlayForwardOnce; this.dyingSprite.reset(); this.activeSprite = this.dyingSprite; } } this.activeSprite.update(elapsed); } }
public Portal(ContentManager content, Random rand) : base(content) { this.lifeStage = Stage.Spawn; Animated2DSpriteLoadSingleRowBasedOnTexture parms = new Animated2DSpriteLoadSingleRowBasedOnTexture(); BaseAnimationManagerParams animationParms = new BaseAnimationManagerParams(); animationParms.AnimationState = AnimationState.PlayForward; animationParms.FrameRate = 100f; animationParms.TotalFrameCount = 7; parms.Position = PositionGenerator.getInstance().generateSpawn(); parms.Texture = LoadingUtils.load <Texture2D>(content, "PortalOpen"); parms.Origin = new Vector2(Constants.TILE_SIZE); parms.AnimationParams = animationParms; this.idleSprite = new Animated2DSprite(parms); animationParms.AnimationState = AnimationState.PlayForwardOnce; animationParms.TotalFrameCount = 6; parms.AnimationParams = animationParms; parms.Texture = LoadingUtils.load <Texture2D>(content, "PortalSpawn"); parms.Position = new Vector2(parms.Position.X, parms.Position.Y); this.spawnSprite = new Animated2DSprite(parms); base.init(this.spawnSprite); BaseParticle2DEmitterParams emitterParams = new BaseParticle2DEmitterParams { ParticleTexture = LoadingUtils.load <Texture2D>(content, "Lightning"), SpawnDelay = 500f }; this.lightningEmitter = new LightningParticleEmitter(emitterParams, parms.Position); this.spawnSFX = LoadingUtils.load <SoundEffect>(content, SPAWN_SFX_NAME); this.idleSFX = LoadingUtils.load <SoundEffect>(content, IDLE_SFX_NAME); this.closingSFX = LoadingUtils.load <SoundEffect>(content, CLOSING_SFX_NAME); SoundEmitterParams sfxEmitterParms = new SoundEmitterParams { SFXEngine = SoundManager.getInstance().SFXEngine, EmittRadius = SFX_EMITT_RADIUS, Position = this.spawnSprite.Position }; this.sfxEmitter = new SoundEmitter(sfxEmitterParms); SoundManager.getInstance().addEmitter(this.sfxEmitter); SoundManager.getInstance().playSoundEffect(this.sfxEmitter, this.spawnSFX); }
public Player(ContentManager content, SpriteFont font, string name, Vector2 scorePosition, Vector2 turnSpritePosition, string aliveTexture, string dyingTexture, Flower.FlowerType flowerType) { this.name = name; this.AliveTexture = LoadingUtils.load <Texture2D>(content, aliveTexture); this.DyingTexture = LoadingUtils.load <Texture2D>(content, dyingTexture); this.FlowerType = flowerType; this.Score = 0; Text2DParams textParams = new Text2DParams(); textParams.Font = font; textParams.LightColour = ResourceManager.getInstance().TextColour; textParams.Position = scorePosition; this.Text = new Text2D(textParams); this.myTurnSprite = FlowerBuilder.getFlowerSprite(content, turnSpritePosition, this.AliveTexture, AnimationState.PlayForwardOnce); this.notMyTurnSprite = FlowerBuilder.getFlowerSprite(content, turnSpritePosition, this.DyingTexture, AnimationState.PlayForwardOnce); }
public void update(float elapsed) { this.Text.WrittenText = name + ": " + this.Score; if (LogicUtils.translateTurnToFlowerType(StateManager.getInstance().WhosTurnIsIt) == this.FlowerType) { this.activeSprite = this.myTurnSprite; this.myTurnSprite.update(elapsed); this.notMyTurnSprite.reset(); this.notMyTurnSprite.AnimationManager.State = AnimationState.PlayForwardOnce; } else { this.activeSprite = this.notMyTurnSprite; this.notMyTurnSprite.update(elapsed); this.myTurnSprite.reset(); this.myTurnSprite.AnimationManager.State = AnimationState.PlayForwardOnce; } }
public Nuke(ContentManager content, SFXEngine sfxEngine) { int frames = 6; BaseAnimationManagerParams animationParms = new BaseAnimationManagerParams(); animationParms.AnimationState = AnimationState.PlayForward; animationParms.FrameRate = 100f; animationParms.TotalFrameCount = frames; BaseAnimated2DSpriteParams spriteParms = new Animated2DSpriteLoadSingleRowBasedOnTexture(); spriteParms.Position = new Vector2(-200f); spriteParms.Rotation = 0f; spriteParms.Origin = new Vector2(32f); spriteParms.Scale = new Vector2(.75f); spriteParms.Texture = LoadingUtils.load <Texture2D>(content, "NukeSprite"); spriteParms.AnimationParams = animationParms; this.bomb = new Animated2DSprite(spriteParms); this.State = SpriteState.InActive; this.textureColourDatas = new List <Color[, ]>(); Rectangle frame; for (int i = 0; i < frames; i++) { frame = this.bomb.Frames[i]; this.textureColourDatas.Add( TextureUtils.getColourData2D(this.bomb.Texture, startX: frame.X, width: frame.X + frame.Width)); } // Smoke emitter BaseParticle2DEmitterParams particleEmitterParms = new BaseParticle2DEmitterParams(); particleEmitterParms.ParticleTexture = LoadingUtils.load <Texture2D>(content, "Smoke"); particleEmitterParms.SpawnDelay = SmokeParticleEmitter.SPAWN_DELAY; this.emitter = new SmokeParticleEmitter(content, particleEmitterParms); // sfx this.sfxEngine = sfxEngine; }
public Person(ContentManager content, string fileStartsWith, Placement startingLocation, float movementSpeed) { BaseAnimationManagerParams animationParams = new BaseAnimationManagerParams(); animationParams.AnimationState = AnimationState.PlayForward; animationParams.FrameRate = FRAME_RATE; animationParams.TotalFrameCount = 4; BaseAnimated2DSpriteParams spriteParams = new Animated2DSpriteLoadSingleRowBasedOnTexture(); spriteParams.Origin = new Vector2(ResourceManager.TILE_SIZE / 2, ResourceManager.TILE_SIZE / 2); spriteParams.Texture = LoadingUtils.load <Texture2D>(content, fileStartsWith + "Right"); spriteParams.AnimationParams = animationParams;; // we actually want his feet in the middle, not his chest which is where the origin is spriteParams.Position = new Vector2(startingLocation.worldPosition.X + spriteParams.Origin.X, startingLocation.worldPosition.Y); this.rightSprite = new Animated2DSprite(spriteParams); spriteParams.SpriteEffect = SpriteEffects.FlipHorizontally; this.leftSprite = new Animated2DSprite(spriteParams); this.Placement = startingLocation; this.direction = Direction.None; this.movementSpeed = movementSpeed; this.activeSprite = this.rightSprite; this.BoundingBox = Helper.getPersonBBox(this.activeSprite.Position); this.previousTypeOfSpace = AIManager.getInstance().Board[this.Placement.index.Y, this.Placement.index.X]; }
protected virtual void updateSpritesVisuals(float elapsed) { updateDirection(elapsed); if (this.previousDirection != this.direction) { if (this.direction == Direction.None) { // we are no longer moving so stop our sprite this.activeSprite.reset(true); } else { this.activeSprite.AnimationManager.State = AnimationState.PlayForward; } } if (this.direction != Direction.None) { // we are moving // if we are not moving in the same direction we need to change our sprite bool updateSprite = false; if (this.direction != this.previousDirection) { updateSprite = true; } if (this.direction == Direction.Up) { if (updateSprite) { this.leftSprite.Position = this.activeSprite.Position; if (this.previousDirection == Direction.Left) { this.activeSprite = this.leftSprite; } else if (this.previousDirection == Direction.Right) { this.activeSprite = this.rightSprite; } else { this.activeSprite = this.leftSprite; } } } else if (this.direction == Direction.Right) { if (updateSprite) { this.rightSprite.Position = this.activeSprite.Position; this.activeSprite = this.rightSprite; } } else if (this.direction == Direction.Down) { if (updateSprite) { this.rightSprite.Position = this.activeSprite.Position; if (this.previousDirection == Direction.Left) { this.activeSprite = this.leftSprite; } else if (this.previousDirection == Direction.Right) { this.activeSprite = this.rightSprite; } else { this.activeSprite = this.rightSprite; } } } else if (this.direction == Direction.Left) { if (updateSprite) { this.leftSprite.Position = this.activeSprite.Position; this.activeSprite = this.leftSprite; } } } }
private void initDelegates() { this.mobDeathFinish = delegate(Character character) { String texture = "Monster1"; if (character.GetType() == typeof(Yeti)) { texture = "Monster2"; } texture += "Death"; Vector2 position = character.Position; int frames = 10; float speed = 100f; BaseAnimationManagerParams animationParms = new BaseAnimationManagerParams() { AnimationState = AnimationState.PlayForwardOnce, TotalFrameCount = frames, FrameRate = speed, }; Animated2DSpriteLoadSingleRowBasedOnTexture parms = new Animated2DSpriteLoadSingleRowBasedOnTexture() { AnimationParams = animationParms, Position = position, LightColour = Color.White, Texture = LoadingUtils.load <Texture2D>(content, texture) }; Animated2DSprite deathSprite = new Animated2DSprite(parms); this.recentlySpawned.Add(new Ghost(content, position, this.ghostObserverHandler, this.mobsInRange, this.ghostDeathFinish)); this.theDead.Add(deathSprite); }; this.ghostDeathFinish = delegate(Character character) { String texture = "GhostDeath"; Vector2 position = character.Position; int frames = 10; float speed = 100f; BaseAnimationManagerParams animationParms = new BaseAnimationManagerParams() { AnimationState = AnimationState.PlayForwardOnce, TotalFrameCount = frames, FrameRate = speed, }; Animated2DSpriteLoadSingleRowBasedOnTexture parms = new Animated2DSpriteLoadSingleRowBasedOnTexture() { AnimationParams = animationParms, Position = position, LightColour = Color.White, Texture = LoadingUtils.load <Texture2D>(content, texture) }; Ghost ghost = (Ghost)character; ghost.Selected = false; this.selectedGhosts.Remove(ghost); this.allGhosts.Remove(ghost); this.theDead.Add(new Animated2DSprite(parms)); }; this.ghostsInRange = delegate(Character character) { return(getCharactersInRange <Ghost>(character, this.allGhosts)); }; this.mobsInRange = delegate(Character character) { return(getCharactersInRange <Mob>(character, this.mobs)); }; this.collisionCheck = delegate(Vector2 newPosition) { bool safe = true; BoundingBox newBoundingBox = CollisionGenerationUtils.getBBox(newPosition); foreach (Wall wall in map.Walls) { if (wall.BBox.Intersects(newBoundingBox)) { safe = false; break; } } return(safe); }; #if DEBUG this.editorsCreator = delegate(MapEditor.MappingState type, MonsterType monsterType, Vector2 position) { switch (type) { case MapEditor.MappingState.Monster: if (monsterType == MonsterType.Devil) { this.mobs.Add(new Devil(content, position, this.ghostsInRange, this.mobDeathFinish, this.collisionCheck)); } else if (monsterType == MonsterType.Yeti) { this.mobs.Add(new Yeti(content, position, this.ghostsInRange, this.mobDeathFinish, this.collisionCheck)); } break; } ; }; #endif }