public override void CollideWithObject(GameObject obj, Room room, BBox collision) { if (obj is Player && obj.Color == Color && !Symbolizing) { if (this != room.CorrectPortal) { Unlocked = true; room.Failed = true; room.Finish(); } else { if (type != RoomType.Acceptance) { curSymAnimation = animations.Find((set) => set.IsCalled(SYM + "1")); Symbolizing = true; } else { Unlocked = true; } } } base.CollideWithObject(obj, room, collision); }
/// <summary> /// Changes the animation being played. Doesn't do anything if called with the name of the currently /// playing animation. /// </summary> /// <param name="name">The name of the new animation.</param> /// <exception cref="System.InvalidOperationException">Specified animation doesn't exist.</exception> protected virtual void ChangeAnimation(string name) { if (!curAnimation.IsCalled(name)) { AnimationSet newAnimation = GetAnimationByName(name); if (newAnimation == null) throw new InvalidOperationException("Specified animation doesn't exist."); newAnimation.Reset(); newAnimation.Update(); curAnimation = newAnimation; } }
protected override void ChangeAnimation(string name) { AnimationSet oldAnimation = curAnimation; base.ChangeAnimation(name); // only reset the splatter animation if the animation changed if (oldAnimation != curAnimation && !curAnimation.IsCalled(DIE)) { splatterAnimation = animations.Find((anim) => anim.IsCalled(name + SPLATTER_TAG)); splatterAnimation.Reset(); } }
public Player(Vector2 pos) : base(pos, Vector2.Zero, new Vector2(MAX_JUMP_SPEED_X, MAX_JUMP_SPEED_Y), new Vector2(ACCELERATION_X, ACCELERATION_Y), new Vector2(DECCELERATION_X, DECCLERATION_Y), Color.Black, true, new Vector2(WIDTH, HEIGHT), new List<AnimationSet> { new AnimationSet(IDLE, ResourceManager.GetTexture("Player_Main"), IDLE_NUM_FRAMES, IDLE_FRAME_WIDTH, FRAME_DURATION), new AnimationSet(IDLE + SPLATTER_TAG, ResourceManager.GetTexture("Player_Main_Splatter"), IDLE_NUM_FRAMES, IDLE_FRAME_WIDTH, FRAME_DURATION), new AnimationSet(WALK, ResourceManager.GetTexture("Player_Main"), WALK_NUM_FRAMES, WALK_FRAME_WIDTH, FRAME_DURATION, true, WALK_START_FRAME), new AnimationSet(WALK + SPLATTER_TAG, ResourceManager.GetTexture("Player_Main_Splatter"), WALK_NUM_FRAMES, WALK_FRAME_WIDTH, FRAME_DURATION, true, WALK_START_FRAME), new AnimationSet(JUMP, ResourceManager.GetTexture("Player_Main"), JUMP_NUM_FRAMES, JUMP_FRAME_WIDTH, FRAME_DURATION, false, JUMP_START_FRAME), new AnimationSet(JUMP + SPLATTER_TAG, ResourceManager.GetTexture("Player_Main_Splatter"), JUMP_NUM_FRAMES, JUMP_FRAME_WIDTH, FRAME_DURATION, false, JUMP_START_FRAME), new AnimationSet(SLIDE, ResourceManager.GetTexture("Player_Main"), SLIDE_NUM_FRAMES, SLIDE_FRAME_WIDTH, FRAME_DURATION, true, SLIDE_START_FRAME), new AnimationSet(SLIDE + SPLATTER_TAG, ResourceManager.GetTexture("Player_Main_Splatter"), SLIDE_NUM_FRAMES, SLIDE_FRAME_WIDTH, FRAME_DURATION, true, SLIDE_START_FRAME), new AnimationSet(LAND, ResourceManager.GetTexture("Player_Main"), LAND_NUM_FRAMES, LAND_FRAME_WIDTH, LAND_DURATION, false, LAND_START_FRAME), new AnimationSet(LAND + SPLATTER_TAG, ResourceManager.GetTexture("Player_Main_Splatter"), LAND_NUM_FRAMES, LAND_FRAME_WIDTH, LAND_DURATION, false, LAND_START_FRAME), new AnimationSet(DIE, ResourceManager.GetTexture("Player_Main"), DIE_NUM_FRAMES, JUMP_FRAME_WIDTH, FRAME_DURATION, false, DIE_START_FRAME) }, JUMP, 0) { jumpKeys = new List<Keys>{Keys.W, Keys.Up, Keys.Space}; leftKeys = new List<Keys> {Keys.A, Keys.Left}; rightKeys = new List<Keys> {Keys.D, Keys.Right}; splatTimer = new Timer {AutoReset = true, Interval = SPLAT_INTERVAL}; splatTimer.Elapsed += (sender, args) => canSplat = true; splatTimer.Start(); splatterAnimation = animations.Find((anim) => anim.IsCalled(curAnimation.Name + SPLATTER_TAG)); }
public override void Update(Room room, GameTime gameTime) { base.Update(room, gameTime); Move(room, Vector2.Zero); // when we're done with the current spin frameset, switch to the next one. if (curAnimation.IsDonePlaying()) { curSpinIndex = (curSpinIndex == NUM_SPIN_TEXTURES ? 1 : curSpinIndex + 1); ChangeAnimation(SPIN + curSpinIndex.ToString()); } // when we're done with the current symbol frameset, switch if (curSymAnimation != null) { curSymAnimation.Update(); if (curSymAnimation.IsDonePlaying()) { if (curSymIndex == NUM_SYM_TEXTURES) Unlocked = true; else { curSymAnimation = animations.Find((set) => set.IsCalled(SYM + (curSymIndex + 1).ToString())); curSymIndex += 1; } } } }