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)
texture = ExtResource("2_veygi")
[connection signal="area_entered" from="." to="." method="_on_area_entered"]
[connection signal="body_entered" from="." to="." method="_on_body_entered"]

View File

@ -318,7 +318,6 @@ animations = [{
[node name="CharacterBody2D" type="CharacterBody2D"]
script = ExtResource("1_5qpif")
metadata/_edit_group_ = true
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
texture_filter = 1
@ -340,9 +339,9 @@ target_position = Vector2(-19, 0)
collide_with_areas = true
[node name="MarkerRight" type="Node2D" parent="."]
position = Vector2(12, -5)
position = Vector2(22, 0)
[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"]

View File

@ -15,4 +15,10 @@ func _physics_process(delta: float) -> void:
position += transform.x * speed * delta
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")
func killPlayer():
print("kill the player")
if living:
living = false
#play death animation
animPlaying="death"
playerSprite.play(animPlaying)
func hurtPlayer(currentHealth):
print("current health is : "+str(currentHealth))
animPlaying="hurt"
playerSprite.play(animPlaying)
@ -112,7 +112,7 @@ func _physics_process(delta: float) -> void:
pushLeftEnabled = true
pushTarget = collider
if collider is Enemy:
print("I can punch on left")
punchTarget = collider
punchLeftEnabled = true
else:
@ -127,7 +127,7 @@ func _physics_process(delta: float) -> void:
pushRightEnabled = true
pushTarget = collider
if collider is Enemy:
print("I can punch on the right")
punchTarget = collider
punchRightEnabled = true
else:
@ -136,7 +136,7 @@ func _physics_process(delta: float) -> void:
func _on_animation_finished() -> void:
print("animation finished "+animPlaying)
if animPlaying=="hurt":
animPlaying="idle"
if animPlaying=="death":

View File

@ -51,6 +51,7 @@ func bulletFactory():
myBullet = bullet.instantiate()
owner.add_child(myBullet)
#or....recycles bullets
myBullet.visible = true
return myBullet
func placeBullet(speed, markerpos):
@ -63,6 +64,17 @@ func placeBullet(speed, markerpos):
# set the position of the bullet
myBullet.transform = markerpos
# 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():
var myCrate = crate.instantiate()