From 5240811f022678fdc9754616eb80fd261c50ef03 Mon Sep 17 00:00:00 2001 From: OddlyTimbot Date: Tue, 27 Oct 2026 17:36:48 -0400 Subject: [PATCH] smarter slimes --- assets/enemies/slime/slime_purple.png | Bin 0 -> 1030 bytes assets/enemies/slime/slime_purple.png.import | 40 ++++++ scenes/game.tscn | 6 + scenes/slime.tscn | 137 +++++++++++++++++++ scripts/slime.gd | 82 +++++++++++ scripts/slime.gd.uid | 1 + 6 files changed, 266 insertions(+) create mode 100644 assets/enemies/slime/slime_purple.png create mode 100644 assets/enemies/slime/slime_purple.png.import create mode 100644 scenes/slime.tscn create mode 100644 scripts/slime.gd create mode 100644 scripts/slime.gd.uid diff --git a/assets/enemies/slime/slime_purple.png b/assets/enemies/slime/slime_purple.png new file mode 100644 index 0000000000000000000000000000000000000000..76f564e1d18d3f4b59c032ee8233ebf4665af431 GIT binary patch literal 1030 zcmeAS@N?(olHy`uVBq!ia0vp^2|(<@!3HEb(?2AGr~;43Vg?3oVGw3ym^DX&fq{94 zr;B4q#hkZu_UB)A5IH_yFgSBs)oT$}vmn=*zw9@ptqPdBe?d}nV{fk>$4CBvg?)Ed z_vO50>IiWPSm-r%m!<3^wh~P~_4RS~ zpI=Gub+-QhIeq%h`RaxX{5TJNc>dLzfkEQSwe9u4|AzdIT*^2{!A86~-QWe|7ymwB zC>Ti{|81}_`+UPPl@+TN=sEg&On58UrMgnvLQXF0_ys@bQ1@EdnLWo=s>t&5b6*sD zcFMcwU?tm(D_Xg)W-Wc$-E!h}Crjk()1K3gUwWA?xq;Wdw18cHo3k~Zx-$Fb`AU$*-@DD zmGPf?jG6V$dCTQj>{2>(Zt>F0fcfj}50vb4xa*Xko3|y%e%9UPUyOMTg5ncDvEEv- z-pIj{ckVgygWdnMA2Z(bzqjb#^{`seQ^pPQ$9_6a&90O2#S*<mC1;UMyZZkxfN& z@uKHWkGnrH91Z`H^EmwCk41a3FUGWg-!^5J_|wx1K5Uz!#D3x7Zw}ELVrNTt9P8IR z_1(WOXsY%rc>^6i*W&vj&+HC_UuW8s@vbNLPX_a void: + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + handleMovement(delta) + handleStates() + handleAnimation() + handleCollisions() + +func _on_body_entered(body: Node2D) -> void: + if body is Player: + print("Attack the player") + currentEnemyState = EnemyStates.ATTACK + direction = 0 + enemyAttackSignal.emit(body, self) + +func handleMovement(delta)->void: + position.x += direction*speed*delta + match facing: + FaceDirection.LEFT: + enemy_graphic.flip_h = true + FaceDirection.RIGHT: + enemy_graphic.flip_h = false + +func handleStates()->void: + match currentEnemyState: + EnemyStates.SPAWN when not direction ==0 : + print("setting state to run") + currentEnemyState = EnemyStates.RUN + + +func handleAnimation()->void: + match currentEnemyState: + EnemyStates.SPAWN: + enemy_graphic.play("spawn") + EnemyStates.RUN: + enemy_graphic.play("idle") + EnemyStates.ATTACK: + enemy_graphic.play("attack") + +func handleCollisions()->void: + if not right_down_cast.is_colliding(): + direction =-1 + facing = FaceDirection.LEFT + if not left_down_cast.is_colliding(): + direction = 1 + facing = FaceDirection.RIGHT + if right_cast.is_colliding() && not right_cast.get_collider() is Player: + direction = -1 + facing=FaceDirection.LEFT + if left_cast.is_colliding() && not left_cast.get_collider() is Player: + direction = 1 + facing=FaceDirection.RIGHT + +func _on_animation_finished() -> void: + match currentEnemyState: + EnemyStates.SPAWN: + currentEnemyState = EnemyStates.RUN + direction = 1 + EnemyStates.ATTACK: + currentEnemyState = EnemyStates.RUN + direction = (randi() % 2) * 2 - 1 diff --git a/scripts/slime.gd.uid b/scripts/slime.gd.uid new file mode 100644 index 0000000..584b910 --- /dev/null +++ b/scripts/slime.gd.uid @@ -0,0 +1 @@ +uid://c83er3jdb7i8d