Skip to content

Commit 8add3ea

Browse files
committed
Added inspectors and levels.
1 parent ed0af1a commit 8add3ea

36 files changed

Lines changed: 11280 additions & 878 deletions

Assets/CameraScript.cs

Lines changed: 13 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class CameraScript : MonoBehaviour
1818
public bool canEdit = true;
1919
public bool isOnTile = false;
2020
public int playerNumber = 1;
21+
2122
void Start()
2223
{
2324
transform.position = new Vector3(4.6f, 3.3f, -5);
@@ -42,7 +43,6 @@ void Update()
4243

4344
GameObject target = gameControlScript.ClosestTile(player);
4445

45-
4646
if(target == null) return;
4747
if(!target.name.Contains("Tile")) return;
4848

@@ -80,8 +80,6 @@ void Update()
8080

8181
ps.storage.Add(childItemName);
8282

83-
Debug.Log(itemPlate);
84-
Debug.Log("Added " + childItemName + "To Pluh");
8583
Destroy(target.transform.GetChild(0).gameObject);
8684
return;
8785
}
@@ -108,13 +106,8 @@ void Update()
108106
if(item.name.Contains("Plate"))
109107
indexFood = item.name;
110108

111-
Debug.Log(indexFood);
112-
Debug.Log(item.name);
113109
GameObject prefab = Resources.Load<GameObject>(indexFood);
114-
if(prefab == null)
115-
{
116-
Debug.LogError("This isnt working: " + indexFood + " " + item.name);
117-
}
110+
118111

119112
GameObject clone = Instantiate(prefab, target.transform);
120113
clone.name = item.name;
@@ -128,7 +121,6 @@ void Update()
128121
Destroy(item.gameObject);
129122
invScript.equippedItem = invScript.inventory.Count == 0 ? 1 : Mathf.Clamp(invScript.equippedItem, 1, invScript.inventory.Count);
130123
invScript.UpdatePlayerChildren();
131-
Debug.Log("Placed down " + clone.name);
132124
return;
133125
}
134126

@@ -168,7 +160,6 @@ void Update()
168160
if(ps.foodCount("Bun") > 2) return;
169161

170162
ps.storage.Add(childItemName);
171-
Debug.Log("Added " + childItemName + "To Food");
172163
}
173164
/*
174165
if(itemPlate.name.Contains("Plate"))
@@ -182,46 +173,24 @@ void Update()
182173
}
183174
if(keyboard.eKey.wasPressedThisFrame && target.transform.childCount == 0 && invScript.inventory.Count == 0)
184175
{
185-
Debug.Log("Tried calling");
186176
if(tileScript.typeOfFood != "")
187177
{
188-
Debug.Log("Called food creation");
189178
invScript.AddItem(tileScript.typeOfFood, null);
190179
}
191180
return;
192181
}
193-
/*
194-
if(keyboard.eKey.wasPressedThisFrame && target.transform.childCount > 0)
195-
{
196-
string childItemName = target.transform.GetChild(0).name;
197-
198-
if(tileScript.typeOfTile == 2 && !childItemName.Contains("Chopped") && !childItemName.Contains("Plate"))
199-
{
200-
Debug.Log("USING CHOPPER");
201-
tileScript.StartCooking(1);
202-
//target.transform.GetChild(0).name = childItemName.Replace("(Clone)", "") + "Chopped";
203-
}
204-
205-
if(tileScript.typeOfTile == 3 && !childItemName.Contains("Cooked") && !childItemName.Contains("Plate"))
206-
{
207-
Debug.Log("Coming from camerascript: " + childItemName);
208-
if(gameControlScript.canBeCooked(childItemName))
209-
tileScript.StartCooking(5);
210-
}
211-
212-
if(tileScript.typeOfTile == 20 && childItemName.Contains("Plate"))
213-
{
214-
Debug.Log("This food is being checked");
215-
gameControlScript.CheckFood(target.GetComponentInChildren<ItemScript>().storage);
216-
Destroy(target.transform.GetChild(0).gameObject);
217-
}
218-
219-
return;
220-
}
221-
*/
222182
}
223183

224-
225184
}
226-
185+
public GameObject Build(GameObject parent, GameObject prefab, Vector3 position)
186+
{
187+
if (parent.name.Contains("Tile"))
188+
parent.GetComponent<TileScript>().isFull = true;
189+
190+
GameObject obj = Instantiate(prefab, position, Quaternion.identity);
191+
obj.transform.SetParent(parent.transform, false);
192+
obj.transform.localPosition = position;
193+
obj.name = prefab.name;
194+
return obj;
195+
}
227196
}

Assets/EnemyScript.cs

Lines changed: 76 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,80 @@
11
using UnityEngine;
22

3+
34
public class EnemyScript : MonoBehaviour
45
{
5-
private GameControlScript gameControlScript;
6+
public InventoryScript inventoryScript;
7+
public GameControlScript gameControlScript;
8+
69
public GameObject bodyPrefab;
710
private GameObject player;
8-
private int health = 100;
11+
public int job;
12+
public float cooldown = 10;
13+
public int health = 100;
914
private float speed = 1.2f;
15+
public float knifeCooldown = 0.5f;
16+
float randomSkinColor;
1017
void Start()
1118
{
1219
player = GameObject.Find("Player");
20+
inventoryScript = GameObject.Find("Inventory").GetComponent<InventoryScript>();
1321
gameControlScript = GameObject.Find("GameControl").GetComponent<GameControlScript>();
22+
/*
23+
if(Random.Range(0f,4f) < 0.5f) {
24+
Debug.Log("Inspector");
25+
job = 1;
26+
gameControlScript.amountOfInspectors++;
27+
GetComponent<SpriteRenderer>().sprite = Resources.Load<Sprite>("Images/Inspector");
28+
}
29+
else job = 0;
30+
*/
31+
if(job == 1)
32+
{
33+
gameControlScript.amountOfInspectors++;
34+
GetComponent<SpriteRenderer>().sprite = Resources.Load<Sprite>("Images/Inspector");
35+
}
36+
37+
health = 100;
38+
knifeCooldown = 0.5f;
1439

15-
float randomSkinColor = Random.Range(0.85f,1f);
40+
randomSkinColor = Random.Range(0.85f,1f);
1641
GetComponent<SpriteRenderer>().color = new Color(randomSkinColor, randomSkinColor, randomSkinColor,1f);
42+
cooldown = 1.5f;
43+
GetComponent<Rigidbody2D>().linearVelocity = transform.up * Random.Range(6.5f, 10.5f);
1744
}
45+
46+
void Update()
47+
{
48+
if(inventoryScript == null)
49+
inventoryScript = GameObject.Find("Inventory").GetComponent<InventoryScript>();
50+
51+
if(gameControlScript == null)
52+
gameControlScript = GameObject.Find("GameControl").GetComponent<GameControlScript>();
53+
if(!gameControlScript.ISPAUSED)
54+
{
55+
cooldown -= Time.deltaTime;
56+
knifeCooldown -= Time.deltaTime;
57+
}
58+
if(health <= 0) {
59+
GameObject body = gameControlScript.CreateParticle(bodyPrefab, transform.position, 2.5f ,2, false, 0);
60+
body.GetComponent<SpriteRenderer>().sprite = GetComponent<SpriteRenderer>().sprite;
61+
body.GetComponent<SpriteRenderer>().color = new Color(randomSkinColor, randomSkinColor, randomSkinColor, 1f);
62+
gameControlScript.Blood(1, gameObject);
63+
if(job == 1)
64+
gameControlScript.amountOfInspectors--;
65+
Destroy(gameObject);
66+
}
67+
}
68+
1869
void FixedUpdate()
1970
{
20-
Vector2 direction = (player.transform.position - transform.position);
71+
if(cooldown <= 0 && !gameControlScript.ISPAUSED)
72+
MoveTowards(player.transform.position);
73+
}
74+
public void MoveTowards(Vector3 targetPosition)
75+
{
76+
//Vector2 direction = (player.transform.position - transform.position);
77+
Vector2 direction = (targetPosition - transform.position);
2178
Rigidbody2D rb = GetComponent<Rigidbody2D>();
2279

2380
direction.y = direction.y;
@@ -44,15 +101,22 @@ private void OnTriggerEnter2D(Collider2D collision)
44101
gameControlScript.Blood(1, gameObject);
45102
Destroy(collision.gameObject);
46103
health -= 20;
47-
if(health <= 0) {
48-
Debug.Log("Dead");
49-
50-
gameControlScript.CreateParticle(bodyPrefab, transform.position, 2.5f ,2, false, 0);
51-
gameControlScript.Blood(1, gameObject);
52-
Destroy(gameObject);
104+
}
105+
}
106+
private void OnTriggerStay2D(Collider2D collision)
107+
{
108+
if(collision.CompareTag("Player") && inventoryScript.currentItem().Contains("Knife"))
109+
{
110+
if(knifeCooldown <= 0)
111+
{
112+
gameControlScript.Blood(2, gameObject);
113+
health -= 50;
114+
knifeCooldown = 0.5f;
53115
}
54-
55-
56116
}
117+
if(collision.CompareTag("Player"))
118+
{
119+
}
120+
57121
}
58122
}

0 commit comments

Comments
 (0)