private void recalculateViewMatrix() { var eye = cameraPosition.WithZ(cameraDistance); var target = cameraPosition.WithZ(); ViewMatrix = Matrix4.LookAt(eye, target, Vector3.UnitY); }
private void drawFace(Vector2 from, Vector2 to, float height, Vector2 normal) { var n = normal.WithZ(); var uv = new Vector2(); this.surface.AddQuad( new BuildingVertex(from.WithZ(0), n, uv), new BuildingVertex(to.WithZ(0), n, uv), new BuildingVertex(to.WithZ(height), n, uv), new BuildingVertex(from.WithZ(height), n, uv) ); }
/// <summary> /// Generates all prefabs in the prefabs list. /// </summary> /// <param name="startingPoint"></param> private void GeneratePrefabs(Vector2 startingPoint) { if (prefabs.Count == 0) { return; } for (var x = 0; x < tileCount.x; x++) { for (var y = 0; y < tileCount.y; y++) { var selectedPrefab = prefabs[Random.Range(0, prefabs.Count)]; var prefab = Instantiate(selectedPrefab).transform; prefab.parent = transform; prefab.name = selectedPrefab.name; prefab.localPosition = startingPoint.WithZ(0) + new Vector3(x * tileSpacing.x, y * tileSpacing.y, 0); prefab.localScale = tileSize; } } var spriteRenderers = GetComponentsInChildren <SpriteRenderer>(); foreach (var spriteRenderer in spriteRenderers) { spriteRenderer.sortingLayerID = sortingLayerID; spriteRenderer.sortingOrder = sortingOrder; spriteRenderer.color = tileColor; } }
/// <summary> /// Generates all sprites within the tiles list. /// </summary> /// <param name="startingPoint"></param> private void GenerateSprites(Vector2 startingPoint) { if (tiles.Count == 0) { return; } for (var x = 0; x < tileCount.x; x++) { for (var y = 0; y < tileCount.y; y++) { var selectedTile = tiles[Random.Range(0, tiles.Count)]; var tile = new GameObject().transform; tile.parent = transform; tile.name = selectedTile.name; tile.localPosition = startingPoint.WithZ(0) + new Vector3(x * tileSpacing.x, y * tileSpacing.y, 0); tile.localScale = tileSize; var spriteRenderer = tile.gameObject.AddComponent <SpriteRenderer>(); spriteRenderer.sprite = selectedTile; spriteRenderer.sortingLayerID = sortingLayerID; spriteRenderer.sortingOrder = sortingOrder; spriteRenderer.color = tileColor; } } }
public void Setup(Vector2 worldPosition, float damage, int order) { SetScale(scaleAnimationCurve.Evaluate(0f)); transform.position = worldPosition.WithZ(-5f); this.worldPosition = worldPosition; meshRenderer.sortingOrder = order; this.damage += damage; tmp.SetText(this.damage.Round().ToString()); currentLifetime = 0f; }
private void drawWallInterior(Vector2 c0, Vector2 c1, Vector2 c2, Vector2 c3, float height) { var n = new Vector3(0, 0, 1); var uv = new Vector2(); this.surface.AddQuad( new BuildingVertex(c0.WithZ(height), n, uv), new BuildingVertex(c1.WithZ(height), n, uv), new BuildingVertex(c2.WithZ(height), n, uv), new BuildingVertex(c3.WithZ(height), n, uv) ); }
public void Damage(float damage, Vector2 direction) { var healthPercentageBefore = this.HealthPercentage; this.health = Math.Max(0, this.health - damage); this.healStartTime = this.game.Time + Settings.Game.Wisp.HealDelay; var healthPercentageDifference = healthPercentageBefore - this.HealthPercentage; if (healthPercentageDifference > 0.2f) { this.particles.Explode(healthPercentageDifference, direction.WithZ(0) * 5, 5); } this.game.Statistics.TotalDamageTaken += healthPercentageDifference; }
private void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { SceneManager.LoadScene(0); } float score = Player1.Score + Player2.Score; LevelSlider.value = Mathf.Lerp(LevelSlider.value, score, Time.deltaTime * 5); if (score >= NextScore) { EnemyDelay -= 0.2f; LevelSlider.minValue = NextScore; NextScore *= 2; Level++; PlayerSpeed++; CurrentHp = MaxHp; CurrentMana = MaxMana; SkillCap -= 0.02f; LevelText.text = "LVL " + Level; LevelSlider.maxValue = NextScore; SplashText("Level " + Level + "!", Color.yellow); for (int i = 0; i < Level; i++) { EnemyController.SpawnEnemy(); } } CurrentHp = Mathf.Min(CurrentHp + HpRegenSpeed * Time.deltaTime, MaxHp); HpSlider.value = Mathf.Lerp(HpSlider.value, CurrentHp, Time.deltaTime * 5);; ManaSlider.value = Mathf.Lerp(ManaSlider.value, CurrentMana, Time.deltaTime * 5);; if (CurrentHp < 0 && !Lose) { Lose = true; if (Player1.Score > Player2.Score) { SplashText("YOU DIED", Color.red); } else { SplashText("YOU DIED", Color.red); } StartCoroutine(Restart()); } _skillCoolDown -= Time.deltaTime; if (_skillCoolDown < 0 && CurrentMana > MinMana && Input.GetAxis(_skillAxis) > 0) { Time.timeScale = Mathf.Max(SkillCap, Time.timeScale - SkillSpeed * Time.deltaTime); CurrentMana -= ManaSpendSpeed * Time.deltaTime; if (CurrentMana < MinMana) { _skillCoolDown = SkillCoolDown; } } else { Time.timeScale = Mathf.Min(1, Time.timeScale + SkillRegenSpeed * Time.deltaTime); CurrentMana = Mathf.Min(MaxMana, CurrentMana + ManaRegenSpeed * Time.deltaTime); } if (PlayerCount == 1) { transform.position = Player1.transform.position.WithZ(-10); } else { Vector2 center = (Player1.transform.position + Player2.transform.position) / 2; transform.position = center.WithZ(-10); Camera.orthographicSize = CameraBorder + Mathf.Max((Player1.transform.position - Player2.transform.position).magnitude / 2, CameraMinSize); } }
public static Vector3 SphericalToEuclidean(Vector2 sphericalCoords) { return(SphericalToEuclidean(sphericalCoords.WithZ(SPHERE_RADIUS))); }