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 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 static Animated2DSprite getFlowerSprite(ContentManager content, Vector2 position, Texture2D texture, AnimationState animationState) { BaseAnimationManagerParams animationParams = new BaseAnimationManagerParams(); animationParams.FrameRate = 100f; animationParams.TotalFrameCount = 5; animationParams.AnimationState = animationState; BaseAnimated2DSpriteParams spriteParams = new Animated2DSpriteLoadSingleRow(); spriteParams.FramesHeight = 96; spriteParams.FramesWidth = 96; spriteParams.Position = position; spriteParams.Origin = new Vector2(40f, 80f); spriteParams.Texture = texture; spriteParams.AnimationParams = animationParams; return(new Animated2DSprite(spriteParams)); }
public Tail(ContentManager content, Vector2 position, Vector2 heading) : base(content, true) { Animated2DSpriteLoadSingleRowBasedOnTexture tailParms = new Animated2DSpriteLoadSingleRowBasedOnTexture(); BaseAnimationManagerParams animationParms = new BaseAnimationManagerParams(); animationParms.AnimationState = AnimationState.PlayForward; animationParms.FrameRate = 100f; animationParms.TotalFrameCount = 4; tailParms.Position = position; tailParms.Rotation = MathHelper.ToRadians(180); tailParms.Texture = LoadingUtils.load <Texture2D>(content, "SnakeTail"); tailParms.Scale = new Vector2(.5f); tailParms.Origin = new Vector2(Constants.TILE_SIZE); tailParms.LightColour = Constants.SNAKE_LIGHT; tailParms.AnimationParams = animationParms; base.init(new Animated2DSprite(tailParms)); this.heading = heading; this.targetPositions = new List <TargetPosition>(); }
public static Base2DSpriteDrawable generateWaveEffect(ContentManager content, Vector2 position, Color light, out float effectLife) { int frames = 6; float speed = 15f; BaseAnimationManagerParams animationParms = new BaseAnimationManagerParams() { AnimationState = AnimationState.PlayForwardOnce, TotalFrameCount = frames, FrameRate = speed, }; Animated2DSpriteLoadSingleRowBasedOnTexture parms = new Animated2DSpriteLoadSingleRowBasedOnTexture() { AnimationParams = animationParms, Position = Vector2.Subtract(position, new Vector2(Constants.TILE_SIZE)), LightColour = light, Origin = new Vector2(Constants.TILE_SIZE), Texture = LoadingUtils.load <Texture2D>(content, "WaveEffect") }; effectLife = frames * speed; return(new Animated2DSprite(parms)); }
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 Snake(ContentManager content, Vector2 heading, float xOffSet, Controls controls) : base(content, true) { this.heading = heading; this.currentSpeed = STARTING_SPEED; this.controls = controls; Animated2DSpriteLoadSingleRowBasedOnTexture headParms = new Animated2DSpriteLoadSingleRowBasedOnTexture(); BaseAnimationManagerParams animationParms = new BaseAnimationManagerParams(); animationParms.AnimationState = AnimationState.PlayForward; animationParms.FrameRate = 100f; animationParms.TotalFrameCount = 4; headParms.Position = new Vector2(xOffSet + PositionUtils.getPosition(Constants.MAX_X_TILES / 2), PositionUtils.getPosition(Constants.MAX_Y_TILES / 2 - 1)); headParms.Texture = LoadingUtils.load <Texture2D>(content, "SnakeHead"); headParms.Scale = new Vector2(.5f); headParms.Origin = new Vector2(Constants.TILE_SIZE); headParms.LightColour = Constants.SNAKE_LIGHT; headParms.AnimationParams = animationParms; base.init(new Animated2DSprite(headParms)); this.body = new Body(content, new Vector2(headParms.Position.X, headParms.Position.Y + Constants.TILE_SIZE - Constants.OVERLAP), this.heading); this.tail = new Tail(content, new Vector2(headParms.Position.X, headParms.Position.Y + (Constants.TILE_SIZE - Constants.OVERLAP) * 2), this.heading); this.cornerParms = new StaticDrawable2DParams { Texture = LoadingUtils.load <Texture2D>(content, "SnakeBody"), Origin = new Vector2(Constants.TILE_SIZE / 2), Scale = new Vector2(.8f), }; this.corners = new List <StaticDrawable2D>(); this.portalEnteredSFX = LoadingUtils.load <SoundEffect>(content, "PortalTakenSFX"); #if DEBUG this.debugPivotPoints = new List <StaticDrawable2D>(); this.pivotParms = new StaticDrawable2DParams(); this.pivotParms.Texture = LoadingUtils.load <Texture2D>(content, "Chip"); this.pivotParms.LightColour = Constants.DEBUG_PIVOT_Color; this.pivotParms.Scale = new Vector2(4f); #endif }
/// <summary> /// Actual building of the sprite /// </summary> /// <param name="texture">Texture2D use to render the sprite</param> /// <param name="framesStartWidth">Starting x point of the sprite in the sprite sheet</param> /// <param name="framesStartHeight">Starting y point of the sprite in the sprite sheet</param> /// <param name="frameWidth">X size of a sprites single frame</param> /// <param name="frameHeight">Y size of a sprites single frame</param> /// <param name="spaceBetweenFrames">Space between the frames in the sprite sheet</param> /// <param name="animationParams">BaseAnimationManagerParams object containing the animation information for the sprite</param> /// <param name="maxColumnsToARow">Maximum columns to a row in the sprite sheet</param> private void initSprite(Texture2D texture, BaseAnimationManagerParams animationParams, int frameWidth, int frameHeight, int spaceBetweenFrames = 0, int framesStartWidth = 0, int framesStartHeight = 0, int maxColumnsToARow = -1) { this.texture = texture; if (typeof(KeyFrameAnimationManagerParams) == animationParams.GetType()) { this.animationManager = new KeyFrameAnimationManager((KeyFrameAnimationManagerParams)animationParams); } else { this.animationManager = new AnimationManager(animationParams); } // if we are the default value for maxColumnsToARow set the value based on the animation's total frames if (maxColumnsToARow == -1) { maxColumnsToARow = animationParams.TotalFrameCount; } // load the frames this.frames = new Rectangle[animationParams.TotalFrameCount]; int x = framesStartWidth; int y = framesStartHeight; for (int i = 0; i < this.frames.Length; i++) { if (i > 0 && i % maxColumnsToARow == 0) { x = framesStartWidth; y = (y + frameHeight + spaceBetweenFrames); } this.frames[i] = new Rectangle(x, y, frameWidth, frameHeight); x = (x + frameWidth + spaceBetweenFrames); } base.renderingRectangle = this.frames[this.animationManager.CurrentFrame]; }
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]; }
/// <summary> /// Builds an AnimationManager based on the AnimationManagerParams object passed in /// </summary> /// <param name="parms">BaseAnimationManagerParams object containing the data required to load the Animation Manager object</param> public AnimationManager(BaseAnimationManagerParams parms) { this.animationState = parms.AnimationState; this.frameRate = parms.FrameRate; resetAnimation(parms.TotalFrameCount - 1); // comes in as an array size so - 1 }
/// <summary> /// Defines a new SpriteParams object with the defaults set. The defaults are listed below; /// AnimationState: AnimationState.Paused /// </summary> public BaseAnimated2DSpriteParams() { // defaults this.AnimationParams = new BaseAnimationManagerParams(); }
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 }