IEnumerator SpawnHumanoids(Obstacle obstacleObject) { yield return new WaitForSeconds(obstacleObject.startWait); while (!isGameOver && Time.time < (bossFightDelay - 8)) { for (int i = 0; i < obstacleObject.obstacleCount; i++) { Vector3 spawnPosition = new Vector3 ( obstacleObject.spawnValues.x + mainCamera.transform.position.x, obstacleObject.spawnValues.y, obstacleObject.spawnValues.z ); Instantiate (obstacleObject.obstacle, spawnPosition, obstacleObject.obstacle.transform.rotation); yield return new WaitForSeconds (Random.Range(1.0f, 3.0f) + obstacleObject.spawnWait); } yield return new WaitForSeconds(obstacleObject.waveWait); if(isGameOver) { break; } } }
public bool CheckLeftObstacleCollision(MovableObject obj, Obstacle platform) { Rectangle collisionBox = obj.CollisionBox = new Rectangle((int)obj.Position.X, (int)obj.Position.Y, obj.Texture.Width, obj.Texture.Height); Rectangle left = new Rectangle((int)platform.Position.X - 10, (int)platform.Position.Y + 5, 10, platform.Texture.Height - 10); return CollisionLeft = (obj.CollisionBox.Intersects(left)); }
// Use this for initialization void Start() { //Buscamos los scripts referenciados m_Random = GameObject.FindGameObjectWithTag("Obstaculos").GetComponent<RandomSpawn>(); m_Obstaculos = GameObject.FindGameObjectWithTag ("Colum").GetComponent<Obstacle> (); m_Player = GameObject.FindGameObjectWithTag ("Check"); }
public bool CheckBottomObstacleCollision(MovableObject obj, Obstacle platform) { obj.CollisionBox = new Rectangle((int)obj.Position.X, (int)obj.Position.Y, obj.SelectedAnimation.FrameWidth, obj.SelectedAnimation.FrameHeight); Rectangle bottom = new Rectangle((int)platform.Position.X + 5, (int)platform.Position.Y + platform.Texture.Height, platform.Texture.Width - 10, 10); return CollisionBottom = (obj.CollisionBox.Intersects(bottom)); }
public BoardSquare(Vector2 pos, int point, Obstacle Obstacle = null) { if (Obstacle == null) containsObstacle = false; Traversed = false; Position = pos; PointValue = point; }
void Awake () { obs = this; cam = Camera.main; playerObj = GameObject.FindGameObjectWithTag ("Player"); spawnDistance = 20f; DontDestroyOnLoad (this.gameObject); }
public void AddPV(int count, Obstacle.DommageType dommageType) { SetPV (m_pv + count); if(count < 0) { m_particuleSystem.Emit(25); } }
public ObstacleSegment(Obstacle obstacle, RotationTreeNode point1, RotationTreeNode point2) { _obstacle = obstacle; _point1 = point1; _point1.Segments.Add(this); _point2 = point2; _point2.Segments.Add(this); }
// Use this for initialization void Start () { obstacle = GetComponent<Obstacle> (); mainController = (MainGameController) GameObject.FindObjectOfType (typeof(MainGameController)); values = 0; foreach (WindowLvl1 window in windows) { if (window.isClosed) values++; } }
// Use this for initialization void Start () { obstacle = GetComponent<Obstacle> (); mainController = (MainGameController) GameObject.FindObjectOfType (typeof(MainGameController)); values = 0; foreach (Switch sw in switches) { if (sw.value) values++; } }
public void AddKill(Obstacle.Type type) { switch (type) { case Obstacle.Type.car: CarKill++; return; case Obstacle.Type.parkedCar: ParkedCarKill++; return; case Obstacle.Type.flying: FlyerKill++; return; case Obstacle.Type.pedestrian: PedestrianKill++; return; } }
void HitPlayer(Obstacle obs) { if (player.beenHit == false) { wheel.PlayerHit = true; UI.showObstacleText (obs.obsName[currentLifeStage]); player.HitPlayer(); } }
public ActionControlModel(ActionControl control, StackPanel parent, Level level, Obstacle obs) { mControlParent = control; mLevel = level; mSwitch = obs; mParent = parent; mData = new Half_Caked.KeyValuePair<Guid, int>(obs.Guid, 0); mTarget= Obstacles[0]; mTarget.Actions.Add(mData); }
private SuperClump JoinSuperClumps(SuperClump obsClump, Obstacle group, SuperClump candClump) { foreach (var clumpee in obsClump.Obstacles) { candClump.Insert(clumpee); this.mapObstacleToSuperClump[clumpee] = candClump; } obsClump = candClump; this.mapObstacleToSuperClump[group] = obsClump; return obsClump; }
void Start () { powerUpRing = GetComponent<PowerUpRing> (); obstacle = GetComponent<Obstacle> (); isBall = GetComponent<Ball> () != null; isMyPhotonView = GetComponent<PhotonView> ().isMine; nextLocalPosition = transform.localPosition; nextLocalRotation = transform.localRotation; }
public void testPlayerDiesOnCollision() { // Arrange var mockObstacleBehaviour = new Mock<IObstacleBehaviour>(); Obstacle obstacle = new Obstacle(mockObstacleBehaviour.Object); // Act obstacle.Collision(); // Assert Assert.AreEqual(StateManager.State.DEAD, StateManager.Instance.GetCurrentState()); }
// Use this for initialization void Start() { obstacles = new Obstacle[ObstacleCount]; //creates a new array of the size requested for (int i = 0; i < ObstacleCount; i++) { obstacles [i] = new Obstacle(PrimitiveType.Sphere, Obstacle.MovementType.Static); treadMillUpdates += new UpdateObstacles(obstacles [i].DrawObstacle); } }
public void Show(Vector3 position, float moveSpeed, Obstacle obstacle) { this.gameObject.SetActive(true); this.transform.position = position; this.moveSpeed = moveSpeed; this.Obstacle = obstacle; if (obstacle.IsMoving) { this.rigidBody.velocity = Vector2.zero; } }
/// <summary> /// Check which square the quad copter is closest to. /// </summary> /// <param name="copter"></param> /// <returns></returns> public Vector3 CopterLocation(Obstacle copter) { float smallest = int.MaxValue; BoardSquare bsReturn = new BoardSquare(); foreach (BoardSquare square in this.GameBoard) { float value = Vector2.Distance((Vector2)copter.transform.position, square.Position); bsReturn = smallest < value ? square : bsReturn; } return (Vector3)bsReturn.Position; }
public override void SetUp() { Params.Load("default.properties"); targetPos = new Vector3(20, 0, -150); startPos = new Vector3(10, 0, 20); List<Entity> children = XNAGame.Instance.Children; fighter = new Fighter(); fighter.Position = startPos; children.Add(fighter); Obstacle obstacle = new Obstacle(10); obstacle.Position = new Vector3(15, 0, -10); children.Add(obstacle); obstacle = new Obstacle(12); obstacle.Position = new Vector3(5, 0, -50); children.Add(obstacle); obstacle = new Obstacle(5); obstacle.Position = new Vector3(15, 0, -70); children.Add(obstacle); pathFinder = new PathFinder(); Path path = pathFinder.FindPath(fighter.Position, targetPos); path.DrawPath = true; path.Looped = false; fighter.Path = path; XNAGame.Instance.Leader = fighter; fighter.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.follow_path); Fighter camFighter = new Fighter(); camFighter.Leader = fighter; camFighter.offset = new Vector3(0, 0, 5); camFighter.Position = fighter.Position + camFighter.offset; camFighter.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.offset_pursuit); camFighter.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.wall_avoidance); camFighter.SteeringBehaviours.turnOn(SteeringBehaviours.behaviour_type.obstacle_avoidance); XNAGame.Instance.CamFighter = camFighter; children.Add(camFighter); foreach (Entity child in children) { child.LoadContent(); } oldState = Keyboard.GetState(); }
public void testResetGame() { // Arrange var mockObstacleBehaviour = new Mock<IObstacleBehaviour>(); mockObstacleBehaviour .Expect(m => m.ReloadScene()) .Verifiable(); Obstacle obstacle = new Obstacle(mockObstacleBehaviour.Object); // Act obstacle.Collision(); // Assert mockObstacleBehaviour.Verify(m => m.ReloadScene()); }
public void SampleSpinnerTest() { var grid = Program.InitializeGrid(5, 5); var spinner = new Obstacle<int>() { Type = "Spinner", ActionData = 270, RobotAction = (r, angle) => r.UpdateDirection(angle), Grid = grid }; var robot = new Robot(); robot = spinner.TakeAction(robot); Assert.IsTrue(robot.Direction == 3); }
public void testScoreAfterReset() { // Arrange var mockObstacleBehaviour = new Mock<IObstacleBehaviour>(); mockObstacleBehaviour .Expect(m => m.ReloadScene()) .Verifiable(); Obstacle obstacle = new Obstacle(mockObstacleBehaviour.Object); // Act obstacle.Collision(); // Assert Assert.AreEqual(0, StateManager.Instance.Score); }
public void SampleRockTest_ObstacleClass() { var grid = Program.InitializeGrid(5, 5); var rock = new Obstacle() { Type = "Rock", RobotAction = r => r, Grid = grid }; var robot = new Robot() { Position = new[] { 3, 3 } }; robot = rock.TakeAction(robot); Assert.IsTrue(robot.Position.SequenceEqual(new[] {3, 3})); }
public void SampleHoleTest() { var grid = Program.InitializeGrid(5, 5); var hole = new Obstacle<int[]>() { Type = "Hole", ActionData = new[] { 4, 4 }, RobotAction = (r, endpoint) => r.UpdatePosition(new [] { endpoint[0] - r.Position[0], endpoint[1] - r.Position[1] }, grid), Grid = grid }; var robot = new Robot() { Position = new[] {3, 3} }; robot = hole.TakeAction(robot); Assert.IsTrue(robot.Position.SequenceEqual(new[] { 4, 4 })); }
public override void Action(MouseState mouse) { Vector2 point = new Vector2(mouse.X, mouse.Y); foreach (Obstacle obs in GameMode.obstacles) { Vector3[] corners = obs.box.GetCorners(); for (int i = 0; i != 4; ++i) { Rectangle rect = new Rectangle((int)corners[i].X - 5, (int)corners[i].Y - 5, 10, 10); if (rect.Contains((int)point.X, (int)point.Y)) { point = new Vector2(corners[i].X, corners[i].Y); break; } } } Obstacle obstacle = new Obstacle(point.X, point.Y); obstacle.LoadContent(content); GameMode.obstacles.Add(obstacle); }
public void CreateObstacle() { Vector3 spawnpos = ObstacleMng.transform.position + new Vector3(0, Random.Range(-1.8f, 1.8f), 0); bool findBullet = false; for (int i = 0; i < ObstacleList.Count; i++) { if (!ObstacleList[i].GetUse()) { ObstacleList[i].CreateObstacle(spawnpos); findBullet = true; break; } } if (!findBullet) { Obstacle playerBullet = Instantiate(OriginalObject).GetComponent <Obstacle>(); ObstacleList.Add(playerBullet); playerBullet.transform.parent = ObstacleMng.transform; playerBullet.CreateObstacle(spawnpos); } }
public Vector3 AvoidObstacle( Obstacle obs ) { m_dv = Vector3.zero; float obRadius = obs.Radius; Vector3 vecToCenter = obs.Position - transform.position; vecToCenter.y = 0; float dist = vecToCenter.magnitude; if ( dist > obsAvoidDist + obRadius + radius ) { return Vector3.zero; } if ( Vector3.Dot( vecToCenter, transform.forward ) < 0 ) { return Vector3.zero; } float rightDotVTC = Vector3.Dot( vecToCenter, transform.right ); if ( Mathf.Abs( rightDotVTC ) > radius + obRadius ) { return Vector3.zero; } if ( rightDotVTC > 0 ) { m_dv += transform.right * -maxSpeed * obsAvoidDist / dist; } else { m_dv += transform.right * maxSpeed * obsAvoidDist / dist; } return m_dv; }
public void Update(Obstacle unObstacle)// mettre à jour une ligne { _DBAL.Update(" Obstacle SET nom = '" + unObstacle.NomObstacle + "', UneDefinition = '" + unObstacle.Definition + "', Photo = '" + unObstacle.Photo + "', typeObstacle = '" + unObstacle.TypeObstacle + "' WHERE nom = '" + unObstacle.NomObstacle + "';"); }
protected void OnTriggerEnter(Collider c) { if (c.gameObject.layer == k_CoinsLayerIndex) { if (magnetCoins.Contains(c.gameObject)) { magnetCoins.Remove(c.gameObject); } if (c.GetComponent <Coin>().isPremium) { Addressables.ReleaseInstance(c.gameObject); GameSensor.instance.SendEvent("premium"); PlayerData.instance.premium += 1; controller.premium += 1; m_Audio.PlayOneShot(premiumSound); } else { Coin.coinPool.Free(c.gameObject); PlayerData.instance.coins += 1; controller.coins += 1; m_Audio.PlayOneShot(coinSound); } } else if (c.gameObject.layer == k_ObstacleLayerIndex) { if (m_Invincible || controller.IsCheatInvincible()) { return; } controller.StopMoving(); c.enabled = false; GameSensor.instance.SendEvent("impact"); Obstacle ob = c.gameObject.GetComponent <Obstacle>(); if (ob != null) { ob.Impacted(); } else { Addressables.ReleaseInstance(c.gameObject); } if (TrackManager.instance.isTutorial) { m_TutorialHitObstacle = true; } else { controller.currentLife -= 1; } controller.character.animator.SetTrigger(s_HitHash); if (controller.currentLife > 0) { m_Audio.PlayOneShot(controller.character.hitSound); SetInvincible(); } // The collision killed the player, record all data to analytics. else { m_Audio.PlayOneShot(controller.character.deathSound); m_DeathData.character = controller.character.characterName; m_DeathData.themeUsed = controller.trackManager.currentTheme.themeName; m_DeathData.obstacleType = ob.GetType().ToString(); m_DeathData.coins = controller.coins; m_DeathData.premium = controller.premium; m_DeathData.score = controller.trackManager.score; m_DeathData.worldDistance = controller.trackManager.worldDistance; } } else if (c.gameObject.layer == k_PowerupLayerIndex) { Consumable consumable = c.GetComponent <Consumable>(); if (consumable != null) { GameSensor.instance.SendEvent("powerup"); controller.UseConsumable(consumable); } } }
public ActionResult <int> PostTile(Obstacle tile) { // return some value from the incoming object to allow testing/debugging //return CreatedAtAction() return(Ok()); }
public Tile AddWall(float angle, Obstacle wallPrefab) { Tile tile = null; for (int i = 0; i < neighbours.Count; i++) { Vector2 dir = new Vector2(neighbours[i].pos.x - pos.x, neighbours[i].pos.z - pos.z); if (type == _TileType.Hex) { float angleN = ((int)(Utility.VectorToAngle(dir))); if (Mathf.Abs(Mathf.DeltaAngle(angle, angleN)) < 30) { tile = neighbours[i]; break; } } else if (type == _TileType.Square) { float angleN = ((int)(Utility.VectorToAngle(dir))); if (Mathf.Abs(Mathf.DeltaAngle(angle, angleN)) < 45) { tile = neighbours[i]; break; } } } for (int i = 0; i < walls.Count; i++) { if (walls[i].Contains(tile, this)) { Debug.Log("wall existed " + tile + " " + this); return(null); } } if (tile == null) { Debug.Log("no neighbour " + this); return(null); } Vector2 dirV = new Vector2(tile.pos.x - pos.x, tile.pos.z - pos.z); float angleW = Utility.VectorToAngle(dirV); Transform wallT = null; if (wallPrefab != null) { wallT = (Transform)Instantiate(wallPrefab.transform); Vector3 direction = tile.pos - pos; if (type == _TileType.Hex) { float gridSize = transform.localScale.x / 1.1628f; wallT.position = pos + (direction.normalized) * gridSize * 0.5f; //+new Vector3(0, gridSize*0.3f, 0); wallT.localScale = new Vector3(gridSize, gridSize, gridSize) * 1.2f; } else if (type == _TileType.Square) { float gridSize = transform.localScale.x; wallT.position = pos + (direction.normalized) * gridSize * 0.5f; //+new Vector3(0, gridSize*0.3f, 0); wallT.localScale = new Vector3(gridSize, gridSize, gridSize); } float rotOffset = 90; wallT.rotation = Quaternion.Euler(0, -(angleW + rotOffset), 0); wallT.parent = transform; } walls.Add(new Wall(wallT, tile, this, angleW)); tile.walls.Add(new Wall(wallT, tile, this, angleW + 180)); RemoveNeighbour(tile); return(tile); }
public void ChangeRoutineDrastically() { Obstacle[] localObstacles = new Obstacle [obstacles.Length]; for (int i = 0; i < obstacles.Length; i++) { localObstacles [i] = obstacles [i]; } int end = localObstacles.Length; for (int i = 0; i < wayPoints.Count; i++) { int randomPointNumber = Random.Range (0, end); var newPointPosition = localObstacles [randomPointNumber].GetComponent<Obstacle>().targetLocation.position; wayPoints[i] = new Vector3(newPointPosition.x, newPointPosition.y, newPointPosition.z); localObstacles [randomPointNumber] = localObstacles [(end - 1)]; end--; } }
public void HandleObstacleCrush(Obstacle obstacle) { OnObstacleCrush(obstacle); }
private void WriteConvexHullId(Obstacle obstacle) { // This writes for both group and non-group. if (!obstacle.IsInConvexHull) { return; } int id; if (!this.convexHullToIdMap.TryGetValue(obstacle.ConvexHull, out id)) { id = this.GetNextConvexHullId(); this.convexHullToIdMap[obstacle.ConvexHull] = id; } this.outputFileWriter.WriteLine(RectFileStrings.WriteConvexHullId, id); }
public IActionResult EditObstacle(EditObstacle data) { data.Obstacle.AdditionalDescription = data.Obstacle.AdditionalDescription == null ? "" : data.Obstacle.AdditionalDescription.Trim(); data.Obstacle.EquipmentTarget = data.Obstacle.EquipmentTarget == null ? "" : data.Obstacle.EquipmentTarget.Trim(); data.Obstacle.EquipmentStart = data.Obstacle.EquipmentStart == null ? "" : data.Obstacle.EquipmentStart.Trim(); data.Obstacle.EquipmentObstacle = data.Obstacle.EquipmentObstacle == null ? "" : data.Obstacle.EquipmentObstacle.Trim(); data.Obstacle.MovementFirst = data.Obstacle.MovementFirst == null ? "" : data.Obstacle.MovementFirst.Trim(); data.Obstacle.ConditionsOvercoming = data.Obstacle.ConditionsOvercoming == null ? "" : data.Obstacle.ConditionsOvercoming.Trim(); data.Obstacle.OptTime = data.Obstacle.OptTime == null?"": data.Obstacle.OptTime.Trim(); data.Obstacle.CriticalTime = data.Obstacle.CriticalTime == null?"": data.Obstacle.CriticalTime.Trim(); var xxx = _context.ObstacleCompetitions.FirstOrDefault(a => a.ObstacleId == data.Obstacle.ObstacleId); if (data.Save == 1) { int change = 0; var temp = _context.Obstacles.FirstOrDefault(a => a.ObstacleId == data.Obstacle.ObstacleId); if (!(temp.Name.Trim().Equals(data.Obstacle.Name) && temp.AdditionalDescription.Trim().Equals(data.Obstacle.AdditionalDescription) && temp.ConditionsOvercoming.Trim().Equals(data.Obstacle.ConditionsOvercoming) && temp.Length == data.Obstacle.Length && temp.Height == data.Obstacle.Height && temp.CriticalTime.Trim().Equals(data.Obstacle.CriticalTime) && temp.OptTime.Trim().Equals(data.Obstacle.OptTime) && temp.EquipmentObstacle.Trim().Equals(data.Obstacle.EquipmentObstacle) && temp.EquipmentStart.Trim().Equals(data.Obstacle.EquipmentStart) && temp.EquipmentTarget.Trim().Equals(data.Obstacle.EquipmentTarget) && temp.MovementFirst.Trim().Equals(data.Obstacle.MovementFirst))) { change = 1; } if (xxx != null && change != 0) { temp = new Obstacle(); _context.Obstacles.Add(temp); } temp.Name = data.Obstacle.Name; temp.AdditionalDescription = data.Obstacle.AdditionalDescription; temp.ConditionsOvercoming = data.Obstacle.ConditionsOvercoming; temp.Length = data.Obstacle.Length; temp.Height = data.Obstacle.Height; temp.CriticalTime = data.Obstacle.CriticalTime; temp.OptTime = data.Obstacle.OptTime; temp.EquipmentObstacle = data.Obstacle.EquipmentObstacle; temp.EquipmentStart = data.Obstacle.EquipmentStart; temp.EquipmentTarget = data.Obstacle.EquipmentTarget; temp.MovementFirst = data.Obstacle.MovementFirst; temp.IsDeleted = 0; _context.SaveChanges(); if (xxx != null && change != 0) { var t = _context.ObstacleCompetitions.FirstOrDefault(a => a.ObstacleId == data.Obstacle.ObstacleId && a.CompetitionId == data.id); t.ObstacleId = temp.ObstacleId; _context.SaveChanges(); } if (data.Back == 1) { return(RedirectToAction("CompetitionAdmin", "Main", new { str = data.str, id = data.id })); } else { return(RedirectToAction("AddObstacle", "Main", new { str = data.str, id = data.id })); } } else { if (data.Back == 1) { return(RedirectToAction("CompetitionAdmin", "Main", new { str = data.str, id = data.id })); } else { return(RedirectToAction("AddObstacle", "Main", new { str = data.str, id = data.id })); } } }
internal static bool IsFirstObstacleEntirelyWithinSecond(Obstacle first, Obstacle second, bool touchingOk) { return(IsFirstPolylineEntirelyWithinSecond(first.VisibilityPolyline, second.VisibilityPolyline, touchingOk)); }
public void buildSet() { //One obstacles Obstacle oneCube = new Obstacle("oneCube", 0, 0, 0, GameObject.CreatePrimitive(PrimitiveType.Cube), false); Obstacle oneSphere = new Obstacle("oneSphere", 0, 2, 0, GameObject.CreatePrimitive(PrimitiveType.Cube), false); Obstacle oneCylinder = new Obstacle("oneCylinder", 0, 4, 0, GameObject.CreatePrimitive(PrimitiveType.Cube), false); //Two obstacles Obstacle twoCube = new Obstacle("twoCube", 2, 0, 0, GameObject.CreatePrimitive(PrimitiveType.Cube), false); Obstacle twoSphere = new Obstacle("twoSphere", 2, 2, 0, GameObject.CreatePrimitive(PrimitiveType.Cube), false); Obstacle twoCylinder = new Obstacle("twoCylinder", 2, 4, 0, GameObject.CreatePrimitive(PrimitiveType.Cube), false); Obstacle oneMcube2 = new Obstacle("twoSphere", 2, 6, 0, GameObject.CreatePrimitive(PrimitiveType.Cube), true); Obstacle oneMCylinder2 = new Obstacle("twoCylinder", 2, 8, 0, GameObject.CreatePrimitive(PrimitiveType.Cube), true); Obstacle oneMCylinder3 = new Obstacle("twoCylinder", 4, 0, 0, GameObject.CreatePrimitive(PrimitiveType.Cube), true); Obstacle oneMCylinder4 = new Obstacle("twoCylinder", 4, 2, 0, GameObject.CreatePrimitive(PrimitiveType.Cube), true); Obstacle oneMCylinder5 = new Obstacle("twoCylinder", 4, 4, 0, GameObject.CreatePrimitive(PrimitiveType.Cube), true); Obstacle oneMCylinder6 = new Obstacle("twoCylinder", 4, 6, 0, GameObject.CreatePrimitive(PrimitiveType.Cube), true); Obstacle oneMCylinder7 = new Obstacle("twoCylinder", 4, 8, 0, GameObject.CreatePrimitive(PrimitiveType.Cube), true); Obstacle oneMCylinder8 = new Obstacle("twoCylinder", 4, 10, 0, GameObject.CreatePrimitive(PrimitiveType.Cube), true); //One obSets //1a List <Obstacle> a1 = new List <Obstacle>(new Obstacle[] { oneCube }); ObSet oneA = new ObSet(a1, "1am", 3, "1am", 2, "1a"); //1b List <Obstacle> b1 = new List <Obstacle>(new Obstacle[] { oneSphere }); ObSet oneB = new ObSet(b1, "1bm", 3, "1bm", 2, "1b"); //1c List <Obstacle> c1 = new List <Obstacle>(new Obstacle[] { oneCylinder }); ObSet oneC = new ObSet(c1, "1cm", 3, "", 0, "1c"); //Two obSets //2a List <Obstacle> a2 = new List <Obstacle>(new Obstacle[] { twoCube }); ObSet twoA = new ObSet(a2, "2am", 3, "", 0, "2a"); //2b List <Obstacle> b2 = new List <Obstacle>(new Obstacle[] { twoSphere }); ObSet twoB = new ObSet(b2, "2bm", 3, "", 0, "2b"); //2c List <Obstacle> c2 = new List <Obstacle>(new Obstacle[] { twoCylinder }); ObSet twoC = new ObSet(c2, "2cm", 3, "", 0, "2c"); //1am List <Obstacle> a1m = new List <Obstacle>(new Obstacle[] { oneMcube2 }); ObSet oneAm = new ObSet(a1m, "", 0, "", 0, "1am"); //1bm List <Obstacle> b1m = new List <Obstacle>(new Obstacle[] { oneMCylinder2 }); ObSet oneBm = new ObSet(b1m, "", 0, "", 0, "1bm"); //Three obSets //1am List <Obstacle> a1m2 = new List <Obstacle>(new Obstacle[] { oneMCylinder3 }); ObSet oneAm2 = new ObSet(a1m2, "", 0, "", 0, "1am"); //1bm List <Obstacle> b1m2 = new List <Obstacle>(new Obstacle[] { oneMCylinder4 }); ObSet oneBm2 = new ObSet(b1m2, "", 0, "", 0, "1bm"); //1cm List <Obstacle> c1m2 = new List <Obstacle>(new Obstacle[] { oneMCylinder5 }); ObSet oneCm2 = new ObSet(c1m2, "", 0, "", 0, "1cm"); //2am List <Obstacle> a2m2 = new List <Obstacle>(new Obstacle[] { oneMCylinder6 }); ObSet twoAm2 = new ObSet(a2m2, "", 0, "", 0, "2am"); //2bm List <Obstacle> b2m2 = new List <Obstacle>(new Obstacle[] { oneMCylinder7 }); ObSet twoBm2 = new ObSet(b2m2, "", 0, "", 0, "2bm"); //2cm List <Obstacle> c2m2 = new List <Obstacle>(new Obstacle[] { oneMCylinder8 }); ObSet twoCm2 = new ObSet(c2m2, "", 0, "", 0, "2cm"); //One Level List <ObSet> levelOneObSets = new List <ObSet>(new ObSet[] { oneA, oneB, oneC }); Level levelOne = new Level(levelOneObSets, 0, 0, 3); //Two Level List <ObSet> levelTwoObSets = new List <ObSet>(new ObSet[] { twoA, twoB, twoC, oneAm, oneBm }); Level levelTwo = new Level(levelTwoObSets, 0, 0, 3); //Three Level List <ObSet> levelThreeObSets = new List <ObSet>(new ObSet[] { oneAm2, oneBm2, oneCm2, twoAm2, twoBm2, twoCm2 }); Level levelThree = new Level(levelThreeObSets, 0, 0, 0); theGame.addLevel(levelOne); theGame.addLevel(levelTwo); theGame.addLevel(levelThree); }
public override ErrorCode onStartElement(string elem, Dictionary <string, string> atts) { if (elem == "Escenari") { escenari = new Level(atts["nom"]); } else if (elem == "Dificultat") { int id = Convert.ToInt32(atts["id"]); float timer = Convert.ToSingle(atts["timer"]); dificultat = new Dificultat(id, timer); percent = 0; } else if (elem == "Obstacle") { string name = atts["nom"]; float btimer = Convert.ToSingle(atts["timer"]); float perc = Convert.ToSingle(atts["percent"]); percent += perc; obstacle = new Obstacle(name, perc, btimer); if (ErrorCode.IS_OK != loadPrefabObstacle(name)) { return(ErrorCode.GO_NOT_FOUND); } dificultat.addObstacle(obstacle); } else if (elem == "Enemic") { string name = atts["nom"]; float btimer = Convert.ToSingle(atts["timer"]); float perc = Convert.ToSingle(atts["percent"]); percent += perc; enemic = new Enemy(name, perc, btimer); if (ErrorCode.IS_OK != loadPrefabEnemy(name)) { return(ErrorCode.GO_NOT_FOUND); } dificultat.addEnemic(enemic); } else if (elem == "Plataforma") { plataforma = new Platform(atts["tipus"]); dificultat.addPlataforma(plataforma); } else if (elem == "Granota") { float percent = Convert.ToSingle(atts["percent"]); granota = new Granota(atts["color"], percent); dificultat.addGranota(granota); } else if (elem == "Layer") { string name = atts["id"]; int idLayer = Convert.ToInt32(name.ToCharArray()[0]) - 48; //OJO si hi ha més de 10 layers LAYER_ID layerId = (LAYER_ID)idLayer; switch (layerId) { case LAYER_ID.LAYER_0: layer = new Layer(name, EnvironmentManager.Instance.ZLayer0, layerId); break; case LAYER_ID.LAYER_1: layer = new Layer(name, EnvironmentManager.Instance.ZLayer1, layerId); break; case LAYER_ID.LAYER_2: layer = new Layer(name, EnvironmentManager.Instance.ZLayer2, layerId); break; case LAYER_ID.LAYER_3: layer = new Layer(name, EnvironmentManager.Instance.ZLayer3, layerId); break; case LAYER_ID.LAYER_4: layer = new Layer(name, EnvironmentManager.Instance.ZLayer4, layerId); break; case LAYER_ID.LAYER_5: layer = new Layer(name, EnvironmentManager.Instance.ZLayer5, layerId); break; case LAYER_ID.LAYER_6: layer = new Layer(name, EnvironmentManager.Instance.ZLayer6, layerId); break; case LAYER_ID.LAYER_7: layer = new Layer(name, EnvironmentManager.Instance.ZLayer7, layerId); break; case LAYER_ID.LAYER_8: layer = new Layer(name, EnvironmentManager.Instance.ZLayer8, layerId); break; case LAYER_ID.LAYER_9: layer = new Layer(name, EnvironmentManager.Instance.ZLayer9, layerId); break; default: return(ErrorCode.LAYER_NOT_DEFINED); } } else if (elem == "Element2D") { float y = Convert.ToSingle(atts["y"]); element2d = new Element2D(atts["nom"], y, layer.layerID); string path = "Environment/" + escenari.name + "/" + layer.name + "/" + element2d.name; GameObject go = EPrefabManager.LoadPrefab(path, EnvironmentManager.Instance.transform_pool_environment); if (go == null) { return(ErrorCode.GO_NOT_FOUND); } element2d.setEnvironmentComponent(go.GetComponent <Comp_Environment_Element>()); layer.addElement(element2d); } return(ErrorCode.IS_OK); }
private void OnTriggerEnter2D(Collider2D other) { if (other.tag == "Obstacle") { Obstacle obstacle = other.GetComponent <Obstacle>(); if (obstacle != null) { if ((obstacle.colorType != colorType && obstacle.colorType != ColorType.White && obstacle.obstaclesType != Obstacle.ObstaclesType.SafeBlock) || obstacle.obstaclesType == Obstacle.ObstaclesType.DeathBlock) { ; OnDamage(); } //TO DO : 색으로 판정내리기 보다는 Obstacle에서 색에 따른 bool 변수 또는, ObstacleType을 지정해서 코드를 간소화할 필요가 있음. if (obstacle.isCollsionUp) { if (other.transform.position.y < playerTr.position.y) { switch (obstacle.obstaclesType) { case Obstacle.ObstaclesType.Standard: if (obstacle.colorType == colorType || obstacle.colorType == ColorType.White) { obstacle.OnDamage(); } break; case Obstacle.ObstaclesType.SafeBlock: SoundManager.instance.PlaySFX("Block_Bounce"); StartCoroutine(BounceBall());; OnBounce(); break; case Obstacle.ObstaclesType.CrackBlock: if (obstacle.colorType == colorType || obstacle.colorType == ColorType.White) { if (obstacle.status != Status.Die) { StartCoroutine(BounceBall()); } obstacle.OnDamage(); OnBounce(); } break; case Obstacle.ObstaclesType.BounceBlock: if (obstacle.colorType == colorType || obstacle.colorType == ColorType.White) { obstacle.OnDamage(); if (obstacle.status != Status.Die) { StartCoroutine(BounceBall()); } OnBounce(); } break; default: break; } } } }//obstacle != null } else if (other.tag == "Item") { Item item = other.GetComponent <Item>(); if (item != null) { if (item.itemType == Item.ItemType.ColorChange) { ChangeColor(item.colorType); SoundManager.instance.PlaySFX("Item_Eat"); } item.OnDamage(); } } else if (other.tag == "Goal") { SoundManager.instance.PlaySFX("Goal_In"); StageManager.instance.isGoal = true; StageManager.instance.FinishStage(); OnInitialize(); } }
public Level1() : base() { width = 27; height = 30; cameraSettings = new CameraSettings(new Vector3(0f, 15f, -10f), new Vector3(60f, 0f, 0f), 2.5f, 2.5f); // (0, 15, -10) player = new Player(1, 1); walls = new Wall[] { // new Wall(x1, z1, x2, z2) // 1:start from x > 2:start from z ^ // 3: > 4:^ new Wall(0, 0, 28, 0), // Bottom Wall new Wall(0, 0, 0, 31), // Left Wall new Wall(27, 0, 28, 31), // Right Wall // new Wall(0, 30, 28, 31),// Top Wall new Wall(5, 0, 6, 10), // Internal Wall: start new Wall(0, 15, 12, 16), new Wall(12, 8, 13, 16), new Wall(18, 5, 19, 20), new Wall(10, 20, 19, 21), new Wall(0, 25, 23, 26), }; wallsBouncy = new WallBouncy[] { new WallBouncy(0, 30, 27, 31),//top wall new WallBouncy(5, 5, 18, 6), new WallBouncy(22, 5, 23, 26), }; goals = new Goal[] { new Goal(1, 27), }; obstacles = new Obstacle[] { new Hole(8, 6), new Hole(23, 6), new Hole(23, 15), new Hole(23, 22), new Hole(21, 26), }; introDialogue = new Dialogue[] { new Dialogue(70, Dialogue.Speaker.Rubik, "Welcome To your doom!"), new Dialogue(50, Dialogue.Speaker.Rubik, "We're going to have some fun you and I!"), new Dialogue(50, Dialogue.Speaker.Rubik, "Because now the walls turn against you! You thought you could find solace against these edges, but now they will push you to your sanity’s edge! HAHAHA!"), }; outroDialogue = new Dialogue[] { new Dialogue(50, Dialogue.Speaker.Rubik, "I have more planned for you, you just wait and see. You'll crack like Humpty Dumpty did in our maze!"), }; failDialogue = new Dialogue[] { new Dialogue(50, Dialogue.Speaker.King, "Hey Rubik, I have a great new idea! You ever try to fit a round peg in a square hole?"), new Dialogue(50, Dialogue.Speaker.Rubik, "I think I know where you're pointing to! I gotta say, it sounds FITTING!"), new Dialogue(50, Dialogue.Speaker.King, "Well, thank cube very much! Now get to it!"), }; buildMap(); }
public override void RunStart(TrackManager manager) { m_Previous = null; m_Hits = new Collider[k_HitColliderCount]; }
public IEnumerator reduces_player_health_to_zero_on_contact_with_pole() { // Arrange List <GameObject> cleanupList = new List <GameObject>(); GameObject gameManagerObject = new GameObject("gameManager"); GameManager gameManager = gameManagerObject.AddComponent <GameManager>(); gameManager.Testing = true; cleanupList.Add(gameManagerObject); CreatePlayer(out GameObject playerObject, out PlayerCharacter player, new Vector3(-1.0f, 0.0f, 0.0f)); cleanupList.Add(playerObject); GameObject poleObject = new GameObject("Pole"); poleObject.transform.tag = "Pole"; poleObject.transform.position = new Vector3(0, 0, 1); Obstacle obstacle = poleObject.AddComponent <Obstacle>(); obstacle.ScrollerRb = poleObject.GetComponent <Rigidbody>(); obstacle.ScrollerRb.useGravity = false; cleanupList.Add(poleObject); CreateDog(out GameObject dogObject, out DogCharacter dog, new Vector3(1.0f, 0.0f, 1.0f)); cleanupList.Add(dogObject); player.Dog = dog; List <float3> spawnPoints = new List <float3> { new float3(-1, 0, 0), new float3(1, 0, 0) }; GameObject ropeObject = new GameObject("Rope"); cleanupList.Add(ropeObject); Rope rope = ropeObject.AddComponent <Rope>(); rope.spawnPoints = spawnPoints; rope.simulation.enabled = true; rope.collisions.enabled = true; rope.simulation.lengthMultiplier = 0.1f; rope.simulation.gravityMultiplier = 0.0f; RopeRigidbodyConnection ropeRBC0 = ropeObject.AddComponent <RopeRigidbodyConnection>(); ropeRBC0.rope = rope; ropeRBC0.ropeLocation = 0; ropeRBC0.automaticallyFindRopeLocation = false; ropeRBC0.rigidbody = dog.Rb; ropeRBC0.localPointOnBody = Vector3.zero; ropeRBC0.rigidbodyDamping = 0.1f; ropeRBC0.stiffness = 1.0f; RopeRigidbodyConnection ropeRBC1 = ropeObject.AddComponent <RopeRigidbodyConnection>(); ropeRBC1.rope = rope; ropeRBC1.ropeLocation = 0; ropeRBC1.automaticallyFindRopeLocation = false; ropeRBC1.rigidbody = player.GetComponent <Rigidbody>(); ropeRBC1.localPointOnBody = Vector3.zero; ropeRBC1.rigidbodyDamping = 0.1f; ropeRBC1.stiffness = 1.0f; // Act poleObject.GetComponent <Rigidbody>().AddForce(Vector3.back, ForceMode.VelocityChange); yield return(new WaitForSeconds(1.0f)); // Assert Assert.AreEqual(0, player.Health.Current); // Clean foreach (GameObject item in cleanupList) { item.SetActive(false); } }
void ReadCell(XElement element) { ICell cell = new Cell(); cell.DiapasonSpawnPositions = new Dictionary <int, IDiapasonSpawnPosition>(); cell.Units = new List <IUnit>(); cell.Difficult = float.Parse(element.Attribute("difficult").Value, CultureInfo.InvariantCulture); cell.Id = int.Parse(element.Attribute("id").Value, CultureInfo.InvariantCulture); foreach (XElement subElement in element.Element("SpawnPositions").Elements("diapasonSpawnPosition")) { IDiapasonSpawnPosition diapasonSpawnPosition = new DiapasonSpawnPosition(); diapasonSpawnPosition.minXPos = float.Parse(subElement.Attribute("minXPos").Value, CultureInfo.InvariantCulture); diapasonSpawnPosition.maxXPos = float.Parse(subElement.Attribute("maxXPos").Value, CultureInfo.InvariantCulture); diapasonSpawnPosition.minYPos = float.Parse(subElement.Attribute("minYPos").Value, CultureInfo.InvariantCulture); diapasonSpawnPosition.maxYPos = float.Parse(subElement.Attribute("maxYPos").Value, CultureInfo.InvariantCulture); diapasonSpawnPosition.ZPos = float.Parse(subElement.Attribute("ZPos").Value); cell.DiapasonSpawnPositions.Add(int.Parse(subElement.Attribute("id").Value), diapasonSpawnPosition); } foreach (XElement subElement in element.Element("Units").Elements("Unit")) { IUnit template = _objectStorage.UnitTemplates[subElement.Attribute("type").Value]; IUnit unit = new Unit { Alias = template.UnitType.ToString(), UnitType = template.UnitType, Health = template.Health, MoveSpeed = template.MoveSpeed, Ghost = template.Ghost, DiapasonSpawnPosition = cell.DiapasonSpawnPositions[int.Parse(subElement.Attribute("diapasonSpawnPosition").Value)], Weapon = template.Weapon, InactiveTime = template.InactiveTime, BonusType = (BonusType)Enum.Parse(typeof(BonusType), subElement.Attribute("bonusType").Value), ExperienceValue = template.ExperienceValue, LootPercent = template.LootPercent, MagazineCapacity = Constants.magazineCapacity }; cell.Units.Add(unit); } IList <IObstacle> obstacles = new List <IObstacle>(); //исправить для пулл менеджера! foreach (IObstacle obstacleTemplate in _objectStorage.ObstacleSet[int.Parse(element.Element("ObstacleSet").Attribute("id").Value)]) { IObstacle obstacle = new Obstacle { Alias = obstacleTemplate.Alias, ObstacleType = obstacleTemplate.ObstacleType, SpawnPosition = obstacleTemplate.SpawnPosition, DamagePercent = obstacleTemplate.DamagePercent, Health = obstacleTemplate.Health }; obstacles.Add(obstacle); } cell.ObstacleSet = obstacles; _objectStorage.Cells.Add(int.Parse(element.Attribute("id").Value), cell); }
private void Start() { // 1. Set WorkingDirectory string ScenarioName = ScenarioAtHand.ScenarioName; string WorkingDirectory = Application.persistentDataPath + "/" + ScenarioName; float WIDTH = 0; float LENGTH = 0; float HEIGHT = 0; // 2. Load in all scenes in the scenario DirectoryInfo dir = new DirectoryInfo(WorkingDirectory); DirectoryInfo[] subdirs = dir.GetDirectories(); List <string> AllScenes = new List <string>(); foreach (DirectoryInfo subdir in subdirs) { AllScenes.Add(subdir.Name); } // 3. For each scene, create a scene object and put it in AllSceneObjects List <GameObject> AllSceneObjects = new List <GameObject>(); foreach (string Scene in AllScenes) { GameObject scene = new GameObject(Scene); scene.tag = "Scene"; scene.transform.position = new Vector3(0, 0, 0); scene.AddComponent <SceneInfo>(); AllSceneObjects.Add(scene); } // 4. For each scene, load the stored data foreach (GameObject Scene in AllSceneObjects) { WorkingDirectory = Application.persistentDataPath + "/" + ScenarioName + "/" + Scene.name; List <string> AllObjectsNames = new List <string>(); // 4.1 read all the names from the AllNames.txt file. if (File.Exists(WorkingDirectory + "/AllNames.txt")) { string name; StreamReader theReader = new StreamReader(WorkingDirectory + "/AllNames.txt"); using (theReader) { do { name = theReader.ReadLine(); if (name != null) { AllObjectsNames.Add(name); } }while (name != null); } theReader.Close(); } // 4.2 read in all the details into sceneDetails (SceneDetails) SceneDetails sceneDetails = new SceneDetails(); if (File.Exists(WorkingDirectory + "/SceneDetails.dat")) { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(WorkingDirectory + "/SceneDetails.dat", FileMode.Open); sceneDetails = (SceneDetails)bf.Deserialize(file); file.Close(); } // 4.3 Recover the scene based on sceneDetails // 4.3.1 Fill in sim info. If it is in design scene Scene.GetComponent <SceneInfo>().SimulationTime = sceneDetails.SimTime; Scene.GetComponent <SceneInfo>().Width = sceneDetails.Width; Scene.GetComponent <SceneInfo>().Length = sceneDetails.Length; Scene.GetComponent <SceneInfo>().Height = sceneDetails.Height; Scene.GetComponent <SceneInfo>().PlayerX = sceneDetails.PlayerX; Scene.GetComponent <SceneInfo>().PlayerY = sceneDetails.PlayerY; // 4.3.2 Fill in the TimeDensity in SceneInfo // and then effectivetimedensity if (Directory.Exists(WorkingDirectory + "/TimeDensity/")) { BinaryFormatter TimeDensitybf = new BinaryFormatter(); FileStream TimeDensityfile = File.Open(WorkingDirectory + "/TimeDensity/" + "AllData.dat", FileMode.Open); List <float> newTimeDensity = (List <float>)TimeDensitybf.Deserialize(TimeDensityfile); TimeDensityfile.Close(); Scene.GetComponent <SceneInfo>().TimeDensity = newTimeDensity; // Fill in EffectiveTimeDensity for model1, density at height 1.8m List <float> newEfftiveTimeDensity = new List <float>(); int Width = Mathf.RoundToInt(sceneDetails.Width); int Length = Mathf.RoundToInt(sceneDetails.Length); int Height = Mathf.RoundToInt(sceneDetails.Height); int Time = Mathf.RoundToInt(sceneDetails.SimTime); for (int i = 0; i < (Width + 1) * (Length + 1) * Time; i++) { newEfftiveTimeDensity.Add(newTimeDensity[1 + i * Height]); } Scene.GetComponent <SceneInfo>().EffectiveTimeDensity = newEfftiveTimeDensity; } // 4.3.2 Create all the walls foreach (wall Wall in sceneDetails.Walls) { GameObject newWall = Instantiate(Resources.Load <GameObject>("Prefabs/Wall")); Wall wallinfo = newWall.GetComponent <Wall>(); wallinfo.FillInfo(AllObjectsNames[Wall.NameIndex], Wall.xpos, Wall.ypos, Wall.zrot, Wall.Height, Wall.Width, Wall.Opacity); newWall.name = wallinfo.Name; newWall.transform.SetParent(Scene.transform); Vector3 Pos = newWall.transform.position; Pos.x = wallinfo.x_pos; Pos.y = wallinfo.Height / 2 + 0.01f; Pos.z = wallinfo.y_pos; newWall.transform.position = Pos; HEIGHT = wallinfo.Height; Vector3 Angles = newWall.transform.eulerAngles; Angles.y = wallinfo.z_rot; newWall.transform.eulerAngles = Angles; Vector3 Scale = newWall.transform.localScale; Scale.x = wallinfo.Width; Scale.y = wallinfo.Height; newWall.transform.localScale = Scale; Vector4 color = newWall.GetComponent <Renderer>().material.color; color[3] = wallinfo.Opacity; newWall.GetComponent <Renderer>().material.color = color; } // 4.3.3 Create all the floors foreach (floor Floor in sceneDetails.Floors) { GameObject newFloor = Instantiate(Resources.Load <GameObject>("Prefabs/InPlayFloor")); Floor floorinfo = newFloor.GetComponent <Floor>(); floorinfo.FillInfo(AllObjectsNames[Floor.NameIndex], Floor.xpos, Floor.ypos, Floor.Length, Floor.Width); newFloor.name = floorinfo.Name; newFloor.transform.SetParent(Scene.transform); Vector3 Scale = newFloor.GetComponent <Terrain>().terrainData.size; Scale.x = floorinfo.Width; Scale.z = floorinfo.Length; newFloor.GetComponent <Terrain>().terrainData.size = Scale; WIDTH = floorinfo.Width; LENGTH = floorinfo.Length; Vector3 Pos = newFloor.transform.position; Pos.x = floorinfo.x_pos - (Scale.x / 2); Pos.z = floorinfo.y_pos - (Scale.z / 2); newFloor.transform.position = Pos; // Bake the floor newFloor.GetComponent <NavMeshLink>().startPoint = new Vector3(0, 0, 0); newFloor.GetComponent <NavMeshLink>().endPoint = new Vector3(Scale.x, 0, Scale.z); newFloor.GetComponent <NavMeshSurface>().BuildNavMesh(); } // ADD a light bulb to the scene GameObject lightbulb = new GameObject("Scene light"); lightbulb.AddComponent <Light>(); lightbulb.GetComponent <Light>().type = LightType.Point; lightbulb.transform.SetParent(Scene.transform); Vector3 ScenePos = Scene.transform.localPosition; lightbulb.transform.localPosition = new Vector3(ScenePos.x, HEIGHT - 0.1f, ScenePos.z); // 4.3.4 Create all the ceilings foreach (ceiling Ceiling in sceneDetails.Ceilings) { GameObject newCeiling = Instantiate(Resources.Load <GameObject>("Prefabs/Ceiling")); Ceiling ceilinginfo = newCeiling.GetComponent <Ceiling>(); ceilinginfo.FillInfo(AllObjectsNames[Ceiling.NameIndex], Ceiling.xpos, Ceiling.ypos, Ceiling.zpos, Ceiling.Length, Ceiling.Width, Ceiling.Opacity); newCeiling.name = ceilinginfo.Name; newCeiling.transform.SetParent(Scene.transform); Vector3 Pos = newCeiling.transform.position; Pos.x = ceilinginfo.x_pos; Pos.y = ceilinginfo.z_pos; Pos.z = ceilinginfo.y_pos; newCeiling.transform.position = Pos; Vector3 Scale = newCeiling.transform.localScale; Scale.x = ceilinginfo.Width; Scale.z = ceilinginfo.Length; newCeiling.transform.localScale = Scale; } // 4.3.5 Create all the obstacles foreach (obstacle Obstacle in sceneDetails.Obstacles) { GameObject newObstacle = Instantiate(Resources.Load <GameObject>("Prefabs/Obstacle")); Obstacle obstacleinfo = newObstacle.GetComponent <Obstacle>(); obstacleinfo.FillInfo(AllObjectsNames[Obstacle.NameIndex], Obstacle.xpos, Obstacle.ypos, Obstacle.Width, Obstacle.Length, Obstacle.Height, Obstacle.Opacity); newObstacle.name = obstacleinfo.Name; newObstacle.transform.SetParent(Scene.transform); Vector3 Pos = newObstacle.transform.position; Pos.x = obstacleinfo.x_pos; Pos.z = obstacleinfo.y_pos; newObstacle.transform.position = Pos; Vector3 Scale = newObstacle.transform.localScale; Scale.x = obstacleinfo.Width; Scale.y = obstacleinfo.Height; Scale.z = obstacleinfo.Length; newObstacle.transform.localScale = Scale; Vector4 color = newObstacle.GetComponent <Renderer>().material.color; color[3] = obstacleinfo.Opacity; newObstacle.GetComponent <Renderer>().material.color = color; } // 4.3.6 Create all the doors foreach (door Door in sceneDetails.Doors) { GameObject newDoor = Instantiate(Resources.Load <GameObject>("Prefabs/Door")); Door doorinfo = newDoor.GetComponent <Door>(); // Fill in the values of variables in Door.cs doorinfo.Name = AllObjectsNames[Door.NameIndex]; doorinfo.WallAttachedTo = Scene.transform.Find(AllObjectsNames[Door.WallNameIndex]).gameObject; foreach (GameObject sceneobj in AllSceneObjects) { if (sceneobj.name == AllObjectsNames[Door.SceneNameIndex]) { doorinfo.NextScene = sceneobj; break; } } if (Door.Open == 1) { doorinfo.Open = true; } else { doorinfo.Open = false; } doorinfo.Width = Door.Width; doorinfo.Height = Door.Height; doorinfo.RelativePosition = Door.RelativePosition; // Create the door gameobject accordingly newDoor.name = doorinfo.Name; Transform WallTransform = doorinfo.WallAttachedTo.transform; newDoor.transform.SetParent(WallTransform); Vector3 WallPosition = WallTransform.position; Vector3 WallDimensions = WallTransform.localScale; newDoor.transform.localEulerAngles = new Vector3(0, 0, 0); // angle float rel_x = doorinfo.RelativePosition / WallDimensions.x; float rel_y = ((doorinfo.Height / 2) - WallPosition.y) / WallDimensions.y; newDoor.transform.localPosition = new Vector3(rel_x, rel_y, 0); // pos newDoor.transform.localScale = new Vector3(doorinfo.Width / WallDimensions.x, doorinfo.Height / WallDimensions.y, 1.033f); //scale } // 4.3.7 Create all the fires foreach (fire Fire in sceneDetails.Fires) { GameObject newFire = Instantiate(Resources.Load <GameObject>("Prefabs/InPlayFire")); Fire fireinfo = newFire.GetComponent <Fire>(); fireinfo.FillInfo(AllObjectsNames[Fire.NameIndex], Fire.xpos, Fire.ypos, Fire.zpos, Fire.Width, Fire.Length, Fire.HRRPUA, Fire.CO_YIELD, Fire.SOOT_YIELD, fireinfo.Fuels[Fire.Fuel]); newFire.name = fireinfo.Name; newFire.transform.SetParent(Scene.transform); Vector3 Pos = newFire.transform.position; Pos.x = fireinfo.x_pos; Pos.y = fireinfo.z_pos; Pos.z = fireinfo.y_pos; newFire.transform.position = Pos; Vector3 Scale = newFire.transform.localScale; Scale.x = fireinfo.Width; Scale.z = fireinfo.Length; newFire.transform.localScale = Scale; } // 4.3.8 Create all the pedestrians foreach (pedestrian Pedestrian in sceneDetails.Pedestrians) { GameObject newPedestrian = Instantiate(Resources.Load <GameObject>("Prefabs/Pedestrian")); Pedestrian pedestrianinfo = newPedestrian.GetComponent <Pedestrian>(); Transform ExitTransform = null; foreach (Transform Object in Scene.transform) { if (Object.tag == "Wall") { ExitTransform = Object.Find(AllObjectsNames[Pedestrian.ExitNameIndex]); if (ExitTransform != null) { break; } } } pedestrianinfo.FillInfo(AllObjectsNames[Pedestrian.NameIndex], Pedestrian.xpos, Pedestrian.ypos, Pedestrian.Speed, Pedestrian.Health, ExitTransform.gameObject); newPedestrian.name = pedestrianinfo.Name; newPedestrian.transform.SetParent(Scene.transform); Vector3 Pos = newPedestrian.transform.position; Pos.x = pedestrianinfo.x_pos; Pos.z = pedestrianinfo.y_pos; newPedestrian.transform.position = Pos; newPedestrian.GetComponent <AICharacterControl>().target = ExitTransform; // For now, set agent's speed to be 0.45 ~ 1.5m/s newPedestrian.GetComponent <NavMeshAgent>().speed = 0.45f; } // 4.3.9 Create the player in InPlayScene, the speed is set to be 2 in // the inspector for now foreach (player Player in sceneDetails.Players) { GameObject newPlayer = Instantiate(Resources.Load <GameObject>("Prefabs/Player")); Player playerinfo = newPlayer.GetComponent <Player>(); playerinfo.FillInfo(AllObjectsNames[Player.NameIndex], Player.xpos, Player.ypos, Player.Speed, Player.Health); newPlayer.name = playerinfo.Name; newPlayer.transform.SetParent(Scene.transform); Vector3 PlayerPos = newPlayer.transform.position; PlayerPos.x = sceneDetails.PlayerX; PlayerPos.z = sceneDetails.PlayerY; newPlayer.transform.position = PlayerPos; // Put the main camera on it GameObject maincamera = GameObject.FindGameObjectWithTag("MainCamera"); maincamera.transform.SetParent(newPlayer.transform); maincamera.transform.localPosition = new Vector3(0, 0, 0); } // 5. Only activate the scene where the player is in if (sceneDetails.Players == null || sceneDetails.Players.Count == 0) { Scene.SetActive(false); } // temporary solution if (Scene.name == "Outside") { Scene.SetActive(false); } // 6. Create all the smoke particles (particle system) List <float> timedensity = Scene.GetComponent <SceneInfo>().TimeDensity; if (timedensity != null) { float d = 1; float t = 1; float T = sceneDetails.SimTime; float maxdensity = Mathf.Max(timedensity.ToArray()); int xnumber = (int)((WIDTH / d) + 1); int ynumber = (int)((LENGTH / d) + 1); int znumber = (int)((HEIGHT / d)); int tnumber = (int)(T / t); for (int x = 0; x < xnumber; x++) { for (int y = 0; y < ynumber; y++) { for (int z = 0; z < znumber; z++) { List <float> smokedensity = new List <float>(); for (int n = 0; n < tnumber; n++) { int index; index = n * (xnumber * ynumber * znumber) + y * (xnumber * znumber) + x * znumber + z; smokedensity.Add(timedensity[index]); } if (Mathf.Max(smokedensity.ToArray()) > (maxdensity / 10)) { GameObject newSmoke = Instantiate(Resources.Load <GameObject>("Prefabs/Smoke")); newSmoke.GetComponent <InPlaySmoke>().MaxDensity = maxdensity; newSmoke.GetComponent <InPlaySmoke>().Density = smokedensity; newSmoke.transform.SetParent(Scene.transform); newSmoke.transform.localPosition = new Vector3(-(WIDTH / 2) + x * d, 0.5f * d + z * d, -(LENGTH / 2) + y * d); } } } } } // 7. Set currenttime to be 0 currenttime = 0; } }
private void Start() { obs = FindObjectOfType <Obstacle>(); transform.Rotate(new Vector3(0f, 0f, -90f)); }
public ObstacleEntry(Obstacle pref, Vector3 pos) { prefab = pref; position = pos; }
void Update() { if (controller.collisions.damagedLeft || controller.collisions.damagedRight || controller.collisions.damagedAbove || controller.collisions.damagedBelow) { Vector2 damageDir = Vector2.zero; if (controller.collisions.damagedLeft) { damageDir.x += 1.0f; } if (controller.collisions.damagedRight) { damageDir.x -= 1.0f; } if (controller.collisions.damagedBelow) { damageDir.y += 1.0f; } if (controller.collisions.damagedAbove) { damageDir.y -= 1.0f; } if (damageDir != Vector2.zero) { damageDir *= damageImpulse / damageDir.magnitude; } velocity = damageDir; controller.Move(Time.deltaTime * velocity); return; } if (controller.collisions.blockedAbove || controller.collisions.blockedBelow) { velocity.y = 0f; } if (controller.collisions.blockedBelow && doubleJumped) { doubleJumped = false; } //if ((controller.collisions.blockedAbove || controller.collisions.blockedBelow || controller.collisions.blockedLeft || controller.collisions.blockedRight) && dashed) { if (controller.collisions.blockedBelow && dashed) { dashed = false; dashing = false; currentDashDuration = 0.0f; } float horizontalInput = Mathf.Clamp(Input.GetAxisRaw("Horizontal"), -1.0f, 1.0f); float verticalInput = Mathf.Clamp(Input.GetAxisRaw("Vertical"), -1.0f, 1.0f); Vector2 input = new Vector2(horizontalInput, verticalInput); bool clingLeftWall = false; bool clingRightWall = false; if (Input.GetButton("Cling")) { if (controller.collisions.blockedLeft) { clingLeftWall = true; } else if (controller.collisions.blockedRight) { clingRightWall = true; } } if (Input.GetButtonDown("Jump")) { if (controller.collisions.blockedBelow) { if (input.y < traversePlatformThreshold && controller.collisions.below.obstacle.obstacleType == Obstacle.ObstacleType.TraversablePlatform) { controller.collisions.below.obstacle.Disable(0.5f); doubleJumped = true; } else { velocity.y = jumpVelocity * Obstacle.GetJumpVelocityFactor(controller.collisions.below.obstacle.obstacleType); } } else if ((input.x > 0 || clingLeftWall) && controller.collisions.blockedLeft) { velocity.x = wallJumpImpulseX * Obstacle.GetJumpVelocityFactor(controller.collisions.left.obstacle.obstacleType); //velocity.y = wallJumpImpulseY * Obstacle.GetJumpVelocityFactor (controller.collisions.left.obstacle.obstacleType); velocity.y = wallJumpImpulseY; } else if ((input.x < 0 || clingRightWall) && controller.collisions.blockedRight) { velocity.x = -wallJumpImpulseX *Obstacle.GetJumpVelocityFactor(controller.collisions.right.obstacle.obstacleType); //velocity.y = wallJumpImpulseY * Obstacle.GetJumpVelocityFactor (controller.collisions.right.obstacle.obstacleType); velocity.y = wallJumpImpulseY; } else if (!doubleJumped) { velocity.y = jumpVelocity; doubleJumped = true; } dashing = false; currentDashDuration = 0.0f; clingLeftWall = false; clingRightWall = false; } if (Input.GetButtonDown("Dash") && !dashed) { Vector2 dashDir = GetDashDirection(input); if (dashDir != Vector2.zero) { dashed = true; dashing = true; dashDirection = dashDir; currentDashDuration = 0.0f; } clingLeftWall = false; clingRightWall = false; } if (dashing) { float frameDashDuration = Mathf.Min(Time.deltaTime, Mathf.Max(0.0f, dashDuration - currentDashDuration)); velocity = dashDirection * dashSpeed; controller.Move(frameDashDuration * velocity); currentDashDuration += Time.deltaTime; if (currentDashDuration >= dashDuration) { dashing = false; currentDashDuration = 0.0f; //velocity = Vector3.zero; } } else { if (clingLeftWall || clingRightWall) { velocity = Vector3.zero; //velocity.x = platformVelocity.x + (clingLeftWall ? -0.5f : 0.5f); //velocity.y = platformVelocity.y; velocity.x = clingLeftWall ? -1.0f : 1.0f; } else { float targetVelocityX = input.x * moveSpeed; //targetVelocityX += platformVelocity.x; velocity.x = Mathf.SmoothDamp(velocity.x, targetVelocityX, ref currentVelocityX, (controller.collisions.blockedBelow) ? smoothX : 2f * smoothX); //velocity.y += gravity * Time.deltaTime + platformVelocity.y; velocity.y += gravity * Time.deltaTime; } controller.Move(Time.deltaTime * velocity); } }
void InitCoverSquare() { if (cover.Count != 4) { cover = new List <_CoverType>(); for (int i = 0; i < 4; i++) { cover.Add(_CoverType.None); } overlayPos = new List <Vector3>(); for (int i = 0; i < 4; i++) { overlayPos.Add(new Vector3(50000, 50000, 50000)); } } List <Tile> adjacentTile = new List <Tile>(); foreach (Tile tile in neighbours) { adjacentTile.Add(tile); } foreach (Tile tile in disconnectedNeighbour) { adjacentTile.Add(tile); } LayerMask mask = 1 << LayerManager.GetLayerObstacle(); foreach (Tile tile in adjacentTile) { int neighbourID = 0; Vector2 dir = new Vector2(tile.transform.position.x - pos.x, tile.transform.position.z - pos.z); float angle = Utility.VectorToAngle(dir); if (angle > 45 && angle < 135) { neighbourID = 1; } else if (angle > 135 && angle < 225) { neighbourID = 2; } else if (angle > 225 && angle < 315) { neighbourID = 3; } else { neighbourID = 0; } float dist = Vector3.Distance(pos, tile.pos); Vector3 direction = tile.pos - pos; float gridSize = GridManager.GetTileSize(); overlayPos[neighbourID] = pos + (direction.normalized) * gridSize * 0.475f + new Vector3(0, gridSize * 0.3f, 0); RaycastHit hit; if (Physics.Raycast(pos, direction.normalized, out hit, dist, mask)) { Obstacle obs = hit.collider.gameObject.GetComponent <Obstacle>(); if (obs != null) { cover[neighbourID] = obs.coverType; } } } }
// Start is called before the first frame update private void Awake() { obstacleLeft.SetActive(true); obstacleRight.SetActive(true); obstacle = this; }
internal void Insert(Obstacle obstacle) { groupsAndClumps.Insert(obstacle); }
/// <summary> /// Calcuates forces to avoid obstacles in the scene /// </summary> /// <returns></returns> public Vector3 ObstacleAvoidance() //maybe pass in the seek vector to check against { Vector3 desiredVelocity = Vector3.zero; //debug lines showing the "safe" area in front of the vehicle //Vector3 safeEnd = Vector3.ClampMagnitude(velocity * 10, safeDistance); //Vector3 vehicleEdge1 = new Vector3(vehiclePosition-) //Debug.DrawLine(vehicleMesh.bounds.max.x, vehiclePosition + safeEnd , Color.magenta); if (manager.obstacles == null || manager.obstacles.Count <= 0) { return(desiredVelocity); } //iterate through list of obstacles foreach (GameObject obstacle in manager.obstacles) { //Debug.DrawLine(obstacle.transform.position, new Vector3(obstacle.transform.position.x, obstacle.transform.position.y + 1000, obstacle.transform.position.z), Color.yellow); Vector3 distance = obstacle.transform.position - vehiclePosition; //check forward or behind if (Vector3.Dot(distance, transform.forward) > 0) { //if its forward //check distance if (distance.sqrMagnitude < sqrSafeDistance) { //check dot products of remaining (against dot of right vector) float dotProduct = Vector3.Dot(transform.right, distance); //variables to clean up if statement //MeshRenderer vehicleMesh = gameObject.GetComponent<MeshRenderer>(); Obstacle obstacleScript = obstacle.GetComponent <Obstacle>(); if (Mathf.Abs(dotProduct) < vehicleMesh.bounds.extents.x + obstacleScript.radius) { Debug.DrawLine(vehiclePosition, obstacle.transform.position, Color.red); Debug.DrawLine(obstacle.transform.position, new Vector3(obstacle.transform.position.x, obstacle.transform.position.y + 100, obstacle.transform.position.z), Color.red); //if it's greater than 0, its on the right (also for exactly forward) //(so move left) if (dotProduct >= 0) { desiredVelocity += (maxSpeed * -transform.right);// - velocity; } else //if it's less than 0, its on the left (so move right) { desiredVelocity += (maxSpeed * transform.right);// - velocity; } } else { Debug.DrawLine(vehiclePosition, obstacle.transform.position); } } } } return(desiredVelocity * avoidWeight - velocity); }
private void OnEnable() { obstacle = (Obstacle)target; }
/// <summary> /// Builds a level object from the given level file path. /// </summary> /// <param name="filepath"></param> /// <returns></returns> public Level GetLevelFromFile(string filepath) { var levelContent = levelLoader.ReadFileContents(filepath); //parsing map var levelMap = levelContent[Constants.MAP]; if (levelMap.Count != 23 || levelMap[0].Length != 40) { throw new Exception( "Error building level. Level must be 40 lines x 23 characters."); } var platformIds = levelParser.ParsePlatformChars(levelContent[Constants.PLATFORMS]); if (platformIds.Count < 1) { throw new Exception("Error building level. Level must contain platforms."); } var levelImages = levelParser.ParseImages(levelContent[Constants.IMAGES]); if (levelImages.Count < 1) { throw new Exception("Error building level. Level must contain image mapping."); } Dictionary <char, Platform> platformDictionary = new Dictionary <char, Platform>(); foreach (char platformChar in platformIds) { platformDictionary.Add(platformChar, new Platform(platformChar)); } EntityContainer <Obstacle> obstacles = new EntityContainer <Obstacle>(); EntityContainer portals = new EntityContainer(); Vec2F extent = new Vec2F(Constants.EXTENT_X, Constants.EXTENT_Y); Vec2F playerStartingPosition = null; Player player = new Player(null, null); //parsing level map int i = 0; foreach (string mapString in levelMap) { for (int j = 0; j < mapString.Length; j++) { char mapChar = mapString[j]; Vec2F position = new Vec2F( j * Constants.EXTENT_X, 1 - i * Constants.EXTENT_Y - Constants.EXTENT_Y ); StationaryShape shape = new StationaryShape(position, extent); if (mapChar == ' ') { continue; } //checking the individual map chars if (platformIds.Contains(mapString[j])) { platformDictionary[mapChar].AddPlatform( shape, imageContainer.GetImageByName(levelImages[mapChar])); } else if (mapChar == '^') { portals.AddStationaryEntity(shape, null); } else if (mapChar == '<' || mapChar == '>') { playerStartingPosition = new Vec2F(j * Constants.EXTENT_X, 1 - i * Constants.EXTENT_Y); player.Shape.Position = playerStartingPosition; } else { var newObstacle = new Obstacle(shape, null) { Image = imageContainer.GetImageByName(levelImages[mapChar]) }; obstacles.AddStationaryEntity(newObstacle); } } i++; } if (playerStartingPosition == null) { throw new Exception( "Error building level. Level map must contain a starting position for player."); } if (portals.CountEntities() < 1) { throw new Exception( "Error building level. Level map must contain portal entities."); } var levelCustomers = levelParser.ParseCustomerStrings(levelContent[Constants.CUSTOMERS]); var name = levelParser.ParseLevelName(levelContent[Constants.NAME]); return(new Level( name, portals, obstacles, platformDictionary, levelCustomers, player, playerStartingPosition)); }
public void Insert(Obstacle unObstacle) //insérer une ligne { _DBAL.Insert(" Obstacle values (" + unObstacle.NomObstacle + ", '" + unObstacle.Definition + "','" + unObstacle.Photo + "','" + unObstacle.TypeObstacle + "');"); }
protected void OnTriggerEnter(Collider c) { if (c.gameObject.layer == k_CoinsLayerIndex) { if (magnetCoins.Contains(c.gameObject)) { magnetCoins.Remove(c.gameObject); } if (c.GetComponent <Coin>().isPremium) { Destroy(c.gameObject); controller.premium += 1; m_Audio.PlayOneShot(premiumSound); } else { Coin.coinPool.Free(c.gameObject); controller.coins += 1; m_Audio.PlayOneShot(coinSound); controller.CoinCollided(); // Everytime it gets a coint the positive reward is updated } } else if (c.gameObject.layer == k_ObstacleLayerIndex) { if (m_Invincible || controller.IsCheatInvincible()) { return; } controller.StopMoving(); c.enabled = false; Obstacle ob = c.gameObject.GetComponent <Obstacle>(); if (ob != null) { ob.Impacted(); } else { Destroy(c.gameObject); } controller.currentLife -= 1; controller.character.animator.SetTrigger(s_HitHash); controller.ObstacleCollided(); // Everytime it hits an obstacle a negative reward is given if (controller.currentLife > 0) { m_Audio.PlayOneShot(controller.character.hitSound); SetInvincible(); } // The collision killed the player, record all data to analytics. else { m_Audio.PlayOneShot(controller.character.deathSound); m_DeathData.character = controller.character.characterName; m_DeathData.themeUsed = controller.trackManager.currentTheme.themeName; m_DeathData.obstacleType = ob.GetType().ToString(); m_DeathData.coins = controller.coins; m_DeathData.premium = controller.premium; m_DeathData.score = controller.trackManager.score; m_DeathData.worldDistance = controller.trackManager.worldDistance; } } else if (c.gameObject.layer == k_PowerupLayerIndex) { Consumable consumable = c.GetComponent <Consumable>(); if (consumable != null) { controller.UseConsumable(consumable); } } }
public void Delete(Obstacle unObstacle) //supprimer une ligne { _DBAL.Delete("Obstacle WHERE nom = '" + unObstacle.NomObstacle + "' ;"); }
private void WriteClumpId(Obstacle obstacle) { if (!obstacle.IsOverlapped) { return; } int id; if (!this.clumpToIdMap.TryGetValue(obstacle.Clump, out id)) { id = this.GetNextClumpId(); this.clumpToIdMap[obstacle.Clump] = id; } this.outputFileWriter.WriteLine(RectFileStrings.WriteClumpId, id); }
public void spawnObstacle(Vector3 spawnPoint) { Obstacle obstaclePrefab = obstaclePrefabs[Random.Range(0, obstaclePrefabs.Count)]; spawnObstacle(spawnPoint, obstaclePrefab); }
public void SaveObstacle(Obstacle obstacle) { _obstacleRepository.CreateObstacle(obstacle); }