diff --git a/project.godot b/project.godot index 7b318b3..8417ace 100644 --- a/project.godot +++ b/project.godot @@ -89,6 +89,11 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://src/behaviours/spawning/SpawnEveryPeriod.gd" }, { +"base": "Node2D", +"class": "SpawnOnShoot", +"language": "GDScript", +"path": "res://src/behaviours/spawning/SpawnOnShoot.gd" +}, { "base": "Node", "class": "TeleportToRandomPosition", "language": "GDScript", @@ -116,6 +121,7 @@ _global_script_class_icons={ "RandomRotationOnReady": "", "SetSpawnedGoalTo": "", "SpawnEveryPeriod": "", +"SpawnOnShoot": "", "TeleportToRandomPosition": "", "TeleportToScreenEdge": "" } diff --git a/src/behaviours/spawning/SpawnOnShoot.gd b/src/behaviours/spawning/SpawnOnShoot.gd new file mode 100644 index 0000000..ff124a1 --- /dev/null +++ b/src/behaviours/spawning/SpawnOnShoot.gd @@ -0,0 +1,42 @@ +extends Node2D +class_name SpawnOnShoot + + +signal shot(bullet) + + +export var bullet: PackedScene +export var cooldown: float setget set_cooldown, get_cooldown +export var rapid_fire: bool + + +onready var parent: Node2D = get_parent() +onready var container: Node = get_tree().root.find_node("Bullets", true, false) + + +func set_cooldown(value): + $Cooldown.wait_time = value + +func get_cooldown() -> float: + return $Cooldown.wait_time + + +func shoot(target): + var node = bullet.instance() + node.set_position(global_position) + node.set_rotation(node.get_angle_to(target)) + container.add_child(node) + node.get_node("Ownership").entity_owner = parent + node.add_collision_exception_with(parent) + emit_signal("shot") + $Sound.play() + $Cooldown.start() + + +func _process(_delta): + var not_on_cooldown: bool = $Cooldown.is_stopped() + var trying_to_shoot: bool = Input.is_action_pressed("player_shoot") if rapid_fire else Input.is_action_just_pressed("player_shoot") + + if not_on_cooldown and trying_to_shoot: + var target = get_global_mouse_position() + shoot(target) diff --git a/src/behaviours/spawning/SpawnOnShoot.tscn b/src/behaviours/spawning/SpawnOnShoot.tscn new file mode 100644 index 0000000..7b95eb2 --- /dev/null +++ b/src/behaviours/spawning/SpawnOnShoot.tscn @@ -0,0 +1,13 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://src/behaviours/spawning/SpawnOnShoot.gd" type="Script" id=1] +[ext_resource path="res://src/sounds/Arrow.mp3" type="AudioStream" id=2] + +[node name="SpawnOnShoot" type="Node2D"] +script = ExtResource( 1 ) + +[node name="Cooldown" type="Timer" parent="."] +one_shot = true + +[node name="Sound" type="AudioStreamPlayer2D" parent="."] +stream = ExtResource( 2 ) diff --git a/src/entities/bullets/ArrowAlternative.gd b/src/entities/bullets/ArrowAlternative.gd index f1e1f84..f85e707 100644 --- a/src/entities/bullets/ArrowAlternative.gd +++ b/src/entities/bullets/ArrowAlternative.gd @@ -12,8 +12,10 @@ export var lit_damage: int = 5 func _on_Flammable_caught_fire(): $Shape/Sprite.texture = lit_texture $Damaging.damage = lit_damage + $Light.visible = true func _on_Flammable_extinguished_fire(): $Shape/Sprite.texture = dim_texture $Damaging.damage = dim_damage + $Light.visible = false diff --git a/src/entities/bullets/ArrowAlternative.tscn b/src/entities/bullets/ArrowAlternative.tscn index 569e964..14c810f 100644 --- a/src/entities/bullets/ArrowAlternative.tscn +++ b/src/entities/bullets/ArrowAlternative.tscn @@ -1,9 +1,10 @@ -[gd_scene load_steps=6 format=2] +[gd_scene load_steps=7 format=2] [ext_resource path="res://src/entities/bullets/AbstractBullet.tscn" type="PackedScene" id=1] [ext_resource path="res://src/entities/bullets/ArrowAlternative.png" type="Texture" id=2] [ext_resource path="res://src/entities/bullets/ArrowAlternative.gd" type="Script" id=3] [ext_resource path="res://src/behaviours/damage/Flammable.tscn" type="PackedScene" id=4] +[ext_resource path="res://src/mechanics/Light.png" type="Texture" id=5] [sub_resource type="RectangleShape2D" id=1] extents = Vector2( 6, 1.5 ) @@ -22,5 +23,11 @@ movement_per_second = 400.0 [node name="Flammable" parent="." index="4" instance=ExtResource( 4 )] +[node name="Light" type="Light2D" parent="." index="5"] +visible = false +texture = ExtResource( 5 ) +texture_scale = 0.02 +color = Color( 1, 0.607843, 0, 1 ) + [connection signal="caught_fire" from="Flammable" to="." method="_on_Flammable_caught_fire"] [connection signal="extinguished_fire" from="Flammable" to="." method="_on_Flammable_extinguished_fire"] diff --git a/src/entities/players/PhaseOnePlayer.tscn b/src/entities/players/PhaseOnePlayer.tscn index bbd8839..7660ecf 100644 --- a/src/entities/players/PhaseOnePlayer.tscn +++ b/src/entities/players/PhaseOnePlayer.tscn @@ -1,7 +1,9 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=6 format=2] [ext_resource path="res://src/entities/players/AbstractPlayer.tscn" type="PackedScene" id=1] [ext_resource path="res://src/mechanics/White.png" type="Texture" id=2] +[ext_resource path="res://src/entities/bullets/ArrowAlternative.tscn" type="PackedScene" id=3] +[ext_resource path="res://src/behaviours/spawning/SpawnOnShoot.tscn" type="PackedScene" id=4] [sub_resource type="RectangleShape2D" id=1] extents = Vector2( 16, 16 ) @@ -13,3 +15,11 @@ shape = SubResource( 1 ) [node name="Sprite" type="Sprite" parent="Shape" index="0"] texture = ExtResource( 2 ) + +[node name="Listener" type="Listener2D" parent="." index="1"] +current = true + +[node name="SpawnOnShoot" parent="." index="2" instance=ExtResource( 4 )] +bullet = ExtResource( 3 ) +cooldown = 0.1 +rapid_fire = true diff --git a/src/levels/Game.tscn b/src/levels/Game.tscn index 4087378..a7099b7 100644 --- a/src/levels/Game.tscn +++ b/src/levels/Game.tscn @@ -49,10 +49,12 @@ position = Vector2( 596, 268 ) [node name="Fire" parent="PhaseOne/Entities" instance=ExtResource( 3 )] position = Vector2( 640, 320 ) -intensity = 5.0 +intensity = 1.0 [node name="Pickups" type="Node" parent="PhaseOne/Entities"] +[node name="Bullets" type="Node" parent="PhaseOne/Entities"] + [node name="Enemies" type="Node" parent="PhaseOne/Entities"] [node name="ScreenEdgeSpawner" parent="PhaseOne/Entities/Enemies" instance=ExtResource( 8 )]