This repository has been archived by the owner on Dec 24, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShipWeapon.boo
117 lines (100 loc) · 3.55 KB
/
ShipWeapon.boo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import UnityEngine
class ShipWeapon(MonoBehaviour):
# laser
public laser as GameObject
public laserSoundEnabled = true
public laserSound as AudioClip
private laserSpeed = 200.0f
private maxLaserFire = 5
private laserTimer = 0.0
private laserCoolDown = 3.0
# missile
public missile as GameObject
public missileAmmo as single
public missileLaunchSound as AudioClip
public emptyClipSound as AudioClip
public maxMissileAmmo = 40
public startMissileCount = 15
private missileSpeed = 120.0f
# nuke
public nuke as GameObject
public nukeAmmo as single
public nukeLaunched = false
public nukeLaunchSound as AudioClip
public nukeExplSound as AudioClip
public maxNukeAmmo = 15
public startNukeCount = 5
private nukeSpeed = 50.0f
def Start():
missileAmmo = startMissileCount
nukeAmmo = startNukeCount
GetComponent[of AudioSource]().clip = laserSound
GetComponent[of AudioSource]().rolloffMode = AudioRolloffMode.Linear
GetComponent[of AudioSource]().volume = 0.25
def Update():
if Input.GetKeyDown("space"):
FireLaser()
if Input.GetKeyDown("m"):
FireMissile()
if Input.GetKeyDown("n"):
FireNuke()
// To keep track of live nukes, since the same key
// is used to launch AND to detonate nukes.
// On detonation, nukes are tagged as "Untagged".
if len(GameObject.FindGameObjectsWithTag("nuke")) == 0: nukeLaunched = false
else: nukeLaunched = true
def FireLaser():
if laserSoundEnabled == false:
GetComponent[of AudioSource]().clip = laserSound
laserSoundEnabled = true
GetComponent[of AudioSource]().volume = 0.25
i = 0
while i < maxLaserFire:
lShot = Instantiate(laser, transform.position + Vector3(2*i,0,0), Quaternion.identity) as GameObject
lShot.transform.Rotate(0,0,90)
lShot.GetComponent[of Rigidbody]().velocity = Vector3.right * laserSpeed
i += 1
GetComponent[of AudioSource]().Play()
def FireMissile():
if missileAmmo > 0:
GetComponent[of AudioSource]().clip = missileLaunchSound
laserSoundEnabled = false
GetComponent[of AudioSource]().volume = 0.5
mShot = Instantiate(missile, transform.position, Quaternion.identity) as GameObject
mShot.transform.Rotate(0,0,90)
mShot.GetComponent[of Rigidbody]().velocity = Vector3.right * missileSpeed
missileAmmo -= 1
GetComponent[of AudioSource]().Play()
else:
GetComponent[of AudioSource]().clip = emptyClipSound
laserSoundEnabled = false
GetComponent[of AudioSource]().volume = 0.1
GetComponent[of AudioSource]().Play()
def FireNuke():
if nukeLaunched == false:
if nukeAmmo > 0:
nShot = Instantiate(nuke, transform.position, Quaternion.identity) as GameObject
nShot.GetComponent[of Rigidbody]().velocity = Vector3.right * nukeSpeed
nukeAmmo -= 1
Ship.playerScore += 5
laserSoundEnabled = false
GetComponent[of AudioSource]().clip = nukeLaunchSound
GetComponent[of AudioSource]().Play()
else:
laserSoundEnabled = false
GetComponent[of AudioSource]().clip = emptyClipSound
GetComponent[of AudioSource]().volume = 0.1
GetComponent[of AudioSource]().Play()
else:
curNuke = GameObject.FindGameObjectWithTag("nuke")
curNukeScript as NukeTrigger = curNuke.GetComponent[of NukeTrigger]()
curNukeScript.detonate = true
laserSoundEnabled = false
GetComponent[of AudioSource]().clip = nukeExplSound
GetComponent[of AudioSource]().volume = 1.0
GetComponent[of AudioSource]().Play()
def OnGUI():
GUI.Label(Rect(10,35,60,20), "Missiles:")
GUI.Label(Rect(75,35,20,20), missileAmmo.ToString())
GUI.Label(Rect(10,60,60,20), "Nukes:")
GUI.Label(Rect(75,60,20,20), nukeAmmo.ToString())