Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
four
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
31
Issues
31
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
gadig
four
Commits
0ad0a4c2
Commit
0ad0a4c2
authored
Oct 21, 2016
by
Luke A Smith
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'folderFixes' into 'master'
Fixed folder names and removed redundent folders See merge request
!12
parents
2ff4cf21
6db14b17
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
0 additions
and
290 deletions
+0
-290
Assets/editor/.gitkeep
Assets/editor/.gitkeep
+0
-0
Assets/script/MapGen.cs
Assets/script/MapGen.cs
+0
-137
Assets/script/Path.cs
Assets/script/Path.cs
+0
-33
Assets/script/Tile.cs
Assets/script/Tile.cs
+0
-79
Assets/script/TraversePath.cs
Assets/script/TraversePath.cs
+0
-41
Assets/sprite/blue.png
Assets/sprite/blue.png
+0
-0
Assets/sprite/white.png
Assets/sprite/white.png
+0
-0
No files found.
Assets/editor/.gitkeep
deleted
100644 → 0
View file @
2ff4cf21
Assets/script/MapGen.cs
deleted
100644 → 0
View file @
2ff4cf21
using
UnityEngine
;
using
System.Collections
;
using
System.Collections.Generic
;
public
class
MapGen
:
MonoBehaviour
{
public
int
rows
=
6
;
public
int
cols
=
6
;
public
GameObject
tile
;
public
GameObject
enemy
;
public
static
Tile
[,]
map
;
public
Tile
startPos
;
public
Tile
endPos
;
public
List
<
Tile
>
open
;
public
List
<
Tile
>
closed
;
void
Start
()
{
map
=
new
Tile
[
rows
,
cols
];
float
startx
=
-(
float
)
rows
/
2f
*
tile
.
transform
.
lossyScale
.
x
;
float
starty
=
(
float
)
cols
/
2f
*
tile
.
transform
.
lossyScale
.
y
;
for
(
int
y
=
0
;
y
<
cols
;
y
++)
{
for
(
int
x
=
0
;
x
<
rows
;
x
++)
{
map
[
x
,
y
]
=
((
GameObject
)
Instantiate
(
tile
,
new
Vector2
(
startx
+
x
*
tile
.
GetComponent
<
BoxCollider2D
>().
size
.
x
,
starty
-
y
*
tile
.
GetComponent
<
BoxCollider2D
>().
size
.
x
),
Quaternion
.
identity
)).
GetComponent
<
Tile
>
();
map
[
x
,
y
].
x
=
x
;
map
[
x
,
y
].
y
=
y
;
}
}
open
=
new
List
<
Tile
>
();
closed
=
new
List
<
Tile
>
();
enemy
=
(
GameObject
)(
Instantiate
(
enemy
,
map
[
0
,
0
].
transform
.
position
,
Quaternion
.
identity
));
}
void
FixedUpdate
()
{
if
(
map
[
rows
-
1
,
cols
-
1
].
prev
!=
null
)
{
Tile
current
=
map
[
rows
-
1
,
cols
-
1
];
while
(
current
.
prev
!=
null
)
{
Debug
.
DrawLine
(
current
.
transform
.
position
,
current
.
prev
.
transform
.
position
,
Color
.
red
);
current
=
current
.
prev
;
}
}
}
public
void
BeginPath
()
{
Path
(
map
[
0
,
0
],
map
[
rows
-
1
,
cols
-
1
]);
}
void
Path
(
Tile
start
,
Tile
finish
)
{
if
(
start
==
finish
)
{
return
;
}
open
.
Add
(
start
);
start
.
goal
=
0
;
start
.
fitness
=
EstimateHeuristic
(
start
,
finish
);
while
(
open
.
Count
!=
0
)
{
Tile
current
=
null
;
int
index
=
0
;
float
lowestFitness
=
open
[
0
].
fitness
;
for
(
int
i
=
0
;
i
<
open
.
Count
;
i
++)
{
if
(
open
[
i
].
fitness
<
lowestFitness
)
{
lowestFitness
=
open
[
i
].
fitness
;
index
=
i
;
}
}
current
=
open
[
index
];
open
.
RemoveAt
(
index
);
closed
.
Add
(
current
);
List
<
Tile
>
neighbors
=
current
.
GetNeighbors
();
for
(
int
i
=
0
;
i
<
neighbors
.
Count
;
i
++)
{
if
(
closed
.
Contains
(
neighbors
[
i
]))
{
continue
;
}
float
tempGoal
=
current
.
goal
+
DistBetween
(
current
,
neighbors
[
i
]);
if
(!
open
.
Contains
(
neighbors
[
i
]))
{
open
.
Add
(
neighbors
[
i
]);
}
else
if
(
tempGoal
>=
neighbors
[
i
].
goal
)
{
continue
;
}
neighbors
[
i
].
prev
=
current
;
neighbors
[
i
].
goal
=
tempGoal
;
neighbors
[
i
].
fitness
=
neighbors
[
i
].
goal
+
EstimateHeuristic
(
neighbors
[
i
],
finish
);
}
}
// PrintPathRetrace (finish);
enemy
.
GetComponent
<
TraversePath
>
().
BeginTraversingPath
(
CreatePath
(
finish
));
}
float
EstimateHeuristic
(
Tile
current
,
Tile
finish
)
{
return
Mathf
.
Abs
(
current
.
x
-
finish
.
x
)
+
Mathf
.
Abs
(
current
.
y
-
finish
.
y
);
}
float
DistBetween
(
Tile
current
,
Tile
neighbor
)
{
return
Mathf
.
Pow
(
current
.
x
-
neighbor
.
x
,
2
)
+
Mathf
.
Pow
(
current
.
y
-
neighbor
.
y
,
2
);
}
void
PrintPathRetrace
(
Tile
end
)
{
while
(
end
!=
null
)
{
Debug
.
Log
(
end
.
x
+
", "
+
end
.
y
);
end
=
end
.
prev
;
}
}
Path
CreatePath
(
Tile
finish
)
{
Path
path
=
new
Path
();
while
(
finish
!=
null
)
{
path
.
Push
(
finish
);
finish
=
finish
.
prev
;
}
return
path
;
}
}
Assets/script/Path.cs
deleted
100644 → 0
View file @
2ff4cf21
using
UnityEngine
;
using
System.Collections
;
using
System.Collections.Generic
;
public
class
Path
{
public
Tile
start
;
public
Tile
finish
;
private
Stack
<
Tile
>
path
;
public
Path
()
:
this
(
0
)
{
}
public
Path
(
int
count
)
{
path
=
new
Stack
<
Tile
>
(
count
);
}
public
void
Push
(
Tile
t
)
{
path
.
Push
(
t
);
}
public
Tile
Pop
()
{
return
path
.
Pop
();
}
public
Tile
Peek
()
{
return
path
.
Peek
();
}
public
bool
IsEmpty
()
{
return
path
.
Count
==
0
;
}
}
Assets/script/Tile.cs
deleted
100644 → 0
View file @
2ff4cf21
using
UnityEngine
;
using
System.Collections
;
using
System.Collections.Generic
;
public
class
Tile
:
MonoBehaviour
{
public
bool
passable
=
true
;
public
Color
canPas
=
new
Color
(
255f
,
255f
,
255f
);
public
Color
cantPas
=
new
Color
(
0f
,
0f
,
0f
);
private
SpriteRenderer
sprite
;
public
int
x
;
public
int
y
;
public
Tile
prev
;
public
float
goal
=
float
.
MaxValue
;
public
float
fitness
=
float
.
MaxValue
;
void
Start
()
{
sprite
=
GetComponent
<
SpriteRenderer
>
();
}
void
OnMouseDown
()
{
passable
=
!
passable
;
if
(
passable
)
{
sprite
.
color
=
canPas
;
}
else
{
sprite
.
color
=
cantPas
;
}
}
public
List
<
Tile
>
GetNeighbors
()
{
List
<
Tile
>
neighbors
=
new
List
<
Tile
>
();
if
(
x
<
MapGen
.
map
.
GetLength
(
0
)
-
1
&&
MapGen
.
map
[
x
+
1
,
y
].
passable
)
{
neighbors
.
Add
(
MapGen
.
map
[
x
+
1
,
y
]);
}
if
(
x
<
MapGen
.
map
.
GetLength
(
0
)
-
1
&&
y
<
MapGen
.
map
.
GetLength
(
1
)
-
1
&&
MapGen
.
map
[
x
+
1
,
y
+
1
].
passable
&&
MapGen
.
map
[
x
,
y
+
1
].
passable
&&
MapGen
.
map
[
x
+
1
,
y
].
passable
)
{
neighbors
.
Add
(
MapGen
.
map
[
x
+
1
,
y
+
1
]);
}
if
(
y
<
MapGen
.
map
.
GetLength
(
1
)
-
1
&&
MapGen
.
map
[
x
,
y
+
1
].
passable
)
{
neighbors
.
Add
(
MapGen
.
map
[
x
,
y
+
1
]);
}
if
(
x
>
0
&&
y
<
MapGen
.
map
.
GetLength
(
1
)
-
1
&&
MapGen
.
map
[
x
-
1
,
y
+
1
].
passable
&&
MapGen
.
map
[
x
,
y
+
1
].
passable
&&
MapGen
.
map
[
x
-
1
,
y
].
passable
)
{
neighbors
.
Add
(
MapGen
.
map
[
x
-
1
,
y
+
1
]);
}
if
(
x
>
0
&&
MapGen
.
map
[
x
-
1
,
y
].
passable
)
{
neighbors
.
Add
(
MapGen
.
map
[
x
-
1
,
y
]);
}
if
(
x
>
0
&&
y
>
0
&&
MapGen
.
map
[
x
-
1
,
y
-
1
].
passable
&&
MapGen
.
map
[
x
,
y
-
1
].
passable
&&
MapGen
.
map
[
x
-
1
,
y
].
passable
)
{
neighbors
.
Add
(
MapGen
.
map
[
x
-
1
,
y
-
1
]);
}
if
(
y
>
0
&&
MapGen
.
map
[
x
,
y
-
1
].
passable
)
{
neighbors
.
Add
(
MapGen
.
map
[
x
,
y
-
1
]);
}
if
(
x
<
MapGen
.
map
.
GetLength
(
0
)
-
1
&&
y
>
0
&&
MapGen
.
map
[
x
+
1
,
y
-
1
].
passable
&&
MapGen
.
map
[
x
,
y
-
1
].
passable
&&
MapGen
.
map
[
x
+
1
,
y
].
passable
)
{
neighbors
.
Add
(
MapGen
.
map
[
x
+
1
,
y
-
1
]);
}
return
neighbors
;
}
}
Assets/script/TraversePath.cs
deleted
100644 → 0
View file @
2ff4cf21
using
UnityEngine
;
using
System.Collections
;
public
class
TraversePath
:
MonoBehaviour
{
public
float
speed
;
public
float
pathErrorRange
;
private
float
speedLerpDistance
;
private
Rigidbody2D
rb2d
;
private
Path
path
;
void
Start
()
{
speedLerpDistance
=
speed
*
Time
.
fixedDeltaTime
;
rb2d
=
GetComponent
<
Rigidbody2D
>
();
}
void
FixedUpdate
()
{
if
(
path
!=
null
&&
!
path
.
IsEmpty
())
{
Vector3
tilePos
=
path
.
Peek
().
transform
.
position
;
float
distance
=
Vector3
.
Distance
(
transform
.
position
,
tilePos
);
transform
.
position
=
Vector3
.
Lerp
(
transform
.
position
,
tilePos
,
1
/
distance
*
speedLerpDistance
);
if
(
distance
<=
pathErrorRange
)
{
path
.
Pop
();
}
}
}
//path must begin on current tile
public
void
BeginTraversingPath
(
Path
path
)
{
this
.
path
=
path
;
}
}
Assets/sprite/blue.png
deleted
100644 → 0
View file @
2ff4cf21
391 Bytes
Assets/sprite/white.png
deleted
100644 → 0
View file @
2ff4cf21
125 Bytes
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment