From e451dfdaa9cbced5fd6d85a1cb14753d1df7e0b6 Mon Sep 17 00:00:00 2001 From: Luna Brovchuk Date: Mon, 2 Oct 2023 16:22:35 +0200 Subject: [PATCH] Create Cards, Fix Enemy Class --- project.godot | 1 - .../sprites/cards => models/card}/Card.tscn | 2 +- .../cards => models/card/sprites}/cards.png | Bin .../card/sprites}/cards.png.import | 6 +- .../card/sprites}/cards_spriteframes.tres | 2 +- src/models/enemies/bat/Bat.tscn | 2 +- src/models/enemies/bat/bat.gd | 2 +- src/models/enemies/ghost/ghost.gd | 2 +- src/models/enemies/rat/rat.gd | 2 +- src/models/player/Player.tscn | 1 + src/models/player/player.gd | 26 ++++-- src/scenes/game/Game.tscn | 82 ++++++++++-------- src/scenes/game/game.gd | 20 +++-- src/scripts/enemy_class.gd | 54 ++++++------ 14 files changed, 116 insertions(+), 86 deletions(-) rename src/{scenes/game/sprites/cards => models/card}/Card.tscn (79%) rename src/{scenes/game/sprites/cards => models/card/sprites}/cards.png (100%) rename src/{scenes/game/sprites/cards => models/card/sprites}/cards.png.import (71%) rename src/{scenes/game/sprites/cards => models/card/sprites}/cards_spriteframes.tres (92%) diff --git a/project.godot b/project.godot index 7b17d93..a0fe573 100644 --- a/project.godot +++ b/project.godot @@ -20,7 +20,6 @@ config/icon="res://icon.png" Global="*res://src/scripts/global.gd" Window="*res://src/scripts/window.gd" -EnemyClass="*res://src/scripts/enemy_class.gd" [display] diff --git a/src/scenes/game/sprites/cards/Card.tscn b/src/models/card/Card.tscn similarity index 79% rename from src/scenes/game/sprites/cards/Card.tscn rename to src/models/card/Card.tscn index cf95eff..1818866 100644 --- a/src/scenes/game/sprites/cards/Card.tscn +++ b/src/models/card/Card.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=3 format=2] -[ext_resource path="res://src/scenes/game/sprites/cards/cards_spriteframes.tres" type="SpriteFrames" id=1] +[ext_resource path="res://src/models/card/sprites/cards_spriteframes.tres" type="SpriteFrames" id=1] [sub_resource type="RectangleShape2D" id=1] extents = Vector2( 47, 51.5 ) diff --git a/src/scenes/game/sprites/cards/cards.png b/src/models/card/sprites/cards.png similarity index 100% rename from src/scenes/game/sprites/cards/cards.png rename to src/models/card/sprites/cards.png diff --git a/src/scenes/game/sprites/cards/cards.png.import b/src/models/card/sprites/cards.png.import similarity index 71% rename from src/scenes/game/sprites/cards/cards.png.import rename to src/models/card/sprites/cards.png.import index 51c404f..6b0646a 100644 --- a/src/scenes/game/sprites/cards/cards.png.import +++ b/src/models/card/sprites/cards.png.import @@ -2,15 +2,15 @@ importer="texture" type="StreamTexture" -path="res://.import/cards.png-de0d7634707005f50aa7f118048a0217.stex" +path="res://.import/cards.png-e5300b701a043110ff3e3d30fc9c32cf.stex" metadata={ "vram_texture": false } [deps] -source_file="res://src/scenes/game/sprites/cards/cards.png" -dest_files=[ "res://.import/cards.png-de0d7634707005f50aa7f118048a0217.stex" ] +source_file="res://src/models/card/sprites/cards.png" +dest_files=[ "res://.import/cards.png-e5300b701a043110ff3e3d30fc9c32cf.stex" ] [params] diff --git a/src/scenes/game/sprites/cards/cards_spriteframes.tres b/src/models/card/sprites/cards_spriteframes.tres similarity index 92% rename from src/scenes/game/sprites/cards/cards_spriteframes.tres rename to src/models/card/sprites/cards_spriteframes.tres index d13bda7..613743e 100644 --- a/src/scenes/game/sprites/cards/cards_spriteframes.tres +++ b/src/models/card/sprites/cards_spriteframes.tres @@ -1,6 +1,6 @@ [gd_resource type="SpriteFrames" load_steps=10 format=2] -[ext_resource path="res://src/scenes/game/sprites/cards/cards.png" type="Texture" id=1] +[ext_resource path="res://src/models/card/sprites/cards.png" type="Texture" id=1] [sub_resource type="AtlasTexture" id=1] atlas = ExtResource( 1 ) diff --git a/src/models/enemies/bat/Bat.tscn b/src/models/enemies/bat/Bat.tscn index 017fa1e..d742495 100644 --- a/src/models/enemies/bat/Bat.tscn +++ b/src/models/enemies/bat/Bat.tscn @@ -20,7 +20,7 @@ script = ExtResource( 2 ) use_parent_material = true frames = ExtResource( 1 ) animation = "idle" -frame = 1 +frame = 3 playing = true centered = false diff --git a/src/models/enemies/bat/bat.gd b/src/models/enemies/bat/bat.gd index 309c9de..50a5387 100644 --- a/src/models/enemies/bat/bat.gd +++ b/src/models/enemies/bat/bat.gd @@ -1,4 +1,4 @@ -extends EnemyClass +extends "res://src/scripts/enemy_class.gd" var velocity = Vector2.ZERO var speed = 64 diff --git a/src/models/enemies/ghost/ghost.gd b/src/models/enemies/ghost/ghost.gd index ef78a18..dcdd6d6 100644 --- a/src/models/enemies/ghost/ghost.gd +++ b/src/models/enemies/ghost/ghost.gd @@ -1,4 +1,4 @@ -extends EnemyClass +extends "res://src/scripts/enemy_class.gd" var dash_target = Vector2.ZERO var afterdash_timer = .0 diff --git a/src/models/enemies/rat/rat.gd b/src/models/enemies/rat/rat.gd index 57c7e67..4999dc7 100644 --- a/src/models/enemies/rat/rat.gd +++ b/src/models/enemies/rat/rat.gd @@ -1,4 +1,4 @@ -extends EnemyClass +extends "res://src/scripts/enemy_class.gd" var velocity = Vector2.ZERO var speed = 24 diff --git a/src/models/player/Player.tscn b/src/models/player/Player.tscn index 982407d..7a091dc 100644 --- a/src/models/player/Player.tscn +++ b/src/models/player/Player.tscn @@ -123,6 +123,7 @@ visible = false position = Vector2( 11, 2 ) frames = ExtResource( 5 ) animation = "idle" +frame = 3 playing = true [connection signal="area_entered" from="EnemyCollision" to="." method="area_entered"] diff --git a/src/models/player/player.gd b/src/models/player/player.gd index 40adc42..1cdcf8a 100644 --- a/src/models/player/player.gd +++ b/src/models/player/player.gd @@ -8,7 +8,7 @@ var invincibility_timer = .0 var velocity = Vector2.ZERO var recharge_timer = .0 var invincible = false -var target: EnemyClass +var target var slowed = false var speed = 80 @@ -91,13 +91,16 @@ func _draw(): draw_dashed_line(Vector2(12, 12), target.global_position - self.global_position + mob_offset, Color("ffde00"), 1) func _process(_delta): - $Sprite.play("idle") if velocity == Vector2.ZERO else $Sprite.play("run") - if abs(velocity.x) > 10: - $Sprite.flip_h = true if velocity.x < 0 else false - - if velocity != Vector2.ZERO: - $CPUParticles2D.emitting = true - $CPUParticles2D.direction.x = 1 if velocity.x < 0 else -1 + if Global.playing: + $Sprite.play("idle") if velocity == Vector2.ZERO else $Sprite.play("run") + if abs(velocity.x) > 10: + $Sprite.flip_h = true if velocity.x < 0 else false + + if velocity != Vector2.ZERO: + $CPUParticles2D.emitting = true + $CPUParticles2D.direction.x = 1 if velocity.x < 0 else -1 + else: + $CPUParticles2D.emitting = false else: $CPUParticles2D.emitting = false @@ -126,7 +129,12 @@ func _physics_process(delta): else: speed_multiplier = 1.0 - velocity = move_and_slide(velocity * speed_multiplier) + if Global.playing: + $Sprite.playing = true + velocity = move_and_slide(velocity * speed_multiplier) + else: + $Sprite.playing = false + choose_target() if target != null and is_instance_valid(target) and not target.dead: diff --git a/src/scenes/game/Game.tscn b/src/scenes/game/Game.tscn index 1d32d47..f22fac6 100644 --- a/src/scenes/game/Game.tscn +++ b/src/scenes/game/Game.tscn @@ -6,9 +6,6 @@ [ext_resource path="res://res/themes/8px.tres" type="Theme" id=4] [ext_resource path="res://src/models/player/Player.tscn" type="PackedScene" id=5] [ext_resource path="res://src/scenes/game/sprites/health/health.png" type="Texture" id=6] -[ext_resource path="res://src/scenes/game/sprites/stun/stun_placeholder_spriteframes.tres" type="SpriteFrames" id=7] -[ext_resource path="res://src/scenes/game/sprites/stun/stun_spriteframes.tres" type="SpriteFrames" id=8] -[ext_resource path="res://src/scenes/game/sprites/cards/Card.tscn" type="PackedScene" id=9] [ext_resource path="res://src/scenes/game/sprites/player_icon.png" type="Texture" id=10] [ext_resource path="res://src/scenes/game/game.gd" type="Script" id=11] [ext_resource path="res://src/scenes/game/sprites/ui_background.png" type="Texture" id=12] @@ -16,6 +13,9 @@ [ext_resource path="res://src/scenes/game/sprites/hatch2.png" type="Texture" id=14] [ext_resource path="res://src/scenes/game/sprites/gameover.png" type="Texture" id=15] [ext_resource path="res://src/scenes/game/spell_recharge_bar.gd" type="Script" id=16] +[ext_resource path="res://src/scenes/game/sprites/stun/stun_spriteframes.tres" type="SpriteFrames" id=17] +[ext_resource path="res://src/models/card/Card.tscn" type="PackedScene" id=18] +[ext_resource path="res://src/scenes/game/sprites/stun/stun_placeholder_spriteframes.tres" type="SpriteFrames" id=19] [sub_resource type="RectangleShape2D" id=2] extents = Vector2( 10, 60 ) @@ -50,9 +50,9 @@ region = Rect2( 0, 0, 31, 11 ) [sub_resource type="SpriteFrames" id=4] animations = [ { "frames": [ SubResource( 7 ), SubResource( 8 ), SubResource( 9 ), SubResource( 10 ), SubResource( 11 ), SubResource( 12 ) ], -"loop": false, -"name": "idle", -"speed": 0.0 +"loop": true, +"name": "default", +"speed": 5.0 } ] [sub_resource type="Animation" id=5] @@ -179,26 +179,26 @@ margin_bottom = 2.0 margin_right = 40.0 margin_bottom = 40.0 -[node name="Stun" type="Control" parent="UIWrapper/UI/Left"] +[node name="Debuffs" type="Control" parent="UIWrapper/UI/Left"] margin_right = 40.0 margin_bottom = 40.0 -[node name="StunPlaceholder1" type="AnimatedSprite" parent="UIWrapper/UI/Left/Stun"] +[node name="Slowed" type="AnimatedSprite" parent="UIWrapper/UI/Left/Debuffs"] position = Vector2( 59, 144 ) -frames = ExtResource( 7 ) +frames = ExtResource( 19 ) animation = "idle" -[node name="StunIcon1" type="AnimatedSprite" parent="UIWrapper/UI/Left/Stun/StunPlaceholder1"] -frames = ExtResource( 8 ) +[node name="Sprite" type="AnimatedSprite" parent="UIWrapper/UI/Left/Debuffs/Slowed"] +frames = ExtResource( 17 ) animation = "idle" -[node name="StunPlaceholder2" type="AnimatedSprite" parent="UIWrapper/UI/Left/Stun"] +[node name="Stun" type="AnimatedSprite" parent="UIWrapper/UI/Left/Debuffs"] position = Vector2( 76, 144 ) -frames = ExtResource( 7 ) +frames = ExtResource( 19 ) animation = "idle" -[node name="StunIcon2" type="AnimatedSprite" parent="UIWrapper/UI/Left/Stun/StunPlaceholder2"] -frames = ExtResource( 8 ) +[node name="Sprite" type="AnimatedSprite" parent="UIWrapper/UI/Left/Debuffs/Stun"] +frames = ExtResource( 17 ) animation = "idle" frame = 1 @@ -209,7 +209,7 @@ margin_bottom = 40.0 [node name="HealthSprite" type="AnimatedSprite" parent="UIWrapper/UI/Left/Health"] position = Vector2( 52, 156 ) frames = SubResource( 4 ) -animation = "idle" +frame = 5 centered = false [node name="PlayerIcon" type="Sprite" parent="UIWrapper/UI/Left"] @@ -247,35 +247,47 @@ script = ExtResource( 16 ) margin_right = 80.0 margin_bottom = 3.0 -[node name="Cards" type="Control" parent="UIWrapper/UI/Center"] -visible = false -margin_right = 40.0 -margin_bottom = 40.0 - -[node name="CardLeft" parent="UIWrapper/UI/Center/Cards" instance=ExtResource( 9 )] -position = Vector2( 11, 10 ) - -[node name="CardCenter" parent="UIWrapper/UI/Center/Cards" instance=ExtResource( 9 )] -position = Vector2( 113, 10 ) -frame = 1 - -[node name="CardRight" parent="UIWrapper/UI/Center/Cards" instance=ExtResource( 9 )] -position = Vector2( 215, 10 ) -frame = 2 - [node name="Right" type="Control" parent="UIWrapper/UI"] margin_right = 40.0 margin_bottom = 40.0 -[node name="Gameover" type="Control" parent="UIWrapper"] +[node name="Cards" type="Control" parent="UIWrapper/UI"] +margin_right = 320.0 +margin_bottom = 120.0 + +[node name="LeftPlaceholder" type="Control" parent="UIWrapper/UI/Cards"] +margin_left = 8.0 +margin_top = 8.0 +margin_right = 102.0 +margin_bottom = 111.0 + +[node name="Card" parent="UIWrapper/UI/Cards/LeftPlaceholder" instance=ExtResource( 18 )] + +[node name="CenterPlaceholder" type="Control" parent="UIWrapper/UI/Cards"] +margin_left = 113.0 +margin_top = 8.0 +margin_right = 207.0 +margin_bottom = 111.0 + +[node name="Card" parent="UIWrapper/UI/Cards/CenterPlaceholder" instance=ExtResource( 18 )] + +[node name="RightPlaceholder" type="Control" parent="UIWrapper/UI/Cards"] +margin_left = 218.0 +margin_top = 8.0 +margin_right = 312.0 +margin_bottom = 111.0 + +[node name="Card" parent="UIWrapper/UI/Cards/RightPlaceholder" instance=ExtResource( 18 )] + +[node name="Gameover" type="Control" parent="UIWrapper/UI"] margin_right = 320.0 margin_bottom = 180.0 -[node name="Sprite" type="Sprite" parent="UIWrapper/Gameover"] +[node name="Sprite" type="Sprite" parent="UIWrapper/UI/Gameover"] modulate = Color( 1, 1, 1, 0 ) texture = ExtResource( 15 ) centered = false -[node name="AnimationPlayer" type="AnimationPlayer" parent="UIWrapper/Gameover"] +[node name="AnimationPlayer" type="AnimationPlayer" parent="UIWrapper/UI/Gameover"] anims/RESET = SubResource( 5 ) anims/gameover = SubResource( 6 ) diff --git a/src/scenes/game/game.gd b/src/scenes/game/game.gd index c013281..85a6d01 100644 --- a/src/scenes/game/game.gd +++ b/src/scenes/game/game.gd @@ -26,16 +26,22 @@ func _physics_process(delta): difficulty = int(Global.play_time / 60) if difficulty != last_diff: + Global.playing = false last_diff = difficulty - $UIWrapper/UI/Center/Cards.visible = true + var cards = range(8) + for card_placeholder in $UIWrapper/UI/Cards.get_children(): + randomize() + card_placeholder.get_node("Card").frame = cards.pop_at(randi()%cards.size()) + $UIWrapper/UI/Cards.visible = true #TODO Pause $UIWrapper/UI/LevelProgressBar/ColorRect.rect_size.x = (Global.play_time - difficulty * 60) / 60.0 * 300 - for i in range(clamp(difficulty + 1, 1, 4)): - mob_timers[i] += delta - if mob_timers[i] >= mob_threshold[i]: - mob_timers[i] = .0 - var mob_instance = mob_preloads[i].instance() - $View/Enemies.add_child(mob_instance) + if Global.playing: + for i in range(clamp(difficulty + 1, 1, 4)): + mob_timers[i] += delta + if mob_timers[i] >= mob_threshold[i]: + mob_timers[i] = .0 + var mob_instance = mob_preloads[i].instance() + $View/Enemies.add_child(mob_instance) diff --git a/src/scripts/enemy_class.gd b/src/scripts/enemy_class.gd index 83fdcc6..ef6b37c 100644 --- a/src/scripts/enemy_class.gd +++ b/src/scripts/enemy_class.gd @@ -30,35 +30,39 @@ func _process(delta): func death(): dead = true $Sprite.playing = false - death_position = self.global_position $Area2D.call_deferred("free") remove_from_group("enemy") material = empty_material $Sprite.material = empty_material func _physics_process(delta): - if dead: + if Global.playing: + death_position = self.global_position + if dead: + self.global_position = death_position + dead_timer += delta + $Sprite.modulate.a = 1 - (dead_timer * 2) + if dead_timer >= 0.5: + self.call_deferred("free") + + if poisoned: + poisoned_timer += delta + poison_damage_timer += delta + if poisoned_timer >= poisoned_time: + poisoned_timer = .0 + poison_damage_timer = .0 + poisoned = false + if poison_damage_timer >= 1: + deal_damage(poisoned_damage) + + if frozen: + frozen_timer += delta + speed_multiplier = 0.5 + if frozen_timer >= frozen_time: + frozen_time = 0 + frozen = false + else: + speed_multiplier = 1 + + if not Global.playing: self.global_position = death_position - dead_timer += delta - $Sprite.modulate.a = 1 - (dead_timer * 2) - if dead_timer >= 0.5: - self.call_deferred("free") - - if poisoned: - poisoned_timer += delta - poison_damage_timer += delta - if poisoned_timer >= poisoned_time: - poisoned_timer = .0 - poison_damage_timer = .0 - poisoned = false - if poison_damage_timer >= 1: - deal_damage(poisoned_damage) - - if frozen: - frozen_timer += delta - speed_multiplier = 0.5 - if frozen_timer >= frozen_time: - frozen_time = 0 - frozen = false - else: - speed_multiplier = 1