This commit is contained in:
2023-01-16 02:10:17 +05:30
commit e5b4d6b6ae
72 changed files with 5809 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraFollower : MonoBehaviour
{
public static CameraFollower instance;
void Awake(){
instance = this;
}
public float Xsmoothness =1f;
public float Ysmoothness =1f;
public static Transform Target;
void Update()
{
}
public static void UpdateFrame(){
instance.updateFrame();
}
void updateFrame(){
float newX = Mathf.Lerp(transform.position.x, Target.position.x, Xsmoothness);
float newY = Mathf.Lerp(transform.position.y, Target.position.y, Ysmoothness);
transform.position = new Vector3(newX, newY, transform.position.z);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c60b0b16fba18a64a9c6fb16c07375ed
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

31
Assets/Scripts/GameUI.cs Normal file
View File

@@ -0,0 +1,31 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class GameUI : MonoBehaviour
{
public static GameUI instance;
[SerializeField]private GameObject deathPanel;
void Awake(){
instance =this;
}
public static void ShowDeath(){
instance.showDeath();
}
void showDeath(){
deathPanel.SetActive(true);
}
public void Restart(){
SceneManager.LoadScene(0);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 79013961d903f3342ae828fd0ead5728
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,60 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LevelGenerator : MonoBehaviour
{
[SerializeField]private GameObject LevelPrefab;
[SerializeField]private GameObject TopPrefab;
private List<GameObject> spawnedLevels = new List<GameObject>();
[SerializeField]private float spaceBetween = 1;
[SerializeField]private float verticalSpace = 2;
[SerializeField]private float maxLow;
[SerializeField]private float maxHigh;
[SerializeField]private List<float> Levels;
void Start()
{
GenerateAhead(150);
}
public void GenerateAhead(int count = 10){
if(Levels.Count <= 0){
Levels = new List<float>();
}
Levels.Add(1);
int startIndex= Levels.Count;
int lastIndex = Levels.Count +count;
for(int i =startIndex; i < lastIndex; i++){
float LastLevel = Levels[i-1];
float NewLevel = LastLevel + Random.Range(-maxLow, maxHigh);
Levels.Add(NewLevel);
float posX = i * spaceBetween;
float posY = Levels[i];
GameObject newLevelObj = Instantiate(LevelPrefab, new Vector3(posX,posY,0), Quaternion.identity);
spawnedLevels.Add(newLevelObj);
newLevelObj.transform.localScale = new Vector3(newLevelObj.transform.localScale.x, Mathf.Abs(LastLevel - NewLevel),1);
Color color = (LastLevel < NewLevel) ? Color.green : Color.red;
Color color2 = (LastLevel < NewLevel) ? new Color(0,0.29f,0) : new Color(0.29f,0,0);
newLevelObj.GetComponent<SpriteRenderer>().color = color;
GameObject topObj = Instantiate(TopPrefab, new Vector3(posX, posY + verticalSpace,0), Quaternion.identity);
topObj.transform.parent = newLevelObj.transform;
topObj.GetComponentInChildren<SpriteRenderer>().color =color2;
}
}
// Update is called once per frame
void Update()
{
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7e1a120442d9ec943abf807c5d94742c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

99
Assets/Scripts/Player.cs Normal file
View File

@@ -0,0 +1,99 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
[SerializeField]private Transform body;
[field:SerializeField]public Vector2 Velocity {get; private set;}
[SerializeField]private float gravity=1;
[SerializeField]private float jumpForce= 5;
[SerializeField]private float forwardSpeed= 0.1f;
[SerializeField]private float jumpCooldown = 0.5f;
[SerializeField]private float radius = 0.5f;
[Header("Sprites")]
public Sprite normalFace;
public Sprite sadFace;
public bool isReadyToJump { get{ return jumpTimer >= jumpCooldown;}}
private float jumpTimer= 0;
private Vector3 startPos;
public bool isAlive{get;private set;}
private SpriteRenderer spriteRenderer;
void Start(){
spriteRenderer = GetComponent<SpriteRenderer>();
isAlive = true;
spriteRenderer.sprite =normalFace;
startPos = body.position;
Velocity = new Vector2(forwardSpeed,0);
CameraFollower.Target= body;
}
void FixedUpdate()
{
if(!isAlive){ return; }
HandleDeath();
if(Input.GetKey(KeyCode.Space)){
Jump();
}
HandleJump();
//Gravity
Velocity -= new Vector2(0, gravity);
body.Translate(Velocity);
CameraFollower.UpdateFrame();
}
void HandleDeath(){
Collider2D col = Physics2D.OverlapCircle(body.position, radius);
if(col == null){ return;}
if(col.tag == "Death"){
Debug.Log("Im dead bro");
isAlive = false;
spriteRenderer.sprite = sadFace;
GameUI.ShowDeath();
}
}
void HandleJump(){
if(jumpTimer < jumpCooldown){
jumpTimer += Time.deltaTime;
}
}
public void Jump(){
if(!isReadyToJump){ return; }
jumpTimer =0;
Velocity = new Vector2(Velocity.x, jumpForce);
}
void OnValidate(){
if(body == null){
body = transform;
}
}
void OnTriggerEnter2D(Collider2D other){
Debug.Log(other.name);
}
void OnGizmos(){
Gizmos.DrawWireSphere(body.position, radius);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 343276379f35b714985aa57c6a87b4d8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: