// in WindowsGame1.LoadContent() // ... AnimationFrame[] frames; animationLookup = new Dictionary(); frames = new AnimationFrame[16]; for (int f = 0; f < 4; f++) frames[f] = new AnimationFrame("sword_se", +16, +10); for (int f = 4; f < 8; f++) frames[f] = new AnimationFrame("sword_e", +16, +2); for (int f = 8; f < 12; f++) frames[f] = new AnimationFrame("sword_ne", +10, -10); for (int f = 12; f < 16; f++) frames[f] = new AnimationFrame("sword_n", +0, -16); animationLookup.Add("sword_swinging_u", frames); frames = new AnimationFrame[16]; for (int f = 0; f < 4; f++) frames[f] = new AnimationFrame("sword_nw", -14, -9); for (int f = 4; f < 8; f++) frames[f] = new AnimationFrame("sword_w", -16, +0); for (int f = 8; f < 12; f++) frames[f] = new AnimationFrame("sword_sw", -11, +12); for (int f = 12; f < 16; f++) frames[f] = new AnimationFrame("sword_s", +0, 16); animationLookup.Add("sword_swinging_d", frames); frames = new AnimationFrame[16]; for (int f = 0; f < 4; f++) frames[f] = new AnimationFrame("sword_ne", +10, -8); for (int f = 4; f < 8; f++) frames[f] = new AnimationFrame("sword_n", +0, -11); for (int f = 8; f < 12; f++) frames[f] = new AnimationFrame("sword_nw", -14, -5); for (int f = 12; f < 16; f++) frames[f] = new AnimationFrame("sword_w", -16, +3); animationLookup.Add("sword_swinging_l", frames); frames = new AnimationFrame[16]; for (int f = 0; f < 4; f++) frames[f] = new AnimationFrame("sword_nw", -10, -8); for (int f = 4; f < 8; f++) frames[f] = new AnimationFrame("sword_n", +0, -11); for (int f = 8; f < 12; f++) frames[f] = new AnimationFrame("sword_ne", +14, -5); for (int f = 12; f < 16; f++) frames[f] = new AnimationFrame("sword_e", +16, +3); animationLookup.Add("sword_swinging_r", frames); frames = new AnimationFrame[12]; for (int f = 0; f < 4; f++) frames[f] = new AnimationFrame("sword_n", +2, -8); for (int f = 4; f < 8; f++) frames[f] = new AnimationFrame("sword_n", +2, -16); for (int f = 8; f < 12; f++) frames[f] = new AnimationFrame("sword_n", +2, -8); animationLookup.Add("sword_stabbing_u", frames); frames = new AnimationFrame[12]; for (int f = 0; f < 4; f++) frames[f] = new AnimationFrame("sword_s", -2, +8); for (int f = 4; f < 8; f++) frames[f] = new AnimationFrame("sword_s", -2, +16); for (int f = 8; f < 12; f++) frames[f] = new AnimationFrame("sword_s", -2, +8); animationLookup.Add("sword_stabbing_d", frames); frames = new AnimationFrame[12]; for (int f = 0; f < 4; f++) frames[f] = new AnimationFrame("sword_w", -8, +3); for (int f = 4; f < 8; f++) frames[f] = new AnimationFrame("sword_w", -16, +3); for (int f = 8; f < 12; f++) frames[f] = new AnimationFrame("sword_w", -8, +3); animationLookup.Add("sword_stabbing_l", frames); frames = new AnimationFrame[12]; for (int f = 0; f < 4; f++) frames[f] = new AnimationFrame("sword_e", +8, +3); for (int f = 4; f < 8; f++) frames[f] = new AnimationFrame("sword_e", +16, +3); for (int f = 8; f < 12; f++) frames[f] = new AnimationFrame("sword_e", +8, +3); animationLookup.Add("sword_stabbing_r", frames); // ... void UpdateSword() { if (sword.state == "swinging" && sword.stateFrames == 16) { sword = null; return; } if (sword.state == "stabbing" && sword.stateFrames == 12) { sword = null; return; } AnimationFrame[] frames = animationLookup["sword_" + sword.state + "_" + sword.dir]; AnimationFrame frame = frames[sword.stateFrames]; sword.srcRect = frame.srcRect; sword.x = player.x + frame.x; sword.y = player.y + frame.y; sword.stateFrames++; }