Hopefully there's okay comments on things now

This commit is contained in:
2024-10-20 02:47:43 -07:00
parent eb47adf2d2
commit fd6657047b
6 changed files with 35 additions and 9 deletions

View File

@@ -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<Teo>().transform.position;
Vector3 playerPosition = GameObject.FindGameObjectWithTag("Player").transform.position;
for (uint _ = 0; _ < wave; _++) {
GameObject newRatbot = Instantiate(
ratbot,

View File

@@ -107,6 +107,7 @@ MonoBehaviour:
moveSpeed: 15
swingRange: 2
damageStrength: 10
attackCooldownSeconds: 2
--- !u!50 &-4152331571693237436
Rigidbody2D:
serializedVersion: 5

View File

@@ -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<GameState>();
}
// Update is called once per frame
void Update()
{
void Update() {
// Constantly move towards player
Rigidbody2D controller = GetComponent<Rigidbody2D>();
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<Teo>().health -= damageStrength;
}
// Die if health below zero
public void Damage(float hurtyAmount) {
health -= hurtyAmount;
if (health <= 0) {

View File

@@ -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,

View File

@@ -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<Rigidbody2D>();
@@ -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<Ratbot>();
if (ratbot == null) continue;

View File

@@ -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: