Skip to content

Commit

Permalink
Level rotating obstacle (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmhatre99 authored Nov 9, 2022
1 parent f395576 commit 363f52d
Show file tree
Hide file tree
Showing 13 changed files with 8,528 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .vsconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"version": "1.0",
"components": [
"Microsoft.VisualStudio.Workload.ManagedGame"
]
}
6 changes: 6 additions & 0 deletions Assets/EnemySpawnerScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ void Start()
spawnLimit=12;
// print("inside if TARGET FROM PLAYER MOVE "+target);
}
else if (sceneName == "level-rotating-obstacle")
{
//print("new level");
spawnLimit = 0;
// print("inside if TARGET FROM PLAYER MOVE "+target);
}
}

void SpawnAMonster(){
Expand Down
54 changes: 54 additions & 0 deletions Assets/JSON/wordsJson1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,60 @@
"purple_letters": ["I","D","T", "X", "Y"]
}

],

"level_rotating_obstacle": [
{
"target_word": "FAMILY",
"blanks": [
0,
1
],
"orange_letters": ["F","L","E"],
"yellow_letters": ["I","Y","G","P"],
"purple_letters": ["A","M","U", "Z", "X"]
},
{
"target_word": "SILVER",
"blanks": [
0,
1
],
"orange_letters": ["S","E","F"],
"yellow_letters": ["L","I","T","G","C","B","K","J"],
"purple_letters": ["V","R","U", "X", "D"]
},
{
"target_word": "NATURE",
"blanks": [
0,
1
],
"orange_letters": ["N","T","M"],
"yellow_letters": ["U","E","F","H","B","K"],
"purple_letters": ["A","R","G", "X", "Y"]
},
{
"target_word": "PERSON",
"blanks": [
0,
1
],
"orange_letters": ["P","O","A"],
"yellow_letters": ["S","E","D","C","B","K"],
"purple_letters": ["R","N","U", "X", "Y"]
},
{
"target_word": "FATHER",
"blanks": [
0,
1
],
"orange_letters": ["F","T","D"],
"yellow_letters": ["E","R","M","F","C","B"],
"purple_letters": ["A","H","P", "X", "Y"]
}

],
"lvl3": [
{
Expand Down
300 changes: 300 additions & 0 deletions Assets/Letter_Spawner_Lvl_lro.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,300 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;

public class Letter_Spawner_Lvl_lro : MonoBehaviour
{
public GameObject[] letterReference;
public GameObject[] highLetterReference;
public GameObject[] mediumLetterReference;
public GameObject[] lowLetterReference;
public GameObject[] spawnRectangles;
// public GameObject power_up_highlight;

public GameObject spawnedLetter;
public Transform leftPos, rightPos;
private int randomSide;
private int randomIndex;
private float randomX;
private float randomY;
//private int[] index = {0, 5, 4, 8, 15, 25, 1, 0, 16};
private int[] orange_index;
private int[] yellow_index;
private int[] purple_index;
private int[] target_index;
private int i = 0;
public List<float[]> seenList;
public int[] indexes;
public int[] colors;

public static string target_word;
private int[] blanks;
private string[] orange_letters;
private string[] yellow_letters;
private string[] purple_letters;

public Collider2D[] colliders;
public float radius;

public TextAsset textJSON;

[System.Serializable]
public class Player
{
public string target_word;
public int[] blanks;
public string[] orange_letters;
public string[] yellow_letters;
public string[] purple_letters;
}

[System.Serializable]
public class PlayerList
{
public Player[] level_rotating_obstacle;
}

public PlayerList myPlayerList = new PlayerList();
// Start is called before the first frame update
void Start()
{
myPlayerList = JsonUtility.FromJson<PlayerList>(textJSON.text);
int len = myPlayerList.level_rotating_obstacle.Length;
int rInt = Random.Range(0, len);
int i = 0;
seenList = new List<float[]>();
radius = 1f;
foreach (Player player in myPlayerList.level_rotating_obstacle)
{
if (i == rInt)
{
target_word = player.target_word;
blanks = player.blanks;
orange_letters = player.orange_letters;
yellow_letters = player.yellow_letters;
purple_letters = player.purple_letters;
}
i++;

}
orange_index = new int[orange_letters.Length];
yellow_index = new int[yellow_letters.Length];
purple_index = new int[purple_letters.Length];
target_index = new int[target_word.Length];
int total_length = orange_letters.Length + yellow_letters.Length + purple_letters.Length;
indexes = new int[total_length];
colors = new int[total_length];
int pointer = 0;
int index_pointer = 0;

for (int j = 0; j < orange_letters.Length; j++)
{
int ascii = (int)orange_letters[j][0];
ascii = ascii - 65;
orange_index[j] = ascii;
//print(index[j]);
}

for (int j = 0; j < yellow_index.Length; j++)
{
int ascii = (int)yellow_letters[j][0];
ascii = ascii - 65;
yellow_index[j] = ascii;
//print(index[j]);
}

for (int j = 0; j < purple_index.Length; j++)
{
int ascii = (int)purple_letters[j][0];
ascii = ascii - 65;
purple_index[j] = ascii;
//print(index[j]);
}

for (int j = 0; j < target_word.Length; j++)
{
int ascii = (int)target_word[j];
ascii = ascii - 65;
target_index[j] = ascii;
//print("tar_index"+target_index[j]);
}

int max_index = System.Math.Max(orange_letters.Length, System.Math.Max(yellow_letters.Length, purple_letters.Length));
while (pointer < max_index)
{
if (pointer < orange_letters.Length)
{
colors[index_pointer] = 1;
indexes[index_pointer] = orange_index[pointer];
index_pointer++;
}
if (pointer < yellow_index.Length)
{
colors[index_pointer] = 2;
indexes[index_pointer] = yellow_index[pointer];
index_pointer++;
}
if (pointer < purple_letters.Length)
{
colors[index_pointer] = 3;
indexes[index_pointer] = purple_index[pointer];
index_pointer++;
}
pointer++;
}


print("Word is =" + target_word);
StartCoroutine(SpawnLetters());
}

IEnumerator SpawnLetters()
{
int t = 10;
while (i < indexes.Length)
{
if (i != 0)
{
yield return new WaitForSeconds(2);
}
randomIndex = Random.Range(0, letterReference.Length);

float x = Random.Range(-7, 30);
float y = Random.Range(0, 16);
Vector3 randomPosition = new Vector3(x, y, 0);

while (true)
{
int sizeOfSpawners = spawnRectangles.Length;
x = (float) Random.Range(spawnRectangles[i%sizeOfSpawners].transform.position[0] - spawnRectangles[i % sizeOfSpawners].transform.localScale[0]/2, spawnRectangles[i % sizeOfSpawners].transform.position[0] + spawnRectangles[i % sizeOfSpawners].transform.localScale[0] / 2);
y = (float)Random.Range(spawnRectangles[i % sizeOfSpawners].transform.position[1] - spawnRectangles[i % sizeOfSpawners].transform.localScale[1] / 2, spawnRectangles[i % sizeOfSpawners].transform.position[1] + spawnRectangles[i % sizeOfSpawners].transform.localScale[1] / 2);


if (checkCollision(x, y))
{
randomPosition = new Vector3(x, y, 0);
seenList.Add(new float[2] { x, y });
break;
}
/*
if( checkCollision(x,y) && ((x >= -8 && x <= -4 && y >=0 && y<=4) ||
(x >= -8 && x <= -0.1 && y >=7 && y<=11) ||
(x >= -8 && x <= -3 && y >=7 && y<=11) ||
(x >= -8 && x <= 31 && y >=15 && y<=17) ||
(x >= 2 && x <= 11 && y >=0 && y<=4) ||
(x >= 10 && x <= 20 && y >= 2.9 && y<=9) ||
(x >= 20 && x <= 31 && y >= 1.75 && y<=4))){
randomPosition = new Vector3(x,y,0);
seenList.Add(new float[2]{x,y});
break;
}else{
x = Random.Range(-7,30);
y = Random.Range(0,16);
}
*/
}

if (i == 0)
{
x = -1;
y = 4;
randomPosition = new Vector3(x, y, 0);
seenList.Add(new float[2] { x, y });
}
int color = colors[i];
int letter_index = indexes[i];
/*
if(i==0){
randomPosition = new Vector3((float)-5.5,(float)-0.25,0);
seenList.Add(new float[2]{-5.5f,-0.25f});
}*/
// if(i==2){
// GameObject power_up_highlight_ins = Instantiate(power_up_highlight);
// power_up_highlight_ins.transform.position = randomPosition;
// }

int LayerLetter = LayerMask.NameToLayer("Letter");

if (color == 1)
{
spawnedLetter = Instantiate(highLetterReference[letter_index]);
spawnedLetter.transform.position = randomPosition;
spawnedLetter.layer = LayerLetter;
}
else if (color == 2)
{
spawnedLetter = Instantiate(mediumLetterReference[letter_index]);
spawnedLetter.transform.position = randomPosition;
spawnedLetter.layer = LayerLetter;
}
else
{
spawnedLetter = Instantiate(lowLetterReference[letter_index]);
spawnedLetter.transform.position = randomPosition;
spawnedLetter.layer = LayerLetter;
}
// if(!target_index.Contains(index[i])){
// //print(index[i]);
// Destroy(spawnedLetter.gameObject, t);
// t+=10;
// }
i += 1;
}



}

bool checkCollision(float x, float y)
{
float left = x - radius;
float right = x + radius;
float low = y - radius;
float high = y + radius;
for (int j = 0; j < seenList.Count; j++)
{
float posX = seenList[j][0];
float posY = seenList[j][1];
if (posX >= left && posX <= right)
{
if (posY >= low && posY <= high)
{
return false;
}
}
}
return true;

}
bool PreventSpawnOverLap(Vector3 spawnPos)
{
colliders = Physics2D.OverlapCircleAll(transform.position, radius);

for (int i = 0; i < colliders.Length; i++)
{
Vector3 centerPoint = colliders[i].bounds.center;
float width = colliders[i].bounds.extents.x;
float height = colliders[i].bounds.extents.y;
float left = centerPoint.x - width;
float right = centerPoint.x + width;
float lower = centerPoint.y - height;
float upper = centerPoint.y + height;

if (spawnPos.x >= left && spawnPos.x <= right)
{
if (spawnPos.y >= lower && spawnPos.y <= upper)
{
return false;
}
}
}
return true;
}
// Update is called once per frame
void Update()
{

}
}
11 changes: 11 additions & 0 deletions Assets/Letter_Spawner_Lvl_lro.cs.meta

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

Loading

0 comments on commit 363f52d

Please sign in to comment.