public void DeliverIAPItem(IAPName iapName) { switch (iapName) { case IAPName.Cash50W: AddCash(500000); break; case IAPName.Cash120W: AddCash(1200000); break; case IAPName.Cash270W: AddCash(2700000); break; case IAPName.Cash750W: AddCash(7500000); break; case IAPName.Cash1650W: AddCash(16500000); break; } GameApp.GetInstance().Save(); }
public void Upgrade(float power, float frequency, float accur) { int i; if (power != 0) { damage += power; i = (int)(damage * 100); damage = (float)(i * 1.0) / 100; DamageLevel++; } if (frequency != 0) { attackFrenquency -= frequency; i = (int)(attackFrenquency * 100); attackFrenquency = (float)(i * 1.0) / 100; FrequencyLevel++; } if (accur != 0) { accuracy += accur; i = (int)(accuracy * 100); accuracy = (float)(i * 1.0) / 100; AccuracyLevel++; } if (DamageLevel + FrequencyLevel + AccuracyLevel == 10) { GameApp.GetInstance().GetGameState().Achievement.UpgradeTenTimes(); } }
public virtual void Init() { gameScene = GameApp.GetInstance().GetGameScene(); rConf = GameApp.GetInstance().GetResourceConfig(); gameCamera = gameScene.GetCamera(); cameraComponent = gameCamera.GetComponent <Camera>(); cameraTransform = gameCamera.CameraTransform; player = gameScene.GetPlayer(); //! 获取场景中的人物 aimTarget = new Vector3(); hitParticles = rConf.hitparticles; projectile = rConf.projectile; hitForce = 0f; weaponBoneTrans = player.GetTransform().Find(BoneName.WEAPON_PATH); //! 获取人物中挂载武器的节点 //gun = weaponBoneTrans.Find("Rifle").gameObject; CreateGun(); gun.transform.parent = weaponBoneTrans; BindGunAndFire(); shootAudio = gun.GetComponent <AudioSource>(); if (shootAudio == null) { } else { } GunOff(); }
public void Fire(float deltaTime) { if (GameApp.GetInstance().GetGameScene().PlayingState == PlayingState.GamePlaying) { weapon.Fire(deltaTime); } }
public void OnDead() { audioPlayer.PlayAudio(AudioName.DEAD); weapon.StopFire(); int rnd = Random.Range(1, 4); Animate(AnimationName.PLAYER_DEATH + rnd, WrapMode.ClampForever); //! 播放死亡动画 //! 显示红色 血的图片 Transform sbdTrans = gameCamera.gameObject.transform.Find("Screen_Blood_Dead"); if (sbdTrans != null) { //! sbdTrans.gameObject.active = true; sbdTrans.gameObject.SetActive(true); } //! 删除碰撞检测 GameObject.Destroy(playerObject.GetComponent <Collider>()); GameScene gameScene = GameApp.GetInstance().GetGameScene(); gameScene.PlayingState = PlayingState.GameLose; GameApp.GetInstance().GetGameState().Achievement.LoseGame(); GameUIScript ui2 = GameObject.Find("SceneGUI").GetComponent <GameUIScript>(); ui2.GetPanel(GameUIName.GAME_OVER).Show(); //BattleEndUI battleEndUI = ui2.GetComponent<BattleEndUI>(); //battleEndUI.enabled = true; gameCamera.GetComponent <AudioSource>().Stop(); gameCamera.loseAudio.Play(); }
public void ChangeToPowerBuffState() { powerBuff = Constant.POWER_BUFF; powerBuffStartTime = Time.time; GameObject powerLogoPrefab = GameApp.GetInstance().GetResourceConfig().powerLogo; if (powerObj == null) { powerObj = Object.Instantiate(powerLogoPrefab, playerTransform.TransformPoint(Vector3.up * 2.0f), Quaternion.identity) as GameObject; powerObj.transform.parent = playerTransform; } //playerObject.transform.Find("buff").gameObject.active = true; if (avatarType != AvatarType.EnegyArmor) { Color color = playerObject.transform.Find("Avatar_Suit").GetComponent <AlphaAnimationScript>().startColor; playerObject.transform.Find("Avatar_Suit").GetComponent <Renderer>().material.shader = Shader.Find("iPhone/SolidTextureBright"); playerObject.transform.Find("Avatar_Suit").GetComponent <Renderer>().material.SetColor("_TintColor", color); playerObject.transform.Find("Avatar_Suit").GetComponent <AlphaAnimationScript>().enableBrightAnimation = true; Transform cap = playerObject.transform.Find("Avatar_Cap"); if (cap != null) { cap.GetComponent <Renderer>().material.shader = Shader.Find("iPhone/SolidTextureBright"); cap.GetComponent <Renderer>().material.SetColor("_TintColor", color); cap.GetComponent <AlphaAnimationScript>().enableBrightAnimation = true; } } }
public void AddBullets(int num) { if (GameApp.GetInstance().GetGameState().Avatar == AvatarType.Marine) { num = (int)(num * Constant.MARINE_POWER_UP); } BulletCount += num; BulletCount = Mathf.Clamp(BulletCount, 0, 9999); }
public static GameApp GetInstance() { if (instance == null) { instance = new GameApp(); instance.PreviousOrientation = DeviceOrientation.Portrait; //FlurryTAd.Init("1.0", "SVUM3MKWJ9LRFPFQJ1F4"); } return(instance); }
// Use this for initialization public virtual void Init(GameObject gObject) { gameScene = GameApp.GetInstance().GetGameScene(); player = gameScene.GetPlayer(); enemyObject = gObject; enemyTransform = enemyObject.transform; animation = enemyObject.GetComponent <UnityEngine.Animation>(); aimedTransform = enemyTransform.Find(BoneName.ENEMY_AIMED_PATH); rigidbody = enemyObject.GetComponent <Rigidbody>(); //collider = enemyObject.transform.Find(BoneName.ENEMY_BODY).collider; collider = enemyObject.transform.GetComponent <Collider>(); //sceneGUI = GameObject.Find("SceneGUI").GetComponent<SceneGUI>(); rConfig = GameApp.GetInstance().GetResourceConfig(); gConfig = GameApp.GetInstance().GetGameConfig(); controller = enemyObject.GetComponent <Collider>() as CharacterController; detectionRange = 150.0f; attackRange = 1.5f; minRange = 1.5f; lootCash = 0; criticalAttacked = false; spawnCenter = enemyTransform.position; target = GameObject.Find("Player").transform; //rigidbody.centerOfMass = Vector3.up; audio = new AudioPlayer(); Transform audioFolderTrans = enemyTransform.Find("Audio"); audio.AddAudio(audioFolderTrans, "Attack"); audio.AddAudio(audioFolderTrans, "Walk"); audio.AddAudio(audioFolderTrans, "Dead"); audio.AddAudio(audioFolderTrans, "Special"); audio.AddAudio(audioFolderTrans, "Shout"); hitBloodObjectPool = GameApp.GetInstance().GetGameScene().HitBloodObjectPool; pathFinding = new GraphPathFinding(); animation.wrapMode = WrapMode.Loop; animation.Play(AnimationName.ENEMY_IDLE); state = IDLE_STATE; lastUpdateTime = Time.time; lastPathFindingTime = Time.time; idleStartTime = -2; enemyObject.GetComponent <UnityEngine.Animation>()[AnimationName.ENEMY_ATTACK].wrapMode = WrapMode.ClampForever; path = GameApp.GetInstance().GetGameScene().GetPath(); }
public override void OnDead() { gameScene.IncreaseKills(); PlayBloodEffect(); deadTime = Time.time; animation[AnimationName.ENEMY_DEATH1].wrapMode = WrapMode.ClampForever; animation.Play(AnimationName.ENEMY_DEATH1); enemyObject.layer = PhysicsLayer.DEADBODY; enemyObject.SendMessage("OnLoot"); GameApp.GetInstance().GetGameState().Achievement.KillEnemy(); }
public void KillEnemy() { enemyKills++; if (GameApp.GetInstance().GetGameScene().GetPlayer().GetWeapon().GetWeaponType() == WeaponType.Saw) { sawKills++; CheckAchievemnet_SawKillers(); } CheckAchievemnet_TookAShoot(); CheckAchievemnet_Killer(); }
public void CheckAchievemnet_WeaponCollector() { if (acheivements[15].complete) { return; } if (GameApp.GetInstance().GetGameState().GotAllWeapons()) { Debug.Log("Achievement: WeaponCollector!"); acheivements[15].submitting = true; acheivements[15].complete = true; } }
public void Init() { if (!inited) { Debug.Log("game state init"); gConfig = GameApp.GetInstance().GetGameConfig(); //! Config cash = gConfig.globalConf.startMoney; //! 玩家金钱 MusicOn = true; infectionRate = new int[4]; for (int i = 0; i < 4; i++) { infectionRate[i] = 100; } infectionRate[2] = 100; Avatar = AvatarType.Human; avatarData = new AvatarState[(int)AvatarType.AvatarCount]; //! 所有人物的状态:可用 & 不可用 & 需购买 for (int i = 0; i < avatarData.Length; i++) { avatarData[i] = AvatarState.ToBuy; } avatarData[0] = AvatarState.Avaliable; //! 第一个人物可用 FirstTimeGame = true; /* * for (int i = 0; i < avatarData.Length; i++) * { * * avatarData[i] = AvatarState.Avaliable; * } * * avatarData[6] = AvatarState.ToBuy; * * avatarData[7] = AvatarState.ToBuy; */ ArmorLevel = 0; LevelNum = 1; inited = true; } }
// Use this for initialization public override void Init() { base.Init(); Transform exitTrans = GameObject.Find("Exit").transform; exitPosition = exitTrans.position; exitGlowRenderer = exitTrans.Find("glow").GetComponent <Renderer>(); exitGlowRenderer.enabled = false; questType = QuestType.Bomb; bombTotal = GameApp.GetInstance().GetGameScene().GetBombSpots().Count; bombLeft = bombTotal; }
public virtual void PlayBodyExlodeEffect() { if (enemyObject) { if (enemyObject.active) { Quaternion rotation = Quaternion.Euler(enemyTransform.rotation.eulerAngles.x, Random.Range(0, 360), enemyTransform.rotation.eulerAngles.z); //GameObject enemyDeadBodyPrefab = rConfig.deadbody[(int)EnemyType]; //GameObject.Instantiate(enemyDeadBodyPrefab, enemyTransform.position + new Vector3(0, 0.2f, 0), rotation); ObjectPool bodyPool = GameApp.GetInstance().GetGameScene().GetDeadBodyPool(enemyType); GameObject body = bodyPool.CreateObject(enemyTransform.position + new Vector3(0, 0.2f, 0), rotation); float fby = Constant.FLOORHEIGHT + 0.02f; body.transform.rotation = deadRotation * body.transform.rotation; } } }
public void CheckBombSpot() { bombSpot = null; List <BombSpot> bsl = GameApp.GetInstance().GetGameScene().GetBombSpots(); foreach (BombSpot bs in bsl) { bs.DoLogic(); if (bs.CheckInSpot()) { bombSpot = bs; } else if (bs.isInstalling()) { bombSpot = bs; } } }
public GameObject CreateAvatar(AvatarType aType) { GameObject avatarObj = null; switch (aType) { case AvatarType.Human: avatarObj = (GameObject)GameObject.Instantiate(GameApp.GetInstance().GetResourceConfig().human, Vector3.zero, Quaternion.identity); break; case AvatarType.Plumber: avatarObj = (GameObject)GameObject.Instantiate(GameApp.GetInstance().GetResourceConfig().plumbers, Vector3.zero, Quaternion.identity); break; case AvatarType.Marine: avatarObj = (GameObject)GameObject.Instantiate(GameApp.GetInstance().GetResourceConfig().marine, Vector3.zero, Quaternion.identity); break; case AvatarType.EnegyArmor: avatarObj = (GameObject)GameObject.Instantiate(GameApp.GetInstance().GetResourceConfig().enegyArmor, Vector3.zero, Quaternion.identity); break; case AvatarType.Nerd: avatarObj = (GameObject)GameObject.Instantiate(GameApp.GetInstance().GetResourceConfig().nerd, Vector3.zero, Quaternion.identity); break; case AvatarType.Doctor: avatarObj = (GameObject)GameObject.Instantiate(GameApp.GetInstance().GetResourceConfig().doctor, Vector3.zero, Quaternion.identity); break; case AvatarType.Cowboy: avatarObj = (GameObject)GameObject.Instantiate(GameApp.GetInstance().GetResourceConfig().cowboy, Vector3.zero, Quaternion.identity); break; case AvatarType.Swat: avatarObj = (GameObject)GameObject.Instantiate(GameApp.GetInstance().GetResourceConfig().swat, Vector3.zero, Quaternion.identity); break; } return(avatarObj); }
public Stack <Transform> FindPath(Vector3 enemyPos, Vector3 playerPos) { GameObject[] points = GameObject.FindGameObjectsWithTag(TagName.WAYPOINT); float minDisSqrEnemy = 99999.0f; float minDisSqrPlayer = 99999.0f; WayPointScript from = null; WayPointScript to = null; foreach (GameObject wObj in points) { WayPointScript w = wObj.GetComponent <WayPointScript>(); w.parent = null; float disSqrEnemy = (w.transform.position - enemyPos).magnitude; if (disSqrEnemy < minDisSqrEnemy) { Ray ray = new Ray(enemyPos + new Vector3(0, 0.5f, 0), w.transform.position - enemyPos); RaycastHit hit; //if (!Physics.CapsuleCast(enemyPos, enemyPos + Vector3.up, 1, w.transform.position - enemyPos, disSqrEnemy, 1 << PhysicsLayer.WALL | 1 << PhysicsLayer.FLOOR)) if (!Physics.Raycast(ray, out hit, disSqrEnemy, 1 << PhysicsLayer.WALL | 1 << PhysicsLayer.TRANSPARENT_WALL | 1 << PhysicsLayer.FLOOR)) { from = w; minDisSqrEnemy = disSqrEnemy; } } to = GameApp.GetInstance().GetGameScene().GetPlayer().NearestWayPoint; } if (from != null && to != null) { path = SearchPath(from, to); } if (to == null) { Debug.Log("to null"); } return(path); }
public void Init() { thumbCenter.x = AutoRect.AutoX(110); thumbCenter.y = AutoRect.AutoY(530); thumbRadius = AutoRect.AutoValue(85); shootThumbCenter.x = AutoRect.AutoX(852); shootThumbCenter.y = AutoRect.AutoY(530); if (AutoRect.GetPlatform() == Platform.IPad) { thumbCenter.x = AutoRect.AutoX(66); shootThumbCenter.x = AutoRect.AutoX(896); thumbCenter.y = AutoRect.AutoY(500); shootThumbCenter.y = AutoRect.AutoY(500); } thumbCenterToScreen = new Vector2(thumbCenter.x, Screen.height - thumbCenter.y); shootThumbCenterToScreen = new Vector2(shootThumbCenter.x, Screen.height - shootThumbCenter.y); lastShootTouch = shootThumbCenterToScreen; for (int i = 0; i < 2; i++) { lastTouch[i] = new Touch(); } gameScene = GameApp.GetInstance().GetGameScene(); player = gameScene.GetPlayer(); EnableMoveInput = true; EnableShootingInput = true; EnableTurningAround = true; }
public virtual void OnDead() { deadTime = Time.time; if (spawn != null) { spawn.gameObject.SendMessage("OnResetSpawnTrigger", SendMessageOptions.DontRequireReceiver); } gameScene.IncreaseKills(); gameScene.ModifyEnemyNum(-1); GameApp.GetInstance().GetGameState().Achievement.KillEnemy(); GameApp.GetInstance().GetGameState().AddCash((int)(lootCash * gameScene.GetDifficultyCashDropFactor)); enemyObject.SendMessage("OnLoot"); if (IsElite && enemyType != global::EnemyType.E_BOOMER) { criticalAttacked = false; } deadRotation = Quaternion.identity; deadPosition = enemyTransform.position; deadPosition.y = Constant.FLOORHEIGHT + 0.02f; if (enemyTransform.position.y > Constant.FLOORHEIGHT + 0.5f) { RaycastHit hitfloor; Ray ray = new Ray(enemyTransform.position + Vector3.up * 0.5f, -Vector3.up); if (Physics.Raycast(ray, out hitfloor, 50.0f, 1 << PhysicsLayer.FLOOR)) { deadRotation = Quaternion.FromToRotation(Vector3.up, hitfloor.normal); deadPosition = hitfloor.point + Vector3.up * 0.01f; } } if (criticalAttacked) { PlayDeadEffects(); } else { if (animation) { animation[AnimationName.ENEMY_DEATH1].wrapMode = WrapMode.ClampForever; animation[AnimationName.ENEMY_DEATH1].speed = 1f; animation.CrossFade(AnimationName.ENEMY_DEATH1); } if (enemyObject) { if (enemyObject.active) { enemyTransform.rotation = deadRotation * enemyTransform.rotation; enemyObject.layer = PhysicsLayer.DEADBODY; } } PlayBloodEffect(); } }
public void OnPickUp(ItemType itemID) { //pick up items audioPlayer.PlayAudio(AudioName.GETITEM); if (itemID == ItemType.Hp) { GetHealed((int)maxHp); } else if (itemID == ItemType.Gold) { int cash = (int)(Constant.WOODBOX_LOOT * GameApp.GetInstance().GetGameScene().GetDifficultyCashDropFactor); GameApp.GetInstance().GetGameState().AddCash(cash); } else if (itemID == ItemType.Power) { ChangeToPowerBuffState(); } else if (itemID == ItemType.AssaultGun) { //List<Weapon> weaponList = GameApp.GetInstance().GetGameState().GetWeapons(); foreach (Weapon w in weaponList) { if (w.GetWeaponType() == WeaponType.AssaultRifle) { w.AddBullets(w.WConf.bullet / 4); break; } } } else if (itemID == ItemType.ShotGun) { foreach (Weapon w in weaponList) { if (w.GetWeaponType() == WeaponType.ShotGun) { w.AddBullets(w.WConf.bullet / 4); break; } } } else if (itemID == ItemType.RocketLauncer) { foreach (Weapon w in weaponList) { if (w.GetWeaponType() == WeaponType.RocketLauncher) { w.AddBullets(w.WConf.bullet / 4); break; } } } else if (itemID == ItemType.LaserGun) { foreach (Weapon w in weaponList) { if (w.GetWeaponType() == WeaponType.LaserGun) { w.AddBullets(w.WConf.bullet / 4); break; } } } else if (itemID == ItemType.Saw) { foreach (Weapon w in weaponList) { if (w.GetWeaponType() == WeaponType.Saw) { w.AddBullets(w.WConf.bullet / 4); break; } } } else if (itemID == ItemType.Sniper) { foreach (Weapon w in weaponList) { if (w.GetWeaponType() == WeaponType.Sniper) { w.AddBullets(w.WConf.bullet / 4); break; } } } else if (itemID == ItemType.MachineGun) { foreach (Weapon w in weaponList) { if (w.GetWeaponType() == WeaponType.MachineGun) { w.AddBullets(w.WConf.bullet / 4); break; } } } }
public void RefreshWoodBoxes() { Object.Instantiate(GameApp.GetInstance().GetResourceConfig().woodBoxes); woodboxList = GameObject.FindGameObjectsWithTag("WoodBox"); spawnWoodBoxesTime = Time.time; }
public void Init() { //! 随机出生点 GameObject[] pss = GameObject.FindGameObjectsWithTag("Respawn"); int rnd = Random.Range(0, pss.Length); GameObject ps = pss[rnd]; respawnTrans = ps.transform; avatarType = GameApp.GetInstance().GetGameState().Avatar; //! playerObject = AvatarFactory.GetInstance().CreateAvatar(avatarType); //! 创建角色 playerObject = AvatarFactory.GetInstance().CreateAvatar(Zombie3D.AvatarType.EnegyArmor); //! 创建钢铁侠 playerObject.transform.position = ps.transform.position; playerObject.transform.rotation = ps.transform.rotation; playerObject.name = "Player"; playerTransform = playerObject.transform; playerConfig = GameApp.GetInstance().GetGameConfig().playerConf; int armorLevel = GameApp.GetInstance().GetGameState().ArmorLevel; hp = playerConfig.hp * (1 + armorLevel * 0.5f); maxHp = hp; //! 特种兵的血量 × 2 if (avatarType == AvatarType.Swat) { hp = hp * Constant.SWAT_HP; maxHp = hp; } else if (avatarType == AvatarType.EnegyArmor) { hp = hp * Constant.ENEGY_ARMOR_HP_BOOST; maxHp = hp; } gameCamera = GameApp.GetInstance().GetGameScene().GetCamera(); charController = playerObject.GetComponent <CharacterController>(); //! 控制器 animation = playerObject.GetComponent <UnityEngine.Animation>(); //! 动画器 collider = playerObject.GetComponent <Collider>(); //! 碰撞检测 //! 音效 audioPlayer = new AudioPlayer(); Transform folderTrans = playerTransform.Find("Audio"); audioPlayer.AddAudio(folderTrans, AudioName.GETITEM); audioPlayer.AddAudio(folderTrans, AudioName.DEAD); audioPlayer.AddAudio(folderTrans, AudioName.SWITCH); audioPlayer.AddAudio(folderTrans, AudioName.WALK); //! 为什么又初始化一边武器列表 GameApp.GetInstance().GetGameState().InitWeapons(); weaponList = GameApp.GetInstance().GetGameState().GetBattleWeapons(); playerState = Player.IDLE_STATE; foreach (Weapon w in weaponList) { w.Init(); } Weapon powerWeapon = null; float maxDamage = 0; foreach (Weapon w in weaponList) { if (maxDamage < w.Damage) { maxDamage = w.Damage; powerWeapon = w; } //! if (w.IsSelectedForBattle) //! { //! ChangeWeapon(w); //! break; //! } } //! 切换武器 ChangeWeapon(powerWeapon); walkSpeed = GameApp.GetInstance().GetGameConfig().playerConf.walkSpeed - weapon.GetSpeedDrag(); //! 人物速度 - 武器武器负重 ChangeToNormalState(); if (gameCamera.GetCameraType() == CameraType.TPSCamera) { inputController = new TPSInputController(); inputController.Init(); } else if (gameCamera.GetCameraType() == CameraType.TopWatchingCamera) { inputController = new TopWatchingInputController(); inputController.Init(); } UpdateNearestWayPoint(); }
public void Init(int index) { GameApp.GetInstance().DebugInfo = ""; sceneIndex = index; //! sceneName = Application.loadedLevelName.Substring(9); sceneName = SceneManager.GetSceneAt(0).name; //! 保存场景名字 //infectionRate = GameApp.GetInstance().GetGameState().GetInfectionRate(index); //! 读取 ai 路标 箱子列表 CreateSceneData(); //! 打中时流血的例子粒子效果 hitBloodObjectPool.Init("HitBlood", GameApp.GetInstance().GetResourceConfig().hitBlood, 3, 0.4f); for (int i = 0; i < deadBodyObjectPool.Length; i++) { deadBodyObjectPool[i] = new ObjectPool(); enemyObjectPool[i] = new ObjectPool(); } //! 死亡时的mesh网格 deadBodyObjectPool[0].Init("DeadBody_Zombie", GameApp.GetInstance().GetResourceConfig().deadbody[0], 10, 2.0f); //! zombie deadBodyObjectPool[1].Init("DeadBody_Nurse", GameApp.GetInstance().GetResourceConfig().deadbody[1], 5, 2.0f); //! 护 士 deadBodyObjectPool[4].Init("DeadBody_Boomer", GameApp.GetInstance().GetResourceConfig().deadbody[4], 5, 2.0f); //! 炸弹 人 deadBodyObjectPool[5].Init("DeadBody_Swat", GameApp.GetInstance().GetResourceConfig().deadbody[5], 5, 2.0f); //! 特种兵 //! 敌人mesh enemyObjectPool[0].Init("Zombies", GameApp.GetInstance().GetResourceConfig().enemy[0], 10, 0f); enemyObjectPool[1].Init("Nurses", GameApp.GetInstance().GetResourceConfig().enemy[1], 5, 0f); enemyObjectPool[2].Init("Tanks", GameApp.GetInstance().GetResourceConfig().enemy[2], 2, 0f); enemyObjectPool[3].Init("Hunters", GameApp.GetInstance().GetResourceConfig().enemy[3], 2, 0f); enemyObjectPool[4].Init("Boomers", GameApp.GetInstance().GetResourceConfig().enemy[4], 5, 0f); enemyObjectPool[5].Init("Swats", GameApp.GetInstance().GetResourceConfig().enemy[5], 5, 0f); camera = GameObject.Find("Main Camera").GetComponent <TPSSimpleCameraScript>(); if (camera == null) { camera = GameObject.Find("Main Camera").GetComponent <TopWatchingCameraScript>(); } else if (!camera.enabled) { camera = GameObject.Find("Main Camera").GetComponent <TopWatchingCameraScript>(); } //! 创建Player player = new Player(); player.Init(); camera.Init(); enemyList = new Hashtable(); playingState = PlayingState.GamePlaying; GameApp.GetInstance().GetGameState().Achievement.CheckAchievemnet_NeverGiveUp(); enemyNum = 0; killed = 0; triggerCount = 0; enemyID = 0; Color[] colors = { Color.white, Color.red, Color.blue, Color.yellow, Color.magenta, Color.gray, Color.grey, Color.cyan }; int cIndex = Random.Range(0, colors.Length); RenderSettings.ambientLight = colors[cIndex]; }
// Use this for initialization public void Init() { spotTransform = bombSpotObj.transform; gameScene = GameApp.GetInstance().GetGameScene(); }
public override void ProcessInput(float deltaTime, InputInfo inputInfo) { //process input from both keyboard/mouse and touch screen Weapon weapon = player.GetWeapon(); GameObject playerObject = player.PlayerObject; Transform playerTransform = player.GetTransform(); Vector3 getHitFlySpeed = player.GetHitFlySpeed; List <Weapon> weaponList = GameApp.GetInstance().GetGameState().GetBattleWeapons(); if (Application.platform != RuntimePlatform.IPhonePlayer) { //In Editor if (EnableShootingInput) { if (Input.GetButton("Fire1")) { inputInfo.fire = true; //player.Fire(); } else { inputInfo.stopFire = true; //player.StopFire(); } } if (EnableMoveInput) { moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); } if (EnableTurningAround) { cameraRotation.x = player.InputController.CameraRotation.x; //Input.GetAxis("Mouse X"); cameraRotation.y = player.InputController.CameraRotation.y; //Input.GetAxis("Mouse Y"); } } else { //Touch screen Input processing: Infinite Input Style touchX = 0; touchY = 0; cameraRotation.x = 0; cameraRotation.y = 0; bool fired = false; if (Input.touchCount == 0) { thumbTouchFingerId = -1; shootingTouchFingerId = -1; lastShootTouch = shootThumbCenterToScreen; } for (int i = 0; i < Input.touchCount; i++) { if (i == 2) { break; } Touch touch = Input.GetTouch(i); phaseStr = touch.phase.ToString() + touch.fingerId + " p:" + touch.position.x + "," + touch.position.y; /* * if (touch.phase != TouchPhase.Stationary) * { * stationaryStartTime[i] = -1f; * } * */ Vector2 diff = touch.position - thumbCenterToScreen; bool inThumb = diff.sqrMagnitude < thumbRadius * thumbRadius; bool stillThumbFinger = (touch.fingerId == thumbTouchFingerId); if (touch.phase == TouchPhase.Began) { /* * if (AutoRect.GetPlatform() == Platform.IPad) * { * if (touch.position.x < Screen.width * 0.5f) * { * thumbCenter = new Vector2(touch.position.x, Screen.height - touch.position.y); * * * } * else * { * shootThumbCenter = new Vector2(touch.position.x, Screen.height - touch.position.y); * } * * thumbCenterToScreen = new Vector2(thumbCenter.x, Screen.height - thumbCenter.y); * shootThumbCenterToScreen = new Vector2(shootThumbCenter.x, Screen.height - shootThumbCenter.y); * * } */ } else if (touch.phase == TouchPhase.Stationary) { /* * if (lastTouch[i].phase == TouchPhase.Began) * { * stationaryStartTime[i] = Time.time; * } **/ if (inThumb || stillThumbFinger) { if (inThumb) { touchX = diff.x / thumbRadius; touchY = diff.y / thumbRadius; } else { touchX = diff.x / thumbRadius; touchY = diff.y / thumbRadius; if (Mathf.Abs(touchX) > Mathf.Abs(touchY)) { touchY = touchY / Mathf.Abs(touchX); touchX = (touchX > 0) ? 1 : -1; } else { if (touchY != 0) { touchX = touchX / Mathf.Abs(touchY); touchY = (touchY > 0) ? 1 : -1; } else { touchX = 0; touchY = 0; } } } thumbTouchFingerId = touch.fingerId; /* * if (Mathf.Abs(diff.x) > Mathf.Abs(diff.y)) * { * touchX = (diff.x > 0) ? 1 : -1; * } * else * { * touchY = (diff.y > 0) ? 1 : -1; * } */ } else { if (EnableShootingInput) { Vector2 diffShootTouch = touch.position - shootThumbCenterToScreen; bool inShootThumb = diffShootTouch.sqrMagnitude < thumbRadius * thumbRadius; if (inShootThumb || shootingTouchFingerId == touch.fingerId) { if (inShootThumb) { cameraRotation.x = Mathf.Clamp(diffShootTouch.x, -thumbRadius, thumbRadius) * 0.005f; lastShootTouch = touch.position; } else { cameraRotation.x = Mathf.Sign(diffShootTouch.x) * thumbRadius * 0.01f; Vector2 d = (touch.position - shootThumbCenterToScreen).normalized; lastShootTouch = shootThumbCenterToScreen + d * thumbRadius; } //cameraRotation.y = Mathf.Sign(diffShootTouch.y) * thumbRadius * 0.02f; inputInfo.fire = true; shootingTouchFingerId = touch.fingerId; fired = true; } } } } else if (touch.phase == TouchPhase.Moved) { if (inThumb || stillThumbFinger) { if (inThumb) { touchX = diff.x / thumbRadius; touchY = diff.y / thumbRadius; } else { touchX = diff.x / thumbRadius; touchY = diff.y / thumbRadius; if (Mathf.Abs(touchX) > Mathf.Abs(touchY)) { touchY = touchY / Mathf.Abs(touchX); touchX = (touchX > 0) ? 1 : -1; } else { if (touchY != 0) { touchX = touchX / Mathf.Abs(touchY); touchY = (touchY > 0) ? 1 : -1; } else { touchX = 0; touchY = 0; } } } thumbTouchFingerId = touch.fingerId; } else { if (EnableTurningAround) { if (lastMoveTouch.phase == TouchPhase.Moved) { if (touch.fingerId == moveTouchFingerId) { cameraRotation.x = (touch.position.x - lastMoveTouch.position.x) * 0.3f; cameraRotation.y = (touch.position.y - lastMoveTouch.position.y) * 0.16f; } else if (touch.fingerId == moveTouchFingerId2) { cameraRotation.x = (touch.position.x - lastMoveTouch2.position.x) * 0.3f; cameraRotation.y = (touch.position.y - lastMoveTouch2.position.y) * 0.16f; } } if (moveTouchFingerId == -1) { moveTouchFingerId = touch.fingerId; } if (moveTouchFingerId != -1 && touch.fingerId != moveTouchFingerId) { moveTouchFingerId2 = touch.fingerId; } if (touch.fingerId == moveTouchFingerId) { lastMoveTouch.phase = TouchPhase.Moved; lastMoveTouch.position = touch.position; } if (touch.fingerId == moveTouchFingerId2) { lastMoveTouch2.phase = TouchPhase.Moved; lastMoveTouch2.position = touch.position; } } Vector2 diffShootTouch = touch.position - shootThumbCenterToScreen; bool inShootThumb = diffShootTouch.sqrMagnitude < thumbRadius * thumbRadius; if (EnableShootingInput) { if (shootingTouchFingerId == touch.fingerId || inShootThumb) { //player.Fire(); inputInfo.fire = true; fired = true; if (inShootThumb) { cameraRotation.x += Mathf.Clamp(diffShootTouch.x, -thumbRadius, thumbRadius) * 0.002f; lastShootTouch = touch.position; } else { Vector2 d = (touch.position - shootThumbCenterToScreen).normalized; lastShootTouch = shootThumbCenterToScreen + d * thumbRadius; cameraRotation.x += Mathf.Sign(diffShootTouch.x) * thumbRadius * 0.006f; //cameraRotation.y = Mathf.Sign(diffShootTouch.y) * thumbRadius * 0.02f; } shootingTouchFingerId = touch.fingerId; } else { } } } } else if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled) { if (touch.fingerId == thumbTouchFingerId) { thumbTouchFingerId = -1; } //GameApp.GetInstance().DebugInfo = touch.phase + "," + touch.fingerId + "," + shootingTouchFingerId; if (touch.fingerId == shootingTouchFingerId) { shootingTouchFingerId = -1; lastShootTouch = shootThumbCenterToScreen; } if (touch.fingerId == moveTouchFingerId) { moveTouchFingerId = -1; lastMoveTouch.phase = TouchPhase.Ended; } if (touch.fingerId == moveTouchFingerId2) { moveTouchFingerId2 = -1; lastMoveTouch2.phase = TouchPhase.Ended; } } lastTouch[i] = touch; } if (!fired) { //player.StopFire(); inputInfo.stopFire = true; } touchX = Mathf.Clamp(touchX, -1, 1); touchY = Mathf.Clamp(touchY, -1, 1); //phaseStr += "touchXY " + touchX + "," + touchY; moveDirection = new Vector3(touchX, 0, touchY); } //move moveDirection = playerTransform.TransformDirection(moveDirection); if (!EnableMoveInput) { moveDirection = Vector3.zero; } if (!EnableShootingInput) { inputInfo.fire = false; } moveDirection += Physics.gravity * deltaTime * 10.0f; /* * getHitFlySpeed.x = Mathf.Lerp(getHitFlySpeed.x, 0, 5.0f * deltaTime); * getHitFlySpeed.y = Mathf.Lerp(getHitFlySpeed.y, 0, -Physics.gravity.y * deltaTime); * getHitFlySpeed.z = Mathf.Lerp(getHitFlySpeed.z, 0, 5.0f * deltaTime); */ inputInfo.moveDirection = moveDirection; for (int i = 1; i <= weaponList.Count; i++) { if (Input.GetButton("Weapon" + i)) { player.ChangeWeapon(weaponList[i - 1]); } } if (Input.GetButton("K")) { player.OnHit(player.GetMaxHp()); } if (Input.GetButton("H")) { player.GetHealed((int)player.GetMaxHp()); } if (Input.GetButtonDown("N")) { GameApp.GetInstance().GetGameState().LevelNum++; Debug.Log(GameApp.GetInstance().GetGameState().LevelNum); GameApp.GetInstance().Save(); } if (Input.GetAxis("Vertical") != 0 || Input.GetAxis("Horizontal") != 0 || touchX != 0 || touchY != 0) { player.Run(); } else { player.StopRun(); } }
public virtual void LoadConfig() { gConfig = GameApp.GetInstance().GetGameConfig(); }
public override void Fire(float deltaTime) { AudioPlayer.PlayAudio(shootAudio); gun.GetComponent <UnityEngine.Animation>()[AnimationName.SHOTGUN_RELOAD].wrapMode = WrapMode.Once; gun.GetComponent <UnityEngine.Animation>().Play(AnimationName.SHOTGUN_RELOAD); gunfire.GetComponent <Renderer>().enabled = true; shotgunFireTimer.SetTimer(0.2f, false); Object.Instantiate(rConf.shotgunBullet, rightGun.position, player.GetTransform().rotation); player.LastHitPosition = player.GetTransform().position; GameObject shotgunfireObj = Object.Instantiate(rConf.shotgunfire, gunfire.transform.position, player.GetTransform().rotation) as GameObject; shotgunfireObj.transform.parent = player.GetTransform(); float tan60 = Mathf.Tan(Mathf.Deg2Rad * 60.0f); int oneShotKills = 0; foreach (Enemy enemy in gameScene.GetEnemies().Values) { if (enemy.GetState() == Enemy.DEAD_STATE) { continue; } Vector3 relativeEnemyPos = player.GetTransform().InverseTransformPoint(enemy.GetPosition()); float dis = (enemy.GetPosition() - player.GetTransform().position).sqrMagnitude; float radiusSqr = range * range; if (relativeEnemyPos.z > 0) { if (Mathf.Abs(relativeEnemyPos.z / relativeEnemyPos.x) > tan60) { DamageProperty dp = new DamageProperty(); dp.damage = damage * player.PowerBuff; if (dis < radiusSqr) { enemy.OnHit(dp, GetWeaponType(), true); } else if (dis < radiusSqr * 2 * 2) { int rnd = Random.Range(0, 100); if (rnd < accuracy) { enemy.OnHit(dp, GetWeaponType(), true); } } else if (dis < radiusSqr * 3 * 3) { int rnd = Random.Range(0, 100); if (rnd < accuracy / 2) { enemy.OnHit(dp, GetWeaponType(), true); } } else if (dis < radiusSqr * 4 * 4) { int rnd = Random.Range(0, 100); if (rnd < accuracy / 4) { enemy.OnHit(dp, GetWeaponType(), true); } } } } if (enemy.HP <= 0) { oneShotKills++; } } if (oneShotKills >= 4) { GameApp.GetInstance().GetGameState().Achievement.CheckAchievemnet_WeaponMaster(); } GameObject[] woodboxes = gameScene.GetWoodBoxes(); foreach (GameObject woodbox in woodboxes) { if (woodbox != null) { Vector3 relativeBoxPos = player.GetTransform().InverseTransformPoint(woodbox.transform.position); float dis = (woodbox.transform.position - player.GetTransform().position).sqrMagnitude; float radiusSqr = range * range; if ((dis < radiusSqr * 2 * 2) && relativeBoxPos.z > 0) { WoodBoxScript ws = woodbox.GetComponent <WoodBoxScript>(); ws.OnHit(damage * player.PowerBuff); } } } lastShootTime = Time.time; sbulletCount--; sbulletCount = Mathf.Clamp(sbulletCount, 0, maxCapacity); }
// Use this for initialization public virtual void Init() { questCompleted = false; gameScene = GameApp.GetInstance().GetGameScene(); }
public override void ProcessInput(float deltaTime, InputInfo inputInfo) { //process input from both keyboard/mouse and touch screen Weapon weapon = player.GetWeapon(); GameObject playerObject = player.PlayerObject; Vector3 getHitFlySpeed = player.GetHitFlySpeed; List <Weapon> weaponList = GameApp.GetInstance().GetGameState().GetWeapons(); Transform respawnTrans = player.GetRespawnTransform(); if (Application.platform != RuntimePlatform.IPhonePlayer) { //In Editor if (Input.GetButton("Fire1")) { player.Fire(deltaTime); } else { player.StopFire(); } moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); } else { //Touch screen Input processing: Infinite Input Style touchX = 0; touchY = 0; lastShootTouch = shootThumbCenterToScreen; cameraRotation.x = 0; cameraRotation.y = 0; bool fired = false; for (int i = 0; i < Input.touchCount; i++) { if (i == 2) { break; } Touch touch = Input.GetTouch(i); phaseStr = touch.phase.ToString() + touch.fingerId + " p:" + touch.position.x + "," + touch.position.y; /* * if (touch.phase != TouchPhase.Stationary) * { * stationaryStartTime[i] = -1f; * } * */ Vector2 diff = touch.position - thumbCenterToScreen; bool inThumb = diff.sqrMagnitude < thumbRadius * thumbRadius; bool stillThumbFinger = (touch.fingerId == thumbTouchFingerId); if (touch.phase == TouchPhase.Stationary) { /* * if (lastTouch[i].phase == TouchPhase.Began) * { * stationaryStartTime[i] = Time.time; * } **/ if (inThumb || stillThumbFinger) { if (inThumb) { touchX = diff.x / thumbRadius; touchY = diff.y / thumbRadius; } else { touchX = diff.x / thumbRadius; touchY = diff.y / thumbRadius; if (Mathf.Abs(touchX) > Mathf.Abs(touchY)) { touchY = touchY / Mathf.Abs(touchX); touchX = (touchX > 0) ? 1 : -1; } else { if (touchY != 0) { touchX = touchX / Mathf.Abs(touchY); touchY = (touchY > 0) ? 1 : -1; } else { touchX = 0; touchY = 0; } } } thumbTouchFingerId = touch.fingerId; /* * if (Mathf.Abs(diff.x) > Mathf.Abs(diff.y)) * { * touchX = (diff.x > 0) ? 1 : -1; * } * else * { * touchY = (diff.y > 0) ? 1 : -1; * } */ } else { Vector2 diffShootTouch = touch.position - shootThumbCenterToScreen; if (diffShootTouch.sqrMagnitude < thumbRadius * thumbRadius) { player.Fire(deltaTime); shootingTouchFingerId = touch.fingerId; fired = true; lastShootTouch = touch.position; } } } else if (touch.phase == TouchPhase.Moved) { if (inThumb || stillThumbFinger) { if (inThumb) { touchX = diff.x / thumbRadius; touchY = diff.y / thumbRadius; } else { touchX = diff.x / thumbRadius; touchY = diff.y / thumbRadius; if (Mathf.Abs(touchX) > Mathf.Abs(touchY)) { touchY = touchY / Mathf.Abs(touchX); touchX = (touchX > 0) ? 1 : -1; } else { if (touchY != 0) { touchX = touchX / Mathf.Abs(touchY); touchY = (touchY > 0) ? 1 : -1; } else { touchX = 0; touchY = 0; } } } thumbTouchFingerId = touch.fingerId; } else { cameraRotation.x = touch.deltaPosition.x * 0.2f; cameraRotation.y = touch.deltaPosition.y * 0.2f; Vector2 diffShootTouch = touch.position - shootThumbCenterToScreen; bool inShootThumb = diffShootTouch.sqrMagnitude < thumbRadius * thumbRadius; if (shootingTouchFingerId == touch.fingerId || inShootThumb) { player.Fire(deltaTime); fired = true; if (inShootThumb) { lastShootTouch = touch.position; } } else { } } } else if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled) { if (touch.fingerId == thumbTouchFingerId) { thumbTouchFingerId = -1; } if (touch.fingerId == shootingTouchFingerId) { shootingTouchFingerId = -1; } } lastTouch[i] = touch; } if (!fired) { player.StopFire(); } touchX = Mathf.Clamp(touchX, -1, 1); touchY = Mathf.Clamp(touchY, -1, 1); //phaseStr += "touchXY " + touchX + "," + touchY; moveDirection = new Vector3(touchX, 0, touchY); } //move moveDirection = respawnTrans.TransformDirection(moveDirection); moveDirection += Physics.gravity * deltaTime; getHitFlySpeed.x = Mathf.Lerp(getHitFlySpeed.x, 0, 5.0f * Time.deltaTime); getHitFlySpeed.y = Mathf.Lerp(getHitFlySpeed.y, 0, -Physics.gravity.y * Time.deltaTime); getHitFlySpeed.z = Mathf.Lerp(getHitFlySpeed.z, 0, 5.0f * Time.deltaTime); for (int i = 1; i <= 3; i++) { if (Input.GetButton("Weapon" + i)) { if (weaponList[i - 1] != null) { player.ChangeWeapon(weaponList[i - 1]); } } } if (Input.GetAxis("Vertical") != 0 || Input.GetAxis("Horizontal") != 0 || touchX != 0 || touchY != 0) { player.Run(); } else { player.StopRun(); } }