Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
gadig
four
Commits
b179b448
Commit
b179b448
authored
Nov 19, 2016
by
Luke Smith
Browse files
Organized Folders
parent
b251d2b3
Changes
23
Hide whitespace changes
Inline
Side-by-side
Assets/Scripts/Actions.cs
0 → 100644
View file @
b179b448
using
UnityEngine
;
using
System.Collections
;
using
UnityEngine.UI
;
public
class
Actions
:
MonoBehaviour
{
public
GameObject
[]
abilities
=
new
GameObject
[
4
];
// The array full of the character's abilities
public
GameObject
currentAbility
=
null
;
// Which ability is currently active
private
int
abilitiesCounter
=
0
;
// A counter which lets you cycle through the abilities
private
Image
abilitiesImage
;
// Picture which shows which ability it active
private
Color
abilityUnusable
;
private
Color
abilityUsable
;
public
int
fireballSpeed
=
5
;
public
bool
waterShieldUsable
=
true
;
private
float
waterShieldTimer
=
0.0f
;
public
float
waterShieldCooldown
=
5.0f
;
private
Vector3
LastInput
=
new
Vector2
(
0
,
-
1
);
void
Start
()
{
abilitiesImage
=
GameObject
.
FindGameObjectWithTag
(
"Cycle"
).
GetComponent
<
Image
>();
// Set the initial ability to something so that it's not null
CycleAbility
();
abilityUnusable
=
new
Color
(
255.0f
,
255.0f
,
255.0f
,
0.5f
);
abilityUsable
=
new
Color
(
255.0f
,
255.0f
,
255.0f
,
1.0f
);
}
void
Update
()
{
RaycastHit2D
hit
=
Physics2D
.
Raycast
(
transform
.
position
,
GetLastDirection
());
Debug
.
DrawRay
(
transform
.
position
,
GetLastDirection
(),
Color
.
red
);
// Constantly check where the player is facing
GetLastDirection
();
if
(
Input
.
GetButtonDown
(
"Fire1"
))
{
UseAbility
(
currentAbility
.
name
);
}
if
(
waterShieldUsable
==
false
)
{
waterShieldTimer
+=
Time
.
deltaTime
;
if
(
waterShieldTimer
>
waterShieldCooldown
)
{
waterShieldUsable
=
true
;
waterShieldTimer
=
0.0f
;
}
abilitiesImage
.
GetComponent
<
Image
>().
color
=
abilityUnusable
;
}
else
{
abilitiesImage
.
GetComponent
<
Image
>().
color
=
abilityUsable
;
}
// If the player presses the button to choose an ability...
if
(
Input
.
GetButtonDown
(
"Fire2"
))
{
// Increment the counter
abilitiesCounter
++;
// Call the ChooseAbility() function
CycleAbility
();
}
}
void
CycleAbility
()
{
// If the counter goes out of range of the array's size, reset it to 0
if
(
abilitiesCounter
>
abilities
.
Length
-
1
)
{
abilitiesCounter
=
0
;
}
// Set the currentAbility to the one chosen by the abilitiesCounter
currentAbility
=
abilities
[
abilitiesCounter
];
// Set the image of the gameObject of the ability equal to the picture of the currentAbility
abilitiesImage
.
GetComponent
<
Image
>().
sprite
=
currentAbility
.
GetComponent
<
SpriteRenderer
>().
sprite
;
}
public
void
UseAbility
(
string
myCurrentAbility
)
{
switch
(
myCurrentAbility
)
{
case
"Ability - Fireball"
:
GameObject
clone
=
Instantiate
(
currentAbility
,
this
.
transform
.
position
,
Quaternion
.
identity
)
as
GameObject
;
clone
.
GetComponent
<
FireballProjectile
>().
move
=
LastInput
;
clone
.
GetComponent
<
FireballProjectile
>().
speed
=
fireballSpeed
;
break
;
case
"Ability - Water Shield"
:
if
(
waterShieldUsable
==
true
)
{
GameObject
myShield
=
(
GameObject
)
Instantiate
(
currentAbility
,
transform
.
position
,
Quaternion
.
identity
);
WaterShield
waterShield
=
myShield
.
GetComponent
<
WaterShield
>();
waterShieldUsable
=
false
;
}
break
;
case
"Ability - Rock"
:
Debug
.
Log
(
"Throwing a rock!"
);
break
;
case
"Ability - Breath of Air"
:
Debug
.
Log
(
"Casting breath of air!"
);
break
;
}
}
public
Vector2
GetLastDirection
()
{
Vector3
input
=
new
Vector3
(
Input
.
GetAxisRaw
(
"Horizontal"
),
Input
.
GetAxisRaw
(
"Vertical"
),
0
);
if
(
input
.
x
==
0
&&
input
.
y
==
0
)
{
//do nothing
}
else
if
(
input
.
y
!=
0
)
{
LastInput
=
new
Vector2
(
0
,
input
.
y
);
}
else
{
LastInput
=
new
Vector2
(
input
.
x
,
0
);
}
return
LastInput
;
}
}
Assets/Scripts/Actions.cs.meta
0 → 100644
View file @
b179b448
fileFormatVersion: 2
guid: 2da14653c84e44ccbaeb9e90ae797be1
timeCreated: 1475808355
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Assets/Scripts/Boss.cs
0 → 100644
View file @
b179b448
using
UnityEngine
;
using
System.Collections
;
public
class
Boss
:
MonoBehaviour
{
private
Rigidbody2D
rb
;
public
float
speed
=
1f
;
public
GameObject
[]
waypoints
;
private
Transform
currentWaypoint
;
public
float
distanceThreshold
=
0.5f
;
public
GameObject
projectile
;
public
float
attackCooldown
=
2.0f
;
public
float
attackRandom
=
1.0f
;
private
float
lastAttack
=
0
;
public
float
projectileSpeed
=
5
;
public
int
health
=
100
;
public
GameObject
diety
;
// Use this for initialization
void
Start
()
{
waypoints
=
GameObject
.
FindGameObjectsWithTag
(
"Waypoint"
);
rb
=
GetComponent
<
Rigidbody2D
>();
PickWaypoint
();
}
// Update is called once per frame
void
Update
()
{
if
(
currentWaypoint
)
{
if
(
Vector2
.
Distance
(
transform
.
position
,
currentWaypoint
.
position
)
<
distanceThreshold
)
{
PickWaypoint
();
}
else
{
Vector2
dir
=
currentWaypoint
.
position
-
transform
.
position
;
Vector2
force
=
new
Vector2
(
dir
.
x
,
dir
.
y
)
*
speed
;
rb
.
AddForce
(
Vector2
.
ClampMagnitude
(
force
,
speed
));
}
}
if
(
Time
.
time
>
lastAttack
)
{
lastAttack
=
Time
.
time
+
attackCooldown
+
Random
.
Range
(
0
,
attackRandom
);
Shoot
(
0
);
Shoot
(
90
);
Shoot
(
180
);
Shoot
(
270
);
}
}
void
PickWaypoint
()
{
currentWaypoint
=
waypoints
[
Random
.
Range
(
0
,
waypoints
.
Length
)].
transform
;
}
void
Shoot
(
int
angle
)
{
float
rad
=
(
angle
+
90
)
*
Mathf
.
Deg2Rad
;
Vector2
vel
=
new
Vector2
(
Mathf
.
Cos
(
rad
),
Mathf
.
Sin
(
rad
))
*
projectileSpeed
;
GameObject
projectile_clone
=
Instantiate
(
projectile
,
transform
.
position
,
Quaternion
.
identity
)
as
GameObject
;
projectile_clone
.
GetComponent
<
Rigidbody2D
>().
velocity
=
vel
;
projectile_clone
.
transform
.
eulerAngles
=
new
Vector3
(
0
,
0
,
angle
);
}
void
GetHit
(
int
amount
)
{
health
-=
health
;
if
(
health
<=
0
)
{
Die
();
}
}
void
Die
()
{
Instantiate
(
diety
,
transform
.
position
,
Quaternion
.
identity
);
Destroy
(
gameObject
);
}
}
Assets/Scripts/Boss.cs.meta
0 → 100644
View file @
b179b448
fileFormatVersion: 2
guid: 1637c8df298d2ef448fab676ee167299
timeCreated: 1479433452
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Assets/Scripts/EnemyProjectile.cs
0 → 100644
View file @
b179b448
using
UnityEngine
;
using
System.Collections
;
public
class
EnemyProjectile
:
MonoBehaviour
{
// TEMPORARY
// Does not damage player
void
OnCollisionEnter2D
(
Collision2D
col
)
{
Destroy
(
gameObject
);
}
}
Assets/Scripts/EnemyProjectile.cs.meta
0 → 100644
View file @
b179b448
fileFormatVersion: 2
guid: 70394bdca2dfef640ba97907cce063d9
timeCreated: 1479437610
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Assets/Scripts/FireballMove.cs
0 → 100644
View file @
b179b448
using
UnityEngine
;
using
System.Collections
;
public
class
FireballMove
:
MonoBehaviour
{
public
float
speed
;
private
Rigidbody2D
fireRB
;
public
Vector2
move
;
// Use this for initialization
void
Start
()
{
fireRB
=
GetComponent
<
Rigidbody2D
>
();
fireRB
.
velocity
=
(
move
*
speed
);
}
void
OnCollisionEnter2D
(
Collision2D
c
){
Destroy
(
gameObject
);
}
}
Assets/Scripts/FireballMove.cs.meta
0 → 100644
View file @
b179b448
fileFormatVersion: 2
guid: b245668d1f70fae43ba9905676a8f688
timeCreated: 1477616043
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Assets/Scripts/FireballProjectile.cs
0 → 100644
View file @
b179b448
using
UnityEngine
;
using
System.Collections
;
public
class
FireballProjectile
:
MonoBehaviour
{
[
HideInInspector
]
public
float
speed
;
private
Rigidbody2D
rb
;
public
Vector2
move
;
void
Start
()
{
rb
=
GetComponent
<
Rigidbody2D
>();
rb
.
velocity
=
(
move
*
speed
);
}
void
OnCollisionEnter2D
(
Collision2D
c
){
Destroy
(
this
.
gameObject
);
}
}
Assets/Scripts/FireballProjectile.cs.meta
0 → 100644
View file @
b179b448
fileFormatVersion: 2
guid: 72a2310fc34324288bd211ed6e4ca008
timeCreated: 1478834992
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Assets/Scripts/MenuActions.cs
0 → 100644
View file @
b179b448
using
UnityEngine
;
using
System.Collections
;
public
class
MenuActions
:
MonoBehaviour
{
public
string
levelName
=
"player_animation_test"
;
public
void
NewGame
(){
Application
.
LoadLevel
(
levelName
);
}
public
void
LoadGame
(){
Application
.
LoadLevel
(
levelName
);
}
public
void
QuitGame
(){
Application
.
Quit
();
}
}
Assets/Scripts/MenuActions.cs.meta
0 → 100644
View file @
b179b448
fileFormatVersion: 2
guid: ee297bebcf01cc54c91c6680e27c1943
timeCreated: 1478831417
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Assets/Scripts/RandomSprite.cs
0 → 100644
View file @
b179b448
using
UnityEngine
;
using
System.Collections
;
public
class
RandomSprite
:
MonoBehaviour
{
public
Sprite
[]
tiles
;
// Use this for initialization
void
Start
()
{
GetComponent
<
SpriteRenderer
>().
sprite
=
tiles
[
Random
.
Range
(
0
,
tiles
.
Length
)];
}
}
Assets/Scripts/RandomSprite.cs.meta
0 → 100644
View file @
b179b448
fileFormatVersion: 2
guid: 19ce3dd12dc0bee4492ca01b39754add
timeCreated: 1478220172
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Assets/Scripts/WalkParticles.cs
0 → 100644
View file @
b179b448
using
UnityEngine
;
using
System.Collections
;
public
class
WalkParticles
:
MonoBehaviour
{
private
ParticleSystem
ps
;
private
ParticleSystem
.
EmissionModule
module
;
private
HeroMobility
hm
;
public
float
speedThreshold
=
0.001f
;
// Use this for initialization
void
Start
()
{
ps
=
GetComponentInChildren
<
ParticleSystem
>();
module
=
ps
.
emission
;
hm
=
GetComponent
<
HeroMobility
>();
}
// Update is called once per frame
void
LateUpdate
()
{
if
(
hm
.
deltaPos
.
sqrMagnitude
>
speedThreshold
)
{
if
(!
ps
.
isPlaying
)
{
ps
.
Simulate
(
0.0f
,
true
,
false
);
module
.
enabled
=
true
;
ps
.
Play
();
}
}
else
{
if
(
ps
.
isPlaying
)
{
module
.
enabled
=
false
;
ps
.
Stop
();
}
}
}
}
Assets/Scripts/WalkParticles.cs.meta
0 → 100644
View file @
b179b448
fileFormatVersion: 2
guid: c02d1600d235a814fa07fba8e5b0289f
timeCreated: 1477012137
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Assets/Scripts/WaterShield.cs
0 → 100644
View file @
b179b448
using
UnityEngine
;
using
System.Collections
;
public
class
WaterShield
:
MonoBehaviour
{
private
float
timerOfShield
=
0.0f
;
public
float
durationOfShield
=
2.0f
;
public
GameObject
projectilePrefab
;
public
int
projectileSpeed
=
5
;
public
int
numberOfProjectiles
=
5
;
private
GameObject
player
;
[
HideInInspector
]
public
Vector2
playerDirection
;
void
Start
()
{
player
=
GameObject
.
FindGameObjectWithTag
(
"Player"
);
}
void
Update
()
{
playerDirection
=
player
.
GetComponent
<
Actions
>().
GetLastDirection
();
transform
.
position
=
player
.
transform
.
position
;
timerOfShield
+=
Time
.
deltaTime
;
if
(
timerOfShield
>=
durationOfShield
)
{
Explode
();
Destroy
(
this
.
gameObject
);
}
}
void
Explode
()
{
for
(
int
i
=
0
;
i
<
numberOfProjectiles
;
i
++)
{
GameObject
waterShieldProjectile
=
(
GameObject
)
Instantiate
(
projectilePrefab
,
transform
.
position
,
Quaternion
.
identity
);
waterShieldProjectile
.
GetComponent
<
WaterShieldProjectile
>().
direction
=
Rotate
(
playerDirection
,
20
-
(
i
*
10
));
waterShieldProjectile
.
GetComponent
<
WaterShieldProjectile
>().
speed
=
projectileSpeed
;
}
}
public
Vector2
Rotate
(
Vector2
v
,
float
degrees
)
{
float
sin
=
Mathf
.
Sin
(
degrees
*
Mathf
.
Deg2Rad
);
float
cos
=
Mathf
.
Cos
(
degrees
*
Mathf
.
Deg2Rad
);
float
tx
=
v
.
x
;
float
ty
=
v
.
y
;
v
.
x
=
(
cos
*
tx
)
-
(
sin
*
ty
);
v
.
y
=
(
sin
*
tx
)
+
(
cos
*
ty
);
return
v
;
}
}
Assets/Scripts/WaterShield.cs.meta
0 → 100644
View file @
b179b448
fileFormatVersion: 2
guid: 1978d911fc9b14ab4939f59a8c10d901
timeCreated: 1477009011
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Assets/Scripts/WaterShieldProjectile.cs
0 → 100644
View file @
b179b448
using
UnityEngine
;
using
System.Collections
;
public
class
WaterShieldProjectile
:
MonoBehaviour
{
[
HideInInspector
]
public
float
speed
;
private
Rigidbody2D
rb
;
[
HideInInspector
]
public
Vector2
direction
;
void
Start
()
{
rb
=
GetComponent
<
Rigidbody2D
>();
rb
.
velocity
=
(
direction
*
speed
);
}
void
OnCollisionEnter2D
(
Collision2D
c
){
Destroy
(
this
.
gameObject
);
}
}
Assets/Scripts/WaterShieldProjectile.cs.meta
0 → 100644
View file @
b179b448
fileFormatVersion: 2
guid: 46b11dc52679b4ddab143bfb8fb3e812
timeCreated: 1478844869
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Prev
1
2
Next
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