Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Mr BigSock
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Gard Aleksander Furre
Mr BigSock
Commits
e8c1d0cf
Commit
e8c1d0cf
authored
2 years ago
by
Robin Ruud Kristensen
Browse files
Options
Downloads
Patches
Plain Diff
refacterd into more functions
parent
5fb051bf
No related branches found
Branches containing commit
No related tags found
1 merge request
!85
Merge
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
MrBigsock/Assets/Code/FollowPlayer.cs
+64
-70
64 additions, 70 deletions
MrBigsock/Assets/Code/FollowPlayer.cs
with
64 additions
and
70 deletions
MrBigsock/Assets/Code/FollowPlayer.cs
+
64
−
70
View file @
e8c1d0cf
...
@@ -8,44 +8,30 @@ namespace Bigsock
...
@@ -8,44 +8,30 @@ namespace Bigsock
{
{
public
class
FollowPlayer
:
MonoBehaviour
public
class
FollowPlayer
:
MonoBehaviour
{
{
[
SerializeField
]
[
SerializeField
]
NeighbourMapGenerator
neighborMapGenerator
;
private
NeighbourMapGenerator
neighborMapGenerator
;
[
SerializeField
]
CinemachineConfiner2D
cameraMap
;
[
SerializeField
]
[
SerializeField
]
GameObject
victoryScreen
;
private
CinemachineConfiner2D
cameraMap
;
[
SerializeField
]
GameObject
VictoryScreen
;
private
int
levels
=
0
;
//Unity varibles
private
GameObject
[]
boss
;
private
GameObject
player
;
Vector3
offset
=
new
Vector3
(
0
,
0
,
-
10
);
private
GameObject
[]
enemies
;
int
i
=
0
;
private
GameObject
[]
Chest
;
private
List
<
GameObject
>
chests
;
private
GameObject
stair
;
GameObject
[]
boss
;
//Normal variables
GameObject
player
;
private
int
levels
=
0
;
GameObject
[]
enemies
;
private
static
int
LEVEL_CAP
=
2
;
GameObject
[]
Chest
;
List
<
GameObject
>
chests
;
GameObject
stair
;
int
finalLevel
=
2
;
private
int
roomNr
=
0
;
private
int
roomNr
=
0
;
bool
stairs_down
;
private
bool
stairs_down
;
int
h
=
0
;
private
int
victoryHold
=
0
;
void
Start
()
void
Start
()
{
{
chests
=
new
List
<
GameObject
>();
chests
=
new
List
<
GameObject
>();
neighborMapGenerator
.
RunProceduralGeneration
();
player
=
GameObject
.
Find
(
"BigSock"
);
player
=
GameObject
.
Find
(
"BigSock"
);
stair
=
GameObject
.
Find
(
"Stairs(Clone)"
);
InitializeLevel
();
Chest
=
GameObject
.
FindGameObjectsWithTag
(
"Chest"
);
foreach
(
GameObject
c
in
Chest
)
{
chests
.
Add
(
c
);
c
.
SetActive
(
false
);
}
stairs_down
=
stair
.
GetComponent
<
Stairs
>().
stairs_touch
;
stair
.
SetActive
(
false
);
}
}
void
LateUpdate
()
void
LateUpdate
()
...
@@ -53,63 +39,30 @@ namespace Bigsock
...
@@ -53,63 +39,30 @@ namespace Bigsock
boss
=
GameObject
.
FindGameObjectsWithTag
(
"Boss"
);
boss
=
GameObject
.
FindGameObjectsWithTag
(
"Boss"
);
enemies
=
GameObject
.
FindGameObjectsWithTag
((
roomNr
).
ToString
());
enemies
=
GameObject
.
FindGameObjectsWithTag
((
roomNr
).
ToString
());
if
(
boss
.
Length
==
0
&&
levels
<
2
)
if
(
boss
.
Length
==
0
&&
levels
<
LEVEL_CAP
)
{
{
if
(!
stair
.
activeInHierarchy
)
if
(!
stair
.
activeInHierarchy
)
{
{
Debug
.
Log
(
"hei"
);
levels
++;
levels
++;
}
}
stair
.
SetActive
(
true
);
stair
.
SetActive
(
true
);
stairs_down
=
stair
.
GetComponent
<
Stairs
>().
stairs_touch
;
stairs_down
=
stair
.
GetComponent
<
Stairs
>().
stairs_touch
;
}
}
if
(
levels
==
finalLevel
&&
h
==
0
)
if
(
levels
==
LEVEL_CAP
&&
victoryHold
==
0
)
{
{
Time
.
timeScale
=
0
;
VictoryScreen
();
GameObject
canvas
=
GameObject
.
Find
(
"Canvas"
);
victoryHold
++;
if
(
canvas
!=
null
)
{
Instantiate
(
VictoryScreen
,
canvas
.
transform
);
h
++;
}
}
}
if
(
stairs_down
)
if
(
stairs_down
)
{
{
roomNr
=
0
;
ClearScene
();
foreach
(
GameObject
c
in
chests
)
{
DestroyImmediate
(
c
);
}
DestroyImmediate
(
stair
);
chests
.
Clear
();
TilemapGenerator
.
resetMaps
();
TilemapGenerator
.
SetRoomIDZero
();
player
.
transform
.
position
=
new
Vector3
(
9
,
5
,
0
);
player
.
transform
.
position
=
new
Vector3
(
9
,
5
,
0
);
neighborMapGenerator
.
RunProceduralGeneration
();
InitializeLevel
();
Chest
=
GameObject
.
FindGameObjectsWithTag
(
"Chest"
);
stair
=
GameObject
.
Find
(
"Stairs(Clone)"
);
stairs_down
=
stair
.
GetComponent
<
Stairs
>().
stairs_touch
;
foreach
(
GameObject
c
in
Chest
)
{
if
(
c
!=
null
)
{
c
.
SetActive
(
false
);
chests
.
Add
(
c
);
}
}
stair
.
SetActive
(
false
);
}
}
int
i
=
0
;
cameraMap
.
InvalidateCache
();
if
(
i
==
0
)
{
cameraMap
.
InvalidateCache
();
}
if
(
enemies
.
Length
==
0
)
if
(
enemies
.
Length
==
0
)
{
{
...
@@ -126,16 +79,57 @@ namespace Bigsock
...
@@ -126,16 +79,57 @@ namespace Bigsock
}
}
private
void
OnDestroy
()
private
void
OnDestroy
()
{
ClearScene
();
}
/*
*Deletes all game objects from the scene that is not the player
*and also resets all arrays that have been made*/
private
void
ClearScene
()
{
{
roomNr
=
0
;
roomNr
=
0
;
foreach
(
GameObject
c
in
chests
)
foreach
(
GameObject
c
in
chests
)
{
{
DestroyImmediate
(
c
);
DestroyImmediate
(
c
);
}
}
chests
.
Clear
();
DestroyImmediate
(
stair
);
DestroyImmediate
(
stair
);
NeighbourMapGenerator
.
ClearRoomList
();
NeighbourMapGenerator
.
ClearRoomList
();
TilemapGenerator
.
SetRoomIDZero
();
TilemapGenerator
.
SetRoomIDZero
();
TilemapGenerator
.
resetMaps
();
TilemapGenerator
.
resetMaps
();
}
}
/*
*Initializes the victory screen*/
private
void
VictoryScreen
()
{
Time
.
timeScale
=
0
;
GameObject
canvas
=
GameObject
.
Find
(
"Canvas"
);
if
(
canvas
!=
null
)
{
Instantiate
(
victoryScreen
,
canvas
.
transform
);
}
}
/*
*Creates a level and adds objects to the different arrays */
private
void
InitializeLevel
()
{
neighborMapGenerator
.
RunProceduralGeneration
();
Chest
=
GameObject
.
FindGameObjectsWithTag
(
"Chest"
);
stair
=
GameObject
.
Find
(
"Stairs(Clone)"
);
stairs_down
=
stair
.
GetComponent
<
Stairs
>().
stairs_touch
;
foreach
(
GameObject
c
in
Chest
)
{
if
(
c
!=
null
)
{
c
.
SetActive
(
false
);
chests
.
Add
(
c
);
}
}
stairs_down
=
stair
.
GetComponent
<
Stairs
>().
stairs_touch
;
stair
.
SetActive
(
false
);
}
}
}
}
}
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