Skip to content

Commit 7d14921

Browse files
authored
Merge pull request #21 from SDev-2018/crafting
Crafting
2 parents 99aaca1 + f3c627b commit 7d14921

28 files changed

+672
-224
lines changed
Binary file not shown.
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
public class PlayerCrafting : MonoBehaviour {
6+
7+
bool crafting;
8+
9+
bool bridgeRune, torchRune, axeRune, netRune, shovelRune;
10+
// Use this for initialization
11+
void Start () {
12+
crafting = false;
13+
bridgeRune = false;
14+
torchRune = false;
15+
axeRune = false;
16+
netRune = false;
17+
shovelRune = false;
18+
}
19+
20+
// Update is called once per frame
21+
void Update () {
22+
23+
GameObject player = GameObject.Find("Player");
24+
PlayerMovement inventory = player.GetComponent<PlayerMovement>(); // !!! change me when inventory moves to own script !!!
25+
26+
// check that user is on transmutation circle and which recipe to use
27+
// crafting for bridge
28+
if (crafting == true && bridgeRune == true && Input.GetKeyDown(KeyCode.Alpha3))
29+
{
30+
31+
// check for necessary materials
32+
if (inventory.logCount >= 3)
33+
{
34+
inventory.logCount -= 3;
35+
inventory.logDisplay.text = inventory.logCount.ToString();
36+
}
37+
}
38+
39+
if (crafting == true && torchRune == true && Input.GetKeyDown(KeyCode.Alpha1))
40+
{
41+
42+
// check for necessary materials
43+
if (inventory.logCount >= 1 && inventory.clothCount >= 2)
44+
{
45+
inventory.logCount -= 1;
46+
inventory.clothCount -= 2;
47+
inventory.logDisplay.text = inventory.logCount.ToString();
48+
inventory.clothDisplay.text = inventory.clothCount.ToString();
49+
}
50+
}
51+
52+
if (crafting == true && axeRune == true && Input.GetKeyDown(KeyCode.Alpha2))
53+
{
54+
55+
// check for necessary materials
56+
if (inventory.logCount >= 1 && inventory.metalCount >= 2)
57+
{
58+
inventory.logCount -= 1;
59+
inventory.metalCount -= 2;
60+
inventory.logDisplay.text = inventory.logCount.ToString();
61+
inventory.metalDisplay.text = inventory.metalCount.ToString();
62+
63+
inventory.hasAxe = true;
64+
}
65+
}
66+
67+
if (crafting == true && netRune == true && Input.GetKeyDown(KeyCode.Alpha4))
68+
{
69+
70+
// check for necessary materials
71+
if (inventory.logCount >= 2 && inventory.clothCount >= 3)
72+
{
73+
inventory.logCount -= 2;
74+
inventory.clothCount -= 3;
75+
inventory.logDisplay.text = inventory.logCount.ToString();
76+
inventory.clothDisplay.text = inventory.clothCount.ToString();
77+
}
78+
}
79+
80+
if (crafting == true && shovelRune == true && Input.GetKeyDown(KeyCode.Alpha5))
81+
{
82+
83+
// check for necessary materials
84+
if (inventory.logCount >= 2 && inventory.metalCount >= 3)
85+
{
86+
inventory.logCount -= 2;
87+
inventory.metalCount -= 3;
88+
inventory.logDisplay.text = inventory.logCount.ToString();
89+
inventory.metalDisplay.text = inventory.metalCount.ToString();
90+
}
91+
}
92+
}
93+
94+
95+
private void OnTriggerEnter2D(Collider2D other)
96+
{
97+
98+
if (other.gameObject.CompareTag("Transmutation"))
99+
{
100+
crafting = true;
101+
}//end Transmutation if
102+
103+
if (other.gameObject.CompareTag("Bridge Rune"))
104+
{
105+
bridgeRune = true;
106+
other.gameObject.SetActive(false);
107+
}
108+
109+
if(other.gameObject.CompareTag("Torch Rune"))
110+
{
111+
torchRune = true;
112+
other.gameObject.SetActive(false);
113+
}
114+
115+
if(other.gameObject.CompareTag("Axe Rune"))
116+
{
117+
axeRune = true;
118+
other.gameObject.SetActive(false);
119+
}
120+
121+
if(other.gameObject.CompareTag("Net Rune"))
122+
{
123+
netRune = true;
124+
other.gameObject.SetActive(false);
125+
}
126+
127+
if(other.gameObject.CompareTag("Shovel Rune"))
128+
{
129+
shovelRune = true;
130+
other.gameObject.SetActive(false);
131+
}
132+
}// end of OnTriggerEnter
133+
134+
private void OnTriggerExit2D(Collider2D other)
135+
{
136+
if (other.gameObject.CompareTag("Transmutation"))
137+
{
138+
crafting = false;
139+
}//end Transmutation if
140+
}// end OnTriggerEnter
141+
}// end PlayerCrafting

Alchemic Forest Game/Assets/PlayerCrafting.cs.meta

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Alchemic Forest Game/Assets/Prefabs.meta

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Alchemic Forest Game/Assets/Scripts/PlayerMovement.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
public class PlayerMovement : MonoBehaviour {
77

88
private Rigidbody2D rigid2D;
9-
private int logCount;
9+
public int logCount;// dependency in PlayerCrafting.cs
1010

1111
public float speed;
1212
public Text logDisplay;
@@ -30,6 +30,8 @@ public class PlayerMovement : MonoBehaviour {
3030

3131
int currentAnimationState = IDLE;
3232

33+
public bool hasAxe;
34+
3335

3436

3537
void Start()
@@ -41,6 +43,8 @@ void Start()
4143
metalCount = 0;
4244
gemCount = 0;
4345

46+
bool hasAxe = false;// for testing when inventory is fully implemented this will be set there
47+
4448
animator = GetComponent<Animator>();
4549
}// end of Start
4650

@@ -144,7 +148,6 @@ private void OnTriggerEnter2D(Collider2D other)
144148
gemDisplay.text = gemCount.ToString();
145149
}//end if
146150

147-
bool hasAxe = false;// for testing when inventory is fully implemented this will be set there
148151
if(other.gameObject.CompareTag("chop"))
149152
{
150153
if (hasAxe == true)

0 commit comments

Comments
 (0)