diff --git a/MrBigsock/Assets/Code/Core/Abilities/BasicProjectile1.cs b/MrBigsock/Assets/Code/Core/Abilities/BasicProjectile1.cs index 202c07916e5bf3974927dd0746813dc966ca4eda..f435a47baa84631c6c7fa8b8fc18c41f291fcc19 100644 --- a/MrBigsock/Assets/Code/Core/Abilities/BasicProjectile1.cs +++ b/MrBigsock/Assets/Code/Core/Abilities/BasicProjectile1.cs @@ -15,6 +15,7 @@ namespace BigSock { public class BasicProjectile1 : BaseAttack { //protected static readonly GameObject PROJECTILE_BASE = new AttackMovement(); public const string PROJECTILE_NAME = "bullets/basicsquarebullet"; + public const string AUDIO_PATH = "The Essential Retro Video Game Sound Effects Collection [512 sounds] By Juhani Junkala/Death Screams/Alien/sfx_deathscream_alien1"; public override ulong Id => 101; @@ -57,6 +58,18 @@ namespace BigSock { bulletScript.Stats = attack; bulletScript.Direction = (target.Value - (Vector2) actor.transform.position).normalized; + // Play sound effect + var source = actor.source; + var audioClip = AudioService.SINGLETON.Get(AUDIO_PATH); + if (source != null && audioClip != null) { + source.clip = audioClip; + source.Play(); + } else { + if(source == null) Debug.Log($"[BasicProjectile1.Activate()] audio source was null."); + if(audioClip == null) Debug.Log($"[BasicProjectile1.Activate()] audio clip was null."); + } + + return true; } diff --git a/MrBigsock/Assets/Code/PlayerController.cs b/MrBigsock/Assets/Code/PlayerController.cs index 6fd71277784eba75697aaec4458e9630de9b5ad3..6a2ca820ac2762d4a22fae2f014e3e3c6b1ab0ae 100644 --- a/MrBigsock/Assets/Code/PlayerController.cs +++ b/MrBigsock/Assets/Code/PlayerController.cs @@ -16,6 +16,11 @@ namespace BigSock { public partial class PlayerController : Character { + public const int SKILL_POINTS_PR_LVL = 3; // Skill points to gain pr level up. + public const int SKILL_POINTS_START = 5; // Skill points to start with. + public const float XP_SCALE_RATE = 3.0f; // Multiplier for xp gain, helps test system while game is tiny. + + public UtilBar utilBar; @@ -174,6 +179,7 @@ namespace BigSock { // Check ability 1. CheckAbilityInput(KeyCode.Space, _testAttack); + CheckAbilityInput(KeyCode.Mouse0, _testAttack); // Check ability 2. CheckAbilityInput(KeyCode.Z, _testAttack2); // Check ability 3. @@ -280,21 +286,31 @@ namespace BigSock { utilBar?.WithHealth(Convert.ToInt32(HP)); } - public void GainXp(float xp){ - GiveXp(xp); + public void GainXp(float xp) { + GiveXp(xp * XP_SCALE_RATE); CheckXp(); utilBar?.WithXP((int)this.xp); } - private void CheckXp(){ - if(xp > maxXp){ + + /* + Checks for, and handles, level-ups. + */ + private void CheckXp() { + // If the character has leveled up. + if(xp > maxXp) { level += 1; xp -= maxXp; maxXp = (level + 1) * 100; utilBar?.WithXP(maxValue: (int)maxXp); - + SkillPoints += SKILL_POINTS_PR_LVL; } + /* + To-do: + - Maybe not flat skill points pr level. + - Scale differently. (Separate function for getting xp requirement pr level) + */ } } @@ -308,7 +324,7 @@ namespace BigSock { /* The number of skill points the user has at their disposal. */ - public int SkillPoints { get; set; } + public int SkillPoints { get; set; } = SKILL_POINTS_START; /* The amount of points the user has currently spent on each skill. diff --git a/MrBigsock/Assets/Code/Services/AudioService.cs b/MrBigsock/Assets/Code/Services/AudioService.cs new file mode 100644 index 0000000000000000000000000000000000000000..ce122a06438b2ee551d4d697de1ea7fb04a51622 --- /dev/null +++ b/MrBigsock/Assets/Code/Services/AudioService.cs @@ -0,0 +1,69 @@ +using System.Collections; +using System; +using System.Linq; +using System.Collections.Generic; +using System.Reflection; + +using UnityEngine; +using UnityEngine.InputSystem; +using UnityEditor; + +using BigSock.Item; + + +namespace BigSock.Service { + + /* + Service for handling audio. + */ + public partial class AudioService { + /* + The instance to use. + */ + public static readonly AudioService SINGLETON = new AudioService(); + + /* + Get a audio of a name. + */ + public AudioClip Get(string name) { + if(_items.TryGetValue(_sanitize(name), out var res)) return res; + return null; + } + + } + + public partial class AudioService { + private Dictionary<string, AudioClip> _items = new Dictionary<string, AudioClip>(); + + private System.Random _rnd = new System.Random(); + + private AudioService() { + _loadItems(); + } + + /* + Load the items into the dictionary. + Based on: https://stackoverflow.com/a/67670629 + */ + private void _loadItems() { + string[] guids = AssetDatabase.FindAssets( "t:AudioClip", new string[] {"Assets/sound"} ); + + var dict = new Dictionary<string, AudioClip>(); + + foreach(var guid in guids) { + var path = AssetDatabase.GUIDToAssetPath( guid ); + var name = _sanitize(path.Replace(".wav", "").Replace(".mp3", "").Replace("Assets/sound/", "")); + AudioClip go = AssetDatabase.LoadAssetAtPath<AudioClip>( path ); + + //Debug.Log($"[SpriteService._loadItems()] {name}"); + dict[name] = go; + } + + _items = dict; + } + + private string _sanitize(string name) + => name.Replace(" ", "").Replace("_", "").ToLower(); + + } +} \ No newline at end of file diff --git a/MrBigsock/Assets/Code/Services/AudioService.cs.meta b/MrBigsock/Assets/Code/Services/AudioService.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..bb831bb06360b92cf640188a81a2c8757fef9481 --- /dev/null +++ b/MrBigsock/Assets/Code/Services/AudioService.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: bace12991ada10e438cef9039856ed10 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/MrBigsock/Assets/Prefabs/BigSock.prefab b/MrBigsock/Assets/Prefabs/BigSock.prefab index d90aa1d783867560cbe5545cae8678c09dc3d7b9..6c255299c02df4c874253b5acbb7dacfa22054d3 100644 --- a/MrBigsock/Assets/Prefabs/BigSock.prefab +++ b/MrBigsock/Assets/Prefabs/BigSock.prefab @@ -47,6 +47,7 @@ GameObject: - component: {fileID: 8339702841083125274} - component: {fileID: 8616172023331984945} - component: {fileID: 8280117626939289948} + - component: {fileID: 2616313082813604002} m_Layer: 9 m_Name: BigSock m_TagString: Player @@ -165,12 +166,18 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: baseAttackSpeed: 4 + source: {fileID: 2616313082813604002} + TakeDamageAudio: {fileID: 0} baseMovementSpeed: 10 baseDamage: 1 knockbackForce: 1 baseHP: 10 baseMaxHP: 10 - hpBar: {fileID: 0} + dropXP: 0 + xp: 0 + maxXp: 0 + level: 0 + utilBar: {fileID: 0} collisionOffset: 0.05 movementFilter: useTriggers: 0 @@ -272,3 +279,99 @@ BoxCollider2D: serializedVersion: 2 m_Size: {x: 0.60876524, y: 0.40417254} m_EdgeRadius: 0 +--- !u!82 &2616313082813604002 +AudioSource: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8799933624292384519} + m_Enabled: 1 + serializedVersion: 4 + OutputAudioMixerGroup: {fileID: 0} + m_audioClip: {fileID: 0} + m_PlayOnAwake: 1 + m_Volume: 1 + m_Pitch: 1 + Loop: 0 + Mute: 0 + Spatialize: 0 + SpatializePostEffects: 0 + Priority: 128 + DopplerLevel: 1 + MinDistance: 1 + MaxDistance: 500 + Pan2D: 0 + rolloffMode: 0 + BypassEffects: 0 + BypassListenerEffects: 0 + BypassReverbZones: 0 + rolloffCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + - serializedVersion: 3 + time: 1 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + panLevelCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + spreadCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + reverbZoneMixCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4