Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* This script is licensed under the BSD license.
- Author: Cody Dostal
- Author Email: allysman21@gmail.com
- The License: http://seafiresoftware.org/wordpress/our-bsd/
- Date Written: 4/22/2012
- Engine Version: 3.5.1f2
- Script Version: v1.1
- */
- /* NOTE: With good chance, you may have to change any hard-coded values in these scripts.
- These values work with my version, and may not with your version. */
- /* In Boo, // == one line comment, # = one line comment, and "/(star)" to "(star)/"
- is a multiline comment.*/
- // Import is the C# equivalent to using, I don't think UnityScript requires any for of imports.
- import UnityEngine
- import System.Collections
- class player (MonoBehaviour):
- /* When setting up variables in Boo, it's alters slightly from C# and from UnityScript. Here are examples:
- In C# you would type: public single variableName
- In UnityScript, you would type: public var variableName
- In Boo, there are actually two ways:
- Way 1: public variableName as single = value
- Way 2: public variableName = value
- If you use way two, it will automatically detect the type. I used Way 1 purely to look similar to 3DBuzz's C# tutorial
- */
- // Setting *GENERAL* Floats. x.xF makes a float
- public flySpeed as single = 0.0F
- private projectileOffset as single = 1.3F
- public slowFlySpeed as single = 0.0F
- public fastFlySpeed as single = 0.0F
- // Setting *GENERAL* Game Objects
- public projPrefab as GameObject
- public explosionPrefab as GameObject
- // Sertting *GENERAL* Integers
- public static score as int = 0
- public static lives as int = 3
- public static missed as int = 0
- private static scoreSub as int = 100
- // Special Spawn. Invincible + Slide on Screen
- private maxBlinkAmt as int = 10
- private curBlinkAmt as int = 0
- private shipInvTime as single = 1.5f
- private shipMoveOnScreenSpeed as single = 3f
- private blinkRate as single = .1f
- private gamePaused = false
- /* Setting up an enum. Kindof like a variable type made by you.
- You set up the type (state in this instance). Kindof like
- int and single. */
- enum state:
- Playing
- Explosion
- Invincible
- /* Setting default state to Playing */
- PlayerState as state = state.Playing
- // Setting up the Menu
- private buttonLocH as single = 35
- private buttonLocV as single = 5
- private labelLocH as int = 30
- private labelLocV as int = 85
- def Start():
- /* StartCoroutine makes the SlideUpInvicible run as an enumerator. An enumerator type (for sections in THIS case)
- allows a portion of the script to be pause while waiting for something. For example, yield WaitForSeconds(time)
- will let the script keep running until the specified time has passed. VERY useful in games especially, moreso than
- many other kinds of scripting/coding.
- */
- StartCoroutine(SlideUpInvincible())
- def SlideUpInvincible() as IEnumerator:
- /* For as long as the ship position is below -5.65 on the Y-axis (remember, the "f" (or "F") designates float,
- I'm finicky on capitalization.)*/
- while transform.position.y < -5.65f:
- // Slide the ship up slowly
- // Info on time.deltaTime: http://unity3d.com/support/documentation/ScriptReference/Time-deltaTime.html
- amtToMove as single = shipMoveOnScreenSpeed * Time.deltaTime
- transform.position = Vector3(0f, transform.position.y + amtToMove, transform.position.z)
- // Return 0, or false. Just makes it keep running.
- yield 0
- // Makes the player INVINCIBLE!!!!!1!!!!one!!
- PlayerState = state.Invincible
- // If the variable curBlinkAmt is below maxBlinkAmt
- while curBlinkAmt < maxBlinkAmt:
- // Alternate between viewable and non-viewable
- gameObject.renderer.enabled = not gameObject.renderer.enabled
- // For each time the ship is viewable.
- if gameObject.renderer.enabled == true:
- // Increase curBlinkAmt by 1
- curBlinkAmt++
- // Wait for (blinkrate)
- yield WaitForSeconds(blinkRate)
- // Set player to Play mode
- PlayerState = state.Playing
- // Set curBlinkAmt to 0, so it will work the next time we use this script.
- curBlinkAmt = 0
- // def is the c# equivalent of void (for the *MOST* part. Functionally, in Unity, it's the same.)
- def Update ():
- /* If (somehow) the score variable/amount gets below 0
- Reset to 0.*/
- if score < 0:
- score = 0
- if PlayerState != state.Explosion:
- // Getting the Axis. "GetAxisRaw" get an old-arcade feel, abrupt end, not smooth
- // Time.deltaTime = 1s (in basis. Remove it, and you *FLY* FAST!)
- amtToMove = Input.GetAxisRaw("Horizontal") * flySpeed * Time.deltaTime
- amtToMoveV = Input.GetAxisRaw("Vertical") * flySpeed * Time.deltaTime
- transform.Translate(Vector3.right * amtToMove)
- transform.Translate(Vector3.up * amtToMoveV)
- // Faster Speed. Hold Shift calls it. It ADDS to flySpeed
- if Input.GetKey(KeyCode.LeftShift):
- fAmtToMove = Input.GetAxisRaw("Horizontal") * fastFlySpeed * Time.deltaTime
- fAmtToMoveV = Input.GetAxisRaw("Vertical") * fastFlySpeed * Time.deltaTime
- transform.Translate(Vector3.right * fAmtToMove)
- transform.Translate(Vector3.up * fAmtToMoveV)
- // Slower Speed. Hold LEFT Control calls it. It ADDS to flySpeed
- if Input.GetKey(KeyCode.LeftControl):
- sAmtToMove = Input.GetAxisRaw("Horizontal") * slowFlySpeed * Time.deltaTime
- sAmtToMoveV = Input.GetAxisRaw("Vertical") * slowFlySpeed * Time.deltaTime
- transform.Translate(Vector3.right * sAmtToMove)
- transform.Translate(Vector3.up * sAmtToMoveV)
- // Setting position for the projectile
- position as Vector3 = Vector3(transform.position.x, projectileOffset + transform.position.y, transform.position.z)
- // Setting the keys you can push/click to actually shoot. Instantiate = Create
- if Input.GetKeyDown(KeyCode.Space):
- Instantiate(projPrefab, position, Quaternion.identity)
- elif Input.GetKeyDown(KeyCode.RightControl):
- Instantiate(projPrefab, position, Quaternion.identity)
- // The 0 in GetMouseButtonDown, in this case, does NOT mean false. It means Left Mouse Button.
- if Input.GetMouseButtonDown(0):
- Instantiate(projPrefab, position, Quaternion.identity)
- if Input.GetKeyDown(KeyCode.Escape):
- if gamePaused == false:
- Time.timeScale = 0
- gamePaused = true
- elif gamePaused == true:
- Time.timeScale = 1
- gamePaused = false
- /* Screen Wrap. Without this, you will fly FOREVER to the Left or the right. Will not wrap to other side.
- Also handles stopping from flying up/down out of screen. ORTHOGRAPHIC VIEWPOINT ONLY (since, techincally, we don't use the Z-axis)
- */
- if transform.position.x <= -7.3:
- transform.position = Vector3(7.3, transform.position.y, transform.position.z)
- elif transform.position.x >= 7.3:
- transform.position = Vector3(-7.3, transform.position.y, transform.position.z)
- elif transform.position.y >= 1.5:
- transform.position = Vector3(transform.position.x, 1.5, transform.position.z)
- elif transform.position.y <= -5.65:
- transform.position = Vector3(transform.position.x, -5.65, transform.position.z)
- // End of Screen Wrap
- // Setting up the GUI, or "HUD" in the Game.
- def OnGUI():
- GUI.Label(Rect(10, 10, 120, 20), "Score: " + player.score.ToString())
- GUI.Label(Rect(10, 30, 60, 20), "Lives: " + player.lives.ToString())
- GUI.Label(Rect(10, 50, 60, 20), "Missed: " + player.missed.ToString())
- if gamePaused == false:
- pass
- elif gamePaused == true:
- GUI.Label(Rect(Screen.width / 2 - labelLocH, Screen.width / 2 - labelLocV, 60, 30), "PAUSED.")
- if GUI.Button(Rect(Screen.width / 2 - buttonLocH, Screen.height / 2 - buttonLocV, 70, 35), "Resume"):
- Time.timeScale = 1
- gamePaused = false
- def OnTriggerEnter(thisObject as Collider):
- if thisObject.tag != "bullet":
- if PlayerState == state.Playing:
- player.lives--
- StartCoroutine(DestroyShip())
- def DestroyShip() as IEnumerator:
- // Change the player state to Explosion
- PlayerState = state.Explosion
- /* Set up the explosion position to last player location
- and Instantiate(Create) the explosion */
- exploPos = Vector3(transform.position.x, transform.position.y, transform.position.z)
- Instantiate(explosionPrefab, exploPos, Quaternion.identity)
- /* Hide the ship
- Move to just off screen
- Wait for a short amount of time */
- gameObject.renderer.enabled = false
- transform.position = Vector3(0f, -7.68, transform.position.z)
- yield WaitForSeconds(shipInvTime)
- if player.lives > 0:
- // Turn the ship to visible again
- gameObject.renderer.enabled = true
- // Decrement score by 300, only if score is greater than 0
- if score > 0:
- score = score - 300
- elif score < 0:
- score = 0
- while transform.position.y < -5.65:
- // Slide the ship up slowly
- amtToMove as single = shipMoveOnScreenSpeed * Time.deltaTime
- transform.position = Vector3(0f, transform.position.y + amtToMove, transform.position.z)
- yield 0
- // Change the player to Invincible
- PlayerState = state.Invincible
- while curBlinkAmt < maxBlinkAmt:
- /* Each time the script returns to begining,
- it will turn it on and off */
- gameObject.renderer.enabled = not gameObject.renderer.enabled
- // Each time the ship is visible, turn curBlinkAmt up
- if gameObject.renderer.enabled == true:
- curBlinkAmt++
- yield WaitForSeconds(blinkRate)
- PlayerState = state.Playing
- // Set curBlinkAmt back to 0 so it will work next time around.
- curBlinkAmt = 0
- else:
- // If lives = 0, destory ship and load lose screen.
- Destroy(gameObject)
- Application.LoadLevel(2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement