diff --git a/WandClass.gd b/WandClass.gd deleted file mode 100644 index c5be963..0000000 --- a/WandClass.gd +++ /dev/null @@ -1,5 +0,0 @@ -extends Sprite -class_name Wand - -func fire(projectile, effect): - diff --git a/characters/Player.tscn b/characters/Player.tscn index b56e3f8..b8477fa 100644 --- a/characters/Player.tscn +++ b/characters/Player.tscn @@ -6,7 +6,7 @@ [ext_resource path="res://script/PlayerStateMachine.gd" type="Script" id=4] [ext_resource path="res://ui/Inventory.tscn" type="PackedScene" id=5] [ext_resource path="res://art/WizardM.png" type="Texture" id=6] -[ext_resource path="res://script/WandManager.gd" type="Script" id=7] +[ext_resource path="res://script/WandPosition.gd" type="Script" id=7] [sub_resource type="OccluderPolygon2D" id=1] polygon = PoolVector2Array( -7, 0, -7, -2, -6, -2, -6, -3, -5, -3, -5, -5, -6, -5, -6, -10, -7, -10, -7, -12, -6, -12, -6, -19, -4, -19, -4, -18, -3, -18, -3, -17, 1, -17, 1, -16, 3, -16, 3, -15, 4, -15, 4, -14, 5, -14, 5, -13, 6, -13, 6, -12, 7, -12, 7, -10, 6, -10, 6, -9, 5, -9, 5, -8, 6, -8, 6, -4, 5, -4, 5, 0, -7, 0 ) @@ -84,8 +84,8 @@ drag_margin_bottom = 0.0 [node name="PlayerStateMachine" type="Node" parent="."] script = ExtResource( 4 ) -[node name="WandManager" type="Position2D" parent="."] -position = Vector2( 0, -8 ) +[node name="WandPosition" type="Position2D" parent="."] +position = Vector2( 0, -7 ) script = ExtResource( 7 ) [node name="Sprite" type="Sprite" parent="."] diff --git a/magic/Projectiles/EcoProjectile.tscn b/magic/Projectiles/EcoProjectile.tscn new file mode 100644 index 0000000..533bcdf --- /dev/null +++ b/magic/Projectiles/EcoProjectile.tscn @@ -0,0 +1,16 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://art/ecoprojectile.png" type="Texture" id=1] +[ext_resource path="res://magic/Projectiles/Projectile.gd" type="Script" id=2] + +[sub_resource type="CircleShape2D" id=1] +radius = 5.0 + +[node name="EcoProjectile" type="KinematicBody2D"] +script = ExtResource( 2 ) + +[node name="Sprite" type="Sprite" parent="."] +texture = ExtResource( 1 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource( 1 ) diff --git a/magic/Projectiles/ExplosiveProjectile.tscn b/magic/Projectiles/ExplosiveProjectile.tscn new file mode 100644 index 0000000..f919223 --- /dev/null +++ b/magic/Projectiles/ExplosiveProjectile.tscn @@ -0,0 +1,16 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://art/MineProjectile.png" type="Texture" id=1] +[ext_resource path="res://magic/Projectiles/Projectile.gd" type="Script" id=2] + +[sub_resource type="CircleShape2D" id=1] +radius = 6.0 + +[node name="ExplosiveProjectile" type="KinematicBody2D"] +script = ExtResource( 2 ) + +[node name="Sprite" type="Sprite" parent="."] +texture = ExtResource( 1 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource( 1 ) diff --git a/magic/Projectiles/PhantomProjectile.tscn b/magic/Projectiles/PhantomProjectile.tscn new file mode 100644 index 0000000..2f17b8c --- /dev/null +++ b/magic/Projectiles/PhantomProjectile.tscn @@ -0,0 +1,18 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://art/PhantomProjectile.png" type="Texture" id=1] +[ext_resource path="res://magic/Projectiles/Projectile.gd" type="Script" id=2] + +[sub_resource type="CapsuleShape2D" id=1] +radius = 5.0 +height = 2.0 + +[node name="PhantomProjectile" type="KinematicBody2D"] +script = ExtResource( 2 ) + +[node name="Sprite" type="Sprite" parent="."] +texture = ExtResource( 1 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +rotation = 1.5708 +shape = SubResource( 1 ) diff --git a/script/Projectile.gd b/magic/Projectiles/Projectile.gd similarity index 93% rename from script/Projectile.gd rename to magic/Projectiles/Projectile.gd index aeeecc2..cc704ab 100644 --- a/script/Projectile.gd +++ b/magic/Projectiles/Projectile.gd @@ -11,7 +11,7 @@ func _physics_process(delta): if collision != null: on_impact(collision) -func launch(): +func launch(wand, effect): velocity = (Vector2(speed, 0)).rotated(rotation) func on_impact(collision): diff --git a/magic/Projectiles/WaveProjectile.tscn b/magic/Projectiles/WaveProjectile.tscn new file mode 100644 index 0000000..dbfe583 --- /dev/null +++ b/magic/Projectiles/WaveProjectile.tscn @@ -0,0 +1,17 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://art/WaveProjectile.png" type="Texture" id=1] +[ext_resource path="res://magic/Projectiles/Projectile.gd" type="Script" id=2] + +[sub_resource type="CapsuleShape2D" id=1] +radius = 4.0 +height = 4.0 + +[node name="WaveProjectile" type="KinematicBody2D"] +script = ExtResource( 2 ) + +[node name="Sprite" type="Sprite" parent="."] +texture = ExtResource( 1 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource( 1 ) diff --git a/magic/Wands/BouncyWand.tscn b/magic/Wands/BouncyWand.tscn index 5dbb3e0..8650c71 100644 --- a/magic/Wands/BouncyWand.tscn +++ b/magic/Wands/BouncyWand.tscn @@ -1,13 +1,16 @@ -[gd_scene load_steps=2 format=2] +[gd_scene load_steps=3 format=2] [ext_resource path="res://art/BouncingWand.png" type="Texture" id=1] +[ext_resource path="res://magic/Wands/WandClass.gd" type="Script" id=2] [node name="BouncyWand" type="Sprite"] rotation = 1.5708 texture = ExtResource( 1 ) offset = Vector2( 0, -11 ) +script = ExtResource( 2 ) -[node name="Position2D" type="Position2D" parent="."] -position = Vector2( -7.86805e-07, -18 ) +[node name="ProjectileSpawn" type="Position2D" parent="."] +position = Vector2( -8.01086e-05, -22 ) +rotation = -1.5708 [node name="ShootDelay" type="Timer" parent="."] diff --git a/magic/Wands/ChargedWand.tscn b/magic/Wands/ChargedWand.tscn index 7134f33..e30585c 100644 --- a/magic/Wands/ChargedWand.tscn +++ b/magic/Wands/ChargedWand.tscn @@ -1,14 +1,17 @@ -[gd_scene load_steps=2 format=2] +[gd_scene load_steps=3 format=2] +[ext_resource path="res://magic/Wands/WandClass.gd" type="Script" id=1] [ext_resource path="res://art/Wand.png" type="Texture" id=2] [node name="ChargedWand" type="Sprite"] position = Vector2( 9, 0 ) rotation = 1.5708 texture = ExtResource( 2 ) +script = ExtResource( 1 ) [node name="ProjectileSpawn" type="Position2D" parent="."] position = Vector2( -6.11959e-07, -7 ) +rotation = -1.5708 [node name="ShootDelay" type="Timer" parent="."] wait_time = 0.3 diff --git a/magic/Wands/PrismWand.tscn b/magic/Wands/PrismWand.tscn index 920361d..daa5f37 100644 --- a/magic/Wands/PrismWand.tscn +++ b/magic/Wands/PrismWand.tscn @@ -1,14 +1,16 @@ -[gd_scene load_steps=2 format=2] +[gd_scene load_steps=3 format=2] [ext_resource path="res://art/PrismaticWand.png" type="Texture" id=1] - +[ext_resource path="res://magic/Wands/WandClass.gd" type="Script" id=2] [node name="PrismWand" type="Sprite"] rotation = 1.5708 texture = ExtResource( 1 ) offset = Vector2( 0, -10 ) +script = ExtResource( 2 ) -[node name="Position2D" type="Position2D" parent="."] +[node name="ProjectileSpawn" type="Position2D" parent="."] position = Vector2( 0, -20 ) +rotation = -1.5708 [node name="ShootDelay" type="Timer" parent="."] diff --git a/magic/Wands/TripleWand.tscn b/magic/Wands/TripleWand.tscn index 5a3d27e..c405d4e 100644 --- a/magic/Wands/TripleWand.tscn +++ b/magic/Wands/TripleWand.tscn @@ -1,12 +1,21 @@ -[gd_scene load_steps=2 format=2] +[gd_scene load_steps=3 format=2] [ext_resource path="res://art/TripleWand.png" type="Texture" id=1] +[ext_resource path="res://magic/Wands/WandClass.gd" type="Script" id=2] [node name="TripleWand" type="Sprite"] rotation = 1.5708 texture = ExtResource( 1 ) offset = Vector2( 0, -11 ) +script = ExtResource( 2 ) -[node name="ProjectileSpawn" type="Position2D" parent="."] +[node name="ProjectileSpawn1" type="Position2D" parent="."] +position = Vector2( -5.00007, -20 ) + +[node name="ProjectileSpawn2" type="Position2D" parent="."] +position = Vector2( -8.01086e-05, -22 ) + +[node name="ProjectileSpawn3" type="Position2D" parent="."] +position = Vector2( 4.99993, -20 ) [node name="ShootDelay" type="Timer" parent="."] diff --git a/magic/Wands/WandClass.gd b/magic/Wands/WandClass.gd new file mode 100644 index 0000000..4df2ce8 --- /dev/null +++ b/magic/Wands/WandClass.gd @@ -0,0 +1,11 @@ +extends Sprite +class_name Wands + +func fire(projectile, effect): + if $ShootDelay.is_stopped() and projectile != null: + print("fire") + var temp = projectile.instance() + get_tree().current_scene.add_child(temp) + temp.global_transform = $ProjectileSpawn.global_transform + temp.launch(null, null) + $ShootDelay.start() diff --git a/project.godot b/project.godot index 2c082df..673fb89 100644 --- a/project.godot +++ b/project.godot @@ -22,7 +22,7 @@ _global_script_classes=[ { "base": "KinematicBody2D", "class": "Projectile", "language": "GDScript", -"path": "res://script/Projectile.gd" +"path": "res://magic/Projectiles/Projectile.gd" }, { "base": "Node", "class": "StateMachine", @@ -30,16 +30,16 @@ _global_script_classes=[ { "path": "res://script/StateMachine.gd" }, { "base": "Sprite", -"class": "Wand", +"class": "Wands", "language": "GDScript", -"path": "res://WandClass.gd" +"path": "res://magic/Wands/WandClass.gd" } ] _global_script_class_icons={ "Collectable": "", "Enemy": "", "Projectile": "", "StateMachine": "", -"Wand": "" +"Wands": "" } [application] diff --git a/script/Inventory.gd b/script/Inventory.gd index fea1d6b..c32c45d 100644 --- a/script/Inventory.gd +++ b/script/Inventory.gd @@ -74,19 +74,39 @@ func add_item(index): func _on_Conduit1_toggled(): if Conduit1.is_visible() and active_conduit != Globals.Magic[Globals.Conduit1]: active_conduit = Globals.Magic[Globals.Conduit1] - parent.WandManager.set_current_conduit(active_conduit) + parent.WandPosition.set_current_conduit(active_conduit) func _on_Conduit2_toggled(): if Conduit2.is_visible() and active_conduit != Globals.Magic[Globals.Conduit2]: active_conduit = Globals.Magic[Globals.Conduit2] - parent.WandManager.set_current_conduit(active_conduit) + parent.WandPosition.set_current_conduit(active_conduit) func _on_Conduit3_toggled(): if Conduit3.is_visible() and active_conduit != Globals.Magic[Globals.Conduit3]: active_conduit = Globals.Magic[Globals.Conduit3] - parent.WandManager.set_current_conduit(active_conduit) + parent.WandPosition.set_current_conduit(active_conduit) func _on_Conduit4_toggled(): if Conduit4.is_visible() and active_conduit != Globals.Magic[Globals.Conduit4]: active_conduit = Globals.Magic[Globals.Conduit4] - parent.WandManager.set_current_conduit(active_conduit) + parent.WandPosition.set_current_conduit(active_conduit) + + +func _on_Projectile1_pressed(): + if Projectile1.is_visible() and active_projectile != Globals.Magic[Globals.Projectile1]: + active_projectile = Globals.Magic[Globals.Projectile1] + + +func _on_Projectile2_pressed(): + if Projectile2.is_visible() and active_projectile != Globals.Magic[Globals.Projectile2]: + active_projectile = Globals.Magic[Globals.Projectile2] + + +func _on_Projectile3_pressed(): + if Projectile3.is_visible() and active_projectile != Globals.Magic[Globals.Projectile3]: + active_projectile = Globals.Magic[Globals.Projectile3] + + +func _on_Projectile4_pressed(): + if Projectile4.is_visible() and active_projectile != Globals.Magic[Globals.Projectile4]: + active_projectile = Globals.Magic[Globals.Projectile4] diff --git a/script/WandManager.gd b/script/WandPosition.gd similarity index 51% rename from script/WandManager.gd rename to script/WandPosition.gd index b96bcb4..2e9a86b 100644 --- a/script/WandManager.gd +++ b/script/WandPosition.gd @@ -1,8 +1,5 @@ extends Position2D -onready var parent = get_parent() -onready var inv = parent.Inventory - func clear_conduit(): for c in get_children(): c.queue_free() @@ -10,3 +7,7 @@ func clear_conduit(): func set_current_conduit(conduit): clear_conduit() add_child(conduit.instance()) + +func _process(delta): + if Input.is_action_pressed("shoot") and get_child_count() != 0: + get_children()[0].fire(get_parent().Inventory.active_projectile, null) diff --git a/script/globals.gd b/script/globals.gd index 4ca8753..32e20a6 100644 --- a/script/globals.gd +++ b/script/globals.gd @@ -1,8 +1,8 @@ extends Node -enum {Conduit1, Conduit2, Conduit3, Conduit4, } -enum {Projectile1, Projectile2, Projectile3, Projectile4} -enum {Effect1, Effect2, Effect3, Effect4} +enum {Conduit1, Conduit2, Conduit3, Conduit4, +Projectile1, Projectile2, Projectile3, Projectile4, +Effect1, Effect2, Effect3, Effect4} const TILE_SIZE = 16 @@ -12,10 +12,10 @@ var conduit2_ps = preload("res://magic/Wands/TripleWand.tscn") var conduit3_ps = preload("res://magic/Wands/BouncyWand.tscn") var conduit4_ps = preload("res://magic/Wands/PrismWand.tscn") -var projectile1_ps -var projectile2_ps -var projectile3_ps -var projectile4_ps +var projectile1_ps = preload("res://magic/Projectiles/EcoProjectile.tscn") +var projectile2_ps = preload("res://magic/Projectiles/PhantomProjectile.tscn") +var projectile3_ps = preload("res://magic/Projectiles/WaveProjectile.tscn") +var projectile4_ps = preload("res://magic/Projectiles/ExplosiveProjectile.tscn") var effect1_ps var effect2_ps diff --git a/script/player.gd b/script/player.gd index 8fe2572..581f199 100644 --- a/script/player.gd +++ b/script/player.gd @@ -24,15 +24,20 @@ onready var Anim: AnimationPlayer = $AnimationPlayer onready var CoyoteTimer: Timer = $CoyoteTimer onready var ShootDelay: Timer = $ShootDelay onready var StateMachine: Node = $PlayerStateMachine -onready var WandManager: Node2D = $WandManager +onready var WandPosition: Node2D = $WandPosition onready var ProjectileSpawn: Node2D = $HoldPosition/ProjectileSpawn onready var Inventory: CanvasLayer = $Inventory -onready var Wand onready var Stats = $Stats onready var health = Stats.health setget set_health, get_health onready var energy = Stats.energy setget set_energy, get_energy +func get_current_conduit(): + return Inventory.active_conduit + +func get_current_projectile(): + return Inventory.active_projectile + func get_type(): return "player" @@ -65,10 +70,7 @@ func _physics_process(delta): func handle_move_input(): input_direction = int(Input.is_action_pressed("right")) - int(Input.is_action_pressed("left")) velocity.x = lerp(velocity.x, speed * input_direction, get_movement_weight()) - WandManager.look_at(get_global_mouse_position()) - - if Input.is_action_pressed("shoot") and Wand != null: - Wand.fire_projectile(WandManager.rotation_degrees) + WandPosition.look_at(get_global_mouse_position()) if input_direction > 0: Spr.flip_h = false diff --git a/ui/Inventory.tscn b/ui/Inventory.tscn index 568fdbe..e884e97 100644 --- a/ui/Inventory.tscn +++ b/ui/Inventory.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=9 format=2] +[gd_scene load_steps=13 format=2] [ext_resource path="res://ui/Inventory.png" type="Texture" id=1] [ext_resource path="res://script/Inventory.gd" type="Script" id=2] @@ -6,6 +6,10 @@ [ext_resource path="res://art/TripleWand.png" type="Texture" id=4] [ext_resource path="res://art/BouncingWand.png" type="Texture" id=5] [ext_resource path="res://art/PrismaticWand.png" type="Texture" id=6] +[ext_resource path="res://art/PhantomProjectile.png" type="Texture" id=7] +[ext_resource path="res://art/ecoprojectile.png" type="Texture" id=8] +[ext_resource path="res://art/WaveProjectile.png" type="Texture" id=9] +[ext_resource path="res://art/MineProjectile.png" type="Texture" id=10] [sub_resource type="Animation" id=1] resource_name = "SlideIn" @@ -109,7 +113,58 @@ __meta__ = { } [node name="Projectiles" type="Node2D" parent="Inventory"] -visible = false + +[node name="Projectile1" type="TextureButton" parent="Inventory/Projectiles"] +margin_left = -28.0 +margin_top = -19.0 +margin_right = -12.0 +margin_bottom = -5.0 +action_mode = 0 +texture_normal = ExtResource( 8 ) +expand = true +stretch_mode = 3 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Projectile2" type="TextureButton" parent="Inventory/Projectiles"] +margin_left = 7.0 +margin_top = -19.0 +margin_right = 23.0 +margin_bottom = -5.0 +action_mode = 0 +texture_normal = ExtResource( 7 ) +expand = true +stretch_mode = 3 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Projectile3" type="TextureButton" parent="Inventory/Projectiles"] +margin_left = -28.0 +margin_top = 1.0 +margin_right = -12.0 +margin_bottom = 15.0 +action_mode = 0 +texture_normal = ExtResource( 9 ) +expand = true +stretch_mode = 3 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Projectile4" type="TextureButton" parent="Inventory/Projectiles"] +margin_left = 7.0 +margin_top = 1.0 +margin_right = 23.0 +margin_bottom = 15.0 +action_mode = 0 +texture_normal = ExtResource( 10 ) +expand = true +stretch_mode = 3 +__meta__ = { +"_edit_use_anchors_": false +} [node name="Effects" type="Node2D" parent="Inventory"] visible = false @@ -117,3 +172,7 @@ visible = false [connection signal="pressed" from="Inventory/Conduits/Conduit2" to="." method="_on_Conduit2_toggled"] [connection signal="pressed" from="Inventory/Conduits/Conduit3" to="." method="_on_Conduit3_toggled"] [connection signal="pressed" from="Inventory/Conduits/Conduit4" to="." method="_on_Conduit4_toggled"] +[connection signal="pressed" from="Inventory/Projectiles/Projectile1" to="." method="_on_Projectile1_pressed"] +[connection signal="pressed" from="Inventory/Projectiles/Projectile2" to="." method="_on_Projectile2_pressed"] +[connection signal="pressed" from="Inventory/Projectiles/Projectile3" to="." method="_on_Projectile3_pressed"] +[connection signal="pressed" from="Inventory/Projectiles/Projectile4" to="." method="_on_Projectile4_pressed"]