private BlockHit Collision(float x, float y, int direction, int blockInfo) { BlockHit blockHit = new BlockHit(true, 0, Vector2.zero); switch (blockInfo) { case 1: if (y < -x + 1) { switch (direction) { default: break; } blockHit.hit = true; } break; case 2: if (y > x) { blockHit.hit = false; } break; default: break; } return(blockHit); }
void Start() { blockHit = GameObject.Find("SceneManager").GetComponent <BlockHit>(); scoreText = GameObject.Find("Canvas/BlankWindow/Score/Score").GetComponent <Text>(); blocksLeftText = GameObject.Find("Canvas/BlankWindow/NumBlocks/BlocksLeft").GetComponent <Text>(); dt = GameObject.Find("SceneManager").GetComponent <DriftingText>(); swapButtonPos = GameObject.Find("Canvas/BlankWindow/SwapAnimal").GetComponent <RectTransform>().TransformPoint(Camera.main.transform.position); shooter = GameObject.Find("SceneManager").GetComponent <CreateGrid>().shooterPrefab.GetComponent <Shooter>(); GameData.remainingBlocks = GameData.numCols * GameData.numRows / 2; blocksLeftText.text = GameData.remainingBlocks.ToString("N0"); //InvokeRepeating("CanIMove", 1f, 0.05f); }
public override void onUse(Entity user, Vector3 useDirection, BlockHit usedOn, World world) { if (Time.time - lastUseTime > useInterval) { bool hasAmmo = false; for (int i = 0; i < user.inventory.items.Length; i++) { if (user.inventory[i] != null && user.inventory[i].type == ItemType.bullet && user.inventory[i].count > 0) { hasAmmo = true; user.inventory.reduceItem(i, 1); } } if (hasAmmo) { lastUseTime = Time.time; GameObject obj = user.world.spawnEntity(bulletType, user.transform.position, useDirection * bulletSpeed); obj.transform.LookAt(user.transform.position + useDirection); } } }
public override void onUse(Entity user, Vector3 useDirection, BlockHit usedOn, World world) { if (!usedOn.hit) { return; } bool hasBlock = false; for (int i = 0; i < user.inventory.items.Length; i++) { if (user.inventory[i] != null && user.inventory[i].type == ItemType.block && user.inventory[i].count > 0) { hasBlock = true; user.inventory.reduceItem(i, 1); } } if (hasBlock) { if (Mathf.Abs(usedOn.hitOffset.z) > Mathf.Abs(usedOn.hitOffset.y) && Mathf.Abs(usedOn.hitOffset.z) > Mathf.Abs(usedOn.hitOffset.x)) { //place on z axis world.setBlock(usedOn.coords + new Vector3Int(0, 0, (int)Mathf.Sign(usedOn.hitOffset.z)), blockType); } else if (Mathf.Abs(usedOn.hitOffset.y) > Mathf.Abs(usedOn.hitOffset.x)) { //place on y axis world.setBlock(usedOn.coords + new Vector3Int(0, (int)Mathf.Sign(usedOn.hitOffset.y), 0), blockType); } else { //place on x axis world.setBlock(usedOn.coords + new Vector3Int((int)Mathf.Sign(usedOn.hitOffset.x), 0, 0), blockType); } } }
public virtual void onUse(Entity user, Vector3 useDirection, BlockHit usedOn, World world) { }
public BlockHit VerticalCollision(float xOrigin, float yOrigin, float yOffset) { BlockHit blockHit = new BlockHit(false, 0, Vector2.zero); Vector2 position; Tile block = GetTile(0, (int)xOrigin, (int)yOrigin); if (block.ID != 0) { if (yOffset > 0) { position = new Vector2(xOrigin, Mathf.Clamp(yOrigin + yOffset, (int)(yOrigin), (int)(yOrigin) + 1)); switch (block.Info) { case 1: blockHit.hit = true; blockHit.distance = (int)position.y - yOrigin; blockHit.normal.y = -1; break; case 2: blockHit.hit = true; blockHit.distance = (int)position.y - yOrigin; blockHit.normal.y = -1; break; default: blockHit.hit = true; blockHit.distance = (int)position.y - yOrigin; blockHit.normal.y = -1; break; } } else if (yOffset < 0) { position = new Vector2(xOrigin, Mathf.Clamp(yOrigin + yOffset, (int)(yOrigin), (int)(yOrigin) + 1)); switch (block.Info) { case 1: if ((yOrigin - (int)yOrigin) - (1 - xOrigin + (int)xOrigin) < -yOffset) { blockHit.hit = true; blockHit.distance = (yOrigin - (int)yOrigin) - (1 - xOrigin + (int)xOrigin); blockHit.normal.x = 1; blockHit.normal.y = 1; } break; case 2: if ((yOrigin - (int)yOrigin) - (xOrigin - (int)xOrigin) < -yOffset) { blockHit.hit = true; blockHit.distance = (yOrigin - (int)yOrigin) - (xOrigin - (int)xOrigin); blockHit.normal.x = -1; blockHit.normal.y = 1; } break; default: break; } } if (blockHit.distance < 0) { blockHit.distance = 0; } if (blockHit.hit == true) { return(blockHit); } } position = new Vector2(xOrigin, yOrigin + yOffset); block = GetTile(0, (int)position.x, (int)position.y); if (block.ID != 0) { if (yOffset > 0) { switch (block.Info) { case 1: blockHit.hit = true; blockHit.distance = (int)position.y - yOrigin; blockHit.normal.y = -1; break; case 2: blockHit.hit = true; blockHit.distance = (int)position.y - yOrigin; blockHit.normal.y = -1; break; default: blockHit.hit = true; blockHit.distance = (int)position.y - yOrigin; blockHit.normal.y = -1; break; } } else if (yOffset < 0) { switch (block.Info) { case 1: if (yOrigin - (int)position.y - 1 + (xOrigin - (int)xOrigin) < -yOffset) { blockHit.hit = true; blockHit.distance = yOrigin - (int)position.y - 1 + (xOrigin - (int)xOrigin); blockHit.normal.x = 1; blockHit.normal.y = 1; } break; case 2: if (yOrigin - (int)position.y - 1 + (1 - xOrigin + (int)xOrigin) < -yOffset) { blockHit.hit = true; blockHit.distance = yOrigin - (int)position.y - 1 + (1 - xOrigin + (int)xOrigin); blockHit.normal.x = -1; blockHit.normal.y = 1; } break; default: blockHit.hit = true; blockHit.distance = yOrigin - (int)position.y - 1; blockHit.normal.y = 1; break; } } if (blockHit.distance < 0) { blockHit.distance = 0; } } return(blockHit); }