Skip to content

Commit

Permalink
Merge branch 'main' into high_poly_main
Browse files Browse the repository at this point in the history
  • Loading branch information
felicijus committed Aug 5, 2021
2 parents 43d4302 + 6e3d823 commit e3c3f4b
Show file tree
Hide file tree
Showing 45 changed files with 1,368 additions and 1,258 deletions.
140 changes: 72 additions & 68 deletions Platformer/Assets/Scripts/Background/Asteroid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,99 +10,103 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Viewport;
using Random = UnityEngine.Random;

public class Asteroid : MonoBehaviour
namespace Background
{
[SerializeField] private List <Transform> asteroid_list; /*SerializeField show im Unity inspector https://stackoverflow.com/a/53192557 */
public class Asteroid : MonoBehaviour
{
[SerializeField] private List <Transform> asteroid_list; /*SerializeField show im Unity inspector https://stackoverflow.com/a/53192557 */

[SerializeField] private int number; /*number of asteroids that are to be placed*/
[SerializeField] private bool viewport;
[SerializeField] private bool deathwall;
[SerializeField] private int number; /*number of asteroids that are to be placed*/
[SerializeField] private bool viewport;
[SerializeField] private bool deathwall;

[SerializeField] private bool position;
[SerializeField] private Vector3 pos;
[SerializeField] private bool position;
[SerializeField] private Vector3 pos;


/*Delegate is a container for one or many Methods that can be used as a variable*/
delegate Vector3 DelegateRandom(); /*Delegate declaration*/
private DelegateRandom delegate_random;
/*Delegate is a container for one or many Methods that can be used as a variable*/
delegate Vector3 DelegateRandom(); /*Delegate declaration*/
private DelegateRandom delegate_random;

private void Awake()
{
if (viewport.Equals(deathwall) && viewport.Equals(position))
private void Awake()
{
Debug.LogException(new Exception("Either Viewport or Deathwall or Position"));
if (viewport.Equals(deathwall) && viewport.Equals(position))
{
Debug.LogException(new Exception("Either Viewport or Deathwall or Position"));
}
}
}

// Start is called before the first frame update
private void Start()
{
StartCoroutine(Wait(0.01f));
}


private IEnumerator Wait(float t)
{
yield return new WaitForSeconds(t);

InitPlace(number);
}

private void InitPlace(int num)
{
if (viewport)
// Start is called before the first frame update
private void Start()
{
delegate_random = VectorRandViewport;
StartCoroutine(Wait(0.01f));
}
else if (deathwall)


private IEnumerator Wait(float t)
{
delegate_random = VectorRandY;
yield return new WaitForSeconds(t);

InitPlace(number);
}
else if (position)

private void InitPlace(int num)
{
delegate_random = VectorViewport;
if (viewport)
{
delegate_random = VectorRandViewport;
}
else if (deathwall)
{
delegate_random = VectorRandY;
}
else if (position)
{
delegate_random = VectorViewport;
}
PlaceAsteroid(delegate_random,num);
}
PlaceAsteroid(delegate_random,num);
}

private void PlaceAsteroid(DelegateRandom del, int num) /* Method actually Placing Asteroid with the desired position declared in delegate_random*/
{
for (int i = 0; num > i; i++)
private void PlaceAsteroid(DelegateRandom del, int num) /* Method actually Placing Asteroid with the desired position declared in delegate_random*/
{
Transform chosen_asteroid = asteroid_list[Random.Range(0, asteroid_list.Count)];
Instantiate(chosen_asteroid, del.Invoke() , Quaternion.identity, transform);
for (int i = 0; num > i; i++)
{
Transform chosen_asteroid = asteroid_list[Random.Range(0, asteroid_list.Count)];
Instantiate(chosen_asteroid, del.Invoke() , Quaternion.identity, transform);
}
}
}


/* Three Methods for the user of the Unity Inspector to set the position of Asteroids*/
private Vector3 VectorRandViewport() /*Random position respective to the Player and the Viewport*/
{
float w = Random.Range(-(ScreenViewport.GetWidth()/2), ScreenViewport.GetWidth()/2);
float h = Random.Range(-(ScreenViewport.GetHeight()/2), ScreenViewport.GetHeight()/2);
/* Three Methods for the user of the Unity Inspector to set the position of Asteroids*/
private Vector3 VectorRandViewport() /*Random position respective to the Player and the Viewport*/
{
float w = Random.Range(-(ScreenViewport.GetWidth()/2), ScreenViewport.GetWidth()/2);
float h = Random.Range(-(ScreenViewport.GetHeight()/2), ScreenViewport.GetHeight()/2);

Vector3 rand = new Vector3(w, h, 0);
Vector3 center = CameraView.GetScreenPos();
Vector3 v = center + rand;
return v;
}
Vector3 rand = new Vector3(w, h, 0);
Vector3 center = CameraView.GetScreenPos();
Vector3 v = center + rand;
return v;
}

private Vector3 VectorRandY() /*Random position respective to the Player and the Viewport but only along the y axis*/
{
float h = Random.Range(-(ScreenViewport.GetHeight()/2), ScreenViewport.GetHeight()/2);
private Vector3 VectorRandY() /*Random position respective to the Player and the Viewport but only along the y axis*/
{
float h = Random.Range(-(ScreenViewport.GetHeight()/2), ScreenViewport.GetHeight()/2);

Vector3 rand = new Vector3(0, h, 0);
//Debug.Log(h);
//Vector3 center = new Vector3(0,CameraView.GetScreenPos().y,0);
//Vector3 v = center + rand;
return rand;
}
Vector3 rand = new Vector3(0, h, 0);
//Debug.Log(h);
//Vector3 center = new Vector3(0,CameraView.GetScreenPos().y,0);
//Vector3 v = center + rand;
return rand;
}

private Vector3 VectorViewport() /*Manual position respective to the Viewport (in Viewportspace)*/
{
Vector3 v = CameraView.GetCamera().ViewportToWorldPoint(pos);
return v;
private Vector3 VectorViewport() /*Manual position respective to the Viewport (in Viewportspace)*/
{
Vector3 v = CameraView.GetCamera().ViewportToWorldPoint(pos);
return v;
}
}
}
72 changes: 38 additions & 34 deletions Platformer/Assets/Scripts/Background/AsteroidMovement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,55 +7,59 @@


using UnityEngine;
using Viewport;
using Random = UnityEngine.Random;

public class AsteroidMovement : MonoBehaviour
namespace Background
{
private Animator animatior;
private float anim_rotation_factor = 5f;
public class AsteroidMovement : MonoBehaviour
{
private Animator animatior;
private float anim_rotation_factor = 5f;

private float velocity;
private float max_velocity = 2.5f;
private float velocity;
private float max_velocity = 2.5f;

private Transform trans;
private Vector3 pos;
private Transform trans;
private Vector3 pos;



private void Awake()
{
animatior = gameObject.GetComponent<Animator>();
trans = gameObject.GetComponent<Transform>();
pos = gameObject.GetComponent<Transform>().position;

}

// Start is called before the first frame update
private void Start()
{
velocity = Random.Range(-max_velocity, max_velocity);

if (velocity > 0)
private void Awake()
{
animatior.speed = velocity * anim_rotation_factor; /* speed of the animation depends on the velocity with which the asteroid moves regulated*/
animatior.SetFloat("rotation", -1); /* "rotation" is a parameter created in the Unity AnimationController and used under speed as a multiplier to change the rotation based on direction*/
animatior = gameObject.GetComponent<Animator>();
trans = gameObject.GetComponent<Transform>();
pos = gameObject.GetComponent<Transform>().position;

}
else

// Start is called before the first frame update
private void Start()
{
animatior.speed = velocity * -anim_rotation_factor;
animatior.SetFloat("rotation", 1);
velocity = Random.Range(-max_velocity, max_velocity);

if (velocity > 0)
{
animatior.speed = velocity * anim_rotation_factor; /* speed of the animation depends on the velocity with which the asteroid moves regulated*/
animatior.SetFloat("rotation", -1); /* "rotation" is a parameter created in the Unity AnimationController and used under speed as a multiplier to change the rotation based on direction*/
}
else
{
animatior.speed = velocity * -anim_rotation_factor;
animatior.SetFloat("rotation", 1);
}
}
}


// Update is called once per frame
private void Update()
{
ScreenViewport.OutBoundary(trans);
// Update is called once per frame
private void Update()
{
ScreenViewport.OutBoundary(trans);

var position = trans.position;
position = position + new Vector3(velocity * Time.deltaTime, 0, 0);
var position = trans.position;
position = position + new Vector3(velocity * Time.deltaTime, 0, 0);

transform.position = position;
transform.position = position;
}
}
}
47 changes: 25 additions & 22 deletions Platformer/Assets/Scripts/Background/Octopus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,34 @@
*/


using Global;
using Player;
using UnityEngine;

public class Octopus : MonoBehaviour
namespace Background
{
[SerializeField] private GameObject octopus;
private GameObject octopus_instance;

private Vector3 pos;

private void Awake()
{
pos = new Vector3(PlayerSpawn.edge_death, GameController.GetStartPos().y, GameController.GetStartPos().z); /* position dependent on StartPos and Deathwall */
}

// Start is called before the first frame update
private void Start()
public class Octopus : MonoBehaviour
{
octopus_instance = Instantiate(octopus, pos, Quaternion.identity,transform); /* creates the object everytime the script is executed */
[SerializeField] private GameObject octopus;
private GameObject octopus_instance;

private Vector3 pos;

private void Awake()
{
pos = new Vector3(PlayerSpawn.edge_death, GameController.GetStartPos().y, GameController.GetStartPos().z); /* position dependent on StartPos and Deathwall */
}

// Start is called before the first frame update
private void Start()
{
octopus_instance = Instantiate(octopus, pos, Quaternion.identity,transform); /* creates the object everytime the script is executed */
}

// Update is called once per frame
private void Update()
{
octopus_instance.transform.position = new Vector3(PlayerSpawn.edge_death, PlayerSpawn.Lerp(octopus_instance.transform.position.y ,PlayerController.GetPlayerPos().y), 0);
}
}

// Update is called once per frame
private void Update()
{
octopus_instance.transform.position = new Vector3(PlayerSpawn.edge_death, PlayerSpawn.Lerp(octopus_instance.transform.position.y ,PlayerController.GetPlayerPos().y), 0);
}


}
Loading

0 comments on commit e3c3f4b

Please sign in to comment.