Commit 0e2c3da3 authored by benxidosz's avatar benxidosz
Browse files

Revert "Merge branch 'GameOverRefactor' into 'master'"

This reverts merge request !29
parent 100acb3b
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(BoxCollider2D))]
public class BackgroundInstance : MonoBehaviour
{
// Start is called before the first frame update
public BackgroundRoller roller;
bool flaggedForDelete = false;
private void OnTriggerExit2D(Collider2D collision)
{
if (collision.gameObject.CompareTag("MainCamera"))
{
Debug.Log("whoosh");
if(!flaggedForDelete)
{
flaggedForDelete = true;
StartCoroutine(DestroyCountdown());
}
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
if(collision.gameObject.CompareTag("MainCamera"))
{
Debug.Log("meow");
roller.SetCurrentBgInstance(this.gameObject);
flaggedForDelete = false;
}
}
private IEnumerator DestroyCountdown()
{
yield return new WaitForSeconds(10);
if(flaggedForDelete && gameObject!=null)
{
Debug.Log("Oh no we're doomed");
Destroy(gameObject);
}
}
}
fileFormatVersion: 2
guid: 677803316bfc6c0408bf86ba89f7cdf1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BackgroundRoller : MonoBehaviour
{
//rolls with constant speed now, could be adjusted to the movement speed of the platforms or the offset of the player
private Camera camera;
public List<Sprite> bgSprites;
private int currentSprite = 0;
public GameObject currentBackgroundInstance;
public GameObject upcomingBackgroundInstance;
private BoxCollider2D bgCollider;
public GameObject backgroundInstancePrefab;
void Start()
{
camera = Camera.main;
bgCollider = currentBackgroundInstance.GetComponent<BoxCollider2D>();
settUpBackgroundInstance(currentBackgroundInstance);
}
// Update is called once per frame
void Update()
{
Debug.Log("current spire" + currentSprite);
if (currentSprite >= bgSprites.Count - 1)
{
currentSprite = -1; //never do this at home kids
}
//if there are sprites left & we are over half the height, we instantiate another sprite at the top
if (currentSprite < bgSprites.Count - 1 &&
camera.transform.position.y > currentBackgroundInstance.transform.position.y + bgCollider.size.y / 2 - camera.orthographicSize &&
upcomingBackgroundInstance == null)
{
upcomingBackgroundInstance = Instantiate(backgroundInstancePrefab);
settUpBackgroundInstance(upcomingBackgroundInstance);
upcomingBackgroundInstance.transform.position = new Vector3(0, currentBackgroundInstance.transform.position.y + bgCollider.size.y * currentBackgroundInstance.transform.localScale.y, 0.1f);
}
}
public void SetCurrentBgInstance(GameObject bg)
{
currentBackgroundInstance = bg.gameObject;
upcomingBackgroundInstance = null;
bgCollider = bg.GetComponent<BoxCollider2D>();
}
public void settUpBackgroundInstance(GameObject upcomingBackgroundInstance)
{
//https://answers.unity.com/questions/890148/scale-and-place-gameobject-as-a-background-of-the.html
//source
upcomingBackgroundInstance.transform.localScale = new Vector2((Camera.main.orthographicSize * 2 * Screen.width * 0.28f) / Screen.height, Camera.main.orthographicSize * 2 * 0.28f);
upcomingBackgroundInstance.transform.SetParent(transform);
upcomingBackgroundInstance.GetComponent<SpriteRenderer>().sprite = bgSprites[currentSprite];
upcomingBackgroundInstance.GetComponent<BackgroundInstance>().roller = this;
currentSprite++;
}
}
fileFormatVersion: 2
guid: 721bec2f5f1e48d4784acc70c548e367
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(BoxCollider2D))]
public class CameraController : MonoBehaviour
{
//this script literally just sets the camera collider size to the size of the viewport
//put here any new camera functionality
public Transform playerTransform;
private Transform cameraTransform;
private int cameraSpeed;
public Vector3 velocity = Vector3.zero;
public float smoothTime = 0.2f;
void Start()
{
GetComponent<BoxCollider2D>().size = new Vector2(Camera.main.orthographicSize * Camera.main.aspect * 2, Camera.main.orthographicSize*2); //width, height
cameraTransform = Camera.main.transform;
}
private void FixedUpdate()
{
if(playerTransform.position.y-cameraTransform.position.y>0.01)//if the player is higher than the middle of the camera
{
Vector3 targetPosition = new Vector3(cameraTransform.position.x, playerTransform.position.y, cameraTransform.position.z);
cameraTransform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, smoothTime);
}
}
}
fileFormatVersion: 2
guid: 5a4449b2421c89a42b923468217fbf76
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CanvasController : MonoBehaviour{
private Text sample;
void Start(){
sample = GetComponentInChildren<Text>();
}
void Update(){
sample.text = "sample";
}
}
fileFormatVersion: 2
guid: 4c98aa5abdae039489ec1d975cb726b4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using UnityEngine.Serialization;
using Random = System.Random;
public class EnemySpawnController : MonoBehaviour{
private Main_camera _cameraScript;
private Player _player;
private Vector3 _newPos;
[FormerlySerializedAs("OwlPrefab")] [SerializeField] private GameObject owlPrefab;
[FormerlySerializedAs("EnemySpawningOffset")] [SerializeField] private double enemySpawningOffset;
[SerializeField] private float ySpawningOffset;
private static readonly Random Random = new Random();
private void Start(){
_cameraScript = GameManager.Instance.MainCamera.GetComponent<Main_camera>();
_player = GameManager.Instance.Player;
_cameraScript.CameraMoved += CameraMove;
_newPos = _player.transform.position;
enemySpawningOffset = _cameraScript.ColliderSize.y * enemySpawningOffset;
}
private void CameraMove(){
var position = _player.transform.position;
var tmpPos = new Vector3(position.x, position.y + _cameraScript.ColliderSize.y * 2, position.z);
if (tmpPos.y - _newPos.y > enemySpawningOffset){
_newPos = tmpPos;
var tmpRoute1 = new Vector3(-GameManager.Instance.x_offset, (float) (_newPos.y + GetRandomNumber(-ySpawningOffset, ySpawningOffset)), _newPos.z);
var tmpRoute2 = new Vector3(GameManager.Instance.x_offset, (float) (_newPos.y + GetRandomNumber(-ySpawningOffset, ySpawningOffset)), _newPos.z);
var newEnemy = Instantiate(owlPrefab, _newPos, Quaternion.identity);
newEnemy.GetComponent<Owl>().AddWayponts(new []{tmpRoute1, tmpRoute2});
}
}
private static double GetRandomNumber(double minValue, double maxValue)
{
var next = Random.NextDouble();
var output = minValue + (next * (maxValue - minValue));
print(output);
return output;
}
}
fileFormatVersion: 2
guid: 76e401c1083713d4891fdd07806c39d8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FellOffController : MonoBehaviour {
private Transform mainCameraTransform;
private Collider2D mainCameraCollider2D;
private Collider2D myCollider;
private bool falled = false;
// Start is called before the first frame update
void Start() {
mainCameraTransform = GameManager.Instance.MainCamera.transform;
mainCameraCollider2D = GameManager.Instance.MainCamera.GetComponent<Collider2D>();
myCollider = GetComponent<Collider2D>();
GetComponent<BoxCollider2D>().size = new Vector2(Camera.main.orthographicSize * Camera.main.aspect * 4, 1);
Vector2 nPos = mainCameraTransform.position;
nPos.y -= (mainCameraCollider2D.bounds.size.y / 2 + myCollider.bounds.size.y / 2);
transform.position = nPos;
}
private void OnTriggerEnter2D(Collider2D other) {
if (other.CompareTag("Player")) {
if (!falled)
GameManager.Instance.FellDown();
}
}
private void OnTriggerExit2D(Collider2D other) {
if (falled)
GameManager.Instance.Player.hurt();
}
public void Fallen() {
falled = true;
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 2c337c71b0ca81d4cabc0efcf6a32922
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ItemDestroyer : MonoBehaviour {
private List<Collider2D> colliders = new List<Collider2D>();
private void OnTriggerExit2D(Collider2D col) {
// Ha platformmal talazunk
if (col.gameObject.CompareTag("Coin") && !colliders.Contains(col)) {
// Toroljuk azt aki lent volt
colliders.Add(col);
col.GetComponent<ItemBaseCollision>().DestroyItem();
ItemSpawner.Instance.DecreaseCoinNum();
}
if (col.gameObject.CompareTag("SpecialItem") && !colliders.Contains(col)) {
// Toroljuk azt aki lent volt
colliders.Add(col);
col.GetComponent<ItemBaseCollision>().DestroyItem();
ItemSpawner.Instance.DecreaseSpecialNum();
}
}
private void Update() {
colliders.Clear();
}
}
fileFormatVersion: 2
guid: 62fff5dd8f0ce9a4ea3cc2832ef5e8a3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEditorInternal;
using UnityEngine;
using Random = UnityEngine.Random;
public class ItemSpawner : MonoBehaviour {
public static ItemSpawner Instance { get; private set; }
private float width;
private float height;
[Header("Special")]
[SerializeField] private float chanceToSpawnSpecial = 0.4f;
[SerializeField] private int maxSpecialNum = 3;
[SerializeField] private int minSpecialNum = 0;
[SerializeField] private BaseItemEffect[] specialItems;
private int specialNum;
[Header("Coin")]
[SerializeField] private float chanceToSpawnCoin = 0.8f;
[SerializeField] private int maxCoinNum = 5;
[SerializeField] private int minCoinNum = 1;
[SerializeField] private Coin coinPrefab;
[SerializeField] private int minCoinValue = 50;
[SerializeField] private int maxCoinValue = 500;
private int coinNum;
private float lastY;
private float m_PlayerY;
void Start() {
if (Instance != null)
Destroy(gameObject);
else
Instance = this;
width = Camera.main.orthographicSize * Camera.main.aspect;
height = Camera.main.orthographicSize * 2;
m_PlayerY = GameManager.Instance.Player.transform.position.y;
coinNum = 0;
specialNum = 0;
lastY = m_PlayerY;
SpawnItems();
}
void Update() {
SpawnItems();
}
private void SpawnItems() {
if (coinNum <= minCoinNum) {
for (int i = 0; i < (maxCoinNum - coinNum); ++i) {
if (Random.Range(0.0f, 1.0f) < chanceToSpawnCoin) {
SpawnCoin();
}
}
while (coinNum < minCoinNum) {
SpawnCoin();
}
lastY += height / 2;
}
if (specialNum <= minSpecialNum) {
for (int i = 0; i < (maxSpecialNum - specialNum); ++i) {
if (Random.Range(0.0f, 1.0f) < chanceToSpawnSpecial) {
SpawnSpecial();
}
}
while (specialNum < minSpecialNum) {
SpawnSpecial();
}
lastY += height / 2;
}
}
private void SpawnCoin() {
var tmp = GenerateNextItemPos();
Coin coin = Instantiate(coinPrefab, tmp, Quaternion.identity);
coin.coinBonusLowerBound = minCoinValue;
coin.coinBonusUpperBound = maxCoinValue;
coinNum++;
}
private void SpawnSpecial() {
var tmp = GenerateNextItemPos();
Instantiate(specialItems[Random.Range(0, specialItems.Length)], tmp, Quaternion.identity);
specialNum++;
}
private Vector2 GenerateNextItemPos() {
float x = Random.Range(-width / 2, width / 2);
float y = Mathf.Max(lastY, m_PlayerY) + Random.Range(0.2f, height / 2);
Vector2 tmp = new Vector2(x, y);
lastY = y;
return tmp;
}
public void DecreaseCoinNum() {
coinNum--;
}
public void DecreaseSpecialNum() {
specialNum--;
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 616440c7c868257439ec39a2ac72a4b9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MenuController : MonoBehaviour {
[SerializeField] private Animator mainMenuAnimator;
[SerializeField] private Animator optionAnimator;
[SerializeField] private Animator leaderboardAnimator;
public void OptionButton() {
mainMenuAnimator.Play("MainOut");
optionAnimator.Play("OptionIn");
}
public void BackButton() {
mainMenuAnimator.Play("MenuIn");
optionAnimator.Play("OptionOut");
}
public void leaderboardButton()
{
mainMenuAnimator.Play("MainOut");
leaderboardAnimator.Play("LeaderboardIn");
}
public void backButtonLeaderboard()
{
mainMenuAnimator.Play("MenuIn");
leaderboardAnimator.Play("LeaderboardOut");
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: bc687a0428b1c9249907e57f5201647e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class OnkoltsegController : MonoBehaviour {
[SerializeField] private float waitingTime = 3;
[SerializeField] private float raisingSpeed = 2;
public float RaisingSpeed {
get => raisingSpeed;
set {
if (value <= 0) {
throw new ArgumentException("Onkoltseg Speed Cannot be zero or less.");
}
raisingSpeed = value;
}
}
public float WaitingTime {
get => waitingTime;
set {
if (value <= 0) {
throw new ArgumentException("Onkoltseg Time Cannot be zero or less.");
}
waitingTime = value;
}
}
public bool Enable{ get; set; }
private Rigidbody2D _rb;
private float tmpWaitingTime;
private Transform mainCameraTransform;
private Collider2D mainCameraCollider2D;
private Collider2D myCollider;
private bool moving;
private bool end = false;
// Start is called before the first frame update
void Start(){
Enable = false;
tmpWaitingTime = waitingTime;
moving = false;
_rb = GetComponent<Rigidbody2D>();
myCollider = GetComponent<Collider2D>();
mainCameraTransform = GameManager.Instance.MainCamera.transform;
mainCameraCollider2D = GameManager.Instance.MainCamera.GetComponent<Collider2D>();
}
public void ResetTimer() {
tmpWaitingTime = waitingTime;
if (moving)
_rb.velocity = Vector2.zero;
moving = false;
}
private void StartMoving() {
if (!Enable) return;
Vector2 nPos = mainCameraTransform.position;
nPos.y -= (mainCameraCollider2D.bounds.size.y / 2 + myCollider.bounds.size.y / 2);
transform.position = nPos;
moving = true;
_rb.velocity = Vector2.up * raisingSpeed;
}