Skip to content

Commit

Permalink
Joias, Pintor-de-vento e etc
Browse files Browse the repository at this point in the history
- Agora joias são spawnadas (ou não) nos blocos.
- Agora todos os blocos são destruídos com apenas um toque. Ficará assim? Não sei.
- Adicionado primeiro obstáculo móvel, o Pintor-de-vento. Ele está muito rápido e não muito bonito, precisa de ajustes.
- Velocidade da Fase aumentada.
  • Loading branch information
TanookiVerde committed Jul 16, 2017
1 parent eb6a314 commit cbcb978
Show file tree
Hide file tree
Showing 51 changed files with 648 additions and 8 deletions.
9 changes: 9 additions & 0 deletions Assets/code/items.meta

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

47 changes: 47 additions & 0 deletions Assets/code/items/Gem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Gem : MonoBehaviour, IItem {
[SerializeField] private SOGem gemData;

public void Effect(){
return;
}
public IEnumerator CatchAnimation(){
yield return new WaitForEndOfFrame();
}
public void Destroy(){
//GameObject.Destroy(this.gameObject);
transform.position = Vector3.zero;
transform.parent = null;
}
public int GetValue(){
return gemData.value;
}
public string GetDescription(){
return gemData.description;
}
public IEnumerator OnTouch(){
int frameDuration = 5;
float rotationAngle = 30;

for(int i = 0; i < frameDuration; i++){
transform.Rotate(0,0,Time.deltaTime*rotationAngle);
yield return new WaitForEndOfFrame();
}
for(int i = 0; i < frameDuration; i++){
transform.Rotate(0,0,-Time.deltaTime*rotationAngle);
yield return new WaitForEndOfFrame();
}
}
public IEnumerator OnFall(){
Rigidbody2D temp = gameObject.AddComponent<Rigidbody2D>();
temp.gravityScale = 5;
temp.AddForceAtPosition(new Vector2(Random.Range(-3f,3f),Random.Range(-3f,3f))*50,
(Vector2)transform.position + Vector2.up,
ForceMode2D.Force);
transform.parent = null;
yield return new WaitForEndOfFrame();
}
}
12 changes: 12 additions & 0 deletions Assets/code/items/Gem.cs.meta

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

11 changes: 11 additions & 0 deletions Assets/code/items/IItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Collections;

public interface IItem {
void Effect();
void Destroy();
int GetValue();
string GetDescription();
IEnumerator CatchAnimation();
IEnumerator OnTouch();
IEnumerator OnFall();
}
12 changes: 12 additions & 0 deletions Assets/code/items/IItem.cs.meta

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

27 changes: 27 additions & 0 deletions Assets/code/items/ItemCatcher.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ItemCatcher : MonoBehaviour {
LevelManager lManager;

private void Start(){
lManager = GameObject.Find("Player").GetComponent<LevelManager>();
}
private void OnTriggerEnter2D(Collider2D other){
if(other.CompareTag("Gem")){
NewGem(other.gameObject);
}
}
private void PlayAnimation(IItem item){
Debug.Log("Play_Animation");
StartCoroutine( item.CatchAnimation() );
}
private void NewGem(GameObject gem){
IItem item = gem.GetComponent<IItem>();
item.Destroy();
lManager.collectedItems.Add(gem.gameObject);
lManager.totalMoney += item.GetValue();
StartCoroutine ( lManager.UpdateMoneyText() );
}
}
12 changes: 12 additions & 0 deletions Assets/code/items/ItemCatcher.cs.meta

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

47 changes: 40 additions & 7 deletions Assets/code/managers/LevelManager.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
#if UNITY_EDITOR
using UnityEditor;
#endif

public class LevelManager : MonoBehaviour {
[Header("Level")]
[SerializeField] private SOLevel levelData;
[SerializeField] private int gemPerTen;

[Header("Spawnable Objects")]
[SerializeField] List<GameObject> packList;
[SerializeField] List<GameObject> tileList;
[SerializeField] List<GameObject> gemList;
[SerializeField] GameObject leafObstacle;
[SerializeField] GameObject spikeObstacle;
[SerializeField] GameObject pegaPegaObstacle;
Expand All @@ -21,8 +24,8 @@ public class LevelManager : MonoBehaviour {
[Header("Runtime")]
[SerializeField] private float levelSoFar;
[SerializeField] private float cameraVelocity;
[SerializeField] private List<GameObject> collectedItems;
[SerializeField] private int totalMoney;
[SerializeField] public List<GameObject> collectedItems;
[SerializeField] public int totalMoney;
[SerializeField] private bool bossDefeated;

private Camera cameraInScene;
Expand All @@ -31,12 +34,15 @@ public class LevelManager : MonoBehaviour {
private float distanceFromLastTile;
private float cameraSize;

private Text moneyText;

private void Start(){
GetPlayer();
GetCamera();
GetInitialPosition();
GetLevelInfo();
GetCameraSize();
GetMoneyText();

StartCoroutine( LevelStructure() );
}
Expand Down Expand Up @@ -107,13 +113,40 @@ private void CreateFromTile(GameObject tile){
go.transform.localPosition = tile.transform.GetChild(i).position;
go.transform.localScale = tile.transform.GetChild(i).localScale;
}else if(tile.transform.GetChild(i).CompareTag("tile_PACK")){
Instantiate(packList[Random.Range(0,packList.Count)],
tile.transform.GetChild(i).position,
Quaternion.identity,
temp.transform).transform.localPosition = tile.transform.GetChild(i).position;
GameObject go = Instantiate(packList[Random.Range(0,packList.Count)],
tile.transform.GetChild(i).position,
Quaternion.identity,
temp.transform);
go.transform.localPosition = tile.transform.GetChild(i).position;
go.GetComponent<Block>().GetGem( GetRandomGem() );
}else if(tile.transform.GetChild(i).CompareTag("tile_PINTOR")){
Debug.Log("VIVA_O_PINTOR");
GameObject go = Instantiate(pintorDeVentoObstacle,
tile.transform.GetChild(i).position,
Quaternion.identity,
temp.transform);
go.transform.localPosition = tile.transform.GetChild(i).position;
}
}

}

private GameObject GetRandomGem(){
int randN = Random.Range(0,10);
if(randN > 10 - gemPerTen){
return gemList[ Random.Range(0,gemList.Count) ];
}
return null;
}
public IEnumerator UpdateMoneyText(){
int past = int.Parse(moneyText.text);

while(past-1 < totalMoney){
moneyText.text = past.ToString();
yield return new WaitForEndOfFrame();
past++;
}
}
private void GetMoneyText(){
moneyText = GameObject.Find("Money_Text").GetComponent<Text>();
}
}
15 changes: 15 additions & 0 deletions Assets/code/objects/Block.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ public class Block : MonoBehaviour,IHook {

[SerializeField] private uint resistance;
[SerializeField] private uint maxResistance;
[SerializeField] private GameObject myGem;


private void OnMouseDown(){
if( OnClick() ){
Expand All @@ -15,6 +17,9 @@ private void OnMouseDown(){
public bool OnClick(){
resistance--;
StartCoroutine( Damage() );
if(myGem != null){
StartCoroutine( myGem.GetComponent<IItem>().OnTouch() );
}
if(resistance <= 0){
StartCoroutine( Fall() );
return true;
Expand All @@ -28,6 +33,9 @@ public void Restart(){
resistance = maxResistance;
}
private IEnumerator Fall(){
if(myGem != null){
StartCoroutine( myGem.GetComponent<IItem>().OnFall() );
}
foreach(BoxCollider2D bc2D in gameObject.GetComponents<BoxCollider2D>()){
bc2D.enabled = false;
}
Expand All @@ -52,5 +60,12 @@ private IEnumerator Destroy(){
yield return new WaitForSeconds(3);
GameObject.Destroy(this.gameObject);
}
public void GetGem(GameObject gem){
if(gem != null) {
Debug.Log("NEW_ITEM");
myGem = Instantiate(gem, Vector3.zero, Quaternion.identity,transform);
myGem.transform.localPosition = Vector3.zero;
}
}

}
1 change: 0 additions & 1 deletion Assets/code/objects/IHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@

bool OnClick();
float MoveTo();
void Restart();
}
9 changes: 9 additions & 0 deletions Assets/code/obstacles.meta

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

105 changes: 105 additions & 0 deletions Assets/code/obstacles/Pintor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif

public class Pintor : MonoBehaviour,IHook {

[Header("Movement Properties")]
[Range(0,1)]
[SerializeField] private float velocity;
private Vector3 targetPosition;

[Header("Smoke Properties")]
[SerializeField] private GameObject smokePrefab;
[SerializeField] private float duration;
[SerializeField] private bool RandomColor;
[SerializeField] private Color initialColor;
[SerializeField] private Color finalColor;
[SerializeField] private Color actualColor;

[Header("Resistance")]
[SerializeField] private int resistance;

private GameObject cameraInScene;
private float cameraHeight;
private float cameraWidth;

private void Start(){
actualColor = initialColor;
GetCamera();
GetTargetPosition();
StartCoroutine( Movement() );
}
private void GetCamera(){
cameraInScene = GameObject.Find("Main Camera");
cameraHeight = cameraInScene.GetComponent<Camera>().orthographicSize*2;
cameraWidth = cameraInScene.GetComponent<Camera>().aspect*cameraHeight;

Debug.Log(cameraHeight+"/"+cameraWidth);
}
private void NewSmoke(){
GameObject go = Instantiate(smokePrefab,transform.position + Vector3.right*2,Quaternion.identity);
actualColor = Vector4.Lerp(actualColor,finalColor,0.25f);
go.GetComponent<SpriteRenderer>().color = actualColor;
}
private IEnumerator Movement(){
float x,y,a,b;
x = transform.position.x; y = transform.position.y;
a = targetPosition.x; b = targetPosition.y;
StartCoroutine( SmokeHandler() );
while(a != b || y != b){
x = Mathf.Lerp(x, a, velocity);
y = Mathf.Lerp(y, b, velocity);
transform.position = new Vector3(x,y,0);
yield return new WaitForEndOfFrame();
}
}
private IEnumerator SmokeHandler(){
GameObject player = GameObject.Find("Player");
while(player.transform.position.x < this.transform.position.x){
yield return new WaitForSeconds(duration);
NewSmoke();
}
}
private void GetTargetPosition(){
Vector3 rand = new Vector3(Random.Range(-60f,-30f),Random.Range(-5f,5f),0);
targetPosition = transform.position + rand;
}
public float MoveTo(){
return transform.position.y;
}
private void OnMouseDown(){
if( OnClick() ){
GameObject.Find("Player").GetComponent<Muquirana>().ChangePosition( MoveTo() );
}
}
public bool OnClick(){
resistance--;
StartCoroutine( Damage() );
if(resistance <= 0){
Fall();
return true;
}
return false;
}
private IEnumerator Damage(){
for(int i = 0;i < 5;i++){
transform.localScale = transform.localScale*1.05f;
yield return new WaitForEndOfFrame();
}
for(int i = 0;i < 5;i++){
transform.localScale = transform.localScale/1.05f;
yield return new WaitForEndOfFrame();
}
}
private void Fall(){
StopAllCoroutines();
GetComponent<BoxCollider2D>().enabled = false;
Rigidbody2D myRB = gameObject.AddComponent<Rigidbody2D>();
myRB.gravityScale = 5;
}

}
Loading

0 comments on commit cbcb978

Please sign in to comment.