diff --git a/Enemies/Enemy.tscn b/Enemies/Enemy.tscn new file mode 100644 index 0000000..c6c044a --- /dev/null +++ b/Enemies/Enemy.tscn @@ -0,0 +1,19 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://Sprites/Enemy.png" type="Texture" id=1] + +[sub_resource type="CapsuleShape2D" id=2] +radius = 3.0 +height = 2.0 + +[node name="Enemy" type="KinematicBody2D" groups=["enemies"]] +collision_mask = 0 + +[node name="Sprite" type="Sprite" parent="."] +position = Vector2( 0, -3 ) +texture = ExtResource( 1 ) + +[node name="Hitbox" type="CollisionShape2D" parent="."] +visible = false +position = Vector2( 0, -3 ) +shape = SubResource( 2 ) diff --git a/GUI/HUD.gd b/GUI/HUD.gd new file mode 100644 index 0000000..b825515 --- /dev/null +++ b/GUI/HUD.gd @@ -0,0 +1,18 @@ +extends CanvasLayer + +signal add_currency(amount) + + +func _on_Add_Currency_pressed() -> void: + emit_signal('add_currency', 1) + return + + +func update_currency(amount: int) -> void: + $Currency.set_text(String(amount)) + return + + +func update_health(value: int) -> void: + $'Health Bar'.value = value + return diff --git a/GUI/HUD.tscn b/GUI/HUD.tscn new file mode 100644 index 0000000..04f8c2b --- /dev/null +++ b/GUI/HUD.tscn @@ -0,0 +1,40 @@ +[gd_scene load_steps=5 format=2] + +[ext_resource path="res://GUI/HUD.gd" type="Script" id=1] +[ext_resource path="res://Sprites/Health_Bar_Under.png" type="Texture" id=2] +[ext_resource path="res://Sprites/Health_Bar_Progress.png" type="Texture" id=3] +[ext_resource path="res://Sprites/Health_Bar_Over.png" type="Texture" id=4] + +[node name="HUD" type="CanvasLayer"] +script = ExtResource( 1 ) + +[node name="Health Bar" type="TextureProgress" parent="."] +margin_right = 104.0 +margin_bottom = 18.0 +rect_min_size = Vector2( 104, 18 ) +texture_under = ExtResource( 2 ) +texture_over = ExtResource( 4 ) +texture_progress = ExtResource( 3 ) +tint_progress = Color( 0.431373, 1, 0.737255, 1 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Currency" type="Label" parent="."] +margin_left = 220.0 +margin_right = 320.0 +align = 2 +valign = 1 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Add Currency" type="Button" parent="."] +margin_left = 300.0 +margin_top = 20.0 +margin_right = 320.0 +__meta__ = { +"_edit_use_anchors_": false +} + +[connection signal="pressed" from="Add Currency" to="." method="_on_Add_Currency_pressed"] diff --git a/GUI/Level Select Menu.gd b/GUI/Level Select Menu.gd new file mode 100644 index 0000000..acfb8c4 --- /dev/null +++ b/GUI/Level Select Menu.gd @@ -0,0 +1,33 @@ +extends Node + +signal complete(option) + + +func _on_hub_world_button_pressed() -> void: + emit_signal('complete', 'H') + return + + +func _on_level_1_button_pressed() -> void: + emit_signal('complete', '1') + return + + +func _on_level_2_button_pressed() -> void: + emit_signal('complete', '2') + return + + +func _on_level_3_button_pressed() -> void: + emit_signal('complete', '3') + return + + +func _on_level_4_button_pressed() -> void: + emit_signal('complete', '4') + return + + +func _on_level_5_button_pressed() -> void: + emit_signal('complete', '5') + return diff --git a/GUI/Level Select Menu.tscn b/GUI/Level Select Menu.tscn new file mode 100644 index 0000000..76ab6dd --- /dev/null +++ b/GUI/Level Select Menu.tscn @@ -0,0 +1,74 @@ +[gd_scene load_steps=8 format=2] + +[ext_resource path="res://Levels/Level_3_Button_Normal.png" type="Texture" id=1] +[ext_resource path="res://Levels/Level_1_Button_Normal.png" type="Texture" id=2] +[ext_resource path="res://Levels/Level_4_Button_Normal.png" type="Texture" id=3] +[ext_resource path="res://Levels/Level_2_Button_Normal.png" type="Texture" id=4] +[ext_resource path="res://Levels/Level_5_Button_Normal.png" type="Texture" id=5] +[ext_resource path="res://Levels/Hub_World_Button_Normal.png" type="Texture" id=6] +[ext_resource path="res://GUI/Level Select Menu.gd" type="Script" id=7] + +[node name="Level Select Menu" type="Node"] +script = ExtResource( 7 ) + +[node name="MarginContainer" type="MarginContainer" parent="."] +margin_left = 10.0 +margin_top = 10.0 +margin_right = 310.0 +margin_bottom = 170.0 +rect_min_size = Vector2( 300, 160 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="CenterContainer" type="CenterContainer" parent="MarginContainer"] +margin_right = 300.0 +margin_bottom = 160.0 + +[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer/CenterContainer"] +margin_left = 20.0 +margin_top = 60.0 +margin_right = 280.0 +margin_bottom = 100.0 + +[node name="Hub World" type="TextureButton" parent="MarginContainer/CenterContainer/HBoxContainer"] +margin_right = 40.0 +margin_bottom = 40.0 +texture_normal = ExtResource( 6 ) + +[node name="Level 1" type="TextureButton" parent="MarginContainer/CenterContainer/HBoxContainer"] +margin_left = 44.0 +margin_right = 84.0 +margin_bottom = 40.0 +texture_normal = ExtResource( 2 ) + +[node name="Level 2" type="TextureButton" parent="MarginContainer/CenterContainer/HBoxContainer"] +margin_left = 88.0 +margin_right = 128.0 +margin_bottom = 40.0 +texture_normal = ExtResource( 4 ) + +[node name="Level 3" type="TextureButton" parent="MarginContainer/CenterContainer/HBoxContainer"] +margin_left = 132.0 +margin_right = 172.0 +margin_bottom = 40.0 +texture_normal = ExtResource( 1 ) + +[node name="Level 4" type="TextureButton" parent="MarginContainer/CenterContainer/HBoxContainer"] +margin_left = 176.0 +margin_right = 216.0 +margin_bottom = 40.0 +texture_normal = ExtResource( 3 ) + +[node name="Level 5" type="TextureButton" parent="MarginContainer/CenterContainer/HBoxContainer"] +margin_left = 220.0 +margin_right = 260.0 +margin_bottom = 40.0 +texture_normal = ExtResource( 5 ) + +[connection signal="pressed" from="MarginContainer/CenterContainer/HBoxContainer/Hub World" to="." method="_on_hub_world_button_pressed"] +[connection signal="pressed" from="MarginContainer/CenterContainer/HBoxContainer/Level 1" to="." method="_on_level_1_button_pressed"] +[connection signal="pressed" from="MarginContainer/CenterContainer/HBoxContainer/Level 2" to="." method="_on_level_2_button_pressed"] +[connection signal="pressed" from="MarginContainer/CenterContainer/HBoxContainer/Level 3" to="." method="_on_level_3_button_pressed"] +[connection signal="pressed" from="MarginContainer/CenterContainer/HBoxContainer/Level 4" to="." method="_on_level_4_button_pressed"] +[connection signal="pressed" from="MarginContainer/CenterContainer/HBoxContainer/Level 5" to="." method="_on_level_5_button_pressed"] diff --git a/Main Menu.gd b/GUI/Main Menu.gd similarity index 100% rename from Main Menu.gd rename to GUI/Main Menu.gd diff --git a/Main Menu.tscn b/GUI/Main Menu.tscn similarity index 97% rename from Main Menu.tscn rename to GUI/Main Menu.tscn index 01f1acd..b8c26d9 100644 --- a/Main Menu.tscn +++ b/GUI/Main Menu.tscn @@ -13,7 +13,7 @@ [ext_resource path="res://Sprites/Quit_Button_Hover.png" type="Texture" id=11] [ext_resource path="res://Sprites/Main_Menu_Background.png" type="Texture" id=12] [ext_resource path="res://Resources/Ash.tres" type="DynamicFontData" id=13] -[ext_resource path="res://Main Menu.gd" type="Script" id=14] +[ext_resource path="res://GUI/Main Menu.gd" type="Script" id=14] [sub_resource type="DynamicFont" id=1] size = 20 @@ -31,6 +31,8 @@ centered = false [node name="Menu Items" type="MarginContainer" parent="."] margin_left = 10.0 margin_top = 10.0 +margin_right = 310.0 +margin_bottom = 170.0 rect_min_size = Vector2( 300, 160 ) __meta__ = { "_edit_use_anchors_": false diff --git a/Splash Screen.gd b/GUI/Splash Screen.gd similarity index 100% rename from Splash Screen.gd rename to GUI/Splash Screen.gd diff --git a/Splash Screen.tscn b/GUI/Splash Screen.tscn similarity index 81% rename from Splash Screen.tscn rename to GUI/Splash Screen.tscn index 53f739c..2bd69d6 100644 --- a/Splash Screen.tscn +++ b/GUI/Splash Screen.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=3 format=2] [ext_resource path="res://Sprites/Splash_Screen.png" type="Texture" id=1] -[ext_resource path="res://Splash Screen.gd" type="Script" id=2] +[ext_resource path="res://GUI/Splash Screen.gd" type="Script" id=2] [node name="Splash Screen" type="Sprite"] self_modulate = Color( 1, 1, 1, 0 ) diff --git a/Item.gd b/Item.gd new file mode 100644 index 0000000..aa5be04 --- /dev/null +++ b/Item.gd @@ -0,0 +1,14 @@ +# Item Class + +var name: String +var type: String + +func _init(name: String, type: String) -> void: + self.name = name + self.type = type + return + +func equals(other) -> bool: + if(self.name == other.name and self.type == other.type): + return true + return false diff --git a/World.gd b/Levels/Hub World.gd similarity index 76% rename from World.gd rename to Levels/Hub World.gd index f349435..dac8a1f 100644 --- a/World.gd +++ b/Levels/Hub World.gd @@ -2,4 +2,5 @@ extends Node2D func _ready() -> void: $YSort/Player.position = get_viewport_rect().size / 2 + $YSort/Player.load_hud($HUD) return diff --git a/Levels/Hub World.tscn b/Levels/Hub World.tscn new file mode 100644 index 0000000..2f6daf6 --- /dev/null +++ b/Levels/Hub World.tscn @@ -0,0 +1,21 @@ +[gd_scene load_steps=5 format=2] + +[ext_resource path="res://Player/Player.tscn" type="PackedScene" id=1] +[ext_resource path="res://Levels/Hub World.gd" type="Script" id=2] +[ext_resource path="res://GUI/HUD.tscn" type="PackedScene" id=3] +[ext_resource path="res://Enemies/Enemy.tscn" type="PackedScene" id=4] + +[node name="World" type="Node2D"] +script = ExtResource( 2 ) + +[node name="YSort" type="YSort" parent="."] + +[node name="Player" parent="YSort" instance=ExtResource( 1 )] +collision_mask = 2 + +[node name="Enemies" type="YSort" parent="YSort"] + +[node name="Enemy" parent="YSort/Enemies" instance=ExtResource( 4 )] +position = Vector2( 204, 95.8129 ) + +[node name="HUD" parent="." instance=ExtResource( 3 )] diff --git a/Levels/Hub_World_Button_Normal.png b/Levels/Hub_World_Button_Normal.png new file mode 100644 index 0000000..8b1bfe4 Binary files /dev/null and b/Levels/Hub_World_Button_Normal.png differ diff --git a/Levels/Hub_World_Button_Normal.png.import b/Levels/Hub_World_Button_Normal.png.import new file mode 100644 index 0000000..133bc3b --- /dev/null +++ b/Levels/Hub_World_Button_Normal.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/Hub_World_Button_Normal.png-e0e0c92697e93b1432bd2175db9ce2c3.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Levels/Hub_World_Button_Normal.png" +dest_files=[ "res://.import/Hub_World_Button_Normal.png-e0e0c92697e93b1432bd2175db9ce2c3.stex" ] + +[params] + +compress/mode=3 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=2 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=0 +process/fix_alpha_border=false +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/Levels/Level_1_Button_Normal.png b/Levels/Level_1_Button_Normal.png new file mode 100644 index 0000000..cd36e34 Binary files /dev/null and b/Levels/Level_1_Button_Normal.png differ diff --git a/Levels/Level_1_Button_Normal.png.import b/Levels/Level_1_Button_Normal.png.import new file mode 100644 index 0000000..52f9978 --- /dev/null +++ b/Levels/Level_1_Button_Normal.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/Level_1_Button_Normal.png-aabb94677b90d525ea57c43e1e096b4c.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Levels/Level_1_Button_Normal.png" +dest_files=[ "res://.import/Level_1_Button_Normal.png-aabb94677b90d525ea57c43e1e096b4c.stex" ] + +[params] + +compress/mode=3 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=2 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=0 +process/fix_alpha_border=false +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/Levels/Level_2_Button_Normal.png b/Levels/Level_2_Button_Normal.png new file mode 100644 index 0000000..cd7a5aa Binary files /dev/null and b/Levels/Level_2_Button_Normal.png differ diff --git a/Levels/Level_2_Button_Normal.png.import b/Levels/Level_2_Button_Normal.png.import new file mode 100644 index 0000000..cfa1839 --- /dev/null +++ b/Levels/Level_2_Button_Normal.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/Level_2_Button_Normal.png-fc84a3c0989fcc3c8e21d71dd29dae79.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Levels/Level_2_Button_Normal.png" +dest_files=[ "res://.import/Level_2_Button_Normal.png-fc84a3c0989fcc3c8e21d71dd29dae79.stex" ] + +[params] + +compress/mode=3 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=2 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=0 +process/fix_alpha_border=false +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/Levels/Level_3_Button_Normal.png b/Levels/Level_3_Button_Normal.png new file mode 100644 index 0000000..bfacbed Binary files /dev/null and b/Levels/Level_3_Button_Normal.png differ diff --git a/Levels/Level_3_Button_Normal.png.import b/Levels/Level_3_Button_Normal.png.import new file mode 100644 index 0000000..b53d6f5 --- /dev/null +++ b/Levels/Level_3_Button_Normal.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/Level_3_Button_Normal.png-13bd64d9d3b134bf83ed84336204422d.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Levels/Level_3_Button_Normal.png" +dest_files=[ "res://.import/Level_3_Button_Normal.png-13bd64d9d3b134bf83ed84336204422d.stex" ] + +[params] + +compress/mode=3 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=2 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=0 +process/fix_alpha_border=false +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/Levels/Level_4_Button_Normal.png b/Levels/Level_4_Button_Normal.png new file mode 100644 index 0000000..84c1499 Binary files /dev/null and b/Levels/Level_4_Button_Normal.png differ diff --git a/Levels/Level_4_Button_Normal.png.import b/Levels/Level_4_Button_Normal.png.import new file mode 100644 index 0000000..929e4ce --- /dev/null +++ b/Levels/Level_4_Button_Normal.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/Level_4_Button_Normal.png-07ee7e0ee4d69f43e44a957232f5dcd0.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Levels/Level_4_Button_Normal.png" +dest_files=[ "res://.import/Level_4_Button_Normal.png-07ee7e0ee4d69f43e44a957232f5dcd0.stex" ] + +[params] + +compress/mode=3 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=2 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=0 +process/fix_alpha_border=false +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/Levels/Level_5_Button_Normal.png b/Levels/Level_5_Button_Normal.png new file mode 100644 index 0000000..9e658ae Binary files /dev/null and b/Levels/Level_5_Button_Normal.png differ diff --git a/Levels/Level_5_Button_Normal.png.import b/Levels/Level_5_Button_Normal.png.import new file mode 100644 index 0000000..32def41 --- /dev/null +++ b/Levels/Level_5_Button_Normal.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/Level_5_Button_Normal.png-5692bf663ad3e725c957095a5773b43c.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Levels/Level_5_Button_Normal.png" +dest_files=[ "res://.import/Level_5_Button_Normal.png-5692bf663ad3e725c957095a5773b43c.stex" ] + +[params] + +compress/mode=3 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=2 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=0 +process/fix_alpha_border=false +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/Main.gd b/Main.gd index 9d139b2..2a7ccb2 100644 --- a/Main.gd +++ b/Main.gd @@ -2,6 +2,7 @@ extends Node export var splash_screen_path: String export var main_menu_path: String +export var level_select_menu_path: String export var world_path: String @@ -19,7 +20,8 @@ func _ready() -> void: func play_splash_screen() -> Node: var splash_screen: Node = load(splash_screen_path).instance() - if splash_screen.connect('complete', self, 'free_connected_node', [splash_screen, 'free_connected_node']) != OK: + if splash_screen.connect('complete', self, 'free_connected_node', + [splash_screen, 'free_connected_node']) != OK: print('ERROR: Splash Screen "complete" signal already connected.') add_child(splash_screen) @@ -29,7 +31,7 @@ func play_splash_screen() -> Node: func play_main_menu() -> Node: var main_menu: Node = load(main_menu_path).instance() if main_menu.connect('complete', self, 'main_menu_option') != OK: - print('ERROR: Main Menu "quit" signal already connected.') + print('ERROR: Main Menu "complete" signal already connected.') add_child(main_menu) return main_menu @@ -37,12 +39,35 @@ func play_main_menu() -> Node: func main_menu_option(option: String) -> void: if option == 'new game': - new_game() + var level_select_menu: Node = play_level_select_menu() + yield(level_select_menu, 'complete') + free_connected_node(level_select_menu, 'level_select_menu_option') + level_select_menu = null elif option == 'quit': quit_game() return +func play_level_select_menu() -> Node: + var level_select_menu: Node = load(level_select_menu_path).instance() + if level_select_menu.connect('complete', self, 'level_select_menu_option') != OK: + print('ERROR: Level Select Menu "complete" signal already connected.') + + add_child(level_select_menu) + return level_select_menu + + +func level_select_menu_option(option: String) -> void: + var level: String = 'res://Levels/' + if option == 'H': + level += 'Hub World.tscn' + elif option == '1': + level += 'Level 1.tscn' + + new_game(level) + return + + func free_connected_node(node: Node, connected_function: String) -> void: node.disconnect('complete', self, connected_function) remove_child(node) @@ -50,9 +75,10 @@ func free_connected_node(node: Node, connected_function: String) -> void: return -func new_game() -> void: - if get_tree().change_scene(world_path) != OK: - print('ERROR: Main failed to change scene to World.') +func new_game(level: String) -> void: + if get_tree().change_scene(level) != OK: + print('ERROR: Main failed to change scene to Level.') + queue_free() return diff --git a/Main.tscn b/Main.tscn index 04cf11e..153388d 100644 --- a/Main.tscn +++ b/Main.tscn @@ -5,9 +5,10 @@ [node name="Main" type="Node"] script = ExtResource( 1 ) -splash_screen_path = "res://Splash Screen.tscn" -main_menu_path = "res://Main Menu.tscn" -world_path = "res://World.tscn" +splash_screen_path = "res://GUI/Splash Screen.tscn" +main_menu_path = "res://GUI/Main Menu.tscn" +level_select_menu_path = "res://GUI/Level Select Menu.tscn" +world_path = "res://Levels/Hub World.tscn" [node name="Background" type="Sprite" parent="."] texture = ExtResource( 3 ) diff --git a/Player.gd b/Player.gd deleted file mode 100644 index 2865a3b..0000000 --- a/Player.gd +++ /dev/null @@ -1,24 +0,0 @@ -extends KinematicBody2D - -const ACCELERATION = 1000 -const MAX_SPEED = 120 -const FRICTION = 1000 - -var velocity: Vector2 = Vector2.ZERO - - -func _physics_process(delta) -> void: - var input_vector: Vector2 = Vector2.ZERO - - input_vector.x = Input.get_action_strength('player_right') - Input.get_action_strength('player_left') - input_vector.y = Input.get_action_strength('player_down') - Input.get_action_strength('player_up') - input_vector = input_vector.normalized() - - if input_vector != Vector2.ZERO: - $AnimationTree.set('parameters/Idle/blend_position', input_vector) - velocity = velocity.move_toward(input_vector * MAX_SPEED, ACCELERATION * delta) - else: - velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta) - - velocity = move_and_slide(velocity) - return diff --git a/Player/Inventory.gd b/Player/Inventory.gd new file mode 100644 index 0000000..807e50d --- /dev/null +++ b/Player/Inventory.gd @@ -0,0 +1,45 @@ +extends Node + +signal update_currency(amount) + +var __currency: int + +var __weapons: Array +var __accessories: Array +var __categories: Dictionary + + +func _ready() -> void: + self.__currency = 100 + + self.__weapons = [] + self.__accessories = [] + self.__categories = { + 'Weapon': self.__weapons, + 'Accessory': self.__accessories} + return + + +func get_currency() -> int: + return self.__currency + + +func add_currency(amount: int) -> void: + self.__currency += amount + emit_signal('update_currency', self.__currency) + return + + +func add(item) -> void: + self.__categories[item.type].append(item) + return + + +func discard(item) -> void: + var index: int = 0 + for itr in self.__categories[item.type]: + if itr.equals(item): + self.__categories[item.type].remove(index) + break + index += 1 + return diff --git a/Player/Inventory.tscn b/Player/Inventory.tscn new file mode 100644 index 0000000..ab9e575 --- /dev/null +++ b/Player/Inventory.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://Player/Inventory.gd" type="Script" id=1] + +[node name="Inventory" type="Node"] +script = ExtResource( 1 ) diff --git a/Player/Player.gd b/Player/Player.gd new file mode 100644 index 0000000..21e54fe --- /dev/null +++ b/Player/Player.gd @@ -0,0 +1,59 @@ +extends KinematicBody2D + +const ACCELERATION: int = 1000 +const MAX_SPEED: int = 120 +const FRICTION: int = 1000 +const HEALTH_SLICES: Array = [0, 20, 35, 50, 65, 80, 100] + +var health_index: int = 6 +var hud: CanvasLayer = null +var velocity: Vector2 = Vector2.ZERO + + +func _physics_process(delta) -> void: + var input_vector: Vector2 = Vector2.ZERO + + input_vector.x = Input.get_action_strength('player_right') \ + - Input.get_action_strength('player_left') + input_vector.y = Input.get_action_strength('player_down') \ + - Input.get_action_strength('player_up') + input_vector = input_vector.normalized() + + if input_vector != Vector2.ZERO: + $AnimationTree.set('parameters/Idle/blend_position', input_vector) + velocity = velocity.move_toward(input_vector * MAX_SPEED, ACCELERATION * delta) + else: + velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta) + + velocity = move_and_slide(velocity) + return + + +func load_hud(node: CanvasLayer) -> void: + hud = node + if hud.connect('add_currency', self, 'add_currency') != OK: + print('ERROR: HUD "add_currency" signal already connected.') + + hud.update_health(HEALTH_SLICES[health_index]) + hud.update_currency($Inventory.get_currency()) + return + + +func add_currency(amount: int) -> void: + $Inventory.add_currency(amount) + return + + +func _on_Inventory_update_currency(amount: int) -> void: + hud.update_currency(amount) + return + + +func _on_Hitbox_body_entered(body: Node) -> void: + if not 'enemies' in body.get_groups(): + return + + if health_index != 0: + health_index -= 1 + hud.update_health(HEALTH_SLICES[health_index]) + return diff --git a/Sprites/Player.png b/Player/Player.png similarity index 100% rename from Sprites/Player.png rename to Player/Player.png diff --git a/Sprites/Player.png.import b/Player/Player.png.import similarity index 68% rename from Sprites/Player.png.import rename to Player/Player.png.import index d60fbdc..442f173 100644 --- a/Sprites/Player.png.import +++ b/Player/Player.png.import @@ -2,15 +2,15 @@ importer="texture" type="StreamTexture" -path="res://.import/Player.png-0662117005c6b9039deb63a286c8efe4.stex" +path="res://.import/Player.png-3d0801c65bdfc563657cfa304115f1c7.stex" metadata={ "vram_texture": false } [deps] -source_file="res://Sprites/Player.png" -dest_files=[ "res://.import/Player.png-0662117005c6b9039deb63a286c8efe4.stex" ] +source_file="res://Player/Player.png" +dest_files=[ "res://.import/Player.png-3d0801c65bdfc563657cfa304115f1c7.stex" ] [params] @@ -28,6 +28,7 @@ process/fix_alpha_border=false 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 diff --git a/Player.tscn b/Player/Player.tscn similarity index 86% rename from Player.tscn rename to Player/Player.tscn index e621a9d..9c6780c 100644 --- a/Player.tscn +++ b/Player/Player.tscn @@ -1,9 +1,10 @@ -[gd_scene load_steps=19 format=2] +[gd_scene load_steps=20 format=2] -[ext_resource path="res://Player.gd" type="Script" id=1] -[ext_resource path="res://Sprites/Player.png" type="Texture" id=2] -[ext_resource path="res://Sprites/Player_Down.png" type="Texture" id=3] -[ext_resource path="res://Sprites/Player_Up.png" type="Texture" id=4] +[ext_resource path="res://Player/Player.gd" type="Script" id=1] +[ext_resource path="res://Player/Player.png" type="Texture" id=2] +[ext_resource path="res://Player/Player_Down.png" type="Texture" id=3] +[ext_resource path="res://Player/Player_Up.png" type="Texture" id=4] +[ext_resource path="res://Player/Inventory.tscn" type="PackedScene" id=5] [sub_resource type="SpriteFrames" id=1] animations = [ { @@ -14,12 +15,12 @@ animations = [ { }, { "frames": [ ExtResource( 2 ) ], "loop": false, -"name": "look_right", +"name": "look_left", "speed": 5.0 }, { "frames": [ ExtResource( 2 ) ], "loop": false, -"name": "look_left", +"name": "look_right", "speed": 5.0 }, { "frames": [ ExtResource( 3 ) ], @@ -192,7 +193,9 @@ visible = false rotation = 1.5708 shape = SubResource( 2 ) -[node name="Hitbox" type="CollisionShape2D" parent="."] +[node name="Hitbox" type="Area2D" parent="."] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Hitbox"] visible = false position = Vector2( 0, -5 ) shape = SubResource( 3 ) @@ -210,3 +213,8 @@ anim_player = NodePath("../AnimationPlayer") active = true parameters/playback = SubResource( 14 ) parameters/Idle/blend_position = Vector2( 0.993787, 0.0189655 ) + +[node name="Inventory" parent="." instance=ExtResource( 5 )] + +[connection signal="body_entered" from="Hitbox" to="." method="_on_Hitbox_body_entered"] +[connection signal="update_currency" from="Inventory" to="." method="_on_Inventory_update_currency"] diff --git a/Sprites/Player_Down.png b/Player/Player_Down.png similarity index 100% rename from Sprites/Player_Down.png rename to Player/Player_Down.png diff --git a/Player/Player_Down.png.import b/Player/Player_Down.png.import new file mode 100644 index 0000000..b876464 --- /dev/null +++ b/Player/Player_Down.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/Player_Down.png-0720a85ec5e36101f691c750d323946c.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Player/Player_Down.png" +dest_files=[ "res://.import/Player_Down.png-0720a85ec5e36101f691c750d323946c.stex" ] + +[params] + +compress/mode=3 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=2 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=0 +process/fix_alpha_border=false +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/Sprites/Player_Up.png b/Player/Player_Up.png similarity index 100% rename from Sprites/Player_Up.png rename to Player/Player_Up.png diff --git a/Sprites/Player_Up.png.import b/Player/Player_Up.png.import similarity index 66% rename from Sprites/Player_Up.png.import rename to Player/Player_Up.png.import index 3e59f41..c2ea171 100644 --- a/Sprites/Player_Up.png.import +++ b/Player/Player_Up.png.import @@ -2,15 +2,15 @@ importer="texture" type="StreamTexture" -path="res://.import/Player_Up.png-3bef5e9a80b83b2419123f6e36070755.stex" +path="res://.import/Player_Up.png-889a827868f4dc454da2bef028bdec76.stex" metadata={ "vram_texture": false } [deps] -source_file="res://Sprites/Player_Up.png" -dest_files=[ "res://.import/Player_Up.png-3bef5e9a80b83b2419123f6e36070755.stex" ] +source_file="res://Player/Player_Up.png" +dest_files=[ "res://.import/Player_Up.png-889a827868f4dc454da2bef028bdec76.stex" ] [params] @@ -28,6 +28,7 @@ process/fix_alpha_border=false 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 diff --git a/Sprites/Enemy.png b/Sprites/Enemy.png new file mode 100644 index 0000000..86d58e4 Binary files /dev/null and b/Sprites/Enemy.png differ diff --git a/Sprites/Player_Down.png.import b/Sprites/Enemy.png.import similarity index 68% rename from Sprites/Player_Down.png.import rename to Sprites/Enemy.png.import index 06a7b1f..c39c100 100644 --- a/Sprites/Player_Down.png.import +++ b/Sprites/Enemy.png.import @@ -2,15 +2,15 @@ importer="texture" type="StreamTexture" -path="res://.import/Player_Down.png-6af5789aad25d026ca2bc30eb096b98e.stex" +path="res://.import/Enemy.png-4f2f37ccc9d782f4030225b9d1bff284.stex" metadata={ "vram_texture": false } [deps] -source_file="res://Sprites/Player_Down.png" -dest_files=[ "res://.import/Player_Down.png-6af5789aad25d026ca2bc30eb096b98e.stex" ] +source_file="res://Sprites/Enemy.png" +dest_files=[ "res://.import/Enemy.png-4f2f37ccc9d782f4030225b9d1bff284.stex" ] [params] @@ -28,6 +28,7 @@ process/fix_alpha_border=false 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 diff --git a/Sprites/Health_Bar_Over.png b/Sprites/Health_Bar_Over.png new file mode 100644 index 0000000..b3fc39e Binary files /dev/null and b/Sprites/Health_Bar_Over.png differ diff --git a/Sprites/Health_Bar_Over.png.import b/Sprites/Health_Bar_Over.png.import new file mode 100644 index 0000000..31a3eb2 --- /dev/null +++ b/Sprites/Health_Bar_Over.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/Health_Bar_Over.png-eb296b5f718c04ea700ee8c8b642b2c2.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Sprites/Health_Bar_Over.png" +dest_files=[ "res://.import/Health_Bar_Over.png-eb296b5f718c04ea700ee8c8b642b2c2.stex" ] + +[params] + +compress/mode=3 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=2 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=0 +process/fix_alpha_border=false +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/Sprites/Health_Bar_Progress.png b/Sprites/Health_Bar_Progress.png new file mode 100644 index 0000000..2d56ea1 Binary files /dev/null and b/Sprites/Health_Bar_Progress.png differ diff --git a/Sprites/Health_Bar_Progress.png.import b/Sprites/Health_Bar_Progress.png.import new file mode 100644 index 0000000..7399b14 --- /dev/null +++ b/Sprites/Health_Bar_Progress.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/Health_Bar_Progress.png-117323bbc852614a5961413bb8cfea0f.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Sprites/Health_Bar_Progress.png" +dest_files=[ "res://.import/Health_Bar_Progress.png-117323bbc852614a5961413bb8cfea0f.stex" ] + +[params] + +compress/mode=3 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=2 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=0 +process/fix_alpha_border=false +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/Sprites/Health_Bar_Under.png b/Sprites/Health_Bar_Under.png new file mode 100644 index 0000000..28df3f6 Binary files /dev/null and b/Sprites/Health_Bar_Under.png differ diff --git a/Sprites/Health_Bar_Under.png.import b/Sprites/Health_Bar_Under.png.import new file mode 100644 index 0000000..5156e66 --- /dev/null +++ b/Sprites/Health_Bar_Under.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/Health_Bar_Under.png-6cd4d04ee9e2525df9d3281f17cae308.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Sprites/Health_Bar_Under.png" +dest_files=[ "res://.import/Health_Bar_Under.png-6cd4d04ee9e2525df9d3281f17cae308.stex" ] + +[params] + +compress/mode=3 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=2 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=0 +process/fix_alpha_border=false +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/World.tscn b/World.tscn deleted file mode 100644 index ced7c73..0000000 --- a/World.tscn +++ /dev/null @@ -1,12 +0,0 @@ -[gd_scene load_steps=3 format=2] - -[ext_resource path="res://Player.tscn" type="PackedScene" id=1] -[ext_resource path="res://World.gd" type="Script" id=2] - -[node name="World" type="Node2D"] -script = ExtResource( 2 ) - -[node name="YSort" type="YSort" parent="."] - -[node name="Player" parent="YSort" instance=ExtResource( 1 )] -collision_mask = 2 diff --git a/project.godot b/project.godot index c88bda6..c59c044 100644 --- a/project.godot +++ b/project.godot @@ -12,6 +12,7 @@ config_version=4 config/name="Embodiment" run/main_scene="res://Main.tscn" +run/delta_sync_after_draw=true boot_splash/image="res://Sprites/Black_Background.png" boot_splash/use_filter=false boot_splash/bg_color=Color( 0, 0, 0, 1 ) @@ -30,22 +31,22 @@ window/stretch/aspect="keep" player_right={ "deadzone": 0.5, -"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"unicode":0,"echo":false,"script":null) +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"physical_scancode":0,"unicode":0,"echo":false,"script":null) ] } player_left={ "deadzone": 0.5, -"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"unicode":0,"echo":false,"script":null) +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"physical_scancode":0,"unicode":0,"echo":false,"script":null) ] } player_up={ "deadzone": 0.5, -"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"unicode":0,"echo":false,"script":null) +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"physical_scancode":0,"unicode":0,"echo":false,"script":null) ] } player_down={ "deadzone": 0.5, -"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"unicode":0,"echo":false,"script":null) +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"physical_scancode":0,"unicode":0,"echo":false,"script":null) ] }