Advertisement
Guest User

Untitled

a guest
Mar 4th, 2015
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.80 KB | None | 0 0
  1. #pragma strict
  2. import System.IO;
  3. import System.IO.Directory;
  4. import System;
  5.  
  6. //Config Mundo
  7. private var MenuInicialAux : MenuInicial;
  8.  
  9. //HUD's
  10. static var HUD : boolean = true;
  11. var TexturaMenu : Texture;
  12. var TexturaVida : Texture;
  13. var TexturaEstamina : Texture;
  14. var TexturaFundo : Texture;
  15.  
  16. private var ArmaAux: BancoDadosItens;
  17. private var SistemaInventario : Inventario;
  18. var Mouser : boolean;
  19.  
  20. //Estatísticas
  21. static var frameCount : float = 0;
  22. static var deltaTimee : float = 0.0f;
  23. static var fps : float = 0.0f;
  24. static var updateRate : float = 4.0f;
  25.  
  26. //Desligar Funçoes
  27. private var DesativarFuncoes : boolean;
  28. private var PlayerAndar = true;
  29.  
  30. //Menu Pausa
  31. private var VerificarSaves : Salvamentos ;
  32. private var qualities = QualitySettings.names; //Qualidades
  33. private var DistanciaPlayer : float; //Otimizaçao
  34. var _OBJETOS : GameObject[]; //Otimizaçao
  35. private var Estatisticas : boolean;
  36. var Sons : AudioClip[]; //Som
  37. private var Render : float = 200;
  38. private var shadows: LightShadows;
  39. private var graficos = false;
  40. private var video = false;
  41. private var jogabilidadeconf = false;
  42. private var FOVConf : float = 50;
  43. private var AntiAliasingConf : float;
  44. static var volumeconf : float = 1.0;
  45. private var SombraON = false;
  46. private var SombraOFF= false;
  47. private var _fullscreen = true;
  48. private var RectWindow : Rect;
  49. private var MouseLookCamera : MouseLook;
  50. private var MouseLook : MouseLook;
  51. private var Sensibilidade : float = 10;
  52. //Config.
  53.  
  54.  
  55. var GUISkinPausa : GUISkin;
  56.  
  57. var controlePause: boolean;
  58.  
  59. //Controles do Player
  60. var Sangue : GameObject;
  61.  
  62. static var Animacao : int;
  63.  
  64. private var DanoArma : BancoDadosItens;
  65. private var DanoAux : FPSInputController;
  66.  
  67. private var LarguraSede : float;
  68. private var LarguraFome : float;
  69. private var LarguraVida : float;
  70. private var LarguraEstamina : float;
  71. private var LarguraFundoVida : float;
  72. private var LarguraFundoFome : float;
  73. private var LarguraFundoSede : float;
  74.  
  75. private var dano : float; //Dano
  76.  
  77. private var FomeTaxa : float; //Taxa de Fome
  78. private var SedeTaxa : float; //Taxa de Sede
  79.  
  80. static var Fome : float; //Fome
  81. static var Sede : float; //Sede
  82. static var Vida : float = 100; //Vida
  83. static var Estamina : float = 100; //Estamina
  84.  
  85. private var PerderVida : boolean; //Vida
  86. private var RecarregarEstamina : boolean;
  87. private var Correr : boolean = true;
  88.  
  89. var Cast : RaycastHit;
  90. var CastCalc : RaycastHit; //Calcular dano da queda
  91.  
  92. public var Player : CharacterController;
  93. private var motor : CharacterMotor;
  94.  
  95. public var Correndo : float;
  96. private var Andar : float;
  97.  
  98. private var i : int;
  99.  
  100. var OBJETOS : GameObject;
  101.  
  102. function SedeFome(TaxaFome : float,TaxaSede: float){
  103. if(Fome<100){
  104. Fome+=TaxaFome;
  105. }
  106.  
  107. if(Sede<100){
  108. Sede+=TaxaSede;
  109. }
  110. }
  111.  
  112. function OnCollisionEnter(collision: Collision){
  113. DanoAux = collision.transform.GetComponent("FPSInputController");
  114.  
  115. if (DanoAux.Animacao==1)
  116. {
  117. //Vida -= DanoArma.Dano;
  118. }
  119. }
  120.  
  121. function Start(){
  122. VerificarSaves = transform.GetComponent("Salvamentos");
  123. VerificarSaves.Saves();
  124. RectWindow = Rect (Screen.width / 2- Screen.width / 2.2, Screen.height / 2-Screen.height / 2.2, Screen.width / 1.1, Screen.height / 1.1);
  125.  
  126. //Pegar Inf sobre o player
  127. if (PlayerPrefs.HasKey ("Sensibilidade")) {
  128. Sensibilidade = PlayerPrefs.GetFloat ("Sensibilidade");
  129. } else {
  130. PlayerPrefs.SetFloat ("Sensibilidade", Sensibilidade);
  131. }
  132.  
  133. if (PlayerPrefs.HasKey ("AntiAliasingConf")) {
  134. AntiAliasingConf = PlayerPrefs.GetFloat ("AntiAliasingConf");
  135. } else {
  136. PlayerPrefs.SetFloat ("AntiAliasingConf", AntiAliasingConf);
  137. }
  138.  
  139. if (PlayerPrefs.HasKey ("Render")) {
  140. Render = PlayerPrefs.GetFloat ("Render");
  141. } else {
  142. PlayerPrefs.SetFloat ("Render", Render);
  143. }
  144.  
  145. if (PlayerPrefs.HasKey ("FOVConf")) {
  146. FOVConf = PlayerPrefs.GetFloat ("FOVConf");
  147. } else {
  148. PlayerPrefs.SetFloat ("FOVConf", FOVConf);
  149. }
  150.  
  151. if (PlayerPrefs.HasKey ("volumeconf")) {
  152. volumeconf = PlayerPrefs.GetFloat ("volumeconf");
  153. } else {
  154. PlayerPrefs.SetFloat ("volumeconf", volumeconf);
  155. }
  156. // OBJETOS = GameObject.FindGameObjectWithTag("Terrain");
  157. // var Objetos = OBJETOS.GetComponentsInChildren(GameObject)as GameObject[];
  158. // for(var Filhos : GameObject[] in Objetos){
  159. //_OBJETOS = Filhos;
  160. // }
  161. _OBJETOS = GameObject.FindGameObjectsWithTag("Arvore");
  162. SistemaInventario = transform.GetComponent("Inventario");
  163. MouseLookCamera = transform.FindChild("Main Camera").GetComponent("MouseLook");
  164. MouseLook = transform.GetComponent("MouseLook");
  165.  
  166. controlePause = true;
  167. Time.timeScale = 1;
  168.  
  169. }
  170.  
  171.  
  172. function Awake () {
  173. motor = GetComponent(CharacterMotor);
  174. Andar = motor.movement.maxForwardSpeed;
  175. }
  176.  
  177. function Update (){
  178.  
  179.  
  180. //Inputs(Clicks)
  181. if(!GetComponent.<Animation>().isPlaying){
  182. if(Input.GetAxis("Vertical")==0){
  183. Animacao = 0;
  184. }else{
  185. Animacao = 1;
  186. }
  187. }
  188. if(Input.GetMouseButtonDown(0)){
  189. Animacao = 2;
  190.  
  191. }
  192. if(Input.GetKeyDown(KeyCode.F1))
  193. HUD = !HUD;
  194.  
  195. if(Input.GetKeyDown(KeyCode.F3)){ //Mostrar Estatisticas
  196. Estatisticas = !Estatisticas;
  197. }
  198.  
  199. if(Input.GetKeyDown("j") && controlePause){ //Quando clicar J vai sumir o cursor do mouse
  200. Mouser = !Mouser;
  201. DesativarFuncoes = !DesativarFuncoes;
  202. MouseLook.ControleMouse = !MouseLook.ControleMouse;
  203. }
  204. if(Mouser){
  205. Cursor.visible = true;
  206. Screen.lockCursor = false;
  207. }else{
  208. Cursor.visible = false;
  209. Screen.lockCursor = true;
  210. }
  211.  
  212. if(Mouser){
  213. Cursor.visible = true;
  214. }else{
  215. Cursor.visible = false;
  216. }
  217.  
  218. if(Estatisticas){ //Estatisticas
  219. frameCount++;
  220. deltaTimee += Time.deltaTime;
  221. if (deltaTimee > 1.0f/updateRate){
  222. fps = frameCount / deltaTimee ;
  223. frameCount = 0;
  224. deltaTimee -= 1.0f/updateRate;
  225. }
  226. }
  227.  
  228. if(DesativarFuncoes){
  229. PlayerAndar = false;
  230. }else{
  231. PlayerAndar = true;
  232. }
  233.  
  234. if(Input.GetKeyDown(KeyCode.Escape) && !SistemaInventario.ExibeMenu) //Exibir menu
  235. {
  236. Mouser = !Mouser;
  237. if (controlePause)
  238. {
  239. MouseLookCamera.ControleMouse=false;
  240. HUD = false;
  241. Time.timeScale = 0;
  242. controlePause = false;
  243. }
  244. else
  245. {
  246. PlayerPrefs.SetFloat ("Sensibilidade", Sensibilidade);
  247. PlayerPrefs.SetFloat ("volumeconf", volumeconf);
  248. PlayerPrefs.SetFloat ("FOVConf", FOVConf);
  249. PlayerPrefs.SetFloat ("Render", Render);
  250. PlayerPrefs.SetFloat ("AntiAliasingConf", AntiAliasingConf);
  251.  
  252. MouseLookCamera.ControleMouse=true;
  253. HUD = true;
  254. Time.timeScale = 1;
  255. controlePause = true;
  256. }
  257.  
  258. }
  259. }
  260.  
  261. function FixedUpdate () {
  262.  
  263.  
  264. for(var i = 0;i<_OBJETOS.Length;i++){ //Rendenizaçao
  265. if ( Vector3.Distance(transform.position, _OBJETOS[i].transform.position) >= Render) {
  266. _OBJETOS [i].active = false;
  267. }else{
  268. _OBJETOS[i].active = true;
  269. }
  270. }
  271. if(_fullscreen)
  272. Screen.fullScreen = true;
  273. else
  274. Screen.fullScreen = false;
  275.  
  276. //Fome & Sede
  277. SedeTaxa = (0.01*Time.deltaTime/24/5)*100;
  278. FomeTaxa = (0.01*Time.deltaTime/24/10)*100;
  279. SedeFome(SedeTaxa,FomeTaxa);
  280.  
  281.  
  282.  
  283. //Configuraçao para o menu
  284. MouseLookCamera.sensitivityY = Sensibilidade;
  285. MouseLook.sensitivityX = Sensibilidade;
  286. AudioListener.volume = volumeconf;
  287. Camera.main.fieldOfView = FOVConf;
  288. QualitySettings.antiAliasing = AntiAliasingConf;
  289.  
  290. LarguraFome =Screen.width/4 - (Fome/100);
  291. LarguraFundoFome = Screen.width/4 * (Fome/100);
  292.  
  293. LarguraSede =Screen.width/4 - (Sede/100);
  294. LarguraFundoSede = Screen.width/4 * (Sede/100);
  295.  
  296. LarguraVida = Screen.width/4 * (Vida/100) ;
  297. LarguraFundoVida = Screen.width/4 - (Vida/100);
  298.  
  299. LarguraEstamina = Screen.width/4 * (Estamina/100) ;
  300.  
  301. //Dano de Queda
  302. if(Player.collisionFlags == CollisionFlags.None){
  303. if(!Physics.Raycast(transform.position , -transform.up,Cast, 5) && !PerderVida){
  304.  
  305. //calculando dano de queda:
  306. if(Physics.Raycast(transform.position , -transform.up,CastCalc)){
  307. if(!PerderVida){
  308. var disCalc = Vector3.Distance(transform.position, CastCalc.point);
  309. dano = disCalc;
  310. PerderVida = true;
  311.  
  312.  
  313. }
  314. }
  315. //--
  316. }
  317. }
  318. if(PlayerAndar){
  319. Movimento();
  320. }
  321.  
  322. if(Player.isGrounded){
  323. if(PerderVida){
  324. Vida = Vida - dano;dano = 0;
  325. Instantiate(Sangue,transform.position,transform.rotation);
  326. }
  327. PerderVida = false;
  328. }
  329.  
  330. }
  331.  
  332. function Movimento(){
  333. //Animaçoes
  334. if(Animacao == 0)
  335. //animation.CrossFade("Parado");
  336. if(Animacao == 1)
  337. //animation.CrossFade("Andando");
  338. if(Animacao == 2){
  339. //animation.Play("Ataque");
  340. Animacao =-1;
  341. }
  342.  
  343. //Andar
  344. var directionVector = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
  345.  
  346. if (directionVector != Vector3.zero) {
  347. var directionLength = directionVector.magnitude;
  348. directionVector = directionVector / directionLength;
  349.  
  350. directionLength = Mathf.Min(1, directionLength);
  351.  
  352. directionLength = directionLength * directionLength;
  353.  
  354. directionVector = directionVector * directionLength;
  355. }
  356.  
  357. // Direçoes
  358. motor.inputMoveDirection = transform.rotation * directionVector;
  359. motor.inputJump = Input.GetButton("Jump");
  360. if(Estamina <= 0){
  361. Correr = false;
  362. }else{
  363. Correr = true;
  364. }
  365. if(Estamina >= 100){
  366. RecarregarEstamina = false;
  367. }else{
  368. RecarregarEstamina = true;
  369. }
  370. //Correr
  371.  
  372. if(Input.GetKey(KeyCode.LeftShift)&& Correr){
  373. Estamina -= 10*Time.deltaTime;
  374. motor.movement.maxForwardSpeed = Correndo;
  375. motor.movement.maxBackwardsSpeed = Correndo;
  376. motor.movement.maxSidewaysSpeed = Correndo;
  377. }
  378. else {
  379. if(RecarregarEstamina){
  380. Estamina += Time.deltaTime * 1;
  381. }
  382. motor.movement.maxForwardSpeed = Andar;
  383. motor.movement.maxBackwardsSpeed = Andar;
  384. motor.movement.maxSidewaysSpeed = Andar;
  385. }
  386. }
  387.  
  388. function OnGUI(){
  389. if(!controlePause){
  390. GUI.Box(Rect(0,0,Screen.width,Screen.height),"Last Survivor");
  391. GUI.skin = GUISkinPausa;
  392. RectWindow = GUI.Window (0, RectWindow, JanelaPausa, "");
  393. }
  394.  
  395. if(Estatisticas){
  396. GUI.Label (new Rect (Screen.width/2-Screen.width/2.05f, Screen.height/2-Screen.height/5.05f, Screen.width/5, Screen.height/12), "Z : " +transform.position.z); //Posicao do Z
  397. GUI.Label (new Rect (Screen.width/2-Screen.width/2.05f, Screen.height/2-Screen.height/4.05f, Screen.width/5, Screen.height/12), "Y : " +transform.position.y); //Posicao do Y
  398. GUI.Label (new Rect (Screen.width/2-Screen.width/2.05f, Screen.height/2-Screen.height/3.3f, Screen.width/5, Screen.height/12), "X : " +transform.position.x);//Posicao do X
  399. GUI.Label (new Rect (Screen.width/2-Screen.width/2.05f, Screen.height/2-Screen.height/2.05f, Screen.width/6, Screen.height/12), "FPS: " +Mathf.RoundToInt(fps + 4));//FPS
  400. }
  401.  
  402. if(HUD){ //HUD-IU
  403. GUI.DrawTexture(Rect(0,Screen.height - 45,LarguraFome,15),TexturaVida); //Textura Fome
  404. GUI.DrawTexture(Rect(0,Screen.height - 45,LarguraFundoFome,15),TexturaFundo); //Fundo Vida
  405.  
  406. GUI.DrawTexture(Rect(0,Screen.height - 30,LarguraSede,15),TexturaVida); //Textura Sede
  407. GUI.DrawTexture(Rect(0,Screen.height - 30,LarguraFundoSede,15),TexturaFundo); //Fundo Sede
  408.  
  409. GUI.DrawTexture(Rect(0,Screen.height - 15,LarguraVida,15),TexturaVida); //Textura Vida
  410. GUI.DrawTexture(Rect(0,Screen.height - 15,LarguraFundoVida,15),TexturaFundo); //Fundo Vida
  411.  
  412. GUI.DrawTexture(Rect(0,Screen.height - 50,LarguraEstamina,5),TexturaEstamina); //Textura Estamina
  413. }
  414.  
  415. }
  416.  
  417. function JanelaPausa (windowID : int) {
  418.  
  419. if(!video && !jogabilidadeconf){
  420. }
  421. //Inicio Menu Pausa
  422. if (GUI.Button(Rect(Screen.height/5,Screen.height/30,100,50),"Video"))
  423. {
  424. GetComponent.<AudioSource>().clip = Sons[0];
  425. GetComponent.<AudioSource>().Play();
  426. video = true;
  427. jogabilidadeconf = false;
  428.  
  429. }
  430. if (GUI.Button(Rect(Screen.height-2,Screen.height/30,200,50),"Jogabilidade/Audio"))
  431. {
  432. GetComponent.<AudioSource>().clip = Sons[0];
  433. GetComponent.<AudioSource>().Play();
  434. jogabilidadeconf = true;
  435. video = false;
  436. }
  437. if (GUI.Button(Rect(Screen.height/1.5,Screen.height/30,100,50),"Sair"))
  438. {
  439. GetComponent.<AudioSource>().clip = Sons[0];
  440. GetComponent.<AudioSource>().Play();
  441. VerificarSaves.Salvar();
  442. MouseLookCamera.ControleMouse = true;
  443. Application.LoadLevel("Menu Inicial");
  444. }
  445.  
  446. if(video){
  447. //if (GUI.Button(Rect(Screen.width/50+1000,Screen.height-500,100,50),"640x480"))
  448. //Screen.SetResolution(640,480,FullScreenAux != !FullScreenAux);
  449.  
  450. //if (GUI.Button(Rect(Screen.width/50+1000,Screen.height-450,100,50),"800x600"))
  451. //Screen.SetResolution(800,600,FullScreenAux != !FullScreenAux);
  452.  
  453. //if (GUI.Button(Rect(Screen.width/50+1000,Screen.height-400,110,50),"1024x640"))
  454. //Screen.SetResolution(1024,640,FullScreenAux != !FullScreenAux);
  455.  
  456. //if (GUI.Button(Rect(Screen.width/50+1000,Screen.height-350,110,50),"1280x720"))
  457. //Screen.SetResolution(1280,720,FullScreenAux != !FullScreenAux);
  458.  
  459. //if (GUI.Button(Rect(Screen.width/50+1000,Screen.height-300,110,50),"1280x800"))
  460. //Screen.SetResolution(1280,800,FullScreenAux != !FullScreenAux);
  461.  
  462. GUILayout.BeginVertical ();
  463. for (var i = 0; i < qualities.Length; i++){
  464. if (GUI.Button(Rect(Screen.width/15 - 50, Screen.height-350 - 200 + i * 35, 120, 30), qualities[i]))
  465. QualitySettings.SetQualityLevel (i, true);
  466. }
  467.  
  468. GUI.Label(Rect(Screen.width/31,Screen.height-125,100,20),"Anti Aliasing");
  469. AntiAliasingConf = GUI.HorizontalScrollbar(Rect(Screen.width/35,Screen.height-100,100,100), AntiAliasingConf, 0.8,0,8);
  470.  
  471. GUI.Label(Rect(Screen.width/31,Screen.height-175,100,20),"Rendenizaçao");
  472. Render = GUI.HorizontalScrollbar(Rect(Screen.width/35,Screen.height-150,100,100), Render, 50,70,500);
  473.  
  474.  
  475.  
  476. }
  477. if(jogabilidadeconf){
  478.  
  479. GUI.Label(Rect(Screen.width/31,Screen.height-475,100,20),"Sensibilidade");
  480. Sensibilidade = GUI.HorizontalScrollbar(Rect(Screen.width/35,Screen.height-450,100,100), Sensibilidade, 5,5,55);
  481.  
  482. _fullscreen = GUI.Toggle(Rect(Screen.width/35,Screen.height-400,100,20), _fullscreen, "FullScreen");
  483. GUI.Label(Rect(Screen.width/31,Screen.height-275,100,20),"Audio");
  484. GUI.Label(Rect(Screen.width/31,Screen.height-125,100,20),"FOV");
  485. FOVConf = GUI.HorizontalScrollbar(Rect(Screen.width/35,Screen.height-100,100,100), FOVConf, 3,50,80);
  486. volumeconf = GUI.HorizontalScrollbar(Rect(Screen.width/35,Screen.height-250,100,100), volumeconf, 0.1,0.0,1.0);
  487. }
  488.  
  489. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement