Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Game_jam19
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Erno Lokkila
Game_jam19
Commits
4d8259c2
Commit
4d8259c2
authored
6 years ago
by
Petteri
Browse files
Options
Downloads
Patches
Plain Diff
collectore update and ground generator change
changed ground generators collector creation to use city add collector method
parent
da94e61c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Assets/Scripts/Collector.cs
+72
-14
72 additions, 14 deletions
Assets/Scripts/Collector.cs
Assets/Scripts/GroundGenerator/GroundGenerator.cs
+1
-1
1 addition, 1 deletion
Assets/Scripts/GroundGenerator/GroundGenerator.cs
with
73 additions
and
15 deletions
Assets/Scripts/Collector.cs
+
72
−
14
View file @
4d8259c2
...
@@ -13,6 +13,15 @@ public class Collector : MonoBehaviour
...
@@ -13,6 +13,15 @@ public class Collector : MonoBehaviour
[
SerializeField
]
[
SerializeField
]
private
int
max_amount
=
10
;
private
int
max_amount
=
10
;
[
SerializeField
]
private
int
Requested_amount
;
[
SerializeField
]
private
Resource
Requested_resource
;
[
SerializeField
]
private
bool
OnkoVapaa
;
[
SerializeField
]
[
SerializeField
]
private
int
amount
;
private
int
amount
;
...
@@ -26,6 +35,8 @@ public class Collector : MonoBehaviour
...
@@ -26,6 +35,8 @@ public class Collector : MonoBehaviour
[
SerializeField
]
[
SerializeField
]
private
GameObject
target_flag
;
private
GameObject
target_flag
;
[
SerializeField
]
private
bool
send_to_resource
;
public
GameObject
flag
;
public
GameObject
flag
;
// Start is called before the first frame update
// Start is called before the first frame update
void
Start
()
void
Start
()
...
@@ -33,6 +44,14 @@ public class Collector : MonoBehaviour
...
@@ -33,6 +44,14 @@ public class Collector : MonoBehaviour
home
=
GameObject
.
FindGameObjectWithTag
(
"Home"
);
home
=
GameObject
.
FindGameObjectWithTag
(
"Home"
);
}
}
public
void
SetOnkoVapaa
(
bool
vapaa
)
{
this
.
OnkoVapaa
=
vapaa
;
}
public
bool
tarkistaVapaus
()
{
return
this
.
OnkoVapaa
;
}
public
void
SetTarget
(
GameObject
target
)
public
void
SetTarget
(
GameObject
target
)
{
{
this
.
target
=
target
;
this
.
target
=
target
;
...
@@ -41,10 +60,18 @@ public class Collector : MonoBehaviour
...
@@ -41,10 +60,18 @@ public class Collector : MonoBehaviour
{
{
this
.
move_to
=
target
;
this
.
move_to
=
target
;
}
}
public
Resource
getResource
()
{
return
this
.
resource
;
}
public
void
SetSend_to_resource
(
bool
r
)
{
this
.
send_to_resource
=
r
;
}
// Update is called once per frame
// Update is called once per frame
void
Update
()
void
Update
()
{
{
if
(
Input
.
GetMouseButtonDown
(
0
))
if
(
Input
.
GetMouseButtonDown
(
0
))
{
{
Vector3
mousePos
=
Camera
.
main
.
ScreenToWorldPoint
(
Input
.
mousePosition
);
Vector3
mousePos
=
Camera
.
main
.
ScreenToWorldPoint
(
Input
.
mousePosition
);
...
@@ -53,6 +80,16 @@ public class Collector : MonoBehaviour
...
@@ -53,6 +80,16 @@ public class Collector : MonoBehaviour
RaycastHit2D
hit
=
Physics2D
.
Raycast
(
mousePos2D
,
Vector2
.
zero
);
RaycastHit2D
hit
=
Physics2D
.
Raycast
(
mousePos2D
,
Vector2
.
zero
);
if
(
hit
.
collider
!=
null
)
if
(
hit
.
collider
!=
null
)
{
{
if
(
hit
.
collider
.
gameObject
.
tag
==
"Home"
)
home
.
gameObject
.
GetComponent
<
City
>().
AddCollector
();
if
(
hit
.
collider
.
gameObject
.
GetComponent
<
Outcrop
>()
!=
null
)
{
this
.
send_to_resource
=
true
;
}
else
{
this
.
send_to_resource
=
false
;
}
DestroyImmediate
(
target_flag
);
DestroyImmediate
(
target_flag
);
target_flag
=
Instantiate
(
flag
,
hit
.
point
,
Quaternion
.
identity
);
target_flag
=
Instantiate
(
flag
,
hit
.
point
,
Quaternion
.
identity
);
target_flag
.
GetComponent
<
Flag
>().
SetWorker
(
this
.
gameObject
);
target_flag
.
GetComponent
<
Flag
>().
SetWorker
(
this
.
gameObject
);
...
@@ -72,30 +109,51 @@ public class Collector : MonoBehaviour
...
@@ -72,30 +109,51 @@ public class Collector : MonoBehaviour
if
(
collision
.
gameObject
.
transform
.
position
==
target_flag
.
transform
.
position
)
{
if
(
collision
.
gameObject
.
transform
.
position
==
target_flag
.
transform
.
position
)
{
if
(
resource
==
null
)
if
(
resource
==
null
)
{
{
/*
if(
target
.GetComponent<
Resource>().vie_tavaraa(
))
if
(
home
.
GetComponent
<
BoxCollider2D
>().
bounds
.
Contains
(
new
Vector3
(
target_flag
.
transform
.
position
.
x
,
target_flag
.
transform
.
position
.
y
,
home
.
transform
.
position
.
z
)
))
{
{
Destroy
(
target_flag
);
}
else
if
(
send_to_resource
&&
target
.
GetComponent
<
Outcrop
>())
{
if
(
this
.
amount
>
0
)
target
.
GetComponent
<
Outcrop
>().
setAmount
(
this
.
amount
);
//Requested_resource = target.GetComponent<Outcrop>();
Requested_amount
=
target
.
GetComponent
<
Outcrop
>().
stillNeeded
();
StartCoroutine
(
"goHome"
);
}
}
else
else
{
*/
{
//Amount of resources worker is carrying right now
//Amount of resources worker is carrying right now
this
.
amount
=
target
.
GetComponent
<
Resource
>().
extractResource
(
this
.
max_amount
);
this
.
amount
=
target
.
GetComponent
<
Resource
>().
extractResource
(
this
.
max_amount
);
//Gives target resource to resource variable
//Gives target resource to resource variable
this
.
resource
=
this
.
target
.
GetComponent
<
Resource
>();
this
.
resource
=
this
.
target
.
GetComponent
<
Resource
>();
//}
StartCoroutine
(
"goHome"
);
}
}
}
StartCoroutine
(
"goHome"
);
else
StartCoroutine
(
"goHome"
);
}
}
}
}
if
(
collision
.
gameObject
.
tag
==
"Home"
&&
this
.
resource
!=
null
)
if
(
move_to
.
gameObject
.
tag
==
"Home"
&&
this
.
resource
!=
null
)
{
{
//resets amount and resource variables
if
(
target
.
GetComponent
<
Outcrop
>())
collision
.
gameObject
.
GetComponent
<
City
>().
AddResource
(
this
.
resource
,
this
.
amount
);
{
this
.
amount
=
0
;
/*if(this.Requested_amount < this.max_amount)
this
.
resource
=
null
;
this.amount = home.GetComponent<City>().UseResource(, this.Requested_amount);
MoveTo
(
this
.
target
);
else
this.amount = home.GetComponent<City>().UseResource(, this.max_amount);*/
}
else
{
//resets amount and resource variables
collision
.
gameObject
.
GetComponent
<
City
>().
AddResource
(
this
.
resource
,
this
.
amount
);
this
.
amount
=
0
;
this
.
resource
=
null
;
}
MoveTo
(
this
.
target
);
}
}
}
}
IEnumerator
goHome
()
IEnumerator
goHome
()
...
...
This diff is collapsed.
Click to expand it.
Assets/Scripts/GroundGenerator/GroundGenerator.cs
+
1
−
1
View file @
4d8259c2
...
@@ -151,7 +151,7 @@ public class GroundGenerator : MonoBehaviour
...
@@ -151,7 +151,7 @@ public class GroundGenerator : MonoBehaviour
private
void
createHome
()
{
private
void
createHome
()
{
ground
[
ground
.
GetLength
(
0
)
/
2
,
ground
.
GetLength
(
1
)
/
2
]
=
home
;
ground
[
ground
.
GetLength
(
0
)
/
2
,
ground
.
GetLength
(
1
)
/
2
]
=
home
;
spawn
(
homeGO
,
houseCoords
[
0
],
houseCoords
[
1
],
houseDepth
);
spawn
(
homeGO
,
houseCoords
[
0
],
houseCoords
[
1
],
houseDepth
);
spawn
(
workerGO
,
houseCoords
[
0
],
houseCoords
[
1
],
workerDepth
);
homeGO
.
GetComponent
<
City
>().
AddCollector
(
);
}
}
private
GameObject
spawn
(
GameObject
go
,
int
x
,
int
y
,
int
z
)
{
private
GameObject
spawn
(
GameObject
go
,
int
x
,
int
y
,
int
z
)
{
return
Instantiate
<
GameObject
>(
go
,
new
Vector3
(
x
,
y
,
z
),
Quaternion
.
identity
);
return
Instantiate
<
GameObject
>(
go
,
new
Vector3
(
x
,
y
,
z
),
Quaternion
.
identity
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment