void DrawBulletPrediction() { World clone = LogicService.CloneWorldWithoutBullets(model); LogicService.ShootBullet( clone, input.GetShootDir() ); int steps = 0; for (int i = 0; i < steps; i++) { for (int j = 0; j < 1; j++) { LogicService.Tick(clone); } foreach (var b in clone.bullets.Values) { Gizmos.color = new Color(0f, 0f, 1f, 1f - (float)i / steps); Gizmos.DrawWireSphere(b.pos.Vector3(), b.radius); Gizmos.DrawLine(b.pos.Vector3(), b.pos.Vector3() + (b.dir * b.speed).Vector3()); } foreach (var g in clone.gizmos) { Gizmos.color = Color.black; Gizmos.DrawSphere(g.Vector3(), 0.1f); } } }
void Awake() { model = new World(); view = ViewService.CreateWorldView(); inputModel = input.GetModel(); inputModel.shootAction += (touchUpPos) => { if (model.gameState == GameState.PlayerTurn) { if (inputModel.distance > 1f) { for (int i = 0; i < 5; i++) { Position shootDir = input.GetShootDir(); Position leftDir = (shootDir + Position.RotateLeft(shootDir) * Config.SPREAD).Normalize(); Position rightDir = (shootDir + Position.RotateRight(shootDir) * Config.SPREAD).Normalize(); LogicService.ShootBullet(model, shootDir); LogicService.ShootBullet(model, leftDir); LogicService.ShootBullet(model, rightDir); } AudioController.Instance.PlaySound(AudioController.Sound.Shot); } } }; }
void Update() { input.Update(); if (inputModel.isDragging) { World clone = LogicService.CloneWorldWithoutBullets(model); Position shootDir = input.GetShootDir(); Position leftDir = (shootDir + Position.RotateLeft(shootDir) * Config.SPREAD).Normalize(); Position rightDir = (shootDir + Position.RotateRight(shootDir) * Config.SPREAD).Normalize(); LogicService.ShootBullet(clone, shootDir); LogicService.ShootBullet(clone, leftDir); LogicService.ShootBullet(clone, rightDir); List <Position> predictionPoints = new List <Position>(); for (int i = 0; i < Config.PREDICTION_STEPS; i++) { for (int j = 0; j < 1; j++) { LogicService.Tick(clone); } foreach (var b in clone.bullets.Values) { predictionPoints.Add(b.pos); } } ViewService.DrawPredictionPoints(view, predictionPoints); var p1 = Camera.main.ScreenToWorldPoint(inputModel.startDragPos); p1.y -= 0.5f; var p2 = Camera.main.ScreenToWorldPoint(inputModel.currentDragPos); p2.y -= 0.5f; ViewService.DrawInputUI(view, p1, p2); } }