From fd6657047b97f5290583b69f65e81182a4228335 Mon Sep 17 00:00:00 2001 From: ProtoSharkk Date: Sun, 20 Oct 2024 02:47:43 -0700 Subject: [PATCH] Hopefully there's okay comments on things now --- Assets/GameState.cs | 4 +++- Assets/Player.prefab | 1 + Assets/Ratbot.cs | 14 ++++++++------ Assets/Sword.cs | 1 + Assets/Teo.cs | 8 +++++++- Assets/teoCropped.png.meta | 16 +++++++++++++++- 6 files changed, 35 insertions(+), 9 deletions(-) diff --git a/Assets/GameState.cs b/Assets/GameState.cs index ad43805..df76e18 100644 --- a/Assets/GameState.cs +++ b/Assets/GameState.cs @@ -24,8 +24,10 @@ public class GameState : MonoBehaviour } public void NewWave() { + // Spawn ratbots around the player + // Amount, health, and damage scale with waves state = "WAVE"; - Vector3 playerPosition = GameObject.FindGameObjectWithTag("Player").GetComponent().transform.position; + Vector3 playerPosition = GameObject.FindGameObjectWithTag("Player").transform.position; for (uint _ = 0; _ < wave; _++) { GameObject newRatbot = Instantiate( ratbot, diff --git a/Assets/Player.prefab b/Assets/Player.prefab index aec03f0..cc17239 100644 --- a/Assets/Player.prefab +++ b/Assets/Player.prefab @@ -107,6 +107,7 @@ MonoBehaviour: moveSpeed: 15 swingRange: 2 damageStrength: 10 + attackCooldownSeconds: 2 --- !u!50 &-4152331571693237436 Rigidbody2D: serializedVersion: 5 diff --git a/Assets/Ratbot.cs b/Assets/Ratbot.cs index 8e9bae7..7c9e6b4 100644 --- a/Assets/Ratbot.cs +++ b/Assets/Ratbot.cs @@ -9,20 +9,20 @@ public class Ratbot : MonoBehaviour float lastDamageTime; GameState gameState; GameObject player; - // Start is called once before the first execution of Update after the MonoBehaviour is created - void Start() - { + + void Start() { + // Set gameState and player objects player = GameObject.FindGameObjectWithTag("Player"); gameState = GameObject.FindGameObjectWithTag("GameController").GetComponent(); } - // Update is called once per frame - void Update() - { + void Update() { + // Constantly move towards player Rigidbody2D controller = GetComponent(); Vector2 direction = (player.transform.position - transform.position).normalized; controller.linearVelocity = direction*moveSpeed; } + void OnCollisionStay2D(Collision2D collision) { // Deal damage when colliding with the player on a 0.5 second cooldown if (collision.gameObject.tag != "Player") return; @@ -30,6 +30,8 @@ public class Ratbot : MonoBehaviour lastDamageTime = Time.fixedTime; collision.gameObject.GetComponent().health -= damageStrength; } + + // Die if health below zero public void Damage(float hurtyAmount) { health -= hurtyAmount; if (health <= 0) { diff --git a/Assets/Sword.cs b/Assets/Sword.cs index daab4be..0cb35d3 100644 --- a/Assets/Sword.cs +++ b/Assets/Sword.cs @@ -11,6 +11,7 @@ public class Sword : MonoBehaviour // Update is called once per frame void Update() { + // Point sword towards mouse cursor with garbage trig transform.rotation = Quaternion.Euler( new Vector3 (0, 0, Mathf.Atan2( Screen.height/2 - Input.mousePosition.y, diff --git a/Assets/Teo.cs b/Assets/Teo.cs index bc2f992..d2b6ac4 100644 --- a/Assets/Teo.cs +++ b/Assets/Teo.cs @@ -6,8 +6,10 @@ public class Teo : MonoBehaviour public float moveSpeed = 10; public float swingRange = 3; public float damageStrength = 10; + public float attackCooldownSeconds = 2; Rigidbody2D controller; GameState gameState; + float lastAttackTime; // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { controller = GetComponent(); @@ -16,12 +18,15 @@ public class Teo : MonoBehaviour // Update is called once per frame void Update() { + // Move player controller.linearVelocity = new Vector2 ( Input.GetAxis("Horizontal"), Input.GetAxis("Vertical") ).normalized * moveSpeed; - if (Input.GetMouseButtonDown(0)) { + // Attack on click if not on cooldown + if (Input.GetMouseButtonDown(0) && Time.fixedTime > lastAttackTime + attackCooldownSeconds) { + // Get all objects in range in the direction of cursor RaycastHit2D[] hits = Physics2D.CircleCastAll( transform.position, swingRange, @@ -30,6 +35,7 @@ public class Teo : MonoBehaviour Screen.height/2 - Input.mousePosition.y ) ); + // Damage all ratbots in scanned area foreach (RaycastHit2D hit in hits) { Ratbot ratbot = hit.collider.GetComponent(); if (ratbot == null) continue; diff --git a/Assets/teoCropped.png.meta b/Assets/teoCropped.png.meta index 01f2326..b67f806 100644 --- a/Assets/teoCropped.png.meta +++ b/Assets/teoCropped.png.meta @@ -96,6 +96,19 @@ TextureImporter: ignorePlatformSupport: 0 androidETC2FallbackOverride: 0 forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 4 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + ignorePlatformSupport: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 spriteSheet: serializedVersion: 2 sprites: @@ -134,7 +147,8 @@ TextureImporter: secondaryTextures: [] spriteCustomMetadata: entries: [] - nameFileIdTable: {} + nameFileIdTable: + teoCropped_0: 4084514856309348668 mipmapLimitGroupName: pSDRemoveMatte: 0 userData: