public void StartLevel(int level) { CurrentLevel = Levels.Where(p => p.Level == level).SingleOrDefault(); if (CurrentLevel == null) { string msg = $"Failed to Start Level {level}."; Log.Fatal(msg); throw new Exception(msg); //we need to stop here since the game is unplayable if this happens } //string[] mapLines = System.IO.File.ReadAllLines(mapFilename); //old method Width = CurrentLevel.Width; Height = CurrentLevel.Height; Tiles = new MapTile[CurrentLevel.Height, CurrentLevel.Width]; for (int yPos = 0; yPos < CurrentLevel.Height; yPos++) { //create the Map 2d array data from the current line char by char for (int xPos = 0; xPos < CurrentLevel.Width; xPos++) { //this calculates row * width of row + column (+1 per row [0 indexed] to adjust for spaces at the end of rows from yaml deserialization) int strpos = yPos * CurrentLevel.Width + xPos + (yPos); CreateTile(CurrentLevel.Map[strpos], xPos, yPos); } } //TODO place player in random available space like monsters are ThePlayer.X = 10; ThePlayer.Y = 10; Random randgen = new Random(); MonsterMgr.AddMonster(Tiles, randgen.Next(2, level + 3)); //MonsterMgr.AddMonster(Tiles, randgen.Next(1, 2)); }
void OnEnable() { nvAgent = GetComponent<NavMeshAgent>(); parentScript = transform.parent.GetComponent<MonsterMgr>(); playerTr = GameObject.FindGameObjectWithTag("Player").transform; StartCoroutine("FindTarget"); StartCoroutine("MoveMonster"); }
private static void PlayerTryMoveOffsetTo(int xoffset, int yoffset) { //this is the proposed new x,y of the player if move is successful. int newx = ThePlayer.X + xoffset; int newy = ThePlayer.Y + yoffset; //perform boundary checking of new location, if it fails then we can't move there just because of boundary issues if (newx > -1 && newx < Width && newy > -1 && newy < Height) { //get the tile that is at the new location MapTile t = GetTileAtPos(newx, newy); //if the space moving upwards is a blank space then move up if (t.IsWalkable) { ThePlayer.Dirty = true; Tiles[ThePlayer.Y, ThePlayer.X].IsWalkable = true; //the space we just moved from ThePlayer.LastX = ThePlayer.X; ThePlayer.LastY = ThePlayer.Y; ThePlayer.X = newx; ThePlayer.Y = newy; Tiles[ThePlayer.Y, ThePlayer.X].IsWalkable = false; //make new tile not walkable because you are on it CheckTileForAction(ThePlayer.X, ThePlayer.Y); } else { //if we can't walk onto this space then what is in this space? a wall, door, monster, etc.? //walls do nothing, doors we can check for keys, monsters we attack. var type = GetTileAtPos(newx, newy).GetType(); if (type == typeof(MapTileWall)) { //do nothing, its a wall } else if (type == typeof(MapTileSpace)) { //so if its a space and its not walkable, probably a monster here. var monster = MonsterMgr.GetMonsterAt(newx, newy); if (monster.IsAlive) { var maxdamage = ThePlayer.CanDealDamage(); //lets hit the monster for damage monster.TakeDamage(maxdamage); MessageBrd.Add($"Monster took {maxdamage} damage."); if (!monster.IsAlive) { MessageBrd.Add($"Monster is DEAD!"); } MonsterMgr.PruneDeadMonsters(); } } } } // end of map boundary check }
//[Header("Animation")] //public Light2D monsterLight; //public float waitTime; //public float lgihtMinSize; //public float animSpeed; // Start is called before the first frame update void Start() { tr = GetComponent <Transform>(); playerTr = GameObject.FindWithTag("Player").GetComponent <Transform>(); monsterMgr = FindObjectOfType <MonsterMgr>().GetComponent <MonsterMgr>(); anim = GetComponent <Animator>(); circle = GetComponent <CircleCollider2D>(); //monsterLight = gameObject.GetComponent<Light2D>(); //StartCoroutine(LightAnim()); //Light Anim 실행 StartCoroutine(Reposition()); }
public void Awake() { // only keep the first copy of this script around if (instance == null) { instance = this; } else { Destroy(this); } }
static public void StartSavedLevel(int level) { Width = CurrentLevel.Width; Height = CurrentLevel.Height; Random randgen = new Random(); MonsterMgr.ClearMonsters(); MonsterMgr.AddMonsters(randgen.Next(2, level + 3)); ObjectMgr.AddObjectsToMap(randgen.Next(3, level + 13)); ThePlayer.Dirty = true; Dirty = true; }
static public void StartLevel(int level) { CurrentLevel = Levels.Where(p => p.Level == level).SingleOrDefault(); if (CurrentLevel == null) { string msg = $"Failed to Start Level {level}."; Log.Fatal(msg); throw new Exception(msg); //we need to stop here since the game is unplayable if this happens } Width = CurrentLevel.Width; Height = CurrentLevel.Height; Tiles = null; Tiles = new MapTile[CurrentLevel.Height, CurrentLevel.Width]; for (int yPos = 0; yPos < CurrentLevel.Height; yPos++) { //create the Map 2d array data from the current line char by char for (int xPos = 0; xPos < CurrentLevel.Width; xPos++) { //this calculates row * width of row + column (+1 per row [0 indexed] to adjust for spaces at the end of rows from yaml deserialization) int strpos = yPos * CurrentLevel.Width + xPos + (yPos); CreateTile(CurrentLevel.Map[strpos], xPos, yPos); } } Random randgen = new Random(); MonsterMgr.ClearMonsters(); MonsterMgr.AddMonsters(randgen.Next(2, level + 3)); ObjectMgr.AddObjects(randgen.Next(3, level + 3)); //ObjectMgr.AddObjects(randgen.Next(10, 20)); ThePlayer.Dirty = true; Dirty = true; }
/// <summary> /// Draw the map /// </summary> public int Update() { var origRow = Console.CursorTop; var origCol = Console.CursorLeft; if (NeedsRedrawing) { Console.Clear(); for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { Tiles[y, x].Draw(); } Console.WriteLine(); //carriage return at end of each line because we're not using SetCursorPosition. } NeedsRedrawing = false; } //if there is a keypress available to capture, take it and perform its action if (Console.KeyAvailable) { var ch = Console.ReadKey(true).Key; switch (ch) { case ConsoleKey.Escape: Log.Information("User is quitting."); return(-1); case ConsoleKey.UpArrow: //perform boundary checking if (ThePlayer.X > 0) { //if the space moving upwards is a blank space then move up if (GetTileAtPos(ThePlayer.X, ThePlayer.Y - 1).IsWalkable) { MovePlayer(PlayerMovement.Up); } } break; case ConsoleKey.DownArrow: if (ThePlayer.Y < Height - 1) { if (GetTileAtPos(ThePlayer.X, ThePlayer.Y + 1).IsWalkable) { MovePlayer(PlayerMovement.Down); } } break; case ConsoleKey.RightArrow: if (ThePlayer.X < Width - 1) { if (GetTileAtPos(ThePlayer.X + 1, ThePlayer.Y).IsWalkable) { MovePlayer(PlayerMovement.Right); } } break; case ConsoleKey.LeftArrow: if (ThePlayer.X > 0) { if (GetTileAtPos(ThePlayer.X - 1, ThePlayer.Y).IsWalkable) { MovePlayer(PlayerMovement.Left); } } break; } } //foreach player in players coming soon.... ThePlayer.Update(); MonsterMgr.UpdateAll(this); MessageBrd.Update(); Console.SetCursorPosition(0, 0); return(0); }
private void Awake() { inst = this; }
void Start() { inst = this; //monsters = new List<Monster>(); }
/// <summary> /// Draw the map /// </summary> static public int Update() { if (ThePlayer.Life < 1) { Console.Clear(); MessageBrd.Add($"You have DIED!"); MessageBrd.Update(); return(-1); } var origRow = Console.CursorTop; var origCol = Console.CursorLeft; UpdateFogOfWar(); for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { Tiles[y, x].Draw(); } } Dirty = false; //foreach player in players coming soon.... ThePlayer.Update(); MonsterMgr.UpdateAll(); MessageBrd.Update(); ScoreCard.Update(); //if there is a keypress available to capture, take it and perform its action if (Console.KeyAvailable) { var ch = Console.ReadKey(true).Key; switch (ch) { case ConsoleKey.Escape: Log.Information("User is quitting."); return(-1); case ConsoleKey.F2: CheatToggleFOW(); break; case ConsoleKey.UpArrow: PlayerTryMoveOffsetTo(0, -1); break; case ConsoleKey.DownArrow: PlayerTryMoveOffsetTo(0, 1); break; case ConsoleKey.RightArrow: PlayerTryMoveOffsetTo(1, 0); break; case ConsoleKey.LeftArrow: PlayerTryMoveOffsetTo(-1, 0); break; } } //Console.SetCursorPosition(0, 0); return(0); }
/// <summary> /// Draw the map /// </summary> static public int Update() { switch (GameState) { case GameStateType.MainMenu: if (Dirty) { Console.Clear(); Console.WriteLine(FiggleFonts.Ogre.Render("Mud2D")); #if DEBUG Console.WriteLine("DEBUG version"); Log.Information("DEBUG version"); #elif RELEASE Console.WriteLine("RELEASE version"); Log.Information("RELEASE version"); #endif Console.WriteLine("------===== Main Menu =====-------"); Console.WriteLine("Press S to start game"); Console.WriteLine("Press L to load last save game"); Console.WriteLine("Press ESC to exit"); Dirty = false; } //if there is a keypress available to capture, take it and perform its action if (Console.KeyAvailable) { var ch = Console.ReadKey(true).Key; switch (ch) { case ConsoleKey.Escape: GameState = GameStateType.Quit; Log.Information("User is quitting game."); return(-1); case ConsoleKey.L: GameState = GameStateType.InGame; LoadLastGame(); break; case ConsoleKey.S: GameState = GameStateType.InGame; InitializeGame(); break; } } break; case GameStateType.InGame: if (ThePlayer.Life < 1) { Console.Clear(); MessageBrd.Add($"You have DIED!"); MessageBrd.Update(); return(-1); } var origRow = Console.CursorTop; var origCol = Console.CursorLeft; UpdateFogOfWar(); for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { Tiles[y, x].Draw(); } } Dirty = false; //foreach player in players coming soon.... ThePlayer.Update(); MonsterMgr.UpdateAll(); MessageBrd.Update(); ScoreCard.Update(); //if there is a keypress available to capture, take it and perform its action if (Console.KeyAvailable) { var ch = Console.ReadKey(true).Key; switch (ch) { case ConsoleKey.Escape: GameState = GameStateType.MainMenu; Dirty = true; SaveGame(); Log.Information("User is quitting game, going back to main menu."); break; case ConsoleKey.F2: CheatToggleFOW(); break; case ConsoleKey.UpArrow: PlayerTryMoveOffsetTo(0, -1); break; case ConsoleKey.DownArrow: PlayerTryMoveOffsetTo(0, 1); break; case ConsoleKey.RightArrow: PlayerTryMoveOffsetTo(1, 0); break; case ConsoleKey.LeftArrow: PlayerTryMoveOffsetTo(-1, 0); break; } } //Console.SetCursorPosition(0, 0); return(0); } return(0); }
public SceneState(string[] s, MonsterMgr r) { role = r; strs = s; }
public MoveBoxState(ClickBox.BoxType t, string[] s, MonsterMgr r) { type = t; role = r; strs = s; }
public MonsterRole AddMonster(int id, Vector3 pos, uint serverid = 0u, float roatate = 0f, int boset_num = 0, int carr = 0, string name = null) { this.init(); bool flag = this.m_mapMonster.ContainsKey(serverid); MonsterRole result; if (flag) { result = null; } else { SXML sXML = this.dMon[id]; int num = sXML.getInt("obj"); float @float = sXML.getFloat("scale"); bool flag2 = serverid <= 0u; if (flag2) { bool flag3 = Globle.m_nTestMonsterID > 0; if (flag3) { num = Globle.m_nTestMonsterID; } } bool flag4 = sXML.getInt("collect_tar") > 0; bool isHardDemo = Globle.isHardDemo; Type type; if (isHardDemo) { type = MonsterMgr.getTypeHandle("Md" + num); } else { bool flag5 = flag4; if (flag5) { bool flag6 = num == 122; if (flag6) { type = Type.GetType("CollectBox"); } else { type = Type.GetType("CollectRole"); } } else { type = Type.GetType("M" + num); } } bool flag7 = id == 4002 || carr == 2; if (flag7) { type = Type.GetType("M000P2"); } else { bool flag8 = id == 4003 || carr == 3; if (flag8) { type = Type.GetType("M000P3"); } else { bool flag9 = id == 4005 || carr == 5; if (flag9) { type = Type.GetType("M000P5"); } } } bool flag10 = type == null; if (flag10) { type = Type.GetType("M00000"); } MonsterRole monsterRole = (MonsterRole)Activator.CreateInstance(type); bool flag11 = name != null; if (flag11) { monsterRole.ownerName = name; } bool flag12 = carr == 0; if (flag12) { monsterRole.roleName = sXML.getString("name"); } monsterRole.tempXMl = sXML; monsterRole.m_circle_type = sXML.getInt("boss_circle"); bool flag13 = sXML.getFloat("boss_circle_scale") == -1f; if (flag13) { monsterRole.m_circle_scale = 1f; } else { monsterRole.m_circle_scale = sXML.getFloat("boss_circle_scale"); } monsterRole.isBoos = (sXML.getInt("boss") == 1); bool flag14 = @float > 0f; if (flag14) { monsterRole.scale = @float; } bool flag15 = monsterRole != null; if (flag15) { bool flag16 = id == 4002 || carr == 2; if (flag16) { monsterRole.Init("profession/warrior_inst", EnumLayer.LM_MONSTER, pos, roatate); } else { bool flag17 = id == 4003 || carr == 3; if (flag17) { monsterRole.Init("profession/mage_inst", EnumLayer.LM_MONSTER, pos, roatate); } else { bool flag18 = id == 4005 || carr == 5; if (flag18) { monsterRole.Init("profession/assa_inst", EnumLayer.LM_MONSTER, pos, roatate); } else { bool flag19 = flag4; if (flag19) { monsterRole.Init("npc/" + num, EnumLayer.LM_MONSTER, pos, roatate); } else { monsterRole.Init("monster/" + num, EnumLayer.LM_MONSTER, pos, roatate); } } } } monsterRole.monsterid = id; bool flag20 = boset_num > 0; if (flag20) { PlayerNameUIMgr.getInstance().show(monsterRole); PlayerNameUIMgr.getInstance().seticon_forDaobao(monsterRole, boset_num); } bool flag21 = ModelBase <A3_ActiveModel> .getInstance().mwlr_map_info.Count > 0; if (flag21) { PlayerNameUIMgr.getInstance().seticon_forMonsterHunter(monsterRole, ModelBase <A3_ActiveModel> .getInstance().mwlr_map_info[0]["target_mid"] != id); } bool flag22 = serverid > 0u; if (flag22) { monsterRole.m_unIID = serverid; this.m_mapMonster.Add(serverid, monsterRole); } else { monsterRole.isfake = true; monsterRole.m_unIID = this.idIdx; this.m_mapFakeMonster.Add(this.idIdx, monsterRole); this.idIdx += 1u; } bool flag23 = !GRMap.loading; if (flag23) { monsterRole.refreshViewType(2); } } this.m_listMonster.Add(monsterRole); bool flag24 = monsterRole != null; if (flag24) { base.dispatchEvent(GameEvent.Create(MonsterMgr.EVENT_MONSTER_ADD, this, monsterRole, false)); } result = monsterRole; } return(result); }
// Update is called once per frame void Update() { for (int i = 0; i < monMaxCnt; ++i) { if (Game.Network.NetWork.monster_data.ContainsKey(i) == false) { continue; } if (Game.Network.NetWork.monster_data[i].get_hp() <= 0 || Game.Network.NetWork.monster_data[i].get_draw() == false) { string name = "Monster(" + i.ToString() + ")"; monsterObj = transform.Find(name).gameObject; Destroy(monsterObj); continue; } string a = "Monster(" + i.ToString() + ")"; //GameObject playerObj = transform.GetChild(id-1).gameObject; Transform tmp = transform.Find(a); if (tmp == null) { GameObject monster = Instantiate(monsterPrefab, Game.Network.NetWork.monster_data[i].get_pos(), Quaternion.identity); monster.name = a; monster.transform.parent = transform; monsterObj = transform.Find(a).gameObject; } else { monsterObj = transform.Find(a).gameObject; } MonsterMgr monsterStatus = monsterObj.GetComponent <MonsterMgr>(); if (Game.Network.NetWork.monster_data.ContainsKey(i)) { // playerStatus.rotation = Game.Network.NetWork.client_data[i].get_rot(); monsterStatus.ID = i; monsterStatus.position = Game.Network.NetWork.monster_data[i].get_pos(); monsterStatus.rotation = Game.Network.NetWork.monster_data[i].get_rot(); monsterStatus.dirX = Game.Network.NetWork.monster_data[i].get_dirX(); monsterStatus.dirZ = Game.Network.NetWork.monster_data[i].get_dirZ(); monsterStatus.chase_id = Game.Network.NetWork.monster_data[i].get_chase_id(); monsterStatus.calculate_id = Game.Network.NetWork.monster_data[i].get_calculate_id(); monsterStatus.animator = Game.Network.NetWork.monster_data[i].get_animator(); //monsterStatus.draw = true; } else { //monsterStatus.draw = false; } //if (monsterStatus.draw) //{ monsterObj.SetActive(true); //} //else //{ // monsterObj.SetActive(false); //} // last_id = Game.Network.NetWork.new_player_id; } }