From ee51bdc8c5ed1b4bbd1f73fd6e58b355518380bd Mon Sep 17 00:00:00 2001 From: Luna Brovchuk Date: Sun, 1 Oct 2023 20:00:15 +0200 Subject: [PATCH] Fireball, Time Bar, Level System, Spawn System, Fix Rat Shaders, Sort Ingame UI --- res/themes/8px.tres | 11 +++ src/models/bullet/Bullet.tscn | 2 +- src/models/bullet/{Bullet.gd => bullet.gd} | 4 + src/models/enemies/ghost/Ghost.tscn | 2 +- src/models/enemies/rat/Rat.tscn | 8 +- src/models/enemies/rat/{Rat.gd => rat.gd} | 4 +- src/models/fireball/Fireball.tscn | 22 ++++++ src/models/fireball/fireball.gd | 30 ++++++++ src/models/fireball/fireball.png | Bin 0 -> 1623 bytes src/models/fireball/fireball.png.import | 35 +++++++++ src/models/player/Player.tscn | 6 +- src/models/player/player.gd | 9 +++ src/scenes/game/Game.tscn | 81 +++++++++++---------- src/scenes/game/game.gd | 33 +++++++++ src/scripts/global.gd | 1 + 15 files changed, 200 insertions(+), 48 deletions(-) create mode 100644 res/themes/8px.tres rename src/models/bullet/{Bullet.gd => bullet.gd} (85%) rename src/models/enemies/rat/{Rat.gd => rat.gd} (81%) create mode 100644 src/models/fireball/Fireball.tscn create mode 100644 src/models/fireball/fireball.gd create mode 100644 src/models/fireball/fireball.png create mode 100644 src/models/fireball/fireball.png.import diff --git a/res/themes/8px.tres b/res/themes/8px.tres new file mode 100644 index 0000000..6a0518a --- /dev/null +++ b/res/themes/8px.tres @@ -0,0 +1,11 @@ +[gd_resource type="Theme" load_steps=3 format=2] + +[ext_resource path="res://res/fonts/silkscreen/Silkscreen-Regular.ttf" type="DynamicFontData" id=1] + +[sub_resource type="DynamicFont" id=1] +size = 8 +extra_spacing_bottom = -8 +font_data = ExtResource( 1 ) + +[resource] +default_font = SubResource( 1 ) diff --git a/src/models/bullet/Bullet.tscn b/src/models/bullet/Bullet.tscn index 27c55c0..22ca2fd 100644 --- a/src/models/bullet/Bullet.tscn +++ b/src/models/bullet/Bullet.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=4 format=2] [ext_resource path="res://src/models/bullet/bullet.png" type="Texture" id=1] -[ext_resource path="res://src/models/bullet/Bullet.gd" type="Script" id=2] +[ext_resource path="res://src/models/bullet/bullet.gd" type="Script" id=2] [sub_resource type="RectangleShape2D" id=1] extents = Vector2( 3.5, 3.5 ) diff --git a/src/models/bullet/Bullet.gd b/src/models/bullet/bullet.gd similarity index 85% rename from src/models/bullet/Bullet.gd rename to src/models/bullet/bullet.gd index a46fa9a..ce9b2d8 100644 --- a/src/models/bullet/Bullet.gd +++ b/src/models/bullet/bullet.gd @@ -12,7 +12,11 @@ func _physics_process(delta): var target_texture = target.get_node("Sprite").frames.get_frame("idle", 0) var target_sprite_size = Vector2(target_texture.get_width(), target_texture.get_width()) var target_center = target.global_position + (target_sprite_size / 2) + if target.is_in_group("rat"): + target_center = target.global_position + Vector2(0, 2) self.global_position = self.global_position.move_toward(target_center, delta * speed) + else: + self.call_deferred("free") func area_entered(area): var parent = area.get_parent() diff --git a/src/models/enemies/ghost/Ghost.tscn b/src/models/enemies/ghost/Ghost.tscn index 13e0c74..df33a2d 100644 --- a/src/models/enemies/ghost/Ghost.tscn +++ b/src/models/enemies/ghost/Ghost.tscn @@ -25,7 +25,7 @@ flip_h = true use_parent_material = true frames = ExtResource( 1 ) animation = "idle" -frame = 4 +frame = 1 playing = true centered = false diff --git a/src/models/enemies/rat/Rat.tscn b/src/models/enemies/rat/Rat.tscn index b02646e..9b134d0 100644 --- a/src/models/enemies/rat/Rat.tscn +++ b/src/models/enemies/rat/Rat.tscn @@ -1,22 +1,24 @@ [gd_scene load_steps=4 format=2] [ext_resource path="res://src/models/enemies/rat/sprites/rat_spriteframes.tres" type="SpriteFrames" id=1] -[ext_resource path="res://src/models/enemies/rat/Rat.gd" type="Script" id=2] +[ext_resource path="res://src/models/enemies/rat/rat.gd" type="Script" id=2] [sub_resource type="RectangleShape2D" id=1] -extents = Vector2( 8, 3 ) +extents = Vector2( 8, 3.5 ) [node name="Rat" type="KinematicBody2D" groups=["enemy", "rat"]] script = ExtResource( 2 ) [node name="Sprite" type="AnimatedSprite" parent="."] +use_parent_material = true frames = ExtResource( 1 ) animation = "idle" +frame = 3 playing = true centered = false [node name="Area2D" type="Area2D" parent="."] [node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"] -position = Vector2( 12, 6 ) +position = Vector2( 11, 5.5 ) shape = SubResource( 1 ) diff --git a/src/models/enemies/rat/Rat.gd b/src/models/enemies/rat/rat.gd similarity index 81% rename from src/models/enemies/rat/Rat.gd rename to src/models/enemies/rat/rat.gd index eed9687..2c71200 100644 --- a/src/models/enemies/rat/Rat.gd +++ b/src/models/enemies/rat/rat.gd @@ -2,7 +2,7 @@ extends EnemyClass onready var player = $"../../Player" var velocity = Vector2.ZERO -var speed = 48 +var speed = 24 func _ready(): hp = 15 @@ -11,4 +11,4 @@ func _process(delta): $Sprite.flip_h = true if player.global_position.x > self.global_position.x else false func _physics_process(delta): - global_position = global_position.move_toward(player.global_position + Vector2(8, 8), speed * delta * speed_multiplier) + global_position = global_position.move_toward(player.global_position + Vector2(8, 8), speed * delta * speed_multiplier) diff --git a/src/models/fireball/Fireball.tscn b/src/models/fireball/Fireball.tscn new file mode 100644 index 0000000..88c37a7 --- /dev/null +++ b/src/models/fireball/Fireball.tscn @@ -0,0 +1,22 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://src/models/fireball/fireball.png" type="Texture" id=1] +[ext_resource path="res://src/models/fireball/fireball.gd" type="Script" id=2] + +[sub_resource type="RectangleShape2D" id=1] +extents = Vector2( 2, 2 ) + +[node name="Fireball" type="KinematicBody2D"] +script = ExtResource( 2 ) + +[node name="Sprite" type="Sprite" parent="."] +position = Vector2( -2, -2 ) +texture = ExtResource( 1 ) +centered = false + +[node name="Area2D" type="Area2D" parent="."] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"] +shape = SubResource( 1 ) + +[connection signal="area_entered" from="Area2D" to="." method="area_entered"] diff --git a/src/models/fireball/fireball.gd b/src/models/fireball/fireball.gd new file mode 100644 index 0000000..2b8273b --- /dev/null +++ b/src/models/fireball/fireball.gd @@ -0,0 +1,30 @@ +extends KinematicBody2D + +var velocity = Vector2.ZERO +var sin_timer = .0 +var speed = 64 +var poisoned = false +var damage = 5 +var frozen = false +var target + +func _physics_process(delta): + sin_timer += delta + if target != null and is_instance_valid(target): + var target_texture = target.get_node("Sprite").frames.get_frame("idle", 0) + var target_sprite_size = Vector2(target_texture.get_width(), target_texture.get_width()) + var target_center = target.global_position + (target_sprite_size / 2) + if target.is_in_group("rat"): + target_center = target.global_position + Vector2(0, 2) + var angle = global_position.angle_to_point(target_center) + move_and_collide(Vector2(speed, sin(sin_timer * 10) * 90).rotated(angle + PI) * delta) + else: + self.call_deferred("free") + +func area_entered(area): + var parent = area.get_parent() + if parent.is_in_group("enemy"): + parent.deal_damage(damage) + parent.frozen = frozen + parent.poisoned = poisoned + call_deferred("free") diff --git a/src/models/fireball/fireball.png b/src/models/fireball/fireball.png new file mode 100644 index 0000000000000000000000000000000000000000..a5fa3c29a51a696c31c14d4c175e4af229b504fd GIT binary patch literal 1623 zcmcIky^q{P6!%30g+mv<8bpB{ry&A+X1wOg%P%Zznzqv2=xoFNF?F7L9Ijv8`RrY|J&|v`S!&vo}s`}mXRHSOe&NpGjx ziQfpBOfAY~Us%&L2ehW0zc|e)+ZC1G7sDirjN9LQXXpu!jO%WU<9tnwl8wVcTs_?E zvBO;!aO2_y{rofpf>cygpQhui45yJX;|*c0UL!-FL8{%zSXBY_op?)MlZDVd%QhLt zSoZ>p^xH1=f>(4K+cv^&L|P{CLZ=-PN3Rb9!WDcFZg*a*gTYf|jH)UR5t>XU)}&?0 zVu(l(1PI&6woO2omMLdQ zj718t5`>W^R6dfGEJyMYc{HD!Z1Qle5VVp-Ps;J4Qd(#h=4UIjAPI5UWFQ`ahcsJxY8@ z_m7r-yu$yF(ra7Uh-O0plM@*#8Kg$cyeR13^_qQqU>q&rFyqv+nXd5A%x94Sbpg{i zKlzUu`%bsB+B@~pTR)Q(?ab5K_uoGC#cA*6>1Td8v2=O$(w$$geEIj=e=J|S{OMn} le*5La&rjTX@$OGcuikj}&)?q<&Z*JgUEl0{ed*?V_W)yE_No8? literal 0 HcmV?d00001 diff --git a/src/models/fireball/fireball.png.import b/src/models/fireball/fireball.png.import new file mode 100644 index 0000000..9b94835 --- /dev/null +++ b/src/models/fireball/fireball.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/fireball.png-cd7388e1024202929d5484e59b923c94.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://src/models/fireball/fireball.png" +dest_files=[ "res://.import/fireball.png-cd7388e1024202929d5484e59b923c94.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=false +svg/scale=1.0 diff --git a/src/models/player/Player.tscn b/src/models/player/Player.tscn index e085f77..780c786 100644 --- a/src/models/player/Player.tscn +++ b/src/models/player/Player.tscn @@ -5,10 +5,10 @@ [ext_resource path="res://res/shaders/colorize.tres" type="Material" id=3] [sub_resource type="RectangleShape2D" id=1] -extents = Vector2( 3.5, 3.5 ) +extents = Vector2( 4, 4 ) [sub_resource type="RectangleShape2D" id=2] -extents = Vector2( 3.5, 9 ) +extents = Vector2( 7, 11 ) [sub_resource type="Animation" id=4] resource_name = "RESET" @@ -48,7 +48,7 @@ tracks/0/loop_wrap = true tracks/0/imported = false tracks/0/enabled = true tracks/0/keys = { -"times": PoolRealArray( 0, 2 ), +"times": PoolRealArray( 0, 0.9 ), "transitions": PoolRealArray( 1, 1 ), "update": 1, "values": [ true, false ] diff --git a/src/models/player/player.gd b/src/models/player/player.gd index f8afbbe..a069b22 100644 --- a/src/models/player/player.gd +++ b/src/models/player/player.gd @@ -1,5 +1,6 @@ extends KinematicBody2D +onready var fireball_preload = preload("res://src/models/fireball/Fireball.tscn") onready var bullet_preload = preload("res://src/models/bullet/Bullet.tscn") var outline_material = load("res://res/shaders/outline_material.tres") var speed_multiplier: float = 1.0 @@ -70,6 +71,12 @@ func _shoot(): get_parent().add_child(bullet) bullet.global_position.x = self.global_position.x + 8 bullet.global_position.y = self.global_position.y + 8 + + bullet = fireball_preload.instance() + bullet.target = target + get_parent().add_child(bullet) + bullet.global_position.x = self.global_position.x + 8 + bullet.global_position.y = self.global_position.y + 8 func _draw(): if target != null and is_instance_valid(target): @@ -79,6 +86,8 @@ func _draw(): mob_offset = Vector2(8, 7) if target.is_in_group("ghost"): mob_offset = Vector2(8, 12) + if target.is_in_group("rat"): + mob_offset = Vector2(14, 6) draw_dashed_line(Vector2(12, 12), target.global_position - self.global_position + mob_offset, Color("ffde00"), 1) func _process(_delta): diff --git a/src/scenes/game/Game.tscn b/src/scenes/game/Game.tscn index 6c3c926..4149a09 100644 --- a/src/scenes/game/Game.tscn +++ b/src/scenes/game/Game.tscn @@ -1,9 +1,9 @@ -[gd_scene load_steps=21 format=2] +[gd_scene load_steps=17 format=2] [ext_resource path="res://src/scenes/menu/background/background.png" type="Texture" id=1] [ext_resource path="res://src/scenes/game/sprites/background_houses.png" type="Texture" id=2] [ext_resource path="res://src/scenes/game/spell_holder.gd" type="Script" id=3] -[ext_resource path="res://res/fonts/silkscreen/Silkscreen-Regular.ttf" type="DynamicFontData" id=4] +[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/3.png" type="Texture" id=6] [ext_resource path="res://src/scenes/game/sprites/health/1.png" type="Texture" id=7] @@ -12,9 +12,6 @@ [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] -[ext_resource path="res://src/models/enemies/trash_can/TrashCan.tscn" type="PackedScene" id=13] -[ext_resource path="res://src/models/enemies/bat/Bat.tscn" type="PackedScene" id=14] -[ext_resource path="res://src/models/enemies/ghost/Ghost.tscn" type="PackedScene" id=15] [ext_resource path="res://src/scenes/game/spell_recharge_bar.gd" type="Script" id=16] [sub_resource type="RectangleShape2D" id=2] @@ -23,10 +20,6 @@ extents = Vector2( 10, 60 ) [sub_resource type="RectangleShape2D" id=3] extents = Vector2( 140, 10.125 ) -[sub_resource type="DynamicFont" id=1] -size = 8 -font_data = ExtResource( 4 ) - [sub_resource type="SpriteFrames" id=4] animations = [ { "frames": [ ExtResource( 9 ), ExtResource( 7 ), ExtResource( 8 ), ExtResource( 6 ) ], @@ -78,16 +71,6 @@ z_index = 1 [node name="Enemies" type="Node2D" parent="View"] -[node name="TrashCan" parent="View/Enemies" instance=ExtResource( 13 )] - -[node name="Bat" parent="View/Enemies" instance=ExtResource( 14 )] - -[node name="Bat2" parent="View/Enemies" instance=ExtResource( 14 )] -position = Vector2( 142, 54 ) - -[node name="Ghost" parent="View/Enemies" instance=ExtResource( 15 )] -position = Vector2( 509, 100 ) - [node name="CPUParticles2D" type="CPUParticles2D" parent="View"] position = Vector2( 160, 90 ) amount = 9 @@ -113,43 +96,65 @@ margin_bottom = 180.0 texture = ExtResource( 12 ) expand = true -[node name="SpellHolder" type="Control" parent="UIWrapper/UI"] +[node name="LevelProgressBar" type="Control" parent="UIWrapper/UI"] +margin_left = 10.0 +margin_top = 126.0 +margin_right = 310.0 +margin_bottom = 128.0 + +[node name="ColorRect" type="ColorRect" parent="UIWrapper/UI/LevelProgressBar"] +margin_right = 300.0 +margin_bottom = 2.0 + +[node name="Left" type="Control" parent="UIWrapper/UI"] +margin_right = 40.0 +margin_bottom = 40.0 + +[node name="Health" type="Control" parent="UIWrapper/UI/Left"] +margin_right = 40.0 +margin_bottom = 40.0 + +[node name="HealthSprite" type="AnimatedSprite" parent="UIWrapper/UI/Left/Health"] +position = Vector2( 52, 148 ) +frames = SubResource( 4 ) +frame = 3 +centered = false + +[node name="PlayerIcon" type="Sprite" parent="UIWrapper/UI/Left"] +position = Vector2( 10, 136 ) +texture = ExtResource( 10 ) +centered = false + +[node name="Center" type="Control" parent="UIWrapper/UI"] +margin_right = 40.0 +margin_bottom = 40.0 + +[node name="SpellHolder" type="Control" parent="UIWrapper/UI/Center"] margin_left = 120.0 margin_top = 145.0 margin_right = 200.0 margin_bottom = 159.0 script = ExtResource( 3 ) -[node name="Text" type="Label" parent="UIWrapper/UI/SpellHolder"] +[node name="Text" type="Label" parent="UIWrapper/UI/Center/SpellHolder"] margin_left = 1.0 margin_top = -14.0 margin_right = 79.0 margin_bottom = 7.0 -custom_fonts/font = SubResource( 1 ) +theme = ExtResource( 4 ) text = "spell modifiers" -[node name="Health" type="Control" parent="UIWrapper/UI"] -margin_right = 40.0 -margin_bottom = 40.0 - -[node name="HealthSprite" type="AnimatedSprite" parent="UIWrapper/UI/Health"] -position = Vector2( 70, 145 ) -frames = SubResource( 4 ) -frame = 2 -centered = false - -[node name="SpellRechargeBar" type="Control" parent="UIWrapper/UI"] +[node name="SpellRechargeBar" type="Control" parent="UIWrapper/UI/Center"] margin_left = 120.0 margin_top = 162.0 margin_right = 200.0 margin_bottom = 165.0 script = ExtResource( 16 ) -[node name="ColorRect" type="ColorRect" parent="UIWrapper/UI/SpellRechargeBar"] +[node name="ColorRect" type="ColorRect" parent="UIWrapper/UI/Center/SpellRechargeBar"] margin_right = 80.0 margin_bottom = 3.0 -[node name="PlayerIcon" type="Sprite" parent="UIWrapper/UI"] -position = Vector2( 20, 134 ) -texture = ExtResource( 10 ) -centered = false +[node name="Right" type="Control" parent="UIWrapper/UI"] +margin_right = 40.0 +margin_bottom = 40.0 diff --git a/src/scenes/game/game.gd b/src/scenes/game/game.gd index 4e41905..685a880 100644 --- a/src/scenes/game/game.gd +++ b/src/scenes/game/game.gd @@ -1,5 +1,38 @@ extends Node +var difficulty = 0 +var last_diff = 0 +var mob_preloads = [ + preload("res://src/models/enemies/rat/Rat.tscn"), + preload("res://src/models/enemies/bat/Bat.tscn"), + preload("res://src/models/enemies/trash_can/TrashCan.tscn"), + preload("res://src/models/enemies/ghost/Ghost.tscn"), +] +var mob_timers = [.0, .0, .0, .0] +var mob_threshold = [5, 7, 10, 7] + func _ready(): + Global.play_time = .0 Global.health = 3 Global.add_health(0) + +func pause(): + Global.playing = false + +func _physics_process(delta): + if Global.playing: + Global.play_time += delta + + difficulty = int(Global.play_time / 60) + if difficulty != last_diff: + last_diff = difficulty + # TODO perk selection + + $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) diff --git a/src/scripts/global.gd b/src/scripts/global.gd index 4662e83..6e92539 100644 --- a/src/scripts/global.gd +++ b/src/scripts/global.gd @@ -4,6 +4,7 @@ var GAME_SCENE = preload("res://src/scenes/game/Game.tscn") var MENU_SCENE = preload("res://src/scenes/menu/Menu.tscn") var playing = true +var play_time = .0 var health = 2 func game_start():