private void meleeHit(Vector2 rayCoords) { GameObject player = GameObject.Find("Player"); bool rightSide = player.GetComponent <SpriteRenderer>().flipX; float offset = 0.5f; if (!rightSide) { offset = -offset + -1; } MapGenerator1.makeSlash(player.transform.position.x + offset, player.transform.position.y, calculateNormalVector(rayCoords)); }
/* Shoots a bullet at mouse position. */ private void rangedHit(Collider2D collider, Vector2 rayCoords) { bool hitUI = collider && collider.gameObject.layer == 5; if (!hitUI) { GameObject player = GameObject.Find("Player"); bool rightSide = rayCoords.x - player.transform.position.x > 0; float offset = 0.5f; if (!rightSide) { offset = -offset + -1; } MapGenerator1.makeBullet(player.transform.position.x + offset, player.transform.position.y, calculateNormalVector(rayCoords)); } }
/* After checking that there is a hotkey in focus and an item in that slot, * 1. Generates the item in-game. * 2. Effectively remove the item from inventory. * 3. Display a blank sprite on the hotkey at the index in focus. * 4. Decrease the current size of the inventory. */ public void dropSelectedItem() { if (hotkeyIDInFocus != -1) { Item item = inventory[hotkeyIDInFocus]; if (item != null) { MapGenerator1.dropItem(gameObject.transform.position.x, gameObject.transform.position.y, facingRight, item); item.Amount--; if (item.Amount == 0) { deleteItem(hotkeyIDInFocus); } else { displayOnHotkeyBar(hotkeyIDInFocus); } } } }
public void Gen() { seed++; MapGenerator1 generator1 = new MapGenerator1(); generator1.SetGeneratorSettings(LevelLength, LevelHeight, MaxWidthRoomInLevel, MaxHightRoomInLevel, (int)seed); generator1.Gen(FloorMap, FloorTile); Debug.Log(FloorMap.size); for (int i = 0; i < FloorMap.size.x; i++) { for (int j = 0; j < FloorMap.size.y; j++) { if (FloorMap.GetTile(new Vector3Int(i, j, 0)) == FloorTile) { if (FloorMap.GetTile(new Vector3Int(i, j + 1, 0)) == null) { ColMap.SetTile(new Vector3Int(i, j + 1, 0), Wall); if (FloorMap.GetTile(new Vector3Int(i, j + 2, 0)) == null) { ColMap.SetTile(new Vector3Int(i, j + 2, 0), Roof); } } if (FloorMap.GetTile(new Vector3Int(i, j - 1, 0)) == null && ColMap.GetTile(new Vector3Int(i, j - 1, 0)) == null) { ColMap.SetTile(new Vector3Int(i, j - 1, 0), Roof); } if (FloorMap.GetTile(new Vector3Int(i - 1, j, 0)) == null && ColMap.GetTile(new Vector3Int(i - 1, j, 0)) == null) { ColMap.SetTile(new Vector3Int(i - 1, j, 0), Roof); } if (FloorMap.GetTile(new Vector3Int(i + 1, j, 0)) == null && ColMap.GetTile(new Vector3Int(i + 1, j, 0)) == null) { ColMap.SetTile(new Vector3Int(i + 1, j, 0), Roof); } } } } Player.transform.position = generator1.AllRooms[0].GetCenterPosition(); }
private void Start() { /* Initialize inventory and hotkeys arrays. */ inventory = new Item[MAX_INVENTORY_SIZE]; hotkeyIDInFocus = -1; // defaults to no hotkey in focus (-1). hotkeys = new GameObject[NUM_HOTKEYS]; for (int i = 0; i < NUM_HOTKEYS; i++) { hotkeys[i] = GameObject.Find("Hotkey " + (i + 1)); } /* Initialize misc. */ bullets = new GameObject(); bullets.name = "Bullets"; /* Get components. */ rb = GetComponent <Rigidbody2D>(); rendr = GetComponent <SpriteRenderer>(); mg = FindObjectOfType(typeof(MapGenerator1)) as MapGenerator1; equippedItem = GameObject.Find("EquippedItem"); facingRight = false; }
public void itemOnClickBehavior() { Vector3 mousePos = Input.mousePosition; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); Vector2 rayCoords = new Vector2(ray.origin.x, ray.origin.y); Collider2D collider = Physics2D.OverlapCircle(rayCoords, 0.01f); if (collider && collider.CompareTag("block")) { //Object.Destroy(collider.gameObject); } else if (!collider) { MapGenerator1.makeBlock((int)System.Math.Floor(rayCoords.x), (int)System.Math.Floor(rayCoords.y), name); amount--; GameObject.Find("Player").GetComponent <PlayerControls>().updateHotKeyItemCount(indexInInventory); if (amount == 0) { GameObject.Find("Player").GetComponent <PlayerControls>().deleteItem(indexInInventory); } } }
private void Update() { if (Input.GetKeyDown(KeyCode.Q)) { debugMode = !debugMode; debugModeText.text = "DebugMode: " + debugMode; } if (debugMode) { int itemID = -1; if (Input.GetKeyDown(KeyCode.Alpha1)) { itemID = 0; } if (Input.GetKeyDown(KeyCode.Alpha2)) { itemID = 1; } if (Input.GetKeyDown(KeyCode.Alpha3)) { itemID = 2; } if (Input.GetKeyDown(KeyCode.Alpha4)) { itemID = 3; } if (Input.GetKeyDown(KeyCode.Alpha5)) { itemID = 4; } if (itemID >= 0) { Vector3 mousePos = Input.mousePosition; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); Vector2 rayCoords = new Vector2(ray.origin.x, ray.origin.y); Collider2D collider = Physics2D.OverlapCircle(rayCoords, 0.01f); if (!collider) { MapGenerator1.generateItem((int)System.Math.Floor(rayCoords.x), (int)System.Math.Floor(rayCoords.y), itemID); } } else { //display: choose an item } } /* Inputs (eventually separate for custom keybinds). */ if (Input.GetKeyDown(KeyCode.Alpha1)) { hotkeyIDInFocus = 0; currentItemText.text = "Selected 1"; } if (Input.GetKeyDown(KeyCode.Alpha2)) { hotkeyIDInFocus = 1; currentItemText.text = "Selected 2"; } if (Input.GetKeyDown(KeyCode.Alpha3)) { hotkeyIDInFocus = 2; currentItemText.text = "Selected 3"; } if (Input.GetKeyDown(KeyCode.Alpha4)) { hotkeyIDInFocus = 3; currentItemText.text = "Selected 4"; } if (Input.GetKeyDown(KeyCode.Alpha5)) { hotkeyIDInFocus = 4; currentItemText.text = "Selected 5"; } if (Input.GetKeyDown(KeyCode.E)) { dropSelectedItem(); } if (hotkeyIDInFocus >= 0) { Item item = inventory[hotkeyIDInFocus]; if (item != null) { equippedItem.GetComponent <SpriteRenderer>().sprite = Resources.Load("Sprites/" + item.Name, typeof(Sprite)) as Sprite; if (Input.GetMouseButtonDown(0)) { /* If there is a hotkey in focus AND an item in the hotkey, then run the item's behavior. */ item.itemOnClickBehavior(); } } else { equippedItem.GetComponent <SpriteRenderer>().sprite = null; } } }
private void Start() { mg = FindObjectOfType(typeof(MapGenerator1)) as MapGenerator1; }
public override void OnInspectorGUI() { base.OnInspectorGUI(); MapGenerator1 mapGenerator = target as MapGenerator1; //mapGenerator1.GenerateMap(); }