public void UpdateMouseInput() { Vector3 mousepos = Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector3Int mousepogrid = Grid.GetObjectPositionToGrid(mousepos); cursor.transform.position = new Vector3(mousepogrid.x * Grid.GetNodeLength, mousepogrid.y * Grid.GetNodeLength + z * Grid.GetNodeLength); if (Input.GetKeyDown(KeyCode.A) && Input.GetKeyDown(KeyCode.Space)) { m_position += "\n" + "mpos: " + new Vector3Int(mousepogrid.x, mousepogrid.y, z) + " in area " + levels[currentLevNum].name; } if (Input.GetKeyDown(KeyCode.B) && Input.GetKeyDown(KeyCode.Space)) { m_position = string.Empty; } if (Grid.GetObjectFromGrid(new Vector3(mousepogrid.x * Grid.GetNodeLength, mousepogrid.y * Grid.GetNodeLength, z * Grid.GetNodeLength))) { txt.text = "Space + A to memorise position \n" + "Space + B to delete position \n" + "Position: " + new Vector3Int(mousepogrid.x, mousepogrid.y, z) + " Focusing on: " + Grid.GetObjectFromGrid(new Vector3(mousepogrid.x * Grid.GetNodeLength, mousepogrid.y * Grid.GetNodeLength, z * Grid.GetNodeLength)) + " " + m_position; } else { txt.text = "Space + A to memorise position \n" + "Space + B to delete position \n" + "Position: " + new Vector3Int(mousepogrid.x, mousepogrid.y, z) + " " + m_position; } switch (TOOLKIT) { case TOOLKT.BRUSH: text.text = "Brush: " + currentblock.name; if (Input.GetMouseButton(0)) { Grid.SpawnObject(currentblock.name, new Vector3(mousepos.x, mousepos.y, z * Grid.GetNodeLength)); } if (Input.GetMouseButton(1)) { Grid.DespawnObject(new Vector3(mousepos.x, mousepos.y, z * Grid.GetNodeLength)); } break; } }
void LoadLevel() { Player.worldpos = new Vector3Int( last_player_pos.x * Grid.GetNodeLength, last_player_pos.y * Grid.GetNodeLength, last_player_pos.z * Grid.GetNodeLength); data_level dat = levels[currentLevNum]; Grid.ClearTiles(); Grid.worldsize = new Vector3Int(dat.size_x, dat.size_y, 45); Grid.Initialize(); for (int x = 0; x < Grid.worldsize.x - 1; x++) { for (int y = 0; y < Grid.worldsize.y - 1; y++) { for (int z = 0; z < Grid.worldsize.z - 1; z++) { data_level.data_block blok = dat.blocks.Find(bl => bl.x == x && bl.y == y && bl.z == z); data_level.data_door dr = dat.doors.Find(bl => bl.x == x && bl.y == y && bl.z == z); data_level.data_item it = dat.items.Find(bl => bl.x == x && bl.y == y && bl.z == z); if (blok != null) { o_block block = Grid.SpawnObject(blok.name, new Vector3Int(x, y, z)); } if (dr != null) { o_block block = Grid.SpawnObject(dr.name, new Vector3Int(x, y, z)); o_door door = block.GetComponent <o_door>(); door.location = dr.lev; door.teleport_position = new Vector3Int(dr.tele_x, dr.tele_y, dr.tele_z); door.locked = dr.locked; door.required_waterstones = dr.require; door.DOOR_STATE = (o_door.DOOR_MODE)dr.doortype; } if (it != null) { o_block block = Grid.SpawnObject(it.name, new Vector3Int(x, y, z)); o_item item = block.GetComponent <o_item>(); item.item = it.item; } } } } }
public IEnumerator Defeat() { defeated = true; s_sound.PlaySound(sound); for (int i = 0; i < 5; i++) { renderer.enabled = false; yield return(new WaitForSeconds(0.1f)); renderer.enabled = true; yield return(new WaitForSeconds(0.1f)); } if (playable) { charctMnger.Players.Remove(this); } else { charctMnger.Enemies.Remove(this); } if (current_item != null) { if (grid.ObjectFromWorld(transform.position) != null) { grid.SpawnObject(current_item.name, transform.position); } } grid.DespawnObject(this); hasdisapeared = true; }
void FeedGridData(s_leveldat levelData) { foreach (s_nodedat block in levelData.nodes_blocks) { Grid.block_layer[block.x, block.y] = Grid.SpawnObject(block.objectstr, new Vector2(20 * block.x, 20 * block.y)); //SpriteRenderer rend = Grid.block_layer[block.x, block.y].gameObject.GetComponent<SpriteRenderer>(); /* * if (rend != null) * if (block.spr != null) * //rend.sprite = block.spr; * * Grid.block_layer[block.x, block.y].transform.rotation = block.rot; */ } foreach (s_nodedat cha in levelData.nodes_character) { o_character character = (o_character)Grid.SpawnObject(cha.objectstr, new Vector2(20 * cha.x, 20 * cha.y)); if (character.GetComponent <ICharacter>() != null) { character.GetComponent <ICharacter>().Intialize(); } } foreach (s_nodedat cha in levelData.nodes_items) { o_item it = (o_item)Grid.SpawnObject(cha.objectstr, new Vector2(20 * cha.x, 20 * cha.y)); if (it != null) { Grid.item_layer[cha.x, cha.y] = it; } } for (int x = 0; x < Grid.gridworldsize.x; x++) { for (int y = 0; y < Grid.gridworldsize.y; y++) { s_nodedat block_nod = levelData.nodes_blocks.Find(obj => obj.x == x && obj.y == y); s_nodedat character_nod = levelData.nodes_character.Find(obj => obj.x == x && obj.y == y); s_nodedat item_nod = levelData.nodes_items.Find(obj => obj.x == x && obj.y == y); } } Grid.ResetNodes(); }
public void DropItem() { Grid.SpawnObject(player.current_item.name, player.transform.position); player.current_item = null; STATES = STATEMACHINE.SELECT_CHAR; }
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; * } */ } } } }