Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
202 lines (178 loc) · 5.17 KB

File metadata and controls

202 lines (178 loc) · 5.17 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlotManager : MonoBehaviour
{
bool isPlanted = false;
SpriteRenderer plant;
BoxCollider2D plantCollider;
int plantStage = 0;
float timer;
public Color availableColor = Color.green;
public Color unavailableColor = Color.red;
SpriteRenderer plot;
PlantObject selectedPlant;
FarmManager fm;
bool isDry = true;
public Sprite drySprite;
public Sprite normalSprite;
public Sprite unavailableSprite;
float speed=1f;
public bool isBought=true;
// Start is called before the first frame update
void Start()
{
plant = transform.GetChild(0).GetComponent<SpriteRenderer>();
plantCollider = transform.GetChild(0).GetComponent<BoxCollider2D>();
fm = transform.parent.GetComponent<FarmManager>();
plot = GetComponent<SpriteRenderer>();
if (isBought)
{
plot.sprite = drySprite;
}
else
{
plot.sprite = unavailableSprite;
}
}
// Update is called once per frame
void Update()
{
if (isPlanted && !isDry)
{
timer -= speed*Time.deltaTime;
if (timer < 0 && plantStage<selectedPlant.plantStages.Length-1)
{
timer = selectedPlant.timeBtwStages;
plantStage++;
UpdatePlant();
}
}
}
private void OnMouseDown()
{
if (isPlanted)
{
if (plantStage == selectedPlant.plantStages.Length - 1 && !fm.isPlanting && !fm.isSelecting)
{
Harvest();
}
}
else if(fm.isPlanting && fm.selectPlant.plant.buyPrice <= fm.money && isBought)
{
Plant(fm.selectPlant.plant);
}
if (fm.isSelecting)
{
switch (fm.selectedTool)
{
case 1:
if (isBought) {
isDry = false;
plot.sprite = normalSprite;
if (isPlanted) UpdatePlant();
}
break;
case 2:
if (fm.money>=10 && isBought)
{
fm.Transaction(-10);
if (speed < 2) speed += .2f;
}
break;
case 3:
if (fm.money >= 100 && !isBought)
{
fm.Transaction(-100);
isBought = true;
plot.sprite = drySprite;
}
break;
default:
break;
}
}
}
private void OnMouseOver()
{
if (fm.isPlanting)
{
if(isPlanted || fm.selectPlant.plant.buyPrice > fm.money || !isBought)
{
//can't buy
plot.color = unavailableColor;
}
else
{
//can buy
plot.color = availableColor;
}
}
if (fm.isSelecting)
{
switch (fm.selectedTool)
{
case 1:
case 2:
if (isBought && fm.money>=(fm.selectedTool-1)*10)
{
plot.color = availableColor;
}
else
{
plot.color = unavailableColor;
}
break;
case 3:
if (!isBought && fm.money>=100)
{
plot.color = availableColor;
}
else
{
plot.color = unavailableColor;
}
break;
default:
plot.color = unavailableColor;
break;
}
}
}
private void OnMouseExit()
{
plot.color = Color.white;
}
void Harvest()
{
isPlanted = false;
plant.gameObject.SetActive(false);
fm.Transaction(selectedPlant.sellPrice);
isDry = true;
plot.sprite = drySprite;
speed = 1f;
}
void Plant(PlantObject newPlant)
{
selectedPlant = newPlant;
isPlanted = true;
fm.Transaction(-selectedPlant.buyPrice);
plantStage = 0;
UpdatePlant();
timer = selectedPlant.timeBtwStages;
plant.gameObject.SetActive(true);
}
void UpdatePlant()
{
if (isDry)
{
plant.sprite = selectedPlant.dryPlanted;
}
else
{
plant.sprite = selectedPlant.plantStages[plantStage];
}
plantCollider.size = plant.sprite.bounds.size;
plantCollider.offset = new Vector2(0,plant.bounds.size.y/2);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.