diff --git a/DangerScheduler.gd b/DangerScheduler.gd index aa1221d..bb92f3a 100644 --- a/DangerScheduler.gd +++ b/DangerScheduler.gd @@ -21,6 +21,8 @@ var speed_multiplier = log(n) / log(7) var segment_speed = speed_multiplier * base_speed +var curr_dragon = 0 + # Called when the node enters the scene tree for the first time. func _ready(): set_autostart(true) @@ -39,14 +41,15 @@ func _ready(): get_parent().move_child.call_deferred(starting_segment, 2) segment_queue.push_back(starting_segment) - dragons.append(get_parent().get_node("laser_dragon")) get_parent().get_node("WallLayer").base_speed = base_speed - dragons[0].activate(125.0) + + + dragons.append(get_parent().get_node("laser_dragon")) dragons.append(get_parent().get_node("fireball_dragon")) - dragons[1].activate(125.0) dragons.append(get_parent().get_node("stone_dragon")) - dragons[2].activate(125.0) + + dragons[curr_dragon].activate(125.0) func next_segment() -> void: var new_obstacles_segment = segments_scenes[randi() % segments_scenes.size()].instantiate() @@ -54,8 +57,7 @@ func next_segment() -> void: get_parent().add_child(new_obstacles_segment) get_parent().move_child(new_obstacles_segment, 2) segment_queue.push_back(new_obstacles_segment) - - dragons[0].start_attack() + n += 1 speed_multiplier = log(n) / log(7) @@ -72,8 +74,13 @@ func next_segment() -> void: wait_time = 1275.0 / segment_speed - dragons[1].start_attack() - dragons[2].start_attack() + if (randi() % 10 == 0): + dragons[curr_dragon].leave() + curr_dragon = (curr_dragon + 1) % 3 + dragons[curr_dragon].activate(125.0 * speed_multiplier) + + if (randi() % 3 == 0): + dragons[curr_dragon].start_attack() # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): diff --git a/assets/character_slide.png.import b/assets/character_slide.png.import index 4015dcc..398ad12 100644 --- a/assets/character_slide.png.import +++ b/assets/character_slide.png.import @@ -3,7 +3,6 @@ importer="texture" type="CompressedTexture2D" uid="uid://ddqlkuyaw8nuu" - path="res://.godot/imported/character_slide.png-252d25389d6bc6e15cd5aa54bae0ea19.ctex" metadata={ "vram_texture": false diff --git a/assets/character_slide_sequence_begin.png.import b/assets/character_slide_sequence_begin.png.import index e426d66..c1dea39 100644 --- a/assets/character_slide_sequence_begin.png.import +++ b/assets/character_slide_sequence_begin.png.import @@ -3,7 +3,6 @@ importer="texture" type="CompressedTexture2D" uid="uid://qpk1nl7txlb7" - path="res://.godot/imported/character_slide_sequence_begin.png-9e4ddf7a339c52dc0d3b47d003b24976.ctex" metadata={ "vram_texture": false diff --git a/assets/character_slide_sequence_end.png.import b/assets/character_slide_sequence_end.png.import index d08cfbd..297ced6 100644 --- a/assets/character_slide_sequence_end.png.import +++ b/assets/character_slide_sequence_end.png.import @@ -3,7 +3,6 @@ importer="texture" type="CompressedTexture2D" uid="uid://dw5cmbo4fwb61" - path="res://.godot/imported/character_slide_sequence_end.png-33a7ca1165d90b7555aeb2c83fb81ecf.ctex" metadata={ "vram_texture": false diff --git a/assets/clouds.png.import b/assets/clouds.png.import index 81edc44..3f2c8e5 100644 --- a/assets/clouds.png.import +++ b/assets/clouds.png.import @@ -3,7 +3,6 @@ importer="texture" type="CompressedTexture2D" uid="uid://bunftb2lai5bs" - path="res://.godot/imported/clouds.png-a944dd817d74fea725de5db08cf2d1fe.ctex" metadata={ "vram_texture": false diff --git a/assets/death_sequence.png.import b/assets/death_sequence.png.import index 4caebe9..305b3e5 100644 --- a/assets/death_sequence.png.import +++ b/assets/death_sequence.png.import @@ -3,6 +3,7 @@ importer="texture" type="CompressedTexture2D" uid="uid://r3u1g6500efr" + path="res://.godot/imported/death_sequence.png-be2f23bf5f8d365506f809a91fbc336e.ctex" metadata={ "vram_texture": false diff --git a/assets/fireball.png.import b/assets/fireball.png.import index 0ae6fd3..1fd2633 100644 --- a/assets/fireball.png.import +++ b/assets/fireball.png.import @@ -3,6 +3,7 @@ importer="texture" type="CompressedTexture2D" uid="uid://d1yjmre0rb48l" + path="res://.godot/imported/fireball.png-ed7e398784db012da0948497b00257d1.ctex" metadata={ "vram_texture": false diff --git a/assets/green_dragon_attack.png.import b/assets/green_dragon_attack.png.import index 32e4b70..e7637fb 100644 --- a/assets/green_dragon_attack.png.import +++ b/assets/green_dragon_attack.png.import @@ -3,7 +3,6 @@ importer="texture" type="CompressedTexture2D" uid="uid://drlo2x1q6hli7" - path="res://.godot/imported/green_dragon_attack.png-173eefdfececba054b0487c276e62e52.ctex" metadata={ "vram_texture": false diff --git a/assets/green_dragon_attack_end.png.import b/assets/green_dragon_attack_end.png.import index 2c60777..c821e0d 100644 --- a/assets/green_dragon_attack_end.png.import +++ b/assets/green_dragon_attack_end.png.import @@ -3,7 +3,6 @@ importer="texture" type="CompressedTexture2D" uid="uid://dbkt1jcoxf8ht" - path="res://.godot/imported/green_dragon_attack_end.png-bb2a5126432a91efec32f2d0813a5297.ctex" metadata={ "vram_texture": false diff --git a/assets/green_dragon_attack_sequence_begin.png.import b/assets/green_dragon_attack_sequence_begin.png.import index 9b5ad1e..df1c8b2 100644 --- a/assets/green_dragon_attack_sequence_begin.png.import +++ b/assets/green_dragon_attack_sequence_begin.png.import @@ -3,7 +3,6 @@ importer="texture" type="CompressedTexture2D" uid="uid://dj3bjsd551i66" - path="res://.godot/imported/green_dragon_attack_sequence_begin.png-99ab663be141b0062e3ed88d2d65d3ac.ctex" metadata={ "vram_texture": false diff --git a/assets/sky1.png.import b/assets/sky1.png.import index faeb942..5fec221 100644 --- a/assets/sky1.png.import +++ b/assets/sky1.png.import @@ -3,7 +3,6 @@ importer="texture" type="CompressedTexture2D" uid="uid://0cmltrarx6sr" - path="res://.godot/imported/sky1.png-df6da1e8f17e6335831371c2de97d6d6.ctex" metadata={ "vram_texture": false diff --git a/assets/you_died.png.import b/assets/you_died.png.import index a53d10e..7bb01a8 100644 --- a/assets/you_died.png.import +++ b/assets/you_died.png.import @@ -3,6 +3,7 @@ importer="texture" type="CompressedTexture2D" uid="uid://d07rhbbg7d14g" + path="res://.godot/imported/you_died.png-5f8b5c92545abce5b3729ea027c3073d.ctex" metadata={ "vram_texture": false diff --git a/danger_scheduler.tscn b/danger_scheduler.tscn index 97f0a56..e4d08fb 100644 --- a/danger_scheduler.tscn +++ b/danger_scheduler.tscn @@ -1,5 +1,6 @@ [gd_scene load_steps=2 format=3 uid="uid://sxxthl7fu7gi"] + [ext_resource type="Script" path="res://DangerScheduler.gd" id="1_bh304"] [node name="DangerScheduler" type="Timer"] diff --git a/dragons/CharacterBody2D.gd b/dragons/CharacterBody2D.gd new file mode 100644 index 0000000..82bbfa0 --- /dev/null +++ b/dragons/CharacterBody2D.gd @@ -0,0 +1,28 @@ +extends CharacterBody2D + + +const SPEED = 300.0 +const JUMP_VELOCITY = -400.0 + +# Get the gravity from the project settings to be synced with RigidBody nodes. +var gravity = ProjectSettings.get_setting("physics/2d/default_gravity") + + +func _physics_process(delta): + # Add the gravity. + if not is_on_floor(): + velocity.y += gravity * delta + + # Handle Jump. + if Input.is_action_just_pressed("ui_accept") and is_on_floor(): + velocity.y = JUMP_VELOCITY + + # Get the input direction and handle the movement/deceleration. + # As good practice, you should replace UI actions with custom gameplay actions. + var direction = Input.get_axis("ui_left", "ui_right") + if direction: + velocity.x = direction * SPEED + else: + velocity.x = move_toward(velocity.x, 0, SPEED) + + move_and_slide() diff --git a/dragons/fireball.gd b/dragons/fireball.gd new file mode 100644 index 0000000..0ccfacb --- /dev/null +++ b/dragons/fireball.gd @@ -0,0 +1,30 @@ +extends Area2D + +var velocity = Vector2(0, -200) +# Called when the node enters the scene tree for the first time. +func _ready(): + var lifetime_timer = Timer.new() + lifetime_timer.set_wait_time(1.2) + lifetime_timer.set_one_shot(true) + lifetime_timer.timeout.connect(kill) + add_child(lifetime_timer) + lifetime_timer.start() + +func init(new_speed: float) -> void: + velocity.x = new_speed + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + velocity.y += gravity * delta + + position += velocity * delta + +func kill(): + + queue_free() + + +func _on_player_hit(area): + print("area_hit") + if area == get_parent().get_node("Player"): + area.player_hit(1.0) diff --git a/dragons/fireball.tscn b/dragons/fireball.tscn new file mode 100644 index 0000000..6f70d09 --- /dev/null +++ b/dragons/fireball.tscn @@ -0,0 +1,79 @@ +[gd_scene load_steps=12 format=3 uid="uid://bl3ke7fpleyp0"] + +[ext_resource type="Script" path="res://dragons/fireball.gd" id="1_4ccul"] +[ext_resource type="Texture2D" uid="uid://d30ikbe4lis2p" path="res://assets/fireball.png" id="1_7isww"] + +[sub_resource type="AtlasTexture" id="AtlasTexture_fcmkv"] +atlas = ExtResource("1_7isww") +region = Rect2(0, 0, 19, 19) + +[sub_resource type="AtlasTexture" id="AtlasTexture_njpyo"] +atlas = ExtResource("1_7isww") +region = Rect2(19, 0, 19, 19) + +[sub_resource type="AtlasTexture" id="AtlasTexture_y6sfg"] +atlas = ExtResource("1_7isww") +region = Rect2(38, 0, 19, 19) + +[sub_resource type="AtlasTexture" id="AtlasTexture_372l3"] +atlas = ExtResource("1_7isww") +region = Rect2(57, 0, 19, 19) + +[sub_resource type="AtlasTexture" id="AtlasTexture_uga0u"] +atlas = ExtResource("1_7isww") +region = Rect2(76, 0, 19, 19) + +[sub_resource type="AtlasTexture" id="AtlasTexture_v3fsn"] +atlas = ExtResource("1_7isww") +region = Rect2(95, 0, 19, 19) + +[sub_resource type="AtlasTexture" id="AtlasTexture_xeqtr"] +atlas = ExtResource("1_7isww") +region = Rect2(114, 0, 19, 19) + +[sub_resource type="SpriteFrames" id="SpriteFrames_3p26w"] +animations = [{ +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_fcmkv") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_njpyo") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_y6sfg") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_372l3") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_uga0u") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_v3fsn") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_xeqtr") +}], +"loop": true, +"name": &"default", +"speed": 8.0 +}] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_m6stc"] +size = Vector2(44, 44) + +[node name="Fireball" type="Area2D"] +script = ExtResource("1_4ccul") + +[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] +texture_filter = 1 +scale = Vector2(4, 4) +sprite_frames = SubResource("SpriteFrames_3p26w") +frame_progress = 0.558254 + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +position = Vector2(4, 4) +shape = SubResource("RectangleShape2D_m6stc") + +[connection signal="body_entered" from="." to="." method="_on_player_hit"] diff --git a/dragons/fireball_dragon.gd b/dragons/fireball_dragon.gd index 56df4d0..c28c106 100644 --- a/dragons/fireball_dragon.gd +++ b/dragons/fireball_dragon.gd @@ -10,6 +10,8 @@ enum State { @export var current_state = State.DEFAULT @export var fireball_attack_time = 2.0 +var fireball_scene = preload("res://dragons/fireball.tscn") + var destination_position var attack_timer = null var attack_started = false @@ -61,7 +63,15 @@ func start_attack(): attack_timer.start() func fireball_attack(): - print("attack") + print("fireball attack") + for v in [300, 500, 700, 900, 1100]: + var fireball = fireball_scene.instantiate() + fireball.init(v) + fireball.position = position + Vector2(150, -50) + print(fireball.global_position) + get_parent().add_child(fireball) + get_parent().move_child(fireball, 4) + current_state = State.ATTACK attack_timer = Timer.new() attack_timer.set_wait_time(fireball_attack_time) diff --git a/dragons/fireball_dragon.tscn b/dragons/fireball_dragon.tscn index 8ada39d..c32b305 100644 --- a/dragons/fireball_dragon.tscn +++ b/dragons/fireball_dragon.tscn @@ -63,7 +63,7 @@ disabled = true wait_time = 5.0 [node name="InitialPosition" type="Marker2D" parent="."] -position = Vector2(-100, 200) +position = Vector2(-300, 200) [node name="DefaultPosition" type="Marker2D" parent="."] position = Vector2(100, 300) @@ -72,4 +72,4 @@ position = Vector2(100, 300) position = Vector2(120, 120) [node name="ExitPosition" type="Marker2D" parent="."] -position = Vector2(1400, 100) +position = Vector2(1800, 100) diff --git a/dragons/laser.gd b/dragons/laser.gd new file mode 100644 index 0000000..fe2cd29 --- /dev/null +++ b/dragons/laser.gd @@ -0,0 +1,24 @@ +extends Area2D + + +# Called when the node enters the scene tree for the first time. +func _ready(): + $Sprite2D.play("start") + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + position.y = get_parent().get_node("laser_dragon").position.y + +#func synced_with_dragon(): + + +func start_animation_finished(): + $Sprite2D.play("cycle") + + +func _on_player_hit(area): + print("area_hit") + if area == get_parent().get_node("Player"): + area.player_hit(1.0) + diff --git a/dragons/laser.tscn b/dragons/laser.tscn new file mode 100644 index 0000000..5ce57c6 --- /dev/null +++ b/dragons/laser.tscn @@ -0,0 +1,212 @@ +[gd_scene load_steps=31 format=3 uid="uid://bosm7uopo1ysh"] + +[ext_resource type="Texture2D" uid="uid://cotgtpelq23h" path="res://assets/laser_beam_cycle.png" id="1_is0si"] +[ext_resource type="Script" path="res://dragons/laser.gd" id="1_jtokj"] +[ext_resource type="Texture2D" uid="uid://wq81u8uqnynd" path="res://assets/laser_beam_end.png" id="2_bq7vm"] +[ext_resource type="Texture2D" uid="uid://dk1lsgnefp8ei" path="res://assets/laser_beam_begin.png" id="3_yxrkq"] + +[sub_resource type="AtlasTexture" id="AtlasTexture_vks23"] +atlas = ExtResource("1_is0si") +region = Rect2(0, 0, 320, 180) + +[sub_resource type="AtlasTexture" id="AtlasTexture_7pwef"] +atlas = ExtResource("1_is0si") +region = Rect2(320, 0, 320, 180) + +[sub_resource type="AtlasTexture" id="AtlasTexture_sp7xp"] +atlas = ExtResource("1_is0si") +region = Rect2(640, 0, 320, 180) + +[sub_resource type="AtlasTexture" id="AtlasTexture_5rhwv"] +atlas = ExtResource("1_is0si") +region = Rect2(960, 0, 320, 180) + +[sub_resource type="AtlasTexture" id="AtlasTexture_0rpoo"] +atlas = ExtResource("1_is0si") +region = Rect2(1280, 0, 320, 180) + +[sub_resource type="AtlasTexture" id="AtlasTexture_vwav2"] +atlas = ExtResource("1_is0si") +region = Rect2(1600, 0, 320, 180) + +[sub_resource type="AtlasTexture" id="AtlasTexture_y8n6r"] +atlas = ExtResource("1_is0si") +region = Rect2(1920, 0, 320, 180) + +[sub_resource type="AtlasTexture" id="AtlasTexture_c2lhj"] +atlas = ExtResource("1_is0si") +region = Rect2(2240, 0, 320, 180) + +[sub_resource type="AtlasTexture" id="AtlasTexture_spanr"] +atlas = ExtResource("2_bq7vm") +region = Rect2(0, 0, 320, 180) + +[sub_resource type="AtlasTexture" id="AtlasTexture_36nvo"] +atlas = ExtResource("2_bq7vm") +region = Rect2(320, 0, 320, 180) + +[sub_resource type="AtlasTexture" id="AtlasTexture_itt7k"] +atlas = ExtResource("2_bq7vm") +region = Rect2(640, 0, 320, 180) + +[sub_resource type="AtlasTexture" id="AtlasTexture_2iqel"] +atlas = ExtResource("2_bq7vm") +region = Rect2(960, 0, 320, 180) + +[sub_resource type="AtlasTexture" id="AtlasTexture_2bprw"] +atlas = ExtResource("2_bq7vm") +region = Rect2(1280, 0, 320, 180) + +[sub_resource type="AtlasTexture" id="AtlasTexture_wj4nd"] +atlas = ExtResource("2_bq7vm") +region = Rect2(1600, 0, 320, 180) + +[sub_resource type="AtlasTexture" id="AtlasTexture_2d74e"] +atlas = ExtResource("2_bq7vm") +region = Rect2(1920, 0, 320, 180) + +[sub_resource type="AtlasTexture" id="AtlasTexture_lk2vk"] +atlas = ExtResource("2_bq7vm") +region = Rect2(2240, 0, 320, 180) + +[sub_resource type="AtlasTexture" id="AtlasTexture_fd7mh"] +atlas = ExtResource("3_yxrkq") +region = Rect2(0, 0, 320, 180) + +[sub_resource type="AtlasTexture" id="AtlasTexture_navub"] +atlas = ExtResource("3_yxrkq") +region = Rect2(320, 0, 320, 180) + +[sub_resource type="AtlasTexture" id="AtlasTexture_437ve"] +atlas = ExtResource("3_yxrkq") +region = Rect2(640, 0, 320, 180) + +[sub_resource type="AtlasTexture" id="AtlasTexture_8jeqv"] +atlas = ExtResource("3_yxrkq") +region = Rect2(960, 0, 320, 180) + +[sub_resource type="AtlasTexture" id="AtlasTexture_i6wsq"] +atlas = ExtResource("3_yxrkq") +region = Rect2(1280, 0, 320, 180) + +[sub_resource type="AtlasTexture" id="AtlasTexture_xleoc"] +atlas = ExtResource("3_yxrkq") +region = Rect2(1600, 0, 320, 180) + +[sub_resource type="AtlasTexture" id="AtlasTexture_tp450"] +atlas = ExtResource("3_yxrkq") +region = Rect2(1920, 0, 320, 180) + +[sub_resource type="AtlasTexture" id="AtlasTexture_x5uoa"] +atlas = ExtResource("3_yxrkq") +region = Rect2(2240, 0, 320, 180) + +[sub_resource type="SpriteFrames" id="SpriteFrames_uj4ce"] +animations = [{ +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_vks23") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_7pwef") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_sp7xp") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_5rhwv") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_0rpoo") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_vwav2") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_y8n6r") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_c2lhj") +}], +"loop": true, +"name": &"cycle", +"speed": 8.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_spanr") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_36nvo") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_itt7k") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_2iqel") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_2bprw") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_wj4nd") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_2d74e") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_lk2vk") +}], +"loop": false, +"name": &"end", +"speed": 8.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_fd7mh") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_navub") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_437ve") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_8jeqv") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_i6wsq") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_xleoc") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_tp450") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_x5uoa") +}], +"loop": false, +"name": &"start", +"speed": 8.0 +}] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_h6epk"] +size = Vector2(1108.5, 39) + +[node name="Laser" type="Area2D"] +script = ExtResource("1_jtokj") + +[node name="Sprite2D" type="AnimatedSprite2D" parent="."] +texture_filter = 1 +scale = Vector2(4, 4) +sprite_frames = SubResource("SpriteFrames_uj4ce") +animation = &"cycle" +frame_progress = 0.0413142 + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +position = Vector2(-84, 22) +shape = SubResource("RectangleShape2D_h6epk") + +[connection signal="body_entered" from="." to="." method="_on_player_hit"] +[connection signal="animation_finished" from="Sprite2D" to="." method="start_animation_finished"] diff --git a/dragons/laser_dragon.gd b/dragons/laser_dragon.gd index f025681..46938e0 100644 --- a/dragons/laser_dragon.gd +++ b/dragons/laser_dragon.gd @@ -17,9 +17,13 @@ var attack_timer = null var attack_started = false var attack_finished = false var active = false +var is_firing = false var track_player = false +var laser_scene = preload("res://dragons/laser.tscn") +var laser + func _ready(): position = $InitialPosition.position $AnimatedSprite2D.play("default") @@ -66,14 +70,17 @@ func start_attack(): moving = true attack_timer = Timer.new() - attack_timer.set_wait_time(600 / move_speed) + attack_timer.set_wait_time(400 / move_speed) attack_timer.set_one_shot(true) attack_timer.timeout.connect(laser_attack) add_child(attack_timer) attack_timer.start() func laser_attack(): - print("attack") + print("laser attack") + + is_firing = true + moving = false track_player = false attack_timer = Timer.new() @@ -84,9 +91,12 @@ func laser_attack(): attack_timer.start() func finish_attack(): + print("aaa") + laser.queue_free() destination_position = $DefaultPosition.position moving = true attack_finished = true + is_firing = false change_state(State.DEFAULT) func calculate_movement_time(): @@ -118,6 +128,7 @@ func _on_animation_finished(): change_state(State.ATTACK) elif current_state == State.END_ATTACK: change_state(State.DEFAULT) + ######################################################33 @@ -128,3 +139,12 @@ func get_move_speed(): return move_speed + + +func _on_animation_looped(): + if is_firing: + laser = laser_scene.instantiate() + laser.position = position + Vector2(1075, 0) + get_parent().add_child(laser) + get_parent().move_child(laser, 2) + is_firing = false diff --git a/dragons/laser_dragon.tscn b/dragons/laser_dragon.tscn index 0545241..17a7cbe 100644 --- a/dragons/laser_dragon.tscn +++ b/dragons/laser_dragon.tscn @@ -1,11 +1,10 @@ [gd_scene load_steps=39 format=3 uid="uid://b0okavcmqim7e"] [ext_resource type="Script" path="res://dragons/laser_dragon.gd" id="1_37bgi"] - [ext_resource type="Texture2D" uid="uid://d01daw7neyryu" path="res://assets/green_dragon_flifht_cycle.png" id="2_663tr"] -[ext_resource type="Texture2D" uid="uid://v8cuejvk8js2" path="res://assets/green_dragon_attack.png" id="2_w0fp6"] -[ext_resource type="Texture2D" uid="uid://c3jt8pgff8ci8" path="res://assets/green_dragon_attack_sequence_begin.png" id="3_4octh"] -[ext_resource type="Texture2D" uid="uid://dixv3ax4j2jdj" path="res://assets/green_dragon_attack_end.png" id="4_ffa46"] +[ext_resource type="Texture2D" uid="uid://bkhma5i4fe2xh" path="res://assets/green_dragon_attack.png" id="2_w0fp6"] +[ext_resource type="Texture2D" uid="uid://1sspblr1w87p" path="res://assets/green_dragon_attack_sequence_begin.png" id="3_4octh"] +[ext_resource type="Texture2D" uid="uid://u3a3q1slm8yi" path="res://assets/green_dragon_attack_end.png" id="4_ffa46"] [sub_resource type="AtlasTexture" id="AtlasTexture_yu0ha"] atlas = ExtResource("2_w0fp6") @@ -277,6 +276,6 @@ position = Vector2(1900, -100) texture_filter = 1 scale = Vector2(4, 4) sprite_frames = SubResource("SpriteFrames_t8lvi") -animation = &"attack_begin" [connection signal="animation_finished" from="AnimatedSprite2D" to="." method="_on_animation_finished"] +[connection signal="animation_looped" from="AnimatedSprite2D" to="." method="_on_animation_looped"] diff --git a/dragons/stone.gd b/dragons/stone.gd new file mode 100644 index 0000000..13a931b --- /dev/null +++ b/dragons/stone.gd @@ -0,0 +1,29 @@ +extends CharacterBody2D + +var speed = 800.0 +var height = position.y + +# Called when the node enters the scene tree for the first time. + +const GRAVITY = 600.0 + +func _ready(): + pass + +func _physics_process(delta): + velocity.y += delta * GRAVITY + + var motion = velocity * delta + move_and_collide(motion) + + if position.y < -20: + print("jest") + queue_free() + elif position.y - height < 0.001: + print("on ground") + position.x -= speed * delta + + height = position.y + +func set_speed(new_speed): + speed = new_speed diff --git a/dragons/stone.tscn b/dragons/stone.tscn new file mode 100644 index 0000000..80f2711 --- /dev/null +++ b/dragons/stone.tscn @@ -0,0 +1,18 @@ +[gd_scene load_steps=4 format=3 uid="uid://dst2l7vd3us1p"] + +[ext_resource type="Texture2D" uid="uid://bory0tc7ixsat" path="res://assets/boulder.png" id="1_14ag1"] +[ext_resource type="Script" path="res://dragons/stone.gd" id="1_ntma4"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_3o3t8"] +size = Vector2(100, 64) + +[node name="Stone" type="CharacterBody2D"] +script = ExtResource("1_ntma4") + +[node name="Sprite2D" type="Sprite2D" parent="."] +texture_filter = 1 +scale = Vector2(4, 4) +texture = ExtResource("1_14ag1") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource("RectangleShape2D_3o3t8") diff --git a/dragons/stone_dragon.gd b/dragons/stone_dragon.gd index 7f0b045..4fbdaa6 100644 --- a/dragons/stone_dragon.gd +++ b/dragons/stone_dragon.gd @@ -79,6 +79,11 @@ func stone_attack(): elif stones_to_shot >= 0: stones_to_shot -= 1 print("attack") + var stone = preload("res://dragons/stone.tscn").instantiate() + stone.position = position + Vector2(0, 100) + get_parent().add_child(stone) + print(stone.position) + attack_timer.set_wait_time(400 / move_speed) attack_timer.timeout.connect(stone_attack) else: diff --git a/dragons/stone_dragon.tscn b/dragons/stone_dragon.tscn index 5f90f6e..61a38b6 100644 --- a/dragons/stone_dragon.tscn +++ b/dragons/stone_dragon.tscn @@ -140,7 +140,7 @@ disabled = true wait_time = 5.0 [node name="InitialPosition" type="Marker2D" parent="."] -position = Vector2(-100, 200) +position = Vector2(-300, 200) [node name="DefaultPosition" type="Marker2D" parent="."] position = Vector2(80, 200) @@ -149,7 +149,7 @@ position = Vector2(80, 200) position = Vector2(300, 40) [node name="ExitPosition" type="Marker2D" parent="."] -position = Vector2(1600, 0) +position = Vector2(1800, 0) [node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] texture_filter = 1 diff --git a/main_scene.tscn b/main_scene.tscn index 01bf7b6..caefe7a 100644 --- a/main_scene.tscn +++ b/main_scene.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=10 format=3 uid="uid://cpdu4s3kjuxpl"] + +[gd_scene load_steps=10 format=3 uid="uid://b04gcujmvf2fx"] [ext_resource type="PackedScene" uid="uid://c3ywqasnt5osa" path="res://src/Player/Player.tscn" id="2_27tub"] -[ext_resource type="PackedScene" uid="uid://sxxthl7fu7gi" path="res://danger_scheduler.tscn" id="3_oo2km"] +[ext_resource type="PackedScene" uid="uid://bc8f76w6nme4d" path="res://danger_scheduler.tscn" id="3_oo2km"] [ext_resource type="PackedScene" uid="uid://b0okavcmqim7e" path="res://dragons/laser_dragon.tscn" id="4_mpgmk"] [ext_resource type="PackedScene" uid="uid://cgd0txrrf22r7" path="res://background/background.tscn" id="5_acqpb"] [ext_resource type="PackedScene" uid="uid://drtkgj2rkr6kp" path="res://ui/ui.tscn" id="6_8y5vv"] diff --git a/obstacles/segments/segment_scaffolding_triangle.tscn b/obstacles/segments/segment_scaffolding_triangle.tscn index 87b3a66..1469512 100644 --- a/obstacles/segments/segment_scaffolding_triangle.tscn +++ b/obstacles/segments/segment_scaffolding_triangle.tscn @@ -32,19 +32,19 @@ position = Vector2(346, -218) position = Vector2(290, -220) [node name="ObstacleBarrel3" parent="." index="8" instance=ExtResource("3_yqjby")] -position = Vector2(324, -284) +position = Vector2(319, -282) [node name="ObstacleBarrel4" parent="." index="9" instance=ExtResource("3_yqjby")] position = Vector2(236, -219) [node name="ObstacleBarrel5" parent="." index="10" instance=ExtResource("3_yqjby")] -position = Vector2(263, -284) +position = Vector2(230, -284) [node name="ObstacleCrate" parent="." index="11" instance=ExtResource("4_gicit")] -position = Vector2(147, -336) +position = Vector2(151, -326) [node name="ObstacleCrate3" parent="." index="12" instance=ExtResource("4_gicit")] position = Vector2(-59, -484) [node name="ObstacleCrate2" parent="." index="13" instance=ExtResource("4_gicit")] -position = Vector2(55, -484) +position = Vector2(49, -478) diff --git a/src/Player/CharacterBody2D.gd b/src/Player/CharacterBody2D.gd index fb83655..8129c6c 100644 --- a/src/Player/CharacterBody2D.gd +++ b/src/Player/CharacterBody2D.gd @@ -28,6 +28,10 @@ var dash_velocity = 0 var last_anim = "" var is_rolling = false var is_alive = true + +var health = 3.0 +var is_invincible = false + # Get the gravity from the project settings to be synced with RigidBody nodes. var gravity = ProjectSettings.get_setting("physics/2d/default_gravity") @@ -152,3 +156,21 @@ func _animation_finished(): $AnimatedSprite2D.play() +func player_hit(impact: float) -> void: + if is_invincible: + return + health -= impact + if health <= 0: + get_tree().paused = true + is_invincible = true + var invincibility_timer = Timer.new() + invincibility_timer.set_wait_time(2.0) + invincibility_timer.set_one_shot(true) + invincibility_timer.timeout.connect(end_invincibility) + add_child(invincibility_timer) + invincibility_timer.start() + get_parent().get_node("UI/HealthBar").health_update(health) + +func end_invincibility(): + print("ending invincibility") + is_invincible = false diff --git a/src/Player/Player.tscn b/src/Player/Player.tscn index 80ede47..ef662a1 100644 --- a/src/Player/Player.tscn +++ b/src/Player/Player.tscn @@ -1,14 +1,14 @@ [gd_scene load_steps=84 format=3 uid="uid://c3ywqasnt5osa"] [ext_resource type="Script" path="res://src/Player/CharacterBody2D.gd" id="1_rjfog"] -[ext_resource type="Texture2D" uid="uid://dw5cmbo4fwb61" path="res://assets/character_slide_sequence_end.png" id="2_mawlu"] -[ext_resource type="Texture2D" uid="uid://ltl2h0gjf1gr" path="res://assets/character_run_cycle.png" id="2_v0srd"] +[ext_resource type="Texture2D" uid="uid://djwvxd58ioch2" path="res://assets/character_slide_sequence_end.png" id="2_mawlu"] +[ext_resource type="Texture2D" uid="uid://cr2atrvwa2tvw" path="res://assets/character_run_cycle.png" id="2_v0srd"] [ext_resource type="Texture2D" uid="uid://bdict254wntu0" path="res://assets/character_double_jump_sequence_spin.png" id="3_fkm0h"] [ext_resource type="Texture2D" uid="uid://cpevwrxsxaafo" path="res://assets/character_double_jump_sequence_end.png" id="3_o5eyg"] -[ext_resource type="Texture2D" uid="uid://dke60fcssgtax" path="res://assets/character_jump_start.png" id="4_71ici"] -[ext_resource type="Texture2D" uid="uid://cr7qs7ll22wb3" path="res://assets/character_jump_landing.png" id="5_wlnmu"] -[ext_resource type="Texture2D" uid="uid://ddqlkuyaw8nuu" path="res://assets/character_slide.png" id="7_0gugt"] -[ext_resource type="Texture2D" uid="uid://qpk1nl7txlb7" path="res://assets/character_slide_sequence_begin.png" id="8_p1vv5"] +[ext_resource type="Texture2D" uid="uid://cixlwqfxxexvn" path="res://assets/character_jump_start.png" id="4_71ici"] +[ext_resource type="Texture2D" uid="uid://dityncy2soyx" path="res://assets/character_jump_landing.png" id="5_wlnmu"] +[ext_resource type="Texture2D" uid="uid://bxmstsrd364ak" path="res://assets/character_slide.png" id="7_0gugt"] +[ext_resource type="Texture2D" uid="uid://cpmlqf1hhpfus" path="res://assets/character_slide_sequence_begin.png" id="8_p1vv5"] [ext_resource type="Texture2D" uid="uid://bymbhbpnrguxc" path="res://assets/character_double_jump_sequence_begin.png" id="9_i14r2"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_jhyvd"] diff --git a/ui/health_bar.gd b/ui/health_bar.gd new file mode 100644 index 0000000..7e4b5d5 --- /dev/null +++ b/ui/health_bar.gd @@ -0,0 +1,5 @@ +extends TextureProgressBar + + +func health_update(health: float) -> void: + value = health * 33.3333 diff --git a/ui/health_bar.tscn b/ui/health_bar.tscn index e848ce3..a9961bf 100644 --- a/ui/health_bar.tscn +++ b/ui/health_bar.tscn @@ -1,13 +1,15 @@ -[gd_scene load_steps=3 format=3 uid="uid://6dbmdew3h0us"] +[gd_scene load_steps=4 format=3 uid="uid://6dbmdew3h0us"] [ext_resource type="Texture2D" uid="uid://byldgq8fqlcfn" path="res://assets/health_bar_behind.png" id="1_bwvem"] [ext_resource type="Texture2D" uid="uid://wadrpb4x5jub" path="res://assets/health_bar_progress.png" id="2_dwre4"] +[ext_resource type="Script" path="res://ui/health_bar.gd" id="3_ru1r1"] [node name="HealthBar" type="TextureProgressBar"] offset_left = 1169.0 offset_top = 689.0 offset_right = 1265.0 offset_bottom = 711.0 -value = 50.0 +value = 100.0 texture_under = ExtResource("1_bwvem") texture_progress = ExtResource("2_dwre4") +script = ExtResource("3_ru1r1")