public void loadCutscenes() { string CutscenePath = "Content/Maps/Cutscenes"; DirectoryInfo di = new DirectoryInfo(CutscenePath); FileInfo[] rgFiles = di.GetFiles("*.*"); int width; List<string> lines; string line; string name; List<int> frames = new List<int>(); List<string> actorNames = new List<string>(); List<string> animationNames = new List<string>(); List<float> xs = new List<float>(); List<float> ys = new List<float>(); foreach (FileInfo fi in rgFiles) { name = fi.Name.Replace(".txt", ""); Cutscene cutscene = new Cutscene(name); if(name.Contains("_ai")) { cutscene.name = name.Replace("_ai", ""); cutscene.allowInput = true; } bool cutoff = false; lines = new List<string>(); string[] fields; using (StreamReader reader = new StreamReader(CutscenePath + "/" + fi.Name)) { cutoff = false; frames.Clear(); actorNames.Clear(); animationNames.Clear(); xs.Clear(); ys.Clear(); line = reader.ReadLine(); width = line.Length; while (line != null) { if (line.Substring(1, 3) == "---") { cutoff = true; line = reader.ReadLine(); width = line.Length; } if (cutoff) { fields = line.Split(';'); int frame = int.Parse(fields[0]); string actorName = fields[1]; string animationName = fields[2]; bool addFrame = false; for (int i = 0; i < frames.Count; i++) { if (frames[i] == frame && actorNames[i].Trim() == actorName.Trim()) animationNames[i] = animationName; else { addFrame = true; } } if(addFrame) { frames.Add(frame); actorNames.Add(actorName); animationNames.Add(animationName); xs.Add(0); ys.Add(0); } } else { fields = line.Split(';'); int frame = int.Parse(fields[0]); string actorName = fields[1]; float x = float.Parse(fields[2]); float y = float.Parse(fields[3]); frames.Add(frame); actorNames.Add(actorName); animationNames.Add(""); xs.Add(x); ys.Add(y); } line = reader.ReadLine(); } for (int i = 0; i < frames.Count; i++) { CutsceneFrame cutsceneFrame = new CutsceneFrame(frames[i], actorNames[i], animationNames[i], xs[i], ys[i]); cutscene.frames.Add(cutsceneFrame); } } cutscene.setMaxFrame(); cutscenes.Add(cutscene); } loadCutsceneTriggers(cutscenes); }
public void UpdateCutscene() { /* if(TileEngine.Map.Name != "downstairs") currentCutscene = null; */ if (currentCutscene == null) return; currentCutscene.currentFrame++; //pan camera Vector2 camPos = Vector2.Zero; foreach (CutsceneFrame frame in currentCutscene.frames) if (frame.actorName == "camera" && frame.frame == currentCutscene.currentFrame) camPos = new Vector2(frame.x, frame.y); if (oldCamPos != Vector2.Zero) { if (camPos == Vector2.Zero) camPos = oldCamPos; Vector2 movement = camPos - oldCamPos; if (movement != Vector2.Zero) { //move camera TileEngine.PartyLeaderPosition.Move(movement, false); } } oldCamPos = camPos; //update player Player player = party.Players[0]; foreach (CutsceneFrame frame in currentCutscene.frames) { if (frame.frame == currentCutscene.currentFrame && player.Name == frame.actorName.Trim()) { if (playerProxyStartPosition == Vector2.Zero) { //playerProxyStartPosition = new Vector2(frame.x, frame.y); playerProxyStartPosition = TileEngine.GetScreenPosition(TileEngine.PartyLeaderPosition.TilePosition); } if (playerProxyPosition == Vector2.Zero) playerProxyPosition = new Vector2(frame.x, frame.y); if (frame.x != 0 || frame.y != 0) { Vector2 currentFramePosition = new Vector2(frame.x, frame.y); playerProxyMovement += currentFramePosition - playerProxyPosition; playerProxyPosition = currentFramePosition; } if (frame.animationName != "" && !currentCutscene.allowInput) { player.MapSprite.PlayAnimationByName(getCutsceneAnimation(frame.animationName)); if (frame.animationName.EndsWith("U") || frame.animationName.EndsWith("Uw")) TileEngine.PartyLeaderPosition.Direction = Direction.North; if (frame.animationName.EndsWith("D") || frame.animationName.EndsWith("Dw")) TileEngine.PartyLeaderPosition.Direction = Direction.South; if (frame.animationName.EndsWith("L") || frame.animationName.EndsWith("Lw")) TileEngine.PartyLeaderPosition.Direction = Direction.West; if (frame.animationName.EndsWith("R") || frame.animationName.EndsWith("Rw")) TileEngine.PartyLeaderPosition.Direction = Direction.East; } } } playerProxyMovement += cutsceneAutoStep(); // update NPCs for (int i = 0; i < singleton.npcs.Count; i++ ) { foreach (CutsceneFrame frame in currentCutscene.frames) { if (npcs[i].Name == "daryxll" && currentCutscene.currentFrame == 200 && frame.frame == 200) npcs[i].Name = npcs[i].Name; if (frame.frame == currentCutscene.currentFrame && npcs[i].Name == frame.actorName.Trim()) { Vector2 currentPosition = new Vector2(frame.x, frame.y); if(npcOldPositions[i] == Vector2.Zero) npcOldPositions[i] = currentPosition; if (frame.x != 0 || frame.y != 0) { npcPositions[i] += currentPosition - npcOldPositions[i]; npcOldPositions[i] = currentPosition; } if (frame.animationName != "") npcs[i].MapSprite.PlayAnimationByName(getCutsceneAnimation(frame.animationName)); } } } //actions/events foreach (CutsceneFrame frame in currentCutscene.frames) { if (frame.frame == currentCutscene.currentFrame && frame.actorName.StartsWith("d:")) singleton.screenManager.AddScreen(new DialogueScreen("Dialogue Screen", frame.actorName.Replace("d:", ""))); if (frame.frame == currentCutscene.currentFrame && frame.actorName.StartsWith("ts:")) { string[] param = frame.actorName.Replace("ts:", "").Split('_'); singleton.screenManager.AddScreen(new TextScreen(int.Parse(param[0]), param[1])); } if (frame.frame == currentCutscene.currentFrame && frame.actorName.StartsWith("f:")) { foreach (MapEntry<FixedCombat> fight in TileEngine.Map.FixedCombatEntries) { if (fight.Content.Name == frame.actorName.Replace("f:", "")) EncounterFixedCombat(fight); } } if (frame.frame == currentCutscene.currentFrame && frame.actorName.StartsWith("w:")) { if (frame.actorName.Replace("w:", "") == party.Players[0].Name) playerProxyStartPosition = new Vector2(frame.x, frame.y); for (int i = 0; i < npcs.Count; i++) if(frame.actorName.Replace("w:", "") == npcs[i].Name) npcPositions[i] = new Vector2(frame.x, frame.y); } if (frame.frame == currentCutscene.currentFrame && frame.actorName.StartsWith("wmap:")) { for (int i = 0; i < npcs.Count; i++) if (frame.actorName.Replace("wmap:", "") == npcs[i].Name) npcPositions[i] = TileEngine.GetScreenPosition(npcs[i].MapPosition); } if (frame.frame == currentCutscene.currentFrame && frame.actorName.StartsWith("wxy:")) { for (int i = 0; i < npcs.Count; i++) if (frame.actorName.Replace("wxy:", "") == npcs[i].Name) npcPositions[i] = new Vector2(TileEngine.Map.QuestNpcEntries[i].MapPosition.X, TileEngine.Map.QuestNpcEntries[i].MapPosition.Y); } if (frame.frame == currentCutscene.currentFrame && frame.actorName.StartsWith("c:")) { foreach(Cutscene c in cutscenes) if (c.name == frame.actorName.Replace("c:", "")) { currentCutscene.currentFrame = 0; currentCutscene = c; } } if (frame.frame == currentCutscene.currentFrame && frame.actorName.StartsWith("fp:")) { for (int i = 0; i < npcs.Count; i++) if (frame.actorName.Replace("fp:", "") == npcs[i].Name) { npcs[i].Direction = facePlayer(npcPositions[i]); npcs[i].ResetAnimation(false); } } if (frame.frame == currentCutscene.currentFrame && frame.actorName.StartsWith("s:")) { loadSong(frame.actorName.Replace("s:", "")); } if (frame.frame == currentCutscene.currentFrame && frame.actorName.StartsWith("se:")) { loadSoundEffect(frame.actorName.Replace("se:", "")); } if (frame.frame == currentCutscene.currentFrame && frame.actorName.StartsWith("r:")) { removeOverlay(frame.actorName.Replace("r:", "")); } if (frame.frame == currentCutscene.currentFrame && frame.actorName.StartsWith("moveToTile:")) { moveToTile(frame.actorName.Replace("moveToTile:", "")); } if (frame.frame == currentCutscene.currentFrame && frame.actorName.StartsWith("goTo:")) { currentCutscene.currentFrame = int.Parse(frame.actorName.Replace("goTo:", "")); } if (frame.frame == currentCutscene.currentFrame && frame.actorName.StartsWith("setCam:")) { setCamera(frame.actorName.Replace("setCam:", "")); } if (frame.frame == currentCutscene.currentFrame && frame.actorName.StartsWith("tileOverride:")) { activateTileOverride(frame.actorName.Replace("tileOverride:", "")); } if (frame.frame == currentCutscene.currentFrame && frame.actorName.StartsWith("act:")) { foreach (CutsceneTrigger ct in CutsceneTriggers) if (ct.cutscene.name == frame.actorName.Replace("act:", "")) ct.activated = false; } if (frame.frame == currentCutscene.currentFrame && frame.actorName.StartsWith("deact:")) { foreach (CutsceneTrigger ct in CutsceneTriggers) if (ct.cutscene.name == frame.actorName.Replace("deact:", "")) ct.activated = true; } if (frame.frame == currentCutscene.currentFrame && frame.actorName.StartsWith("cm:")) { ChangeMap(frame.actorName.Replace("cm:", ""), null); } if (frame.frame == currentCutscene.currentFrame && frame.actorName.StartsWith("e:")) { string[] list = frame.actorName.Replace("e:", "").Split('_'); foreach (string item in list) { if (item == "rain") { loadRain(); } if (item == "darken") { loadDarken(); } if (item == "dusk") { loadDusk(); } if (item == "black") { loadBlack(); } if (item == "thunder") { loadLightening(); } if (item == "fog") { loadFog(); } if (item == "mist") { loadMist(); } if (item == "red") { loadRed(); } if (item == "blue") { loadBlue(); } if (item.StartsWith("cf:")) { string[] param = item.Replace("cf:", "").Split(','); loadColorFade(int.Parse(param[0]), float.Parse(param[1]), float.Parse(param[2]), param[3]); } } } } //end cutscene if (currentCutscene.currentFrame == currentCutscene.maxFrame) { currentCutscene.currentFrame = 0; currentCutscene = null; //update player position Vector2 playerCustsceneDist = playerProxyStartPosition + playerProxyMovement - TileEngine.PartyLeaderPosition.ScreenPosition; //TileEngine.PartyLeaderPosition.Move(playerCustsceneDist, false); // update NPCs positions for (int i = 0; i < singleton.npcs.Count; i++) npcOldPositions[i] = Vector2.Zero; playerProxyMovement = Vector2.Zero; playerProxyPosition = Vector2.Zero; playerProxyStartPosition = Vector2.Zero; playerProxyAutoMove = Vector2.Zero; oldCamPos = Vector2.Zero; } }
public void checkDialogue() { Vector2 playerPosition = new Vector2( TileEngine.PartyLeaderPosition.TilePosition.X * TileEngine.Map.TileSize.X + TileEngine.PartyLeaderPosition.TileOffset.X , TileEngine.PartyLeaderPosition.TilePosition.Y * TileEngine.Map.TileSize.Y + TileEngine.PartyLeaderPosition.TileOffset.Y ); float deltaX = 0; float deltaY = 0; for (int i = 0; i < singleton.npcs.Count; i++) { deltaX = npcPositions[i].X - playerPosition.X; deltaY = npcPositions[i].Y - playerPosition.Y; if (Math.Sqrt(deltaX * deltaX + deltaY * deltaY) < 64) if ((InputManager.IsActionPressed(InputManager.Action.Ok) || InputManager.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.Enter))) { //check for cutscene foreach(CutsceneTrigger ct in CutsceneTriggers) if (ct.npcName == npcs[i].Name && ct.mapName == TileEngine.Map.Name && !ct.activated) { currentCutscene = ct.cutscene; if(!ct.repeat) ct.activated = true; } //normal dialogue if(currentCutscene == null) singleton.screenManager.AddScreen(new DialogueScreen("Dialogue Screen", "DUDE")); } } }