working bullets

This commit is contained in:
OddlyTimbot 2024-10-07 20:56:53 -04:00
parent e50ead9360
commit 614fc9860b
5 changed files with 27 additions and 9 deletions

View File

@ -20,4 +20,5 @@ rotation = 3.14794
scale = Vector2(0.09375, 0.09375) scale = Vector2(0.09375, 0.09375)
texture = ExtResource("2_veygi") texture = ExtResource("2_veygi")
[connection signal="area_entered" from="." to="." method="_on_area_entered"]
[connection signal="body_entered" from="." to="." method="_on_body_entered"] [connection signal="body_entered" from="." to="." method="_on_body_entered"]

View File

@ -318,7 +318,6 @@ animations = [{
[node name="CharacterBody2D" type="CharacterBody2D"] [node name="CharacterBody2D" type="CharacterBody2D"]
script = ExtResource("1_5qpif") script = ExtResource("1_5qpif")
metadata/_edit_group_ = true
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] [node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
texture_filter = 1 texture_filter = 1
@ -340,9 +339,9 @@ target_position = Vector2(-19, 0)
collide_with_areas = true collide_with_areas = true
[node name="MarkerRight" type="Node2D" parent="."] [node name="MarkerRight" type="Node2D" parent="."]
position = Vector2(12, -5) position = Vector2(22, 0)
[node name="MarkerLeft" type="Node2D" parent="."] [node name="MarkerLeft" type="Node2D" parent="."]
position = Vector2(-15, -5) position = Vector2(-21, 0)
[connection signal="animation_finished" from="AnimatedSprite2D" to="." method="_on_animation_finished"] [connection signal="animation_finished" from="AnimatedSprite2D" to="." method="_on_animation_finished"]

View File

@ -15,4 +15,10 @@ func _physics_process(delta: float) -> void:
position += transform.x * speed * delta position += transform.x * speed * delta
func _on_body_entered(body: Node2D) -> void: func _on_body_entered(body: Node2D) -> void:
print("I done hit somethin") if body is Enemy:
print("blow away enemy")
func _on_area_entered(area: Area2D) -> void:
if area is Enemy:
print("blow this enemy away")
hit.emit(self, area)

View File

@ -28,14 +28,14 @@ var punchTarget:Enemy
var bullet = preload("res://scenes/bullet.tscn") var bullet = preload("res://scenes/bullet.tscn")
func killPlayer(): func killPlayer():
print("kill the player")
if living: if living:
living = false living = false
#play death animation #play death animation
animPlaying="death" animPlaying="death"
playerSprite.play(animPlaying) playerSprite.play(animPlaying)
func hurtPlayer(currentHealth): func hurtPlayer(currentHealth):
print("current health is : "+str(currentHealth))
animPlaying="hurt" animPlaying="hurt"
playerSprite.play(animPlaying) playerSprite.play(animPlaying)
@ -112,7 +112,7 @@ func _physics_process(delta: float) -> void:
pushLeftEnabled = true pushLeftEnabled = true
pushTarget = collider pushTarget = collider
if collider is Enemy: if collider is Enemy:
print("I can punch on left")
punchTarget = collider punchTarget = collider
punchLeftEnabled = true punchLeftEnabled = true
else: else:
@ -127,7 +127,7 @@ func _physics_process(delta: float) -> void:
pushRightEnabled = true pushRightEnabled = true
pushTarget = collider pushTarget = collider
if collider is Enemy: if collider is Enemy:
print("I can punch on the right")
punchTarget = collider punchTarget = collider
punchRightEnabled = true punchRightEnabled = true
else: else:
@ -136,7 +136,7 @@ func _physics_process(delta: float) -> void:
func _on_animation_finished() -> void: func _on_animation_finished() -> void:
print("animation finished "+animPlaying)
if animPlaying=="hurt": if animPlaying=="hurt":
animPlaying="idle" animPlaying="idle"
if animPlaying=="death": if animPlaying=="death":

View File

@ -51,6 +51,7 @@ func bulletFactory():
myBullet = bullet.instantiate() myBullet = bullet.instantiate()
owner.add_child(myBullet) owner.add_child(myBullet)
#or....recycles bullets #or....recycles bullets
myBullet.visible = true
return myBullet return myBullet
func placeBullet(speed, markerpos): func placeBullet(speed, markerpos):
@ -63,6 +64,17 @@ func placeBullet(speed, markerpos):
# set the position of the bullet # set the position of the bullet
myBullet.transform = markerpos myBullet.transform = markerpos
# make the bullet visible by adding it # make the bullet visible by adding it
myBullet.hit.connect(bulletHit)
func bulletHit(bullet, body):
print("bullet hit a target")
body.queue_free()
bullet.setSpeed(0)
bullet.visible = false
func spendBullet():
#place a spent bullet back in the pool
pass
func crateFactory(): func crateFactory():
var myCrate = crate.instantiate() var myCrate = crate.instantiate()