private List <CrateGroup> GetWeldGroups() { List <CrateGroup> weldGroups = new List <CrateGroup>(); foreach (Vector2 cardinal in cardinalDirections) { Vector2 target = xy + direction; Vector2 adjacent = target + cardinal; bool weldingThere = GetWeldSquares().Contains(adjacent); Crate targetCrate = Crates.At(target); Crate adjacentCrate = Crates.At(adjacent); if (weldingThere) { if (targetCrate && adjacentCrate) { bool targetAlreadyAdded = weldGroups.Contains(targetCrate.group); if (!targetAlreadyAdded) { weldGroups.Add(targetCrate.group); } bool adjacentAlreadyAdded = weldGroups.Contains(adjacentCrate.group); if (!adjacentAlreadyAdded) { weldGroups.Add(adjacentCrate.group); } } } } return(weldGroups); }
public CarePackage() { Entity ent = Function.Call <Entity>("GetEnt", "care_package", "targetname"); _airdropCollision = Function.Call <Entity>("GetEnt", ent.GetField <string>("target"), "targetname"); OnNotify("run_crate", (owner, sourcePos, force, model, streakName, solid) => PhysCP(owner.As <Entity>(), sourcePos.As <Vector3>(), force.As <Vector3>(), model.As <string>(), streakName.As <string>(), solid.As <bool>())); OnNotify("run_init_crate", (crate) => { if (!Crates.ContainsKey(crate.As <Entity>())) { Crates.Add(crate.As <Entity>(), new Dictionary <string, object>() { ["streakName"] = crate.As <Entity>().GetField <string>("streakName"), ["owner"] = crate.As <Entity>().GetField <Entity>("owner"), ["team"] = crate.As <Entity>().GetField <Entity>("owner").GetField <string>("SessionTeam"), ["isUse"] = 0, ["useRate"] = 0 }); } InitCrate(crate.As <Entity>()); }); UsableLogic(); }
public void Move(Vector2 direction) { // Debug.LogFormat("Confirm: moving {0} in dir {1}", this.xy, direction); if (hasMoved || direction == Vector2.zero || IsNanVector(direction)) { return; } hasMoved = true; // Debug.LogFormat("xy = {0}, direction = {1}", xy, direction); Vector2 target = xy + direction; bool offGrid = !Crates.InBounds(target); if (offGrid) { FallOffGrid(target, direction); return; } Crate targetCrate = Crates.At(target); if (targetCrate && targetCrate != this) { targetCrate.group.Move(direction); } Crates.Remove(xy); xy = target; Crates.Add(this); StartCoroutine(AnimateMove(target, direction)); }
private bool TryMove(int dx, int dy) { //preconditions if (dx * dy != 0) { throw new InvalidOperationException("Only horizontal or vertical movement allowed."); } if (dx < -1 || dx > 1) { throw new ArgumentException(nameof(dx)); } if (dy < -1 || dy > 1) { throw new ArgumentException(nameof(dy)); } var x = PlayerX + dx; var y = PlayerY + dy; if (x < 0 || x >= Width || y < 0 || y >= Height) { return(false); } //Wall if (Walls.Any(wall => wall.Item1 == x && wall.Item2 == y)) { return(false); } var step = new Step(); //Crate var crate = Crates.FirstOrDefault(c => c.X == x && c.Y == y); if (crate != null) { var x0 = x + dx; var y0 = y + dy; if (Walls.Any(wall => wall.Item1 == x0 && wall.Item2 == y0) || Crates.Any(c => c.X == x0 && c.Y == y0)) { return(false); } step.Crate = crate; step.OldCrateX = crate.X; step.OldCrateY = crate.Y; crate.X += dx; crate.Y += dy; } step.OldPlayerX = PlayerX; step.OldPlayerY = PlayerY; _steps.Push(step); PlayerX += dx; PlayerY += dy; return(true); }
private void FallOffGrid(Vector2 destination, Vector2 direction) { Crates.Remove(xy); hasMoved = true; bool destroyAfter = true; StartCoroutine(AnimateMove(destination, direction, destroyAfter)); }
private Level Load(LevelData data) { Crates.Clear(); Crates.AddRange(data.Crates); PlayerX = data.PlayerX; PlayerY = data.PlayerY; return(this); }
public override void OnStepStart() { Crate crate = Crates.At(xy); if (crate) { crate.group.netForce += direction; } }
void Awake() { instance = this; stairMaster = gameObject.GetComponent <StairMaster>(); Machines.Init(height, width); Crates.Init(height, width); TileBackground(); }
public void DestroyUnmovedCrate() { Crate crate = Crates.At(xy); bool occupied = crate != null; if (occupied) { Crates.Remove(xy); Destroy(crate.gameObject); } }
public void Rotate(Vector3 spin) { foreach (Crate crate in crates) { Crates.Remove(crate.xy); } foreach (Crate crate in crates) { crate.Rotate(spin); } }
public bool CanRotate(Vector3 spin) { // List<Vector2> toCheck = Rotator.GetSquaresToCheck(this.xy, spin); // foreach (Vector2 p in toCheck) { // // Debug.Log(p); // } // ------testing: // spin = new Vector3 (10, 10, 1); // Vector2 pos = new Vector3 (10, 20); // Debug.Log("GROUP:::::::"); // foreach (Crate crate in this.group.crates) { // Debug.Log(crate.xy); // } List <Vector2> toCheck = Rotator.GetSquaresToCheck(this.xy, spin); if (dot) { foreach (Vector2 v in toCheck) { GameObject dotGO = Instantiate(dotPrefab); dotGO.transform.position = v; } } // Debug.LogFormat("Crate: Can Rotate {0}", this.xy); foreach (Vector2 target in toCheck) { // Debug.LogFormat("Checking {0}",target); Machine targetMachine = Machines.At(target); bool blockedByObstacle = targetMachine && targetMachine.isObstacle; if (blockedByObstacle) { Debug.Log("blockedByObstacle"); return(false); } bool blockedByPusherArm = CheckPusherArms(target); if (blockedByPusherArm) { Debug.Log("blockedByPusherArm"); return(false); } Crate targetCrate = Crates.At(target); if (targetCrate) { if (targetCrate && !group.crates.Contains(targetCrate)) { Debug.Log("blockedByOtherCrateGroup"); return(false); } } } return(true); }
private void Paint() { Vector2 paintZone = this.direction + this.xy; Crate targetCrate = Crates.At(paintZone); if (targetCrate) { // Debug.LogFormat("painting at {0}", paintZone); targetCrate.Paint(-direction); } }
public Crate MakeCrate() { GameObject crateGO = Instantiate(cratePrefab, xy, Quaternion.identity); Crate crate = crateGO.GetComponent <Crate>(); crate.xy = crate.RoundedPosition; crate.group = new CrateGroup(); crate.group.crates = new List <Crate>(); crate.group.crates.Add(crate); //Debug.LogFormat("group count = {0}", crate.group.crates.Count); crate.group.netForce += direction; Crates.Add(crate); return(crate); }
void Start() { Camera camera = GetComponent <Camera>(); float halfCamHeight = camera.orthographicSize; float halfCamWidth = camera.orthographicSize * camera.aspect; float offset = 0.5f; float verticalOffset = 4f; leftBound = halfCamWidth - mapBuffer - offset; rightBound = Crates.Width() + mapBuffer - offset - halfCamWidth; lowerBound = halfCamHeight - mapBuffer - offset - verticalOffset; upperBound = Crates.Height() + mapBuffer - offset - halfCamHeight; SnapToBoundaries(); }
private void Reset() { Pause(); Crates.ForEach((crate) => Destroy(crate.gameObject)); Crates.RemoveAll(); Machines.ForEach((machine) => { if (machine is DropZone) { DropZone zone = (DropZone)machine; zone.group.count = 0; } }); this.Hide(); UI.Machines.Show(); }
public override void OnStepStart() { if (AnySensorActivated()) { Crate crate = Crates.At(xy + direction); if (crate) { crate.group.pusherForce += direction; } Extend(); } else { Retract(); } }
public override void OnStepStart() { // Debug.Log("Rotator onsttepstart"); Crate crate = Crates.At(xy); int isCCWInt = (isCCW) ? 1:0; Vector3 spin = new Vector3(this.x, this.y, isCCWInt); if (crate) { if (crate.group != this.lastGroup) { crate.group.spins.Add(spin); this.lastGroup = crate.group; } } }
public void Rotate(Vector3 spin) { if (hasMoved) { return; } hasMoved = true; Vector2 target = Rotator.RotateVector(this.xy, spin); // Crates.Remove(xy); Vector2 direction = target - xy; xy = target; Crates.Add(this); // try {Crates.Add(this);} // catch (ArgumentException) { // Debug.Log("gridofCrates doesn't register this move correctly"); // } StartCoroutine(AnimateRotation(target, spin)); }
public bool CanMove(Vector2 direction) { if (hasMoved) { return(false); } Vector2 target = xy + direction; bool offGrid = !Crates.InBounds(target); if (offGrid) { return(true); } Machine targetMachine = Machines.At(target); bool blockedByObstacle = targetMachine && targetMachine.isObstacle; if (blockedByObstacle) { return(false); } bool blockedByPusherArm = CheckPusherArms(target); if (blockedByPusherArm) { return(false); } Crate targetCrate = Crates.At(target); if (!targetCrate) { return(true); } if (group.crates.Contains(targetCrate)) { return(true); } return(targetCrate.group.CanMove(direction)); }
public void Reset() { // Rebuild the level from the tile data. tileSprites.Clear(); Crates.Clear(); for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { int tileId = TileData[y, x]; if (tileId == 0) { continue; // Nothing } var bgSprite = new Sprite { Position = new Vector2f(x, y) * TileSize, Texture = tileId switch { Tiles.Ground => Resources.groundTexture, Tiles.Wall => Resources.bricksTexture, Tiles.Target => Resources.targetTexture, Tiles.Crate => Resources.groundTexture, Tiles.Player => Resources.groundTexture, _ => null } }; tileSprites.Add(bgSprite); if (tileId == Tiles.Crate) { var crate = new Crate(this, new Vector2i(x, y)); Crates.Add(crate); } else if (tileId == Tiles.Player) { Player.Position = new Vector2i(x, y); } } } }
public void Buzz() { CrateGroup g = null; foreach (DropZone zone in zones) { Crate crate = Crates.At(zone.xy); if (crate == null) { return; } if (!zone.CheckPaint(crate)) { return; } if (g == null) { g = crate.group; } else if (crate.group != g) { return; } } if (g.crates.Count != zones.Count) { Debug.LogFormat("Broke cuz group overflow\n {0} crates, {1} zones", g.crates.Count, zones.Count); return; } count++; foreach (Crate crate in g.crates) { Crates.Remove(crate.xy); GridThing.Destroy(crate.gameObject); } }
public void linkSpots(string[] maze) { Spot[,] spots = new Spot[maze.Length, getLongestLine(maze)]; int x = 0; int y = 0; foreach (String line in maze) { y = 0; foreach (char symbol in line.ToCharArray()) { Spot spot = null; switch (symbol) { case 'x': spot = new Destination(); Destinations.Add((Destination)spot); break; case '.': spot = new Floor(); break; case 'o': spot = new Floor(); Crate crate = new Crate(spot); spot.ContainsItem = crate; Crates.Add(crate); break; case '~': spot = new Trap(); break; case '@': spot = new Floor(); Truck truck = new Truck(spot); spot.ContainsItem = truck; _truck = truck; break; case '$': spot = new Floor(); Colleague colleague = new Colleague(spot); spot.ContainsItem = colleague; _colleague = colleague; break; case '#': spot = new Wall(); break; case '0': spot = new Destination(); Destinations.Add((Destination)spot); crate = new Crate(spot); spot.ContainsItem = crate; Crates.Add(crate); break; case ' ': spot = new Floor(); spot.IsEmpty = true; break; } spots[x, y] = spot; y++; } x++; } for (int i = 0; i < spots.GetLength(0); i++) { for (int j = 0; j < spots.GetLength(1); j++) { Spot spot = spots[i, j]; if (spot == null) { continue; } spot.UpSpot = getSpot(spots, i - 1, j); spot.RightSpot = getSpot(spots, i, j + 1); spot.DownSpot = getSpot(spots, i + 1, j); spot.LeftSpot = getSpot(spots, i, j - 1); if (i == 0 && j == 0) { _first = spot; } } } }
public bool Activated() { return(Crates.ElementAt(xy + direction)); }
private void ApplyForces() { Action <CrateGroup> applyForces = (group) => group.ApplyForces(); Crates.ForEachGroup(applyForces); }
private void OnStepStart() { Crates.ForEach((crate) => crate.OnStepStart()); Crates.ForEachGroup((group) => group.OnStepStart()); Machines.ForEach((machine) => machine.OnStepStart()); }
private void SpawnCrateAt(Vector3 pos) => Crates.Add(Instantiate(Crate, GetFixedPosition(pos), Quaternion.Euler(0, pos.y, 0)));
public void DeleteCrate(Crate c) => Crates.Remove(c.transform);