Added turret
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
@tool
|
||||
class_name Turret
|
||||
extends Node2D
|
||||
|
||||
|
||||
enum Direction {
|
||||
Left,
|
||||
Right,
|
||||
}
|
||||
|
||||
|
||||
const ANIMATION_IDLE = "idle"
|
||||
const ANIMATION_SHOOT = "shoot"
|
||||
|
||||
const SHOT_FRAME = 3
|
||||
|
||||
|
||||
@export_range(0.0, 60.0) var shoot_delay := 3.0
|
||||
|
||||
@export var direction := Direction.Left:
|
||||
set(value):
|
||||
direction = value
|
||||
if is_node_ready():
|
||||
_update_direction()
|
||||
|
||||
|
||||
@onready var left_sprite : AnimatedSprite2D = $LeftSprite
|
||||
@onready var right_sprite : AnimatedSprite2D = $RightSprite
|
||||
|
||||
@onready var left_muzzle : Node2D = $LeftMuzzle
|
||||
@onready var right_muzzle : Node2D = $RightMuzzle
|
||||
|
||||
@onready var shoot_timer : Timer = $ShootTimer
|
||||
|
||||
|
||||
var _current_sprite : AnimatedSprite2D
|
||||
var _current_muzzle : Node2D
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
left_sprite.hide()
|
||||
right_sprite.hide()
|
||||
_update_direction()
|
||||
if not Engine.is_editor_hint():
|
||||
shoot_timer.start(shoot_delay)
|
||||
|
||||
|
||||
func _shoot() -> void:
|
||||
print("Shot")
|
||||
|
||||
|
||||
func _update_direction() -> void:
|
||||
if _current_sprite:
|
||||
_current_sprite.hide()
|
||||
match direction:
|
||||
Direction.Left:
|
||||
_current_sprite = left_sprite
|
||||
_current_muzzle = left_muzzle
|
||||
Direction.Right:
|
||||
_current_sprite = right_sprite
|
||||
_current_muzzle = right_muzzle
|
||||
_current_sprite.show()
|
||||
|
||||
|
||||
func _on_left_sprite_animation_finished() -> void:
|
||||
left_sprite.play(ANIMATION_IDLE)
|
||||
|
||||
|
||||
func _on_right_sprite_animation_finished() -> void:
|
||||
right_sprite.play(ANIMATION_IDLE)
|
||||
|
||||
|
||||
func _on_shoot_timer_timeout() -> void:
|
||||
_current_sprite.play(ANIMATION_SHOOT)
|
||||
SoundManager.play_sfx_stream(SoundManager.sfx_stream_turret_shot, global_position)
|
||||
|
||||
|
||||
func _on_sprite_frame_changed() -> void:
|
||||
if _current_sprite.frame == SHOT_FRAME:
|
||||
_shoot()
|
||||
@@ -0,0 +1 @@
|
||||
uid://cpcawuflstr35
|
||||
@@ -0,0 +1,170 @@
|
||||
[gd_scene format=3 uid="uid://dn3x1qj88r8pn"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cpcawuflstr35" path="res://game/entities/turret/turret.gd" id="1_t2kwx"]
|
||||
[ext_resource type="Texture2D" uid="uid://drbm7sgovja7y" path="res://images/entities/turret.png" id="2_dk6qj"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_xc2wu"]
|
||||
atlas = ExtResource("2_dk6qj")
|
||||
region = Rect2(0, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_xyas7"]
|
||||
atlas = ExtResource("2_dk6qj")
|
||||
region = Rect2(32, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_5ypow"]
|
||||
atlas = ExtResource("2_dk6qj")
|
||||
region = Rect2(64, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_jpkta"]
|
||||
atlas = ExtResource("2_dk6qj")
|
||||
region = Rect2(96, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_ofwyn"]
|
||||
atlas = ExtResource("2_dk6qj")
|
||||
region = Rect2(128, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_1lhwr"]
|
||||
atlas = ExtResource("2_dk6qj")
|
||||
region = Rect2(160, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_ep464"]
|
||||
atlas = ExtResource("2_dk6qj")
|
||||
region = Rect2(192, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_anymp"]
|
||||
atlas = ExtResource("2_dk6qj")
|
||||
region = Rect2(224, 0, 32, 32)
|
||||
|
||||
[sub_resource type="SpriteFrames" id="SpriteFrames_t2kwx"]
|
||||
animations = [{
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_xc2wu")
|
||||
}],
|
||||
"loop": 1,
|
||||
"name": &"idle",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_xyas7")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_5ypow")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_jpkta")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_ofwyn")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_1lhwr")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_ep464")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_anymp")
|
||||
}],
|
||||
"loop": 0,
|
||||
"name": &"shoot",
|
||||
"speed": 10.0
|
||||
}]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_dk6qj"]
|
||||
atlas = ExtResource("2_dk6qj")
|
||||
region = Rect2(0, 32, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_yfd5k"]
|
||||
atlas = ExtResource("2_dk6qj")
|
||||
region = Rect2(32, 32, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_ch0l6"]
|
||||
atlas = ExtResource("2_dk6qj")
|
||||
region = Rect2(64, 32, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_2od74"]
|
||||
atlas = ExtResource("2_dk6qj")
|
||||
region = Rect2(96, 32, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_o0sii"]
|
||||
atlas = ExtResource("2_dk6qj")
|
||||
region = Rect2(128, 32, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_bw4r7"]
|
||||
atlas = ExtResource("2_dk6qj")
|
||||
region = Rect2(160, 32, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_b3apy"]
|
||||
atlas = ExtResource("2_dk6qj")
|
||||
region = Rect2(192, 32, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_viadk"]
|
||||
atlas = ExtResource("2_dk6qj")
|
||||
region = Rect2(224, 32, 32, 32)
|
||||
|
||||
[sub_resource type="SpriteFrames" id="SpriteFrames_dk6qj"]
|
||||
animations = [{
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_dk6qj")
|
||||
}],
|
||||
"loop": 1,
|
||||
"name": &"idle",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_yfd5k")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_ch0l6")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_2od74")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_o0sii")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_bw4r7")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_b3apy")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_viadk")
|
||||
}],
|
||||
"loop": 0,
|
||||
"name": &"shoot",
|
||||
"speed": 10.0
|
||||
}]
|
||||
|
||||
[node name="Turret" type="Node2D" unique_id=328367237]
|
||||
script = ExtResource("1_t2kwx")
|
||||
shoot_delay = null
|
||||
|
||||
[node name="LeftSprite" type="AnimatedSprite2D" parent="." unique_id=1558853615]
|
||||
position = Vector2(0, -16)
|
||||
sprite_frames = SubResource("SpriteFrames_t2kwx")
|
||||
animation = &"idle"
|
||||
|
||||
[node name="RightSprite" type="AnimatedSprite2D" parent="." unique_id=664817745]
|
||||
visible = false
|
||||
sprite_frames = SubResource("SpriteFrames_dk6qj")
|
||||
animation = &"shoot"
|
||||
|
||||
[node name="LeftMuzzle" type="Node2D" parent="." unique_id=1708157273]
|
||||
position = Vector2(-12, -19)
|
||||
|
||||
[node name="RightMuzzle" type="Node2D" parent="." unique_id=1799037147]
|
||||
position = Vector2(12, -19)
|
||||
|
||||
[node name="ShootTimer" type="Timer" parent="." unique_id=1043641466]
|
||||
|
||||
[connection signal="animation_finished" from="LeftSprite" to="." method="_on_left_sprite_animation_finished"]
|
||||
[connection signal="frame_changed" from="LeftSprite" to="." method="_on_sprite_frame_changed"]
|
||||
[connection signal="animation_finished" from="RightSprite" to="." method="_on_right_sprite_animation_finished"]
|
||||
[connection signal="sprite_frames_changed" from="RightSprite" to="." method="_on_sprite_frame_changed"]
|
||||
[connection signal="timeout" from="ShootTimer" to="." method="_on_shoot_timer_timeout"]
|
||||
@@ -1199,6 +1199,8 @@ script = ExtResource("1_o2mui")
|
||||
[node name="TileMapLayer" type="TileMapLayer" parent="." unique_id=502099522]
|
||||
tile_set = SubResource("TileSet_71ysb")
|
||||
|
||||
[node name="Turrets" type="Node2D" parent="." unique_id=491073452]
|
||||
|
||||
[node name="Dangers" type="Node2D" parent="." unique_id=608961351]
|
||||
|
||||
[node name="CanvasLayer" type="CanvasLayer" parent="." unique_id=1125559156]
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
[gd_scene format=4 uid="uid://cuig5x5fd47hs"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://hdnty666fw1h" path="res://game/levels/abstract_level.tscn" id="1_46m3m"]
|
||||
[ext_resource type="PackedScene" uid="uid://dn3x1qj88r8pn" path="res://game/entities/turret/turret.tscn" id="2_giiqr"]
|
||||
[ext_resource type="PackedScene" uid="uid://dxqq07mde0b4a" path="res://game/entities/danger/danger.tscn" id="2_yeikn"]
|
||||
|
||||
[sub_resource type="ViewportTexture" id="ViewportTexture_yeikn"]
|
||||
[sub_resource type="ViewportTexture" id="ViewportTexture_80l8l"]
|
||||
viewport_path = NodePath("CanvasLayer/CodeViewport")
|
||||
|
||||
[node name="TestLevel" unique_id=1001045799 instance=ExtResource("1_46m3m")]
|
||||
@@ -16,6 +17,10 @@ position = Vector2(0, -38)
|
||||
[node name="TileMapLayer" parent="." index="1" unique_id=502099522]
|
||||
tile_map_data = PackedByteArray("AAAMAP//AAAFAAoAAAAMAP7/AAALAAYAAAAMAP3/AAAIAAYAAAAMAPz/AAAKAAYAAAAMAPv/AAADAAYAAAAMAPr/AAAGAAYAAAAMAPn/AAABAAYAAAAMAPj/AAAIAAYAAAAMAPf/AAAFAAYAAAAMAPb/AAAIAAYAAAAMAPX/AAALAAYAAAAMAPT/AAALAAYAAAAMAPP/AAADAAYAAAAMAPL/AAACAAYAAAAMAPH/AAAFAAYAAAAMAPD/AAABAAYAAAAAAPn/AAADAAQAAAAAAPj/AAAKAAYAAAAAAPf/AAACAAYAAAAAAPb/AAADAAYAAAAAAPX/AAAJAAYAAAAAAPT/AAADAAYAAAAAAPP/AAAIAAYAAAAAAPL/AAAKAAYAAAAAAPH/AAAGAAYAAAAAAPD/AAAJAAYAAAAAAO//AAAJAAYAAAD0////AAAGAAcAAAD0//7/AAAGAAYAAAD0//3/AAABAAYAAAD0//z/AAAGAAYAAAD0//v/AAAFAAYAAAD0//r/AAAHAAYAAAD0//n/AAAHAAYAAAD0//j/AAACAAYAAAD0//f/AAAEAAYAAAD0//b/AAABAAYAAAD0//X/AAABAAYAAAD0//T/AAAIAAYAAAD0//P/AAALAAYAAAD0//L/AAAFAAYAAAD0//H/AAAGAAYAAAD0//D/AAAKAAYAAAD0/+//AAA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AAN//AAAGAAYAAAAAAN7/AAAEAAYAAAAAAN3/AAABAAYAAAAAANz/AAAKAAYAAAAAANv/AAADAAYAAAAAANr/AAACAAMAAAALAP//AAAHAAUAAAAKAP//AAAFAAUAAAAJAP//AAACAAUAAAAIAP//AAAIAAUAAAAHAP//AAAAAAUAAAAGAP//AAABAAUAAAAFAP//AAAJAAUAAAAEAP//AAALAAUAAAADAP//AAAEAAUAAAACAP//AAADAAUAAAABAP//AAAJAAUAAAAAAP//AAAJAAUAAAD/////AAAJAAUAAAD+////AAACAAUAAAD9////AAADAAUAAAD8////AAAGAAUAAAD7////AAACAAUAAAD6////AAAIAAUAAAD5////AAACAAUAAAD4////AAAHAAUAAAD3////AAACAAUAAAD2////AAAKAAUAAAD1////AAAEAAUAAADk/+X/AAAGAAUAAADj/+X/AAAKAAUAAADi/+X/AAACAAUAAADh/+X/AAAFAAUAAADg/+X/AAAGAAUAAADf/+X/AAAKAAUAAADe/+X/AAAIAAUAAADd/+X/AAAKAAUAAADc/+X/AAAIAAUAAADb/+X/AAAEAAUAAADa/+X/AAABAAUAAADZ/+X/AAAKAAUAAADY/+X/AAAAAAUAAADX/+X/AAAGAAUAAADW/+X/AAAKAAUAAADV/+X/AAAJAAUAAADU/+X/AAABAAUAAADT/+X/AAAEAAUAAADS/+X/AAALAAUAAADR/+X/AAACAAUAAADQ/+X/AAAJAAUAAADP/+X/AAAAAAUAAADO/+X/AAAJAAUAAADN/+X/AAAAAAUAAADM/+X/AAAKAAUAAADL/+X/AAACAAUAAADK/+X/AAABAAUAAADJ/+X/AAAJAAUAAADI/+X/AAAFAAUAAADH/+X/AAAAAAEAAAAcAOX/AAAFAAUAAAAdAOX/AAACAAUAAAAeAOX/AAAEAAUAAAAfAOX/AAACAAUAAAAgAOX/AAACAAUAAAAhAOX/AAACAAUAAAAiAOX/AAAJAAUAAAAjAOX/AAAGAAUAAAAkAOX/AAAAAAUAAAAlAOX/AAAEAAUAAAAmAOX/AAAKAAUAAAAnAOX/AAAKAAUAAAAoAOX/AAAEAAUAAAApAOX/AAADAAIAAAA=")
|
||||
|
||||
[node name="Turret" parent="Turrets" parent_id_path=PackedInt32Array(491073452) index="0" unique_id=328367237 instance=ExtResource("2_giiqr")]
|
||||
position = Vector2(606, -432)
|
||||
shoot_delay = 3.0
|
||||
|
||||
[node name="Danger" parent="Dangers" parent_id_path=PackedInt32Array(608961351) index="0" unique_id=554396375 instance=ExtResource("2_yeikn")]
|
||||
offset_left = 89.0
|
||||
offset_top = -75.0
|
||||
@@ -23,4 +28,4 @@ offset_right = 189.0
|
||||
offset_bottom = -55.0
|
||||
|
||||
[node name="CodeSprite" parent="CanvasLayer" parent_id_path=PackedInt32Array(1125559156) index="1" unique_id=1152584149]
|
||||
texture = SubResource("ViewportTexture_yeikn")
|
||||
texture = SubResource("ViewportTexture_80l8l")
|
||||
|
||||
@@ -32,6 +32,7 @@ const MUSIC_BUS = "Music"
|
||||
@export var sfx_stream_jump : AudioStream
|
||||
@export var sfx_stream_land : AudioStream
|
||||
@export var sfx_stream_swing : AudioStream
|
||||
@export var sfx_stream_turret_shot : AudioStream
|
||||
@export var sfx_stream_wall_jump : AudioStream
|
||||
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
[ext_resource type="AudioStream" uid="uid://byn27t4ualxmi" path="res://sound/sfx/danger.wav" id="6_wyfta"]
|
||||
[ext_resource type="AudioStream" uid="uid://bj6ausg5hyuyg" path="res://sound/sfx/swing.wav" id="7_ab171"]
|
||||
[ext_resource type="AudioStream" uid="uid://33unutlwsika" path="res://sound/sfx/wall_jump.wav" id="8_22ptj"]
|
||||
[ext_resource type="AudioStream" uid="uid://bnrvkm5wy8wda" path="res://sound/sfx/turret_shot.wav" id="13_814q3"]
|
||||
|
||||
[node name="SoundManager" type="Node" unique_id=1576371552]
|
||||
process_mode = 3
|
||||
@@ -34,4 +35,5 @@ sfx_stream_game_over = ExtResource("6_6ll5c")
|
||||
sfx_stream_jump = ExtResource("5_fpnh3")
|
||||
sfx_stream_land = ExtResource("6_22ptj")
|
||||
sfx_stream_swing = ExtResource("7_ab171")
|
||||
sfx_stream_turret_shot = ExtResource("13_814q3")
|
||||
sfx_stream_wall_jump = ExtResource("8_22ptj")
|
||||
|
||||
Reference in New Issue
Block a user