// attack the object in front of the player if it can be destroyed public void Attack() { if (attackType == AttackType.None) { return; } if (!InAir() && !isSliding) { if (attackType == AttackType.Fixed) { playerAnimation.Attack(); RaycastHit hit; if (Physics.Raycast(thisTransform.position + Vector3.up / 2, thisTransform.forward, out hit, farAttackDistance, obstacleLayer)) { // the player will collide with the obstacle if they are too close if (hit.distance > closeAttackDistance) { ObstacleObject obstacle = hit.collider.GetComponent <ObstacleObject>(); if (obstacle.isDestructible) { obstacle.ObstacleAttacked(); } } } } else if (projectileManager.CanFire()) // projectile { playerAnimation.Attack(); projectileManager.Fire(); } } }
// attack the object in front of the player if it can be destroyed public void attack() { if (!allowAttack) { return; } if (!isJumping && !isJumpPending && !isSliding) { playerAnimation.attack(); RaycastHit hit; if (Physics.Raycast(thisTransform.position + Vector3.up / 2, thisTransform.forward, out hit, farAttackDistance, 1 << obstacleLayer)) { // the player will collide with the obstacle if they are too close if (hit.distance > closeAttackDistance) { ObstacleObject obstacle = hit.collider.GetComponent <ObstacleObject>(); if (obstacle.isDestructible) { obstacle.obstacleAttacked(); } } } } }
public Obstacle(GameObject obstacleObject, Bounds bounds) { this.ObstacleObject = obstacleObject; this.PositionRange = new Range() { Min = bounds.Bottom() + ObstacleObject.RendererSize().y / 2, Max = bounds.Top() - ObstacleObject.RendererSize().y / 2, }; }
private void SucceedObstacle(ObstacleObject obstacleObj) { obstacleObjList.Remove(obstacleObj); UnityUtil.DestroyWithChildren(obstacleObj.transform); if (obstacleObjList.Count == 0 && obstacleIndex == obstacleDataList.Count) { Debug.Log("IMPLEMENT ENDGAME / WIN GAME"); } }
private void SpawnObstacle(int index) { ObstacleObject newObject = Instantiate(obstaclePrefab, obstacleSpawnPoint.position, Quaternion.identity).GetComponent <ObstacleObject>(); newObject.Init(obstacleDataList[index], obstacleSpawnPoint.position, obstacleDestinationPoint.position, PREVIEW_STEPS); newObject.PlayerSucceeded += SucceedObstacle; newObject.PlayerFailed += RestartGame; obstacleObjList.Add(newObject); // pass in the Fail() and SucceedObstacle() functions like callbacks (???) }
void SpawnObstacle() { int obstacleIndex = Random.Range(0, obstacle.Count); ObstacleObject obs = obstacle[obstacleIndex]; float x = Random.Range(obstacleMinX, obstacleMaxX); float y = Random.Range(obs.MinY, obs.MaxY); Vector3 position = new Vector3(x, y, 0); Instantiate(obs.Obstacle, position, Quaternion.identity); }
public void obstacleCollision(ObstacleObject obstacle, Vector3 position) { if (!powerUpManager.isPowerUpActive(PowerUpTypes.Invincibility) && !godMode) { playerController.obstacleCollision(obstacle.getTransform(), position); dataManager.obstacleCollision(); if (dataManager.getCollisionCount() == playerController.maxCollisions) { gameOver(obstacle.isJump ? GameOverType.JumpObstacle : GameOverType.DuckObstacle, true); } else { audioManager.playSoundEffect(SoundEffects.ObstacleCollisionSoundEffect); } } }
/// <summary> /// Generate obstacles by number /// </summary> /// <param name="num">Number of genarated obstacles</param> private void GenerateObstacles(int num) { int i = 0; while (i != num) { int posX = rnd.Next(0, 50); int posY = rnd.Next(0, 30); ObstacleObject o = new ObstacleObject() { Point = new Point(posX, posY) }; this.GameModel.Obstacles.Add(o); i++; } }
bool AddObstacle(Floor floor) { if (floor.Position.x == Mathf.FloorToInt(roomBounds.min.x + GameConst.RoomOutsize)) { return(false); } if (floor.Position.x == Mathf.FloorToInt(roomBounds.max.x - GameConst.RoomOutsize - 1)) { return(false); } if (floor.Position.y == Mathf.FloorToInt(roomBounds.min.y + GameConst.RoomOutsize)) { return(false); } if (floor.Position.y == Mathf.FloorToInt(roomBounds.max.y - GameConst.RoomOutsize - 1)) { return(false); } GameObject Prefab = (ResourceManager.instance.GetAsset <GameObject>("Prefabs/Obstacle")); try { GameObject obstacleObject = Instantiate(Prefab); string name = gameObject.name + "Obstacle_" + floor.Position.x + "_" + floor.Position.y; ObstacleObject obstacle = obstacleObject.GetComponent <ObstacleObject>(); obstacle.Init(LevelManager.GetElementID(), roomId, name, floor.Position.x, floor.Position.y); objList[obstacle.ID] = obstacle; obstacleList.Add(obstacle.ID); obstacleDictionary[GetPosKey(Mathf.FloorToInt(floor.Position.x), Mathf.FloorToInt(floor.Position.y))] = obstacle.ID; floor.OrnamentId = obstacle.ID; } finally { Prefab = null; } return(true); }
public void ObstacleCollision(ObstacleObject obstacle, Vector3 position) { if (!powerUpManager.IsPowerUpActive(PowerUpTypes.Invincibility) && !powerUpManager.IsPowerUpActive(PowerUpTypes.SpeedIncrease) && !playerController.WithinReviveGracePeriod() && !godMode && gameActive) { playerController.ObstacleCollision(obstacle.GetTransform(), position); dataManager.ObstacleCollision(); if (dataManager.GetCollisionCount() == playerController.maxCollisions) { GameOver(obstacle.isJump ? GameOverType.JumpObstacle : GameOverType.DuckObstacle, true); } else { // the chase object will end the game if (playerController.maxCollisions == 0 && chaseController != null) { if (chaseController.IsVisible()) { GameOver(obstacle.isJump ? GameOverType.JumpObstacle : GameOverType.DuckObstacle, true); } else { chaseController.Approach(); audioManager.PlaySoundEffect(SoundEffects.ObstacleCollisionSoundEffect); } } else { // have the chase object approach the character when the collision count gets close if (chaseController != null && dataManager.GetCollisionCount() == playerController.maxCollisions - 1) { chaseController.Approach(); } audioManager.PlaySoundEffect(SoundEffects.ObstacleCollisionSoundEffect); } } } }
public void ObstacleCollision(ObstacleObject obstacle, Vector3 position) { PlayerController.instance.ObstacleCollision(obstacle.GetTransform(), position); GameOver(); }
public void obstacleCollision(ObstacleObject obstacle, Vector3 position) { if (!powerUpManager.isPowerUpActive(PowerUpTypes.Invincibility) && !powerUpManager.isPowerUpActive(PowerUpTypes.SpeedIncrease) && !godMode && gameActive) { playerController.obstacleCollision(obstacle.getTransform(), position); dataManager.obstacleCollision(); if (dataManager.getCollisionCount() == playerController.maxCollisions) { gameOver(obstacle.isJump ? GameOverType.JumpObstacle : GameOverType.DuckObstacle, true); } else { // the chase object will end the game if (playerController.maxCollisions == 0 && chaseController != null) { if (chaseController.isVisible()) { gameOver(obstacle.isJump ? GameOverType.JumpObstacle : GameOverType.DuckObstacle, true); } else { chaseController.approach(); audioManager.playSoundEffect(SoundEffects.ObstacleCollisionSoundEffect); } } else { // have the chase object approach the character when the collision count gets close if (chaseController != null && dataManager.getCollisionCount() == playerController.maxCollisions - 1) { chaseController.approach(); } audioManager.playSoundEffect(SoundEffects.ObstacleCollisionSoundEffect); } } } }
public Vector2 Size() { return(ObstacleObject.RendererSize()); }