1
Fork 0
mirror of https://github.com/RYGhub/the-cold-night.git synced 2024-11-25 06:04:19 +00:00

🔧 Re-add arrow shooting

This commit is contained in:
Steffo 2022-04-04 00:01:37 +02:00
parent 08f220606d
commit 5621f27d7c
Signed by: steffo
GPG key ID: 6965406171929D01
7 changed files with 85 additions and 3 deletions

View file

@ -89,6 +89,11 @@ _global_script_classes=[ {
"language": "GDScript", "language": "GDScript",
"path": "res://src/behaviours/spawning/SpawnEveryPeriod.gd" "path": "res://src/behaviours/spawning/SpawnEveryPeriod.gd"
}, { }, {
"base": "Node2D",
"class": "SpawnOnShoot",
"language": "GDScript",
"path": "res://src/behaviours/spawning/SpawnOnShoot.gd"
}, {
"base": "Node", "base": "Node",
"class": "TeleportToRandomPosition", "class": "TeleportToRandomPosition",
"language": "GDScript", "language": "GDScript",
@ -116,6 +121,7 @@ _global_script_class_icons={
"RandomRotationOnReady": "", "RandomRotationOnReady": "",
"SetSpawnedGoalTo": "", "SetSpawnedGoalTo": "",
"SpawnEveryPeriod": "", "SpawnEveryPeriod": "",
"SpawnOnShoot": "",
"TeleportToRandomPosition": "", "TeleportToRandomPosition": "",
"TeleportToScreenEdge": "" "TeleportToScreenEdge": ""
} }

View file

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

View file

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

View file

@ -12,8 +12,10 @@ export var lit_damage: int = 5
func _on_Flammable_caught_fire(): func _on_Flammable_caught_fire():
$Shape/Sprite.texture = lit_texture $Shape/Sprite.texture = lit_texture
$Damaging.damage = lit_damage $Damaging.damage = lit_damage
$Light.visible = true
func _on_Flammable_extinguished_fire(): func _on_Flammable_extinguished_fire():
$Shape/Sprite.texture = dim_texture $Shape/Sprite.texture = dim_texture
$Damaging.damage = dim_damage $Damaging.damage = dim_damage
$Light.visible = false

View file

@ -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/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.png" type="Texture" id=2]
[ext_resource path="res://src/entities/bullets/ArrowAlternative.gd" type="Script" id=3] [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/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] [sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 6, 1.5 ) 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="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="caught_fire" from="Flammable" to="." method="_on_Flammable_caught_fire"]
[connection signal="extinguished_fire" from="Flammable" to="." method="_on_Flammable_extinguished_fire"] [connection signal="extinguished_fire" from="Flammable" to="." method="_on_Flammable_extinguished_fire"]

View file

@ -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/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/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] [sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 16, 16 ) extents = Vector2( 16, 16 )
@ -13,3 +15,11 @@ shape = SubResource( 1 )
[node name="Sprite" type="Sprite" parent="Shape" index="0"] [node name="Sprite" type="Sprite" parent="Shape" index="0"]
texture = ExtResource( 2 ) 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

View file

@ -49,10 +49,12 @@ position = Vector2( 596, 268 )
[node name="Fire" parent="PhaseOne/Entities" instance=ExtResource( 3 )] [node name="Fire" parent="PhaseOne/Entities" instance=ExtResource( 3 )]
position = Vector2( 640, 320 ) position = Vector2( 640, 320 )
intensity = 5.0 intensity = 1.0
[node name="Pickups" type="Node" parent="PhaseOne/Entities"] [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="Enemies" type="Node" parent="PhaseOne/Entities"]
[node name="ScreenEdgeSpawner" parent="PhaseOne/Entities/Enemies" instance=ExtResource( 8 )] [node name="ScreenEdgeSpawner" parent="PhaseOne/Entities/Enemies" instance=ExtResource( 8 )]