public s_object CheckCollision(s_object obj, Vector3 velocity) { //For checking the player's future 'X' position float x = worldpos.x + (Collider.size.x * (int)Mathf.Sign(vecloicty.x)); float y = worldpos.y + (Collider.size.y * (int)Mathf.Sign(vecloicty.y)); float z = worldpos.z + (Collider.size.z * (int)Mathf.Sign(vecloicty.z)); Vector3 futurepos = new Vector3(x, y, z); Vector3Int futrgridpos = grid.GetObjectPositionToGrid(futurepos); Vector3Int worlgridpos = grid.GetObjectPositionToGrid(worldpos); if (futrgridpos.y > 1 && futrgridpos.y < grid.worldsize.y - 2) { if (grid.blocks[futrgridpos.x, worlgridpos.y, worlgridpos.z] != null) { return(grid.blocks[futrgridpos.x, worlgridpos.y, worlgridpos.z]); } } if (futrgridpos.y > 1 && futrgridpos.y < grid.worldsize.y - 2) { if (grid.blocks[worlgridpos.x, futrgridpos.y, worlgridpos.z] != null) { return(grid.blocks[worlgridpos.x, futrgridpos.y, worlgridpos.z]); } } if (grid.blocks[worlgridpos.x, worlgridpos.y, futrgridpos.z] != null) { return(grid.blocks[worlgridpos.x, worlgridpos.y, futrgridpos.z]); } return(null); }
public int MoveCost(Vector3 cursorpos) { Vector3 mousePositon = cursorpos; if (path.PathFind(transform.position, mousePositon)) { o_node goal = grid.NodeFromWorld(mousePositon); o_node thischaracter = grid.NodeFromWorld(transform.position); if (!grid.NodeFromWorld(mousePositon).walkable) { s_object objectm = grid.ObjectFromWorld(mousePositon); return(-1); } else { return(path.RetracePath(goal, thischaracter).Count); } } else { return(-1); } }
public void DespawnObject(Vector2 positon) { s_object obj = ObjectFromWorld(positon); if (obj == null) { return; } Vector2Int lastpos = VectorPositionFromWorld(obj.transform.position); if (obj.GetType() == typeof(o_character)) { character_layer[lastpos.x, lastpos.y] = null; } else if (obj.GetType() == typeof(o_tile)) { block_layer[lastpos.x, lastpos.y] = null; } else if (obj.GetType() == typeof(o_item)) { item_layer[lastpos.x, lastpos.y] = null; } obj.gameObject.SetActive(false); }
void FillObjectPooler() { foreach (s_object obj in blockObjects) { Type type = obj.GetType(); if (type == typeof(o_tile)) { for (int i = 0; i < 900; i++) { s_object objectt = Instantiate(obj, transform.position, Quaternion.identity); objectt.name = obj.name; objPool[obj.name].Enqueue(objectt); objectt.gameObject.SetActive(false); } } else { for (int i = 0; i < 20; i++) { s_object objectt = Instantiate(obj, transform.position, Quaternion.identity); objectt.name = obj.name; objPool[obj.name].Enqueue(objectt); objectt.gameObject.SetActive(false); } } } }
public void DespawnObject(s_object obje, int layerInt) { s_object obj = obje; /* * if (obj == null) * return; */ Vector2Int lastpos = VectorPositionFromWorld(obj.transform.position); if (layerInt == 0) { character_layer[lastpos.x, lastpos.y] = null; } else if (layerInt == 1) { block_layer[lastpos.x, lastpos.y] = null; } else if (layerInt == 2) { item_layer[lastpos.x, lastpos.y] = null; } obj.gameObject.SetActive(false); }
public s_object CheckCollisionInside(s_object obj) { //For checking the player's future 'X' position float x = worldpos.x; float y = worldpos.y; float z = worldpos.z; Vector3 futurepos = new Vector3(x, y, z); Vector3Int futrgridpos = grid.GetObjectPositionToGrid(futurepos); Vector3Int worlgridpos = grid.GetObjectPositionToGrid(worldpos); if (futrgridpos.y > 1 && futrgridpos.y < grid.worldsize.y - 2) { if (grid.blocks[futrgridpos.x, worlgridpos.y, worlgridpos.z] != null) { return(grid.blocks[futrgridpos.x, worlgridpos.y, worlgridpos.z]); } } if (futrgridpos.y > 1 && futrgridpos.y < grid.worldsize.y - 2) { if (grid.blocks[worlgridpos.x, futrgridpos.y, worlgridpos.z] != null) { return(grid.blocks[worlgridpos.x, futrgridpos.y, worlgridpos.z]); } } if (grid.blocks[worlgridpos.x, worlgridpos.y, futrgridpos.z] != null) { return(grid.blocks[worlgridpos.x, worlgridpos.y, futrgridpos.z]); } return(null); }
public s_object SpawnObject(string typeofobj, Vector2 positon) { if (objPool[typeofobj] == null) { print(typeofobj); return(null); } s_object obj = objPool[typeofobj].Peek(); //if(objPool[typeofobj].Peek()) Vector2Int cells = VectorPositionFromWorld(positon); /* * bool check = false; * * //Compare the 'obj' to what exists on the current position * if (obj.GetType() == typeof(o_character)) * check = character_layer[cells.x, cells.y] != null; * else if (obj.GetType() == typeof(o_tile)) * check = block_layer[cells.x, cells.y] != null; * else if (obj.GetType() == typeof(o_item)) * check = item_layer[cells.x, cells.y] != null; * * if (check) * return null; */ //Delete the last position from the world Vector2Int lastpos = VectorPositionFromWorld(obj.transform.position); /* * if (obj.GetType() == typeof(o_character)) * character_layer[lastpos.x, lastpos.y] = null; * else if(obj.GetType() == typeof(o_tile)) * block_layer[lastpos.x, lastpos.y] = null; * else if (obj.GetType() == typeof(o_item)) * item_layer[lastpos.x, lastpos.y] = null; */ if (obj.GetType() == typeof(o_character)) { character_layer[cells.x, cells.y] = (o_character)obj; } else if (obj.GetType() == typeof(o_tile)) { block_layer[cells.x, cells.y] = (o_tile)obj; } else if (obj.GetType() == typeof(o_item)) { item_layer[cells.x, cells.y] = (o_item)obj; } objPool[typeofobj].Dequeue(); objPool[typeofobj].Enqueue(obj); obj.transform.position = SnapToGrid(positon); obj.gameObject.SetActive(true); return(obj); }
public void DisplayData(s_object otype) { string datatype = otype.GetType().ToString(); switch (datatype) { case "o_door": o_door door = (o_door)otype; door.location = GUI.TextField(new Rect(50, 60, 80, 20), door.location); if (levels.Exists(d => d.name == door.location)) { GUI.Box(new Rect(50, 80, 160, 20), "Position: " + door.teleport_position); data_level dat = levels.Find(d => d.name == door.location); door.teleport_position.x = (int)GUI.HorizontalSlider(new Rect(50, 100, 90, 20), door.teleport_position.x, dat.size_x, 0); door.teleport_position.y = (int)GUI.HorizontalSlider(new Rect(50, 120, 90, 20), door.teleport_position.y, dat.size_y, 0); door.teleport_position.z = (int)GUI.HorizontalSlider(new Rect(50, 140, 90, 20), door.teleport_position.z, dat.size_z, 0); GUI.Box(new Rect(50, 160, 270, 20), "Requirements: " + door.DOOR_STATE.ToString()); if (GUI.Button(new Rect(50, 180, 200, 40), "Change requirement +")) { door.DOOR_STATE++; } if (GUI.Button(new Rect(250, 180, 200, 40), "Change requirement -")) { door.DOOR_STATE--; } door.DOOR_STATE = (o_door.DOOR_MODE)Mathf.Clamp((float)door.DOOR_STATE, 0, 2); switch (door.DOOR_STATE) { case o_door.DOOR_MODE.WATERSTONE: door.locked = true; GUI.Box(new Rect(50, 220, 270, 20), "Water stones: " + door.required_waterstones); door.required_waterstones = (int)GUI.HorizontalSlider(new Rect(50, 240, 90, 20), door.required_waterstones, 0, 30); break; case o_door.DOOR_MODE.NONE: door.locked = false; break; } } break; case "o_block": dataobj = null; break; } if (GUI.Button(new Rect(50, 260, 90, 20), "Exit")) { dataobj = null; } }
public s_object CheckCollision(s_object obj) { //For checking the player's future 'X' position float x = worldpos.x + (Collider.size.x); float y = worldpos.y + (Collider.size.y); float z = worldpos.z + (Collider.size.z); Vector3 futurepos = new Vector3(x, y, z); Vector3Int futrgridpos = grid.GetObjectPositionToGrid(futurepos); Vector3Int worlgridpos = grid.GetObjectPositionToGrid(worldpos); for (int i = -1; i != 1; i++) { if (i == 0) { continue; } if (futrgridpos.y + i > 1 && futrgridpos.y + i < grid.worldsize.y - 2) { if (grid.blocks[futrgridpos.x + i, worlgridpos.y, worlgridpos.z] != null) { return(grid.blocks[futrgridpos.x, worlgridpos.y, worlgridpos.z]); } } } for (int i = -1; i != 1; i++) { if (i == 0) { continue; } if (futrgridpos.y + i > 1 && futrgridpos.y + i < grid.worldsize.y - 2) { if (grid.blocks[worlgridpos.x, futrgridpos.y + i, worlgridpos.z] != null) { return(grid.blocks[worlgridpos.x, futrgridpos.y, worlgridpos.z]); } } } for (int i = -1; i != 1; i++) { if (i == 0) { continue; } if (grid.blocks[worlgridpos.x, worlgridpos.y, futrgridpos.z] != null) { return(grid.blocks[worlgridpos.x, worlgridpos.y, futrgridpos.z + i]); } } return(null); }
public Vector3Int GetObjectPositionToGrid(s_object obj) { Vector3 position = obj.worldpos; int x = Mathf.RoundToInt(position.x / nodeLength); int y = Mathf.RoundToInt(position.y / nodeLength); int z = Mathf.RoundToInt(position.z / nodeLength); return(new Vector3Int(x, y, z)); }
public void SetObject(int menu) { List <s_object> blocks = Grid.blockObjects; select += menu; select = Mathf.Clamp(select, 0, blocks.Count - 1); selected_object = blocks[select]; UpdateToolText(); }
public bool IsCharacter(Vector3 mousePositon, s_object obj) { if (obj != null) { if (obj.GetType() == typeof(o_character)) { return(true); } } return(false); }
void SetStringToObjectName(ref ev_details det) { objectItem = (s_object)EditorGUILayout.ObjectField(objectItem, typeof(s_object), true); if (GUILayout.Button("Set string to object")) { if (objectItem != null) { det.string0 = objectItem.name; } } }
public s_object GetObjectFromWorld(Vector3 mousePositon) { Vector2 snap = Grid.SnapToGrid(mousePositon); s_object obj = Grid.ObjectFromWorld(snap); if (obj != null) { return(obj); } else { return(null); } }
public void DespawnObject(s_object obj) { Vector3Int posInGrid = GetObjectPositionToGrid(obj.worldpos); bool check = blocks[posInGrid.x, posInGrid.y, posInGrid.z] == null; if (check) { return; } if (posInGrid.x > worldsize.x || posInGrid.x < 0 || posInGrid.y > worldsize.y || posInGrid.y < 0 || posInGrid.z > worldsize.z || posInGrid.z < 0) { return; } blocks[posInGrid.x, posInGrid.y, posInGrid.z].gameObject.SetActive(false); blocks[posInGrid.x, posInGrid.y, posInGrid.z] = null; }
private void OnGUI() { Vector3 mousepos = Camera.main.ScreenToWorldPoint(Input.mousePosition); switch (TOOLKIT) { case TOOLKT.BRUSH: break; case TOOLKT.EDIT: if (dataobj == null) { s_object obj = Grid.GetObjectFromGrid(new Vector3(mousepos.x, mousepos.y, z * Grid.GetNodeLength)); if (obj == null) { break; } object otype = obj.GetType(); if (Input.GetMouseButtonDown(0)) { dataobj = obj; } } else { DisplayData(dataobj); } break; } z_depth = (int)GUI.VerticalSlider(new Rect(45, 55, 150, 75), z_depth, 0, 10); wordsiz_temp.x = (int)GUI.HorizontalSlider(new Rect(32, 23, 150, 23), wordsiz_temp.x, 1, 45); wordsiz_temp.y = (int)GUI.VerticalSlider(new Rect(32, 45, 23, 150), wordsiz_temp.y, 1, 45); GUI.Label(new Rect(0, 0, 90, 90), "(" + wordsiz_temp.x + ", " + wordsiz_temp.y + ")" + " Z-Fill: " + z_depth); }
private void Start() { if (GameObject.Find("Position") != null) { txt = GameObject.Find("Position").GetComponent <UnityEngine.UI.Text>(); } cursor = GameObject.Find("Cursor"); left_bar = GameObject.Find("<").GetComponent <Button>(); right_bar = GameObject.Find(">").GetComponent <Button>(); button = GameObject.Find("Brush").GetComponent <Button>(); load_level = GameObject.Find("Load Level").GetComponent <Button>(); inpfeild = GameObject.Find("Level Name").GetComponent <InputField>(); text = button.gameObject.transform.GetChild(0).GetComponent <Text>(); Grid = GetComponent <s_grid>(); Grid.Initialize(); currentblock = Grid.BlockTypes[0]; if (Resources.Load("Game") != null) { LevelStructureLoad(); } }
private void OnGUI() { if (player != null) { if (TURNSTATE == TURNS.PLAYER) { DrawBar(); } } if (game_on) { switch (STATES) { case STATEMACHINE.IDLE: switch (TURNSTATE) { case TURNS.PLAYER: if (GetWinner == VICTORY_DICTATOR.PLAYER) { if (PushButton(new Rect(90, 90, 125, 30), "Claim Victory")) { EndTurn(); } } else if (PushButton(new Rect(90, 90, 90, 30), "End Turn")) { EndTurn(); } break; } break; case STATEMACHINE.SELECT_CHAR: switch (TURNSTATE) { case TURNS.PLAYER: if (Players.Contains(player)) { item_on_floor = Grid.ObjectFromWorld(player.transform.position, 1); if (item_on_floor != null) { if (player.current_item == null) { if (PushButton(new Rect(5, 180, 115, 30), "Pick up item")) { PickUpItem(); s_sound.PlaySound(select); } } } if (player.current_item != null) { if (PushButton(new Rect(5, 180, 90, 30), "Use item")) { UseItem(); } if (item_on_floor == null) { if (PushButton(new Rect(5, 210, 90, 30), "Drop item")) { DropItem(); } } } } if (Input.GetMouseButtonDown(1)) { LooseFocus(); } break; } //Have a cancel button where this player is no longer the focus //Attack button where it checks enemies break; case STATEMACHINE.ATTACK_SELECT: switch (TURNSTATE) { case TURNS.PLAYER: DrawTargetBar(); break; } break; } } }
public void CheckCharacterSurroundings(bool is_enemy) { //If an enemy or two appears enable the confirm attack button targets.Clear(); HashSet <o_node> enemynodes = Grid.CheckAroundNode(Grid.NodeFromWorld(player.transform.position)); foreach (o_node e in enemynodes) { s_object enemyObject = Grid.ObjectFromWorld(e); if (enemyObject == null) { continue; } if (enemyObject.GetType() == typeof(o_character)) { o_character enemy = enemyObject.GetComponent <o_character>(); if (PlayerPrefs.GetInt("MonsterMode") == 0) { if (!is_enemy) { if (!Heroes.Contains(enemy.name)) { targets.Add(enemy); } } else { if (!Adversaries.Contains(enemy.name)) { targets.Add(enemy); } } } else if (PlayerPrefs.GetInt("MonsterMode") == 1) { if (!is_enemy) { if (!Adversaries.Contains(enemy.name)) { targets.Add(enemy); } } else { if (!Heroes.Contains(enemy.name)) { targets.Add(enemy); } } } } else { continue; } } }
new void Update() { if (CheckCollisionInside(this) != null) { s_object collidedobj = CheckCollisionInside(this); if (collidedobj.GetType() == typeof(o_door)) { o_door d = collidedobj.GetComponent <o_door>(); if (d.CanPass()) { reqtext = ""; if (d.location != "Ending") { saved_number_of_water = water_stones_cap; gman.LoadRoom(d); } else { UnityEngine.SceneManagement.SceneManager.LoadScene("Ending"); } } else { reqtext = d.PassReq(); } } else if (collidedobj.GetType() == typeof(o_block)) { if (collidedobj.name == "Spike") { if (!isdying) { water_stones_cap = saved_number_of_water; isgrounded = false; StartCoroutine(DyingAnim()); } } } else if (collidedobj.GetType() == typeof(o_item)) { o_item i = collidedobj.GetComponent <o_item>(); water_stones_cap++; grid.DespawnObject(i); } } else { reqtext = ""; } base.Update(); ite = "Water stones: " + water_stones_cap; gman.txt.text = ite + "\n" + reqtext; if (Input.GetAxisRaw("Horizontal") != 0 || Input.GetAxisRaw("Vertical") != 0) { anim.SetBool("Walk", true); } else { anim.SetBool("Walk", false); } if (!Input.GetButton("Vertical")) { anim.SetFloat("Y", 0); anim.SetFloat("X", (int)Input.GetAxisRaw("Horizontal")); if (Input.GetKey(KeyCode.RightArrow)) { vecloicty.x = speed; } if (Input.GetKey(KeyCode.LeftArrow)) { vecloicty.x = -speed; } } if (!Input.GetButton("Horizontal")) { anim.SetFloat("X", 0); anim.SetFloat("Y", (int)Input.GetAxisRaw("Vertical")); if (Input.GetKey(KeyCode.UpArrow)) { vecloicty.y = speed; } if (Input.GetKey(KeyCode.DownArrow)) { vecloicty.y = -speed; } } if (isgrounded) { if (Input.GetKeyDown(KeyCode.Space)) { vecloicty.z = 5; } } }
private void Update() { if (Grid.gridworldsize.y > 0 && Grid.gridworldsize.x > 0) { Vector3 mousePositon = Camera.main.ScreenToWorldPoint(Input.mousePosition); s_object selectedObj = Grid.ObjectFromWorld(mousePositon); if (Input.GetKeyDown(KeyCode.W)) { spritenum++; } if (Input.GetKeyDown(KeyCode.S)) { spritenum--; } if (Input.GetKeyDown(KeyCode.E)) { angle += 90; } if (angle > 360) { angle = 0; } examplerend.gameObject.transform.localRotation = Quaternion.Euler(0, 0, angle); spritenum = Mathf.Clamp(spritenum, 0, spriteArray.Length - 1); examplerend.sprite = spriteArray[spritenum]; if (Grid.NodeFromWorld(mousePositon) != null) { Vector2 snap = Grid.SnapToGrid(mousePositon); if (Input.GetMouseButton(0)) { if (selectedObj != null) { if (selectedObj.GetComponent <s_object>().GetType() == typeof(o_tile)) { SpriteRenderer ren = selectedObj.GetComponent <SpriteRenderer>(); ren.sprite = spriteArray[spritenum]; ren.gameObject.transform.localRotation = examplerend.gameObject.transform.localRotation; } } //target.transform.position = mousePositon; if (Grid.ObjectFromWorld(mousePositon) == null) { Vector2Int vecint = Grid.VectorPositionFromWorld(mousePositon); if (selected_object != null) { s_object obj = Grid.SpawnObject(selected_object.name, snap); } } } if (Input.GetMouseButton(1)) { if (Grid.ObjectFromWorld(mousePositon) != null) { Vector2Int vecint = Grid.VectorPositionFromWorld(mousePositon); if (selected_object != null) { Grid.DespawnObject(snap); } } } } } if (Grid.nodes != null) { for (int x = 0; x < Grid.gridworldsize.x; x++) { for (int y = 0; y < Grid.gridworldsize.y; y++) { /* * SpriteRenderer colourRender = Grid.nodegameobjects[x, y].GetComponent<SpriteRenderer>(); * colourRender.color = Color.white; * if (Grid.CheckForNodeOnGrid(mousePositon, x, y)) * { * colourRender.color = Color.blue; * } */ } } } }
private void Update() { if (PlayerPrefs.GetInt("MonsterMode") == 0) { if (Players.Count < 10) { PlayerCount.text = "0" + Players.Count; } else { PlayerCount.text = "" + Players.Count; } if (Enemies.Count < 10) { EnemyCount.text = "0" + Enemies.Count; } else { EnemyCount.text = "" + Enemies.Count; } } else { if (Players.Count < 10) { PlayerCount.text = "0" + Enemies.Count; } else { PlayerCount.text = "" + Enemies.Count; } if (Enemies.Count < 10) { EnemyCount.text = "0" + Players.Count; } else { EnemyCount.text = "" + Players.Count; } } Vector3 mousePositon = Camera.main.ScreenToWorldPoint(Input.mousePosition); if (player == null) { pathfcost = 0; stats.text = "Nothing"; } if (GetWinner == VICTORY_DICTATOR.ENEMY) { s_camera.staticCam.StartCoroutine(s_camera.staticCam.Fade(Color.black, 0.3f)); game_on = false; if (s_camera.staticCam.isfaded) { UnityEngine.SceneManagement.SceneManager.LoadScene("Title"); } } if (game_on) { switch (STATES) { case STATEMACHINE.IDLE: switch (TURNSTATE) { case TURNS.PLAYER: if (Input.GetMouseButtonDown(0)) { if (CheckForObject(mousePositon)) { s_object obj = GetObjectFromWorld(mousePositon); if (IsCharacter(mousePositon, obj)) { o_character obselect = obj.GetComponent <o_character>(); if (obselect.health > 0) { if (obselect.playable) { pathfcost = 0; SwitchCharacter((o_character)obj); CheckCharacterSurroundings(false); } player = obselect; STATES = STATEMACHINE.SELECT_CHAR; } } } } break; #region ENEMY case TURNS.ENEMY: if (EnemyQueue.Count > 0) { //print("Chara " + EnemyQueue.Peek()); player = EnemyQueue.Peek(); //print("pl " + player); STATES = STATEMACHINE.SELECT_CHAR; } else { s_camera.staticCam.StartCoroutine(s_camera.staticCam.Fade(Color.clear, 4)); if (s_camera.staticCam.isfaded) { print("Progress END: " + EnemyQueue.Count); EndTurn(); } } break; #endregion } break; case STATEMACHINE.SELECT_CHAR: switch (TURNSTATE) { case TURNS.PLAYER: if (player.current_item != null) { stats.text = player.name + "\n" + "Item: " + player.current_item.name; } else { stats.text = player.name; } //actionpoints = "AP: " + player.actionPoints + "/" + player.maxActionPoints; if (CheckForObject(mousePositon)) { if (Input.GetMouseButtonDown(0)) { CheckCharacterSurroundings(false); s_object obj = GetObjectFromWorld(mousePositon); if (obj != null) { if (obj.GetType() == typeof(o_character)) { o_character chara = obj.GetComponent <o_character>(); if (targets.Contains(chara)) { if (!chara.playable) { targetToAttack = chara; STATES = STATEMACHINE.ATTACK_SELECT; } } } } } } if (Input.GetMouseButtonDown(0)) { Vector2 mousepos = Camera.main.ScreenToWorldPoint(Input.mousePosition); if (player.MoveCost(mousepos) != -1) { Grid.UnpaintAllNodes(); pathfcost = player.MoveCost(mousepos); player.SetDirections(Grid.NodeFromWorld(mousepos)); List <o_node> dir = player.directions; foreach (o_node d in dir) { Grid.PaintNode(Grid.NodePositionFromWorld(d), Color.yellow); } STATES = STATEMACHINE.MOVE_TO; } } break; #region ENEMY case TURNS.ENEMY: if (player.current_item != null) { UseItem(); } /*if (targetToAttack != null) * if (targetToAttack.health == 0 && !targetToAttack.IsDisappear()) * return; */ CheckCharacterSurroundings(true); if (targets.Count == 0) { STATES = STATEMACHINE.MOVE_TO; } else { STATES = STATEMACHINE.ATTACK_SELECT; } break; #endregion } //Have a cancel button where this player is no longer the focus //Attack button where it checks enemies break; case STATEMACHINE.MOVE_TO: switch (TURNSTATE) { case TURNS.PLAYER: if (Input.GetMouseButtonDown(0)) { Vector2 mousepos = Camera.main.ScreenToWorldPoint(Input.mousePosition); if (player.playable) { if (player.actionPoints >= pathfcost) { if (Grid.NodeFromWorld(mousepos) == player.directions[player.directions.Count - 1]) { ConfirmMovement(); return; } } } if (player.MoveCost(mousepos) != -1) { Grid.UnpaintAllNodes(); pathfcost = player.MoveCost(mousepos); player.SetDirections(Grid.NodeFromWorld(mousepos)); List <o_node> dir = player.directions; foreach (o_node d in dir) { Grid.PaintNode(Grid.NodePositionFromWorld(d), Color.yellow); } } } if (Input.GetMouseButtonDown(1)) { Grid.UnpaintAllNodes(); LooseFocus(); } break; #region ENEMY case TURNS.ENEMY: int newcost = int.MaxValue; o_character tar = null; foreach (o_character e in Players) { //Check around the target and pathfind for each position. HashSet <o_node> aroundChar = Grid.CheckAroundNode(Grid.NodeFromWorld(e.transform.position)); int potentialMoveCost = int.MaxValue; e.GetComponent <SpriteRenderer>().color = Color.red; o_node nof = null; foreach (o_node no in aroundChar) { if (!no.walkable) { continue; } int comp = player.MoveCost(no.position); if (comp == -1) { continue; } potentialMoveCost = Mathf.Min(potentialMoveCost, comp); if (potentialMoveCost == comp) { nof = no; } } e.GetComponent <SpriteRenderer>().color = Color.white; if (potentialMoveCost <= player.range) { if (potentialMoveCost <= player.actionPoints) { tar = e; newcost = Mathf.Min(newcost, potentialMoveCost); if (newcost == potentialMoveCost) { if (nof != null) { player.SetDirections(nof); } } } } else { continue; } Grid.UnpaintAllNodes(); } if (newcost != int.MaxValue) { Grid.UnpaintAllNodes(); pathfcost = newcost; if (pathfcost > 0) { ConfirmMovement(); } else { NextEnemy(); } } else { NextEnemy(); } break; #endregion } //Confirm? //Cancecl Move break; case STATEMACHINE.ATTACK_SELECT: switch (TURNSTATE) { case TURNS.PLAYER: if (targetToAttack != null) { targetToAttack.renderer.color = Color.magenta; } if (Input.GetMouseButtonDown(0)) { s_object obj = GetObjectFromWorld(mousePositon); if (obj != targetToAttack) { o_character newtarg = targets.Find(x => obj == x); if (newtarg != null) { targetToAttack.renderer.color = Color.white; targetToAttack = newtarg; return; } } } if (targetToAttack.health > 0 && player.actionPoints >= 2) { if (Input.GetMouseButtonDown(0)) { targetToAttack.renderer.color = Color.white; STATES = STATEMACHINE.ATTACK_EXECUTE; } } if (targetToAttack.health <= 0 || player.actionPoints < 2) { targetToAttack.renderer.color = Color.white; LooseFocus(); } if (Input.GetMouseButtonDown(1)) { if (targetToAttack != null) { targetToAttack.renderer.color = Color.white; } LooseFocus(); } break; #region ENEMY case TURNS.ENEMY: CheckCharacterSurroundings(true); if (targets.Count > 0) { //The enemy can attack the player again if they have sufficent points if (player.actionPoints >= 2) { targetToAttack = GetTargetWithLowestHealth(); if (targetToAttack.health > 0) { if (!isattacking && !IsSkipped) { StartCoroutine(AttackingAnim()); } if (IsSkipped) { AttackCalculations(targetToAttack); } } } else { NextEnemy(); } } else { STATES = STATEMACHINE.SELECT_CHAR; } break; #endregion } break; case STATEMACHINE.ATTACK_EXECUTE: if (!isattacking) { StartCoroutine(AttackingAnim()); } else if (TURNSTATE == TURNS.PLAYER) { STATES = STATEMACHINE.ATTACK_SELECT; } break; case STATEMACHINE.WALK: //Call Player enumarator to walk //Once done go back to select char break; } } }
public override IEnumerator EventPlay() { switch ((EVENT_TYPES)current_ev.eventType) { default: yield return(StartCoroutine(base.EventPlay())); break; case EVENT_TYPES.CAMERA_MOVEMENT: GameObject ca = GameObject.Find("Main Camera"); ca.GetComponent <s_camera>().focus = false; ca.GetComponent <s_camera>().ResetSpeedProg(); ca.GetComponent <s_camera>().lerping = true; float spe = current_ev.float0; //SPEED float s = 0; s_object obje = null; if (current_ev.string0 != "o_player") { if (GameObject.Find(current_ev.string0) != null) { obje = GameObject.Find(current_ev.string0).GetComponent <s_object>(); } } else { if (host != null) { obje = host; } else { obje = player; } } Vector2 pos = new Vector2(0, 0); if (obje != null) { pos = obje.transform.position; } if (obje != null) { ca.GetComponent <s_camera>().targetPos = obje.transform.position; } else { ca.GetComponent <s_camera>().targetPos = new Vector2(current_ev.pos.x, current_ev.pos.y); } if (current_ev.boolean) { float dista = Vector2.Distance(ca.transform.position, new Vector3(pos.x, pos.y)); while (Vector2.Distance(ca.transform.position, new Vector3(pos.x, pos.y)) > dista * 0.05f) { // s += spe * Time.deltaTime * travSpeed; // ca.transform.position = Vector3.Lerp(ca.transform.position, new Vector3(pos.x, pos.y, -15), s); yield return(new WaitForSeconds(Time.deltaTime)); } if (current_ev.boolean1) { ca.GetComponent <s_camera>().focus = true; // ca.GetComponent<s_camera>(). = obje.GetComponent<o_character>(); } } else { float dista = Vector2.Distance(ca.transform.position, new Vector3(current_ev.pos.x, current_ev.pos.y)); while (Vector2.Distance(ca.transform.position, new Vector3(current_ev.pos.x, current_ev.pos.y)) > dista * 0.05f) { // s += spe * Time.deltaTime * travSpeed; // ca.transform.position = Vector2.Lerp(ca.transform.position, new Vector3(current_ev.pos.x, current_ev.pos.y, -15), s); //ca.transform.position = new Vector3(ca.transform.position.x, ca.transform.position.y, -15); yield return(new WaitForSeconds(Time.deltaTime)); } } ca.GetComponent <s_camera>().lerping = false; break; case EVENT_TYPES.MOVEMNET: float timer = 1.02f; o_character charaMove = null; s_map.s_tileobj to = s_levelloader.LevEd.mapDat.tilesdata.Find( x => x.TYPENAME == "teleport_object" && x.name == current_ev.string1); if (current_ev.string0 == "o_player") { if (host == null) { charaMove = player; } else { charaMove = host; } } else { charaMove = GameObject.Find(current_ev.string0).GetComponent <o_character>(); } Vector2 newpos = charaMove.transform.position; if (current_ev.boolean) { newpos = new Vector2(to.pos_x, to.pos_y); charaMove.transform.position = new Vector3(newpos.x, newpos.y, 0); break; } float dist = Vector2.Distance(charaMove.transform.position, newpos); Vector2 dir = (newpos - new Vector2(charaMove.transform.position.x, charaMove.transform.position.y)).normalized; print(newpos); while (Vector2.Distance(charaMove.transform.position, newpos) > dist * 0.01f) { charaMove.transform.position += (Vector3)(dir * current_ev.float0 * current_ev.float1) * 0.007f; yield return(new WaitForSeconds(Time.deltaTime)); } break; case EVENT_TYPES.CHANGE_MAP: dialogueChoices.Clear(); if (player != null) { player.direction = new Vector2(0, 0); player.rbody2d.velocity = Vector2.zero; player.control = false; player.SetAnimation("idle_d", false); player.CHARACTER_STATE = o_character.CHARACTER_STATES.STATE_IDLE; } if (host != null) { host.direction = new Vector2(0, 0); host.rbody2d.velocity = Vector2.zero; host.control = false; host.SetAnimation("idle_d", false); host.CHARACTER_STATE = o_character.CHARACTER_STATES.STATE_IDLE; } float t2 = 0; while (fade.color != Color.black) { t2 += Time.deltaTime; fade.color = Color.Lerp(Color.clear, Color.black, t2); yield return(new WaitForSeconds(Time.deltaTime)); } if (host == null) { s_levelloader.LevEd.TriggerSpawn(current_ev.string0, current_ev.string1, player); } else { s_levelloader.LevEd.TriggerSpawn(current_ev.string0, current_ev.string1, host); } t2 = 0; while (fade.color != Color.clear) { t2 += Time.deltaTime; fade.color = Color.Lerp(Color.black, Color.clear, t2); yield return(new WaitForSeconds(Time.deltaTime)); } if (player != null) { player.control = true; } if (host != null) { host.control = true; } pointer = -1; doingEvents = false; break; case EVENT_TYPES.DEPOSSES: if (host != null) { host.OnDeposess(); host = null; } break; case EVENT_TYPES.ADD_CHOICE_OPTION: s_dialogue_choice dialo = new s_dialogue_choice(current_ev.string0, FindLabel(current_ev.string1)); if (dialogueChoices != null) { dialogueChoices.Add(dialo); } else { dialogueChoices = new List <s_dialogue_choice>(); dialogueChoices.Add(dialo); } break; case EVENT_TYPES.CHECK_FLAG: int integr = s_globals.GetGlobalFlag(current_ev.string0); int labelNum = FindLabel(current_ev.string1); if (labelNum == int.MinValue) { labelNum = current_ev.int1 - 1; } switch ((LOGIC_TYPE)current_ev.logic) { default: yield return(StartCoroutine(base.EventPlay())); break; case LOGIC_TYPE.CHECK_CHARACTER: if (host != null) { if (host.ID == current_ev.string0) //Check if it is equal to the value { pointer = labelNum; //Label to jump to } } break; case LOGIC_TYPE.CHECK_CHARACTER_NOT: if (host != null) { if (host.ID != current_ev.string0) { pointer = labelNum; //Label to jump to } } else { pointer = labelNum; } break; /* * case LOGIC_TYPE.CHECK_UTILITY_RETURN_NUM: * * //This checks utilities after the INITIALIZE function * if (GetComponent<s_utility>().eventState == current_ev.int0) * { * pointer = current_ev.int1 - 1; //Label to jump to * } * else * { * pointer = current_ev.int2 - 1; * } * break; */ } break; case EVENT_TYPES.CHOICE: int choice = 0, finalchoice = -1; print(choice); while (finalchoice == -1) { if (Input.GetKeyDown(KeyCode.UpArrow)) { choice--; } if (Input.GetKeyDown(KeyCode.DownArrow)) { choice++; } choice = Mathf.Clamp(choice, 0, dialogueChoices.Count - 1); if (Input.GetKeyDown(KeyCode.Z)) { print("Chosen"); finalchoice = choice; } Dialogue.text = "Arrow keys to scroll, Z to select" + "\n"; Dialogue.text += current_ev.string0 + "\n"; for (int i = 0; i < dialogueChoices.Count - 1; i++) { if (choice == i) { Dialogue.text += "-> "; } Dialogue.text += dialogueChoices[i].option + "\n"; } print(choice); yield return(new WaitForSeconds(Time.deltaTime)); } Dialogue.text = ""; pointer = dialogueChoices[finalchoice].flagTojump - 1; break; case EVENT_TYPES.CLEAR_CHOICES: dialogueChoices.Clear(); break; case EVENT_TYPES.RUN_CHARACTER_SCRIPT: if (current_ev.string0 == "o_player") { o_character ch = null; if (host == null) { ch = player.GetComponent <o_character>(); } else { ch = host.GetComponent <o_character>(); } if (ch.rbody2d != null) { ch.rbody2d.velocity = Vector2.zero; } ch.control = current_ev.boolean; ch.CHARACTER_STATE = o_character.CHARACTER_STATES.STATE_IDLE; } else { GameObject obj = GameObject.Find(current_ev.string0); if (obj != null) { o_character ch = obj.GetComponent <o_character>(); if (ch != null) { if (ch.rbody2d != null) { ch.rbody2d.velocity = Vector2.zero; } ch.control = current_ev.boolean; ch.CHARACTER_STATE = o_character.CHARACTER_STATES.STATE_IDLE; } } } break; } }
public void SwitchObject(int i) { sel += i; sel = Mathf.Clamp(sel, 0, Grid.BlockTypes.Count - 1); currentblock = Grid.BlockTypes[sel]; }