Skip to content

Commit

Permalink
very final version
Browse files Browse the repository at this point in the history
  • Loading branch information
niclas frohberg committed Nov 2, 2022
1 parent e50d302 commit 53d44ed
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Assets/Materials/Skybox.mat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions Assets/Scripts/Collision.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using UnityEngine;
using UnityEngine.SceneManagement;

// TODO: this class handles player movement and
public class Collision : MonoBehaviour
{
public int jumpMultiplier = 10;
Expand All @@ -14,6 +13,7 @@ public class Collision : MonoBehaviour
private Rigidbody _rigidbody;
private float originalStepOffset;
private float ySpeed;
private bool first_play = true;

private int _score = 0;
private bool is_grounded = true;
Expand Down Expand Up @@ -41,7 +41,6 @@ private void OnCollisionEnter(UnityEngine.Collision collision)

private void OnCollisionStay(UnityEngine.Collision collisionInfo)
{
print("onStay");
is_grounded = true;
animator.SetBool("is_grounded", true);
is_jumping = false;
Expand Down Expand Up @@ -73,7 +72,7 @@ private void FixedUpdate()

private IEnumerator HandleInput()
{
// getestet mit Xbox Controller und funktioniert :
// works with xbox controller
var horizontalValue = Input.GetAxis("Horizontal");
var verticalValue = Input.GetAxis("Vertical");
var newVector = transform.position;
Expand All @@ -90,12 +89,17 @@ private IEnumerator HandleInput()

if (verticalValue > 0 && is_grounded)
{
Debug.Log(is_grounded);
is_grounded = false;
animator.SetBool("is_grounded", false);
animator.SetBool("is_jumping", true);
is_jumping = true;
audioSource.Play(0);

if (first_play) {
first_play = false;
audioSource.Play(0);
} else {
first_play = true;
}
_rigidbody.AddForce(new Vector3(0, 2, 0) * jumpMultiplier, ForceMode.Impulse);
}

Expand Down
23 changes: 13 additions & 10 deletions Assets/Scripts/MapGeneration/NewLevelGeneration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ public class NewLevelGeneration : MonoBehaviour
private float _nextPlayerCheck = 0;

public int amountOfPreGeneratedFloors = 3;

public GameObject[] obstacles;
public int[] obstaclesWidth;
public int obstaclePercentageGrowthFactor = 2;
public int obstaclePercentageGrowthFactor = 1;
private readonly float[] _xPosForObstacles = { -0.5f, 0.5f, 1.5f };
private int _percentageForGeneratingObstacle = 0;
private int _leftBorder = 33;
Expand All @@ -24,7 +24,7 @@ public class NewLevelGeneration : MonoBehaviour
public float zPosition = 0.5f;

// Allocation is important!!!
private List<GameObject> _generatedObjects = new List<GameObject>();
private readonly List<GameObject> _generatedObjects = new List<GameObject>();

// Start is called before the first frame update
void Start()
Expand All @@ -51,7 +51,7 @@ void Update()
if (player.transform.position.z >= _nextPlayerZForDiffInc)
{
obstaclePercentageGrowthFactor += 1;
_nextPlayerZForDiffInc += 500;
_nextPlayerZForDiffInc += 200;
}
}

Expand All @@ -61,23 +61,24 @@ private void GenerateSection()
_generatedObjects.Add(Instantiate(floor, new Vector3(0.5f, 0.5f, zPosition), Quaternion.identity));

// Create Obstacle
for (int i = -zPositionDifference / 2; i < +zPositionDifference / 2; i++)
for (int i = (-zPositionDifference / 2) + 1; i < +zPositionDifference / 2; i++)
{
if (RandomizerObstacles())
{
Random rnd = new Random();

int selectedObstacleIndex = rnd.Next(0, obstacles.Length);

print(obstaclesWidth[selectedObstacleIndex]);

int xPosForObstacleIndex;
switch (obstaclesWidth[selectedObstacleIndex])
{
case 1: xPosForObstacleIndex = RandomizerXPosForObstacle();
i+=1;
break;
case 2: xPosForObstacleIndex = 0;
case 2: xPosForObstacleIndex = rnd.Next(1,2);
break;
case 3: xPosForObstacleIndex = 1;
i+=3;
break;
default: xPosForObstacleIndex = 0;
break;
Expand All @@ -89,6 +90,8 @@ private void GenerateSection()
new Vector3(_xPosForObstacles[xPosForObstacleIndex],
1.5f, zPosition + i), Quaternion.identity)
);

print(zPosition+i);
}
}

Expand Down Expand Up @@ -125,7 +128,7 @@ private bool RandomizerObstacles()
bool isGeneratingObstacle = rnd.Next(1,100) <= _percentageForGeneratingObstacle;

_percentageForGeneratingObstacle = (isGeneratingObstacle) ? 0 : _percentageForGeneratingObstacle + obstaclePercentageGrowthFactor;

return isGeneratingObstacle;
}

Expand Down Expand Up @@ -167,4 +170,4 @@ private int RandomizerXPosForObstacle()
//This Shouldn't happen
return 0;
}
}
}
1 change: 0 additions & 1 deletion Assets/Scripts/RotateSky.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ void Start()

void FixedUpdate()
{
print("Hello");
RenderSettings.skybox.SetFloat("_Rotation", Time.time * RotateSpeed);
}
}
4 changes: 3 additions & 1 deletion ProjectSettings/ProjectSettings.asset

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 53d44ed

Please sign in to comment.