From 9218838fbb438a0e677507617954a364f3dc8a7c Mon Sep 17 00:00:00 2001 From: Teascade Date: Sun, 4 Aug 2019 20:48:26 +0300 Subject: [PATCH] Make punches work and make damage boost work --- .../Enemies/Enemy (Default Melee).prefab | 4 +- Assets/Prefabs/Player.prefab | 66 ++++++++++++++++++- Assets/Scripts/Bullets/RevolverBullet.cs | 2 +- Assets/Scripts/ExplodableHealth.cs | 5 +- Assets/Scripts/Player.cs | 23 +++++-- Assets/Scripts/PlayerFun.cs | 2 +- Assets/Scripts/PunchingHand.cs | 29 ++++++++ Assets/Scripts/PunchingHand.cs.meta | 11 ++++ ProjectSettings/InputManager.asset | 6 +- 9 files changed, 135 insertions(+), 13 deletions(-) create mode 100644 Assets/Scripts/PunchingHand.cs create mode 100644 Assets/Scripts/PunchingHand.cs.meta diff --git a/Assets/Prefabs/Enemies/Enemy (Default Melee).prefab b/Assets/Prefabs/Enemies/Enemy (Default Melee).prefab index 45234b1..9335c72 100644 --- a/Assets/Prefabs/Enemies/Enemy (Default Melee).prefab +++ b/Assets/Prefabs/Enemies/Enemy (Default Melee).prefab @@ -120,8 +120,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 7d43d0a4a6d1e2d46a74083bdecde13e, type: 3} m_Name: m_EditorClassIdentifier: - MaxHealth: 3 - CurrentHealth: 3 + MaxHealth: 30 + CurrentHealth: 30 --- !u!114 &592487110401094200 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/Prefabs/Player.prefab b/Assets/Prefabs/Player.prefab index f5d4266..37c3622 100644 --- a/Assets/Prefabs/Player.prefab +++ b/Assets/Prefabs/Player.prefab @@ -211,6 +211,8 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 340836170559364036} + - component: {fileID: 3148879525607712928} + - component: {fileID: 7903806047682221272} m_Layer: 0 m_Name: SubHand m_TagString: Untagged @@ -233,6 +235,45 @@ Transform: m_Father: {fileID: 8334477035414792174} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!61 &3148879525607712928 +BoxCollider2D: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6171388266710565393} + m_Enabled: 1 + m_Density: 1 + m_Material: {fileID: 0} + m_IsTrigger: 1 + m_UsedByEffector: 0 + m_UsedByComposite: 0 + m_Offset: {x: 0.0075235516, y: -0.3507555} + m_SpriteTilingProperty: + border: {x: 0, y: 0, z: 0, w: 0} + pivot: {x: 0, y: 0} + oldSize: {x: 0, y: 0} + newSize: {x: 0, y: 0} + adaptiveTilingThreshold: 0 + drawMode: 0 + adaptiveTiling: 0 + m_AutoTiling: 0 + serializedVersion: 2 + m_Size: {x: 0.23259524, y: 0.62920177} + m_EdgeRadius: 0 +--- !u!114 &7903806047682221272 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6171388266710565393} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 757c56aa5236c3c42a2afcc7a4b2eadf, type: 3} + m_Name: + m_EditorClassIdentifier: + Punching: 0 --- !u!1 &8489029732241002798 GameObject: m_ObjectHideFlags: 0 @@ -346,9 +387,10 @@ GameObject: - component: {fileID: 8489029732530782792} - component: {fileID: 412028545510300634} - component: {fileID: 8489029732530782806} + - component: {fileID: 5050980832709922958} m_Layer: 0 m_Name: Player - m_TagString: Untagged + m_TagString: Player m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 @@ -434,8 +476,30 @@ MonoBehaviour: HandRight: {fileID: 1270933798917005542} HandMiddle: {fileID: 3118287694834230934} CameraFX: {fileID: 0} + PunchingHand: {fileID: 7903806047682221272} + PlayerFun: {fileID: 5050980832709922958} HandRetractSpeed: 10 HandRotationRetractSpeed: 300 +--- !u!114 &5050980832709922958 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8489029732530782804} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c0a7560055c54ab479467ce5b1c7cfcd, type: 3} + m_Name: + m_EditorClassIdentifier: + Player: {fileID: 8489029732530782806} + MaxFun: 100 + FunDegradeSpeed: 5 + StandingStillMultiplier: 1.5 + WeaponFun: 20 + EnemyExplosionFun: 2 + FurnitureExplosionFun: 1 + DebugAdd10Fun: 0 --- !u!1 &8489029732599905358 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Bullets/RevolverBullet.cs b/Assets/Scripts/Bullets/RevolverBullet.cs index a78c0b2..9faedfe 100644 --- a/Assets/Scripts/Bullets/RevolverBullet.cs +++ b/Assets/Scripts/Bullets/RevolverBullet.cs @@ -48,7 +48,7 @@ namespace Saltosion.OneWeapon.Bullets { ExplodableHealth Health = collider.GetComponent(); Vector2 Direction = (collider.transform.position - transform.position).normalized; if (Health != null) { - Health.Damage(1f, -Direction); + Health.Damage(12f, -Direction); } else if (Explodable != null) { Explodable.Explode(true); } else if (collider.tag == "Environment") { diff --git a/Assets/Scripts/ExplodableHealth.cs b/Assets/Scripts/ExplodableHealth.cs index 7e02382..07f45a1 100644 --- a/Assets/Scripts/ExplodableHealth.cs +++ b/Assets/Scripts/ExplodableHealth.cs @@ -10,13 +10,16 @@ namespace Saltosion.OneWeapon { private Explodable Explodable; + private PlayerFun PlayerFun; + private void Start() { Explodable = GetComponent(); + PlayerFun = GameObject.FindGameObjectWithTag("Player").GetComponent(); } public void Damage(float amount, Vector2 fromDirection) { BloodLauncher.Splatter(transform.position, -fromDirection, (int)(10 * amount), 100f, 100); - MaxHealth -= amount; + MaxHealth -= amount * (1 + PlayerFun.CurrentDamageBoost); if (MaxHealth <= 0) { MaxHealth = 0; Explodable.Explode(true); diff --git a/Assets/Scripts/Player.cs b/Assets/Scripts/Player.cs index c51a24e..a500787 100644 --- a/Assets/Scripts/Player.cs +++ b/Assets/Scripts/Player.cs @@ -22,6 +22,10 @@ namespace Saltosion.OneWeapon { public CameraFX CameraFX; + public PunchingHand PunchingHand; + + public PlayerFun PlayerFun; + private Gun Gun; private Vector2 GunLocation = new Vector2(0, -0.6f); @@ -106,13 +110,16 @@ namespace Saltosion.OneWeapon { CameraFX.ScreenShake(4f); } else if (CurrentHandDistance <= 0) { CurrentHandDistance = 1.5f; - CurrentHandRotation = 100; + CurrentHandRotation = 55; + PunchingHand.Punching = true; } } if (CurrentHandDistance > 0) { CurrentHandDistance -= HandRetractSpeed * Time.deltaTime; CurrentHandDistance = Mathf.Max(CurrentHandDistance, 0); + } else { + PunchingHand.Punching = false; } if (CurrentHandRotation > 0) { @@ -127,16 +134,24 @@ namespace Saltosion.OneWeapon { Vector3 HandRotation = SubHand.localEulerAngles; HandRotation.z = CurrentHandRotation; SubHand.localEulerAngles = HandRotation; + + bool Drop = Input.GetButtonDown("DropWeapon"); + if (Gun != null && Drop) { + SetGun(null); + } } public void SetGun(Gun gun) { + PlayerFun.ReceiveNewWeapon(); if (Gun != null) { Destroy(Gun.gameObject); } Gun = gun; - Gun.transform.parent = Hand; - Gun.transform.localPosition = GunLocation; - Gun.transform.localEulerAngles = GunRotation; + if (gun != null) { + Gun.transform.parent = Hand; + Gun.transform.localPosition = GunLocation; + Gun.transform.localEulerAngles = GunRotation; + } } } diff --git a/Assets/Scripts/PlayerFun.cs b/Assets/Scripts/PlayerFun.cs index 6049891..d354740 100644 --- a/Assets/Scripts/PlayerFun.cs +++ b/Assets/Scripts/PlayerFun.cs @@ -22,7 +22,7 @@ namespace Saltosion.OneWeapon { public float CurrentDamageBoost { private set; get; } void Start() { - CurrentFun = MaxFun; + CurrentFun = MaxFun * 0.75f; } void Update() { diff --git a/Assets/Scripts/PunchingHand.cs b/Assets/Scripts/PunchingHand.cs new file mode 100644 index 0000000..b79b384 --- /dev/null +++ b/Assets/Scripts/PunchingHand.cs @@ -0,0 +1,29 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Saltosion.OneWeapon { + public class PunchingHand : MonoBehaviour { + + public bool Punching = false; + + void Update() { + + } + + void OnTriggerEnter2D(Collider2D collider) { + if (Punching) { + Punching = false; + + Explodable Explodable = collider.GetComponent(); + ExplodableHealth Health = collider.GetComponent(); + Vector2 Direction = (collider.transform.position - transform.position).normalized; + if (Health != null) { + Health.Damage(8f, -Direction); + } else if (Explodable != null) { + Explodable.Explode(true); + } + } + } + } +} diff --git a/Assets/Scripts/PunchingHand.cs.meta b/Assets/Scripts/PunchingHand.cs.meta new file mode 100644 index 0000000..8f2a1fa --- /dev/null +++ b/Assets/Scripts/PunchingHand.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 757c56aa5236c3c42a2afcc7a4b2eadf +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/ProjectSettings/InputManager.asset b/ProjectSettings/InputManager.asset index 65e7286..0ccfa20 100644 --- a/ProjectSettings/InputManager.asset +++ b/ProjectSettings/InputManager.asset @@ -54,13 +54,13 @@ InputManager: axis: 0 joyNum: 0 - serializedVersion: 3 - m_Name: Fire2 + m_Name: DropWeapon descriptiveName: descriptiveNegativeName: negativeButton: - positiveButton: left alt + positiveButton: q altNegativeButton: - altPositiveButton: mouse 1 + altPositiveButton: gravity: 1000 dead: 0.001 sensitivity: 1000