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
B
Birb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gadig
Birb
Commits
7b321b5c
Commit
7b321b5c
authored
Mar 02, 2017
by
Tanner Grehawick
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of git.gmu.edu:gadig/Birb
parents
e61bda3f
c2f1d8b9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
101 additions
and
0 deletions
+101
-0
Assets/Scripts/Enemy/BaseEnemy.cs
Assets/Scripts/Enemy/BaseEnemy.cs
+40
-0
Assets/Scripts/Enemy/HorizontalEnemy.cs
Assets/Scripts/Enemy/HorizontalEnemy.cs
+22
-0
Assets/Scripts/Enemy/VerticalEnemy.cs
Assets/Scripts/Enemy/VerticalEnemy.cs
+21
-0
Assets/Scripts/Util/BreakawayPlatform.cs
Assets/Scripts/Util/BreakawayPlatform.cs
+18
-0
No files found.
Assets/Scripts/Enemy/BaseEnemy.cs
0 → 100644
View file @
7b321b5c
using
System.Collections
;
using
System.Collections.Generic
;
using
UnityEngine
;
public
class
BaseEnemy
:
MonoBehaviour
{
public
float
speed
=
2f
;
Rigidbody2D
body
;
protected
SpriteRenderer
sr
;
protected
float
startMoveTime
;
public
Transform
rightCollisionPos
;
public
Transform
leftCollisionPos
;
void
Start
()
{
body
=
GetComponent
<
Rigidbody2D
>();
sr
=
GetComponent
<
SpriteRenderer
>();
startMoveTime
=
Time
.
time
+
.
4f
;
}
protected
void
Move
(
Vector2
dir
,
bool
isFlipped
)
{
body
.
transform
.
Translate
((
isFlipped
?
-
dir
:
dir
)
*
speed
*
Time
.
deltaTime
);
}
protected
bool
CheckCollision
(
Vector2
dir
,
bool
isFlipped
)
{
Vector3
position
=
isFlipped
?
leftCollisionPos
.
position
:
rightCollisionPos
.
position
;
Debug
.
DrawRay
(
position
,
(
isFlipped
?
-
dir
:
dir
)
*
.
1f
,
Color
.
blue
,
.
1f
);
Debug
.
DrawRay
(
position
,
-
transform
.
up
*
.
1f
,
Color
.
red
,
.
1f
);
RaycastHit2D
hitSide
=
Physics2D
.
Raycast
(
position
,
isFlipped
?
-
dir
:
dir
,
.
1f
);
RaycastHit2D
hitDown
=
Physics2D
.
Raycast
(
position
,
-
transform
.
up
,
.
1f
);
if
(
hitDown
.
collider
!=
null
&&
hitSide
.
collider
==
null
)
{
return
true
;
}
return
false
;
}
}
Assets/Scripts/Enemy/HorizontalEnemy.cs
0 → 100644
View file @
7b321b5c
using
System.Collections
;
using
System.Collections.Generic
;
using
UnityEngine
;
public
class
HorizontalEnemy
:
BaseEnemy
{
// Update is called once per frame
void
Update
()
{
if
(
CheckCollision
(
transform
.
right
,
sr
.
flipX
))
{
if
(
startMoveTime
<
Time
.
time
)
{
Move
(
transform
.
right
,
sr
.
flipX
);
}
}
else
{
sr
.
flipX
=
!
sr
.
flipX
;
}
}
}
Assets/Scripts/Enemy/VerticalEnemy.cs
0 → 100644
View file @
7b321b5c
using
System.Collections
;
using
System.Collections.Generic
;
using
UnityEngine
;
public
class
VerticalEnemy
:
BaseEnemy
{
public
bool
leftWall
;
void
Update
()
{
if
(
CheckCollision
(
transform
.
right
,
leftWall
?
!
sr
.
flipX
:
sr
.
flipX
))
{
if
(
startMoveTime
<
Time
.
time
)
{
Move
(-
transform
.
up
,
sr
.
flipX
);
}
}
else
{
sr
.
flipX
=
!
sr
.
flipX
;
}
}
}
Assets/Scripts/Util/BreakawayPlatform.cs
0 → 100644
View file @
7b321b5c
using
UnityEngine
;
using
System.Collections
;
public
class
BreakawayPlatform
:
MonoBehaviour
{
public
float
timeTilBreak
=
3f
;
private
void
Break
(){
Destroy
(
gameObject
);
}
private
void
OnCollisionEnter2D
(
Collision2D
col
)
{
if
(
col
.
gameObject
.
CompareTag
(
"Player"
))
{
Invoke
(
"Break"
,
timeTilBreak
);
}
}
}
\ No newline at end of file
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