public bool Absorb(EnergyInfo energy) { AbsorbedEnergy.Add(energy.Color); for (int i = 0; i < ColorSequence.Length; i++) { if (i == AbsorbedEnergy.Count) { Debug.Log("Not enough energy yet"); return(true); } if (ColorSequence[i] != AbsorbedEnergy[i]) { Debug.Log("Energy signature did not match (expected " + ColorSequence[i] + ", got " + AbsorbedEnergy[i] + ")"); Empty(); return(false); } // Else, accept PartDestOpacity[i] = 64 / 255f; } Debug.Log("Energy sequence is complete!"); AbsorbedEnergy.Clear(); Pico.CycleLevels(NextLevel); return(true); }
private void CargarDatos() { sectores = cSectores.ListarSectores(true); picoSeleccionado = sectores.Where(s => s.ExistePico(idPicoSeleccionado)).First().FindPico(idPicoSeleccionado); sectorSeleccionado = picoSeleccionado.Sector; CargarSectores(); textBoxNombrePico.Text = picoSeleccionado.Nombre; textBoxNumeroPico.Text = picoSeleccionado.Id.ToString(); }
void Awake() { Pico.ProjectorTemplate = ProjectorTemplate; Pico.EmitterTemplate = EmitterTemplate; Pico.AccumulatorTemplate = AccumulatorTemplate; Pico.ReceiverTemplate = ReceiverTemplate; Pico.EnergyTemplate = EnergyTemplate; Pico.CycleLevels(WorldMap); }
public int EditarPico(int id, string nuevoNombre) { try { using (var db = new ModeloBDPicos()) { Pico pico = db.Picos.Find(id); pico.Nombre = nuevoNombre; return(db.SaveChanges()); } } catch (Exception) { } return(0); }
public Pico CrearPico(int id, string nombre, int idSector) { try { using (var db = new ModeloBDPicos()) { Sector sector = db.Sectores .Include("Picos") .SingleOrDefault(s => s.Id == idSector); if (sector != null) { Pico pico = sector.CrearPico(id, nombre); db.SaveChanges(); return(pico); } } } catch (Exception ex) { } return(null); }
public int EditarPico(int id, int nuevoId, string nuevoNombre, int idSector, int idSectorNuevo) { try { if (id != nuevoId) { if (idSector != idSectorNuevo) { Pico pico = CrearPico(nuevoId, nuevoNombre, idSectorNuevo); EliminarPico(id); if (pico != null) { return(1); } } using (var db = new ModeloBDPicos()) { Sector sector = db.Sectores .Include("Picos") .SingleOrDefault(s => s.Id == idSector); Pico pico = sector.FindPico(id); pico.Id = nuevoId; pico.Nombre = nuevoNombre; return(db.SaveChanges()); } } if (idSector != idSectorNuevo) { EliminarPico(id); Pico pico = CrearPico(nuevoId, nuevoNombre, idSectorNuevo); if (pico != null) { return(1); } } using (var db = new ModeloBDPicos()) { Sector sector = db.Sectores .Include("Picos") .SingleOrDefault(s => s.Id == idSector); sector.FindPico(id).Nombre = nuevoNombre; return(db.SaveChanges()); } } catch (Exception) { } return(0); }
void Update() { var anyGamepad = Gamepads.Any; // Beat match SinceBeatMatch += Time.deltaTime; if (anyGamepad.X.State == ComplexButtonState.Pressed || Keyboard.GetKeyState(KeyCode.Space) == ComplexButtonState.Pressed) { if (SinceBeatMatch < 2) { Pico.HeartbeatDuration = SinceBeatMatch; Pico.TimeLeftToHeartbeat = SinceBeatMatch; } SinceBeatMatch = 0; } Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition); var basePlane = new Plane(Vector3.up, new Vector3(0, ActualHeight - 0.5f, 0)); float distance; switch (Phase) { case PlacingPhase.ChoosingPosition: if (!anyGamepad.Connected) { if (Mouse.RightButton.State == MouseButtonState.Idle && Keyboard.GetKeyState(KeyCode.LeftControl) == ComplexButtonState.Up && basePlane.Raycast(mouseRay, out distance)) { Vector3 p = (Camera.main.transform.position + mouseRay.direction * distance).Round(); var hs = Pico.Level.Size / 2; var clampedPosition = p.Clamp(-Pico.Level.Size / 2, Pico.Level.Size / 2 - 1); if (Camera.main.transform.position.y < ActualHeight - 0.5f) { clampedPosition.y++; } if (Pico.Level.GetAccumulatorAt(clampedPosition) == null && Pico.Level.GetEmitterAt(clampedPosition) == null && Pico.Level.GetProjectorAt(clampedPosition) == null && Pico.Level.GetReceiverAt(clampedPosition) == null) { Anchor.transform.position = clampedPosition; if (p.x < -hs || p.x >= hs || p.y < -hs || p.y >= hs || p.z < -hs || p.z >= hs) { ; // Do nothing } else if (Mouse.LeftButton.State == MouseButtonState.Clicked && !Pico.IsChangingLevel) { Phase = PlacingPhase.ChoosingDirection; } } } } else { var mat = Camera.main.camera.worldToCameraMatrix; var right = mat.GetRow(0).ToVector3().MaxClampXZ(); Vector3 up; var camUp = mat.GetRow(1).ToVector3(); var camForward = mat.GetRow(2).ToVector3(); if (Math.Abs(camUp.x) > Math.Abs(camUp.z)) { camUp = new Vector3(camUp.x, 0, 0); } else { camUp = new Vector3(0, 0, camUp.z); } if (Math.Abs(camForward.x) > Math.Abs(camForward.z)) { camForward = new Vector3(camForward.x, 0, 0); } else { camForward = new Vector3(0, 0, camForward.z); } if (Math.Abs(camUp.x + camUp.z) > Math.Abs(camForward.x + camForward.z)) { up = camUp.Sign(); } else { up = -camForward.Sign(); } if (anyGamepad.LeftStick.Right.State == ComplexButtonState.Pressed || anyGamepad.DPad.Right.State == ComplexButtonState.Pressed) { Anchor.transform.position += right; } if (anyGamepad.LeftStick.Left.State == ComplexButtonState.Pressed || anyGamepad.DPad.Left.State == ComplexButtonState.Pressed) { Anchor.transform.position -= right; } if (anyGamepad.LeftStick.Up.State == ComplexButtonState.Pressed || anyGamepad.DPad.Up.State == ComplexButtonState.Pressed) { Anchor.transform.position += up; } if (anyGamepad.LeftStick.Down.State == ComplexButtonState.Pressed || anyGamepad.DPad.Down.State == ComplexButtonState.Pressed) { Anchor.transform.position -= up; } if (anyGamepad.LeftStick.Right.TimePressed > 0.3 || anyGamepad.DPad.Right.TimePressed > 0.3) { SinceLongPress += Time.deltaTime; if (SinceLongPress > 0.05) { Anchor.transform.position += right; SinceLongPress = 0; } } if (anyGamepad.LeftStick.Left.TimePressed > 0.3 || anyGamepad.DPad.Left.TimePressed > 0.3) { SinceLongPress += Time.deltaTime; if (SinceLongPress > 0.05) { Anchor.transform.position -= right; SinceLongPress = 0; } } if (anyGamepad.LeftStick.Up.TimePressed > 0.3 || anyGamepad.DPad.Up.TimePressed > 0.3) { SinceLongPress += Time.deltaTime; if (SinceLongPress > 0.05) { Anchor.transform.position += up; SinceLongPress = 0; } } if (anyGamepad.LeftStick.Down.TimePressed > 0.3 || anyGamepad.DPad.Down.TimePressed > 0.3) { SinceLongPress += Time.deltaTime; if (SinceLongPress > 0.05) { Anchor.transform.position -= up; SinceLongPress = 0; } } Anchor.transform.position = Anchor.transform.position.Clamp(-Pico.Level.Size / 2, Pico.Level.Size / 2 - 1); var worldPos = Anchor.transform.position; if (Pico.Level.GetAccumulatorAt(worldPos) == null && Pico.Level.GetEmitterAt(worldPos) == null && Pico.Level.GetProjectorAt(worldPos) == null && Pico.Level.GetReceiverAt(worldPos) == null && anyGamepad.A.State == ComplexButtonState.Pressed && !Pico.IsChangingLevel) { FaceNormal = -mat.GetRow(2).ToVector3().MaxClamp(); Phase = PlacingPhase.ChoosingDirection; } } // Move up/down one layer if ((anyGamepad.RightShoulder.State == ComplexButtonState.Pressed || Keyboard.GetKeyState(KeyCode.W) == ComplexButtonState.Pressed) && DestinationHeight < Pico.Level.Size / 2 - 1) { LastHeight = DestinationHeight; DestinationHeight++; EasingTimeLeft = 0; } if ((anyGamepad.LeftShoulder.State == ComplexButtonState.Pressed || Keyboard.GetKeyState(KeyCode.S) == ComplexButtonState.Pressed) && DestinationHeight > -Pico.Level.Size / 2) { LastHeight = DestinationHeight; DestinationHeight--; EasingTimeLeft = 0; } if (!Pico.IsChangingLevel) { // Undo last placement if (AllPlacedProjectors.Count > 0 && (anyGamepad.B.State == ComplexButtonState.Pressed || Keyboard.GetKeyState(KeyCode.Z) == ComplexButtonState.Pressed)) { var anchorAt = Pico.Level.GetProjectorAt(Anchor.transform.position); if (anchorAt != null) { Destroy(anchorAt); AllPlacedProjectors.Remove(anchorAt); } else { Destroy(AllPlacedProjectors[AllPlacedProjectors.Count - 1]); AllPlacedProjectors.RemoveAt(AllPlacedProjectors.Count - 1); } Pico.Level.PlacedCount--; } // Undo ALL placements if (anyGamepad.Back == ComplexButtonState.Pressed || Keyboard.GetKeyState(KeyCode.R) == ComplexButtonState.Pressed) { Pico.Level.PlacedCount = 0; Pico.RebootLevel(); } } break; case PlacingPhase.ChoosingDirection: if (!Pico.IsChangingLevel) { // Undo last placement if (anyGamepad.B.State == ComplexButtonState.Pressed || Keyboard.GetKeyState(KeyCode.Z) == ComplexButtonState.Pressed) { HighlightFace.GetComponentInChildren <Renderer>().enabled = false; Phase = PlacingPhase.ChoosingPosition; break; } } if (!anyGamepad.Connected) { RaycastHit hitInfo; if (Anchor.collider.Raycast(mouseRay, out hitInfo, float.MaxValue)) { HighlightFace.GetComponentInChildren <Transform>().LookAt(HighlightFace.transform.position + hitInfo.normal); HighlightFace.transform.position = Anchor.transform.position + hitInfo.normal * 0.5f; HighlightFace.GetComponentInChildren <Renderer>().enabled = true; if (Mouse.LeftButton.State == MouseButtonState.Clicked && !Pico.IsChangingLevel) { Phase = PlacingPhase.ChoosingPosition; HighlightFace.GetComponentInChildren <Renderer>().enabled = false; var cellPosition = (Anchor.transform.position + VectorEx.New(Pico.Level.Size / 2)).Round(); //Debug.Log("Adding projector @ " + cellPosition); AllPlacedProjectors.Add(Pico.Level.AddProjectorAt( (int)cellPosition.x, (int)cellPosition.y, (int)cellPosition.z, DirectionEx.FromVector(hitInfo.normal))); Pico.Level.PlacedCount++; } } else { HighlightFace.GetComponentInChildren <Renderer>().enabled = false; if (Mouse.LeftButton.State == MouseButtonState.Clicked && !Pico.IsChangingLevel) { if (basePlane.Raycast(mouseRay, out distance)) { Vector3 p = (Camera.main.transform.position + mouseRay.direction * distance).Round(); var hs = Pico.Level.Size / 2; if (p.x < -hs || p.x >= hs || p.y < -hs || p.y >= hs || p.z < -hs || p.z >= hs) { Phase = PlacingPhase.ChoosingPosition; } } else { Phase = PlacingPhase.ChoosingPosition; } } } } else { var mat = Camera.main.camera.worldToCameraMatrix; var right = mat.GetRow(0).ToVector3().MaxClamp(); var up = -mat.GetRow(2).ToVector3().MaxClamp(); if (anyGamepad.LeftStick.Position.sqrMagnitude > 0.5) { FaceNormal = (right * anyGamepad.LeftStick.Position.x + up * anyGamepad.LeftStick.Position.y).MaxClamp(); } if (anyGamepad.DPad.Direction.sqrMagnitude > 0.5) { FaceNormal = (right * anyGamepad.DPad.Direction.x + up * anyGamepad.DPad.Direction.y).MaxClamp(); } HighlightFace.GetComponentInChildren <Transform>().LookAt(HighlightFace.transform.position + FaceNormal); HighlightFace.transform.position = Anchor.transform.position + FaceNormal * 0.479035f; HighlightFace.GetComponentInChildren <Renderer>().enabled = true; if (anyGamepad.A.State == ComplexButtonState.Pressed && !Pico.IsChangingLevel) { Phase = PlacingPhase.ChoosingPosition; HighlightFace.GetComponentInChildren <Renderer>().enabled = false; var cellPosition = (Anchor.transform.position + VectorEx.New(Pico.Level.Size / 2)).Round(); Debug.Log("Adding projector for " + FaceNormal); AllPlacedProjectors.Add(Pico.Level.AddProjectorAt( (int)cellPosition.x, (int)cellPosition.y, (int)cellPosition.z, DirectionEx.FromVector(FaceNormal))); Pico.Level.PlacedCount++; } } break; } EasingTimeLeft += Time.deltaTime; float step = Mathf.Clamp01(EasingTimeLeft / EasingTime); Pico.GridHeight = ActualHeight = Mathf.Lerp(LastHeight, DestinationHeight, Easing.EaseIn(step, EasingType.Quartic)); Anchor.transform.position = new Vector3(Anchor.transform.position.x, DestinationHeight, Anchor.transform.position.z); for (int i = 0; i <= Pico.Level.Size; i++) { Lines[i].transform.position = new Vector3(i - Pico.Level.Size / 2 - 0.5f, ActualHeight - 0.5f, -0.5f); } for (int i = 0; i <= Pico.Level.Size; i++) { Lines[i + (Pico.Level.Size + 1)].transform.position = new Vector3(-0.5f, ActualHeight - 0.5f, i - Pico.Level.Size / 2 - 0.5f); Lines[i + (Pico.Level.Size + 1)].transform.rotation = Quaternion.AngleAxis(90, Vector3.up); } }
void Update() { Pico.Update(); }