diff --git a/game/characters/SimpleCharacter.gd b/game/characters/SimpleCharacter.gd new file mode 100644 index 0000000..26b8b61 --- /dev/null +++ b/game/characters/SimpleCharacter.gd @@ -0,0 +1,99 @@ +extends CharacterSkeleton2D + +# Copyright Péter Magyar relintai@gmail.com +# MIT License, functionality from this class needs to be protable to the entity spell system + +# Copyright (c) 2019 Péter Magyar + +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +#export (NodePath) var sprite_path : NodePath = "" + +var sprite : Sprite + +var _facing : int = 0 + +var effects : Array + +var _atlas : CharacterAtlas2D + +enum CharacterFacing { + FACING_FRONT = 0, + FACING_BACK = 1, + FACING_RIGHT = 2, + FACING_LEFT = 3, +} + +#func _ready() -> void: +# sprite = get_node(sprite_path) as Sprite + +func _enter_tree(): + sprite = get_node("/root/Main").get_body().instance() + add_child(sprite) + +func update_facing(input_direction : Vector2) -> void: + + if input_direction.x > 0.01 and _facing != CharacterFacing.FACING_RIGHT: + _facing = CharacterFacing.FACING_RIGHT + sprite.transform.x.x = -1 + elif input_direction.x < -0.01 and _facing != CharacterFacing.FACING_LEFT: + _facing = CharacterFacing.FACING_LEFT + sprite.transform.x.x = 1 + +#func add_effect(bone_id : int, effect : PackedScene) -> void: +# pass +# +#func remove_effect(bone_id : int, effect : PackedScene) -> void: +# pass +# +func _common_attach_point_index_get(point): + if point == EntityEnums.COMMON_SKELETON_POINT_LEFT_HAND: + return 0 + elif point == EntityEnums.COMMON_SKELETON_POINT_ROOT: + return 3 + elif point == EntityEnums.COMMON_SKELETON_POINT_SPINE_2: + return 6 + elif point == EntityEnums.COMMON_SKELETON_POINT_RIGHT_HAND: + return 1 + elif point == EntityEnums.COMMON_SKELETON_POINT_BACK: + return 6 + elif point == EntityEnums.COMMON_SKELETON_POINT_RIGHT_HIP: + return 4 + elif point == EntityEnums.COMMON_SKELETON_POINT_WEAPON_LEFT: + return 7 + elif point == EntityEnums.COMMON_SKELETON_POINT_WEAPON_LEFT_BACK: + return 9 + elif point == EntityEnums.COMMON_SKELETON_POINT_WEAPON_RIGHT: + return 8 + elif point == EntityEnums.COMMON_SKELETON_POINT_WEAPON_RIGHT_BACK: + return 10 + elif point == EntityEnums.COMMON_SKELETON_POINT_WEAPON_LEFT_SHIELD: + return 11 + + return 3 + +func get_animation_player() -> AnimationPlayer: + return null + +func get_animation_tree() -> AnimationTree: + return null + +func set_character_atlas(atlas : CharacterAtlas) -> void: + _atlas = atlas as CharacterAtlas2D + diff --git a/game/characters/SimpleCharacter.tscn b/game/characters/SimpleCharacter.tscn new file mode 100644 index 0000000..6de1dec --- /dev/null +++ b/game/characters/SimpleCharacter.tscn @@ -0,0 +1,65 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://characters/SimpleCharacter.gd" type="Script" id=1] +[ext_resource path="res://player/CharacterSkeletonAttachPoint.gd" type="Script" id=2] + +[node name="Character" type="CharacterSkeleton2D"] +entity_type = 1 +attach_point_paths/0_left_hand = NodePath("LeftHand") +attach_point_paths/1_right_hand = NodePath("RightHand") +attach_point_paths/2_torso = NodePath("Torso") +attach_point_paths/3_root = NodePath("Root") +attach_point_paths/4_right_hip = NodePath("RightHip") +attach_point_paths/5_left_hip = NodePath("LeftHip") +attach_point_paths/6_spine_2 = NodePath("Spine2") +attach_point_paths/7_weapon_left = NodePath("WeaponLeft") +attach_point_paths/8_weapon_right = NodePath("WeaponRight") +attach_point_paths/9_weapon_left_back = NodePath("WeaponLeft") +attach_point_paths/10_weapon_right_back = NodePath("WeaponLeft") +attach_point_paths/11_weapon_shield_left = NodePath("WeaponLeft") +script = ExtResource( 1 ) + +[node name="LeftHand" type="Node2D" parent="."] +position = Vector2( 5.95948, 5.29732 ) +z_index = 1 +script = ExtResource( 2 ) + +[node name="RightHand" type="Node2D" parent="."] +position = Vector2( -6.0257, 5.2311 ) +z_index = 1 +script = ExtResource( 2 ) + +[node name="Torso" type="Node2D" parent="."] +position = Vector2( 0.0662193, 1.39054 ) +z_index = 1 +script = ExtResource( 2 ) + +[node name="Root" type="Node2D" parent="."] +position = Vector2( -0.0662155, 14.369 ) +z_index = 1 +script = ExtResource( 2 ) + +[node name="RightHip" type="Node2D" parent="."] +position = Vector2( -2.45001, 3.77434 ) +z_index = 1 +script = ExtResource( 2 ) + +[node name="LeftHip" type="Node2D" parent="."] +position = Vector2( 2.45001, 4.0392 ) +z_index = 1 +script = ExtResource( 2 ) + +[node name="Spine2" type="Node2D" parent="."] +position = Vector2( -0.132435, -1.98649 ) +z_index = 1 +script = ExtResource( 2 ) + +[node name="WeaponLeft" type="Node2D" parent="."] +position = Vector2( 6.09191, 5.2311 ) +z_index = 1 +script = ExtResource( 2 ) + +[node name="WeaponRight" type="Node2D" parent="."] +position = Vector2( -6.0257, 5.16488 ) +z_index = 1 +script = ExtResource( 2 ) diff --git a/game/modules/species/Human/Body.tscn b/game/modules/species/Human/Body.tscn index 5715a55..e151a8f 100644 --- a/game/modules/species/Human/Body.tscn +++ b/game/modules/species/Human/Body.tscn @@ -1,59 +1,16 @@ -[gd_scene load_steps=10 format=2] +[gd_scene load_steps=4 format=2] -[ext_resource path="res://characters/Character.tscn" type="PackedScene" id=1] -[ext_resource path="res://scripts/item_visuals/CharacterAtlasEntry2D.gd" type="Script" id=2] -[ext_resource path="res://scripts/item_visuals/CharacterAtlas2D.gd" type="Script" id=3] -[ext_resource path="res://characters/char_t1_outline_split.png" type="Texture" id=5] +[ext_resource path="res://characters/SimpleCharacter.tscn" type="PackedScene" id=1] [ext_resource path="res://player/Body.gd" type="Script" id=6] -[sub_resource type="CharacterAtlasEntry" id=1] -script = ExtResource( 2 ) -front_rect = Rect2( 101, 15, 9, 12 ) -back_rect = Rect2( 74, 18, 9, 12 ) -right_rect = Rect2( 8, 13, 9, 12 ) -left_rect = Rect2( 8, 13, 9, 12 ) - -[sub_resource type="CharacterAtlasEntry" id=2] -script = ExtResource( 2 ) -front_rect = Rect2( 102, 2, 7, 8 ) -back_rect = Rect2( 75, 5, 7, 8 ) -right_rect = Rect2( 9, 0, 7, 8 ) -left_rect = Rect2( 9, 0, 7, 8 ) - -[sub_resource type="CharacterAtlas" id=3] -script = ExtResource( 3 ) -comments = "HUMANOID_BONE_HIP = 0, -HUMANOID_BONE_TORSO = 1, -HUMANOID_BONE_LEG_R = 2, -HUMANOID_BONE_FOOT_R = 3, -HUMANOID_BONE_TOE_R = 4, -HUMANOID_BONE_LEG_L = 5, -HUMANOID_BONE_FOOT_L = 6, -HUMANOID_BONE_TOE_L = 7, -HUMANOID_BONE_ARM_R = 8, -#HUMANOID_BONE_SHOULDER_GUARD_R = 0, -HUMANOID_BONE_HAND_R = 9, -HUMANOID_BONE_FINGERS_R = 10, -HUMANOID_BONE_ARM_L = 11, -#HUMANOID_BONE_SHOULDER_GUARD_L = 0, -HUMANOID_BONE_HAND_L = 12, -HUMANOID_BONE_FINGERS_L = 13, -HUMANOID_BONE_HEAD = 14, -HUMANOID_BONE_HEAD_TOP = 15, -HUMANOID_BONES_MAX = 16," -texture = ExtResource( 5 ) -slots = [ null, SubResource( 1 ), null, null, null, null, null, null, null, null, null, null, null, null, SubResource( 2 ), null ] - [sub_resource type="CircleShape2D" id=4] radius = 8.0 [node name="Body" type="KinematicBody2D"] script = ExtResource( 6 ) +character_skeleton_path = NodePath("") [node name="Character" parent="." instance=ExtResource( 1 )] -front_node_path = NodePath("../../Body/Character/CharacterFrontModel") -side_node_path = NodePath("../../Body/Character/CharacterSideModel") -character_atlas = SubResource( 3 ) [node name="CollisionShape2D" type="CollisionShape2D" parent="."] shape = SubResource( 4 ) diff --git a/game/player/Body.gd b/game/player/Body.gd index b6996f9..dccf53d 100644 --- a/game/player/Body.gd +++ b/game/player/Body.gd @@ -182,11 +182,11 @@ func process_input(delta: float) -> void: var input_length : float = input_dir.length_squared() - if input_length > 0.1: +# if input_length > 0.1: #handle_graphic_facing(abs(dir.dot(Vector2(0, 1))) > 0.9) - character_skeleton.update_facing(input_dir) +# character_skeleton.update_facing(input_dir) - character_skeleton.get_animation_tree().set("parameters/walking/blend_amount", input_dir.length()) +# character_skeleton.get_animation_tree().set("parameters/walking/blend_amount", input_dir.length()) func process_movement(delta : float) -> void: diff --git a/game/player/CharacterSkeletonAttachPoint.gd b/game/player/CharacterSkeletonAttachPoint.gd index 178058f..96fff5f 100644 --- a/game/player/CharacterSkeletonAttachPoint.gd +++ b/game/player/CharacterSkeletonAttachPoint.gd @@ -1,10 +1,11 @@ -extends Spatial +tool +extends Node2D class_name CharacterSkeketonAttachPoint # Copyright Péter Magyar relintai@gmail.com # MIT License, functionality from this class needs to be protable to the entity spell system -# Copyright (c) 2019 Péter Magyar +# Copyright (c) 2019-2020 Péter Magyar # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -27,7 +28,7 @@ class_name CharacterSkeketonAttachPoint var effects : Dictionary var timed_effects : Dictionary -func add_effect(effect : PackedScene) -> void: +func add(effect : PackedScene) -> void: if effects.has(effect): effects[effect][0] = effects[effect][0] + 1 else: @@ -39,7 +40,7 @@ func add_effect(effect : PackedScene) -> void: var data : Array = [ 1, eff ] effects[effect] = data -func add_effect_timed(effect : PackedScene, time : float) -> void: +func add_timed(effect : PackedScene, time : float) -> void: if timed_effects.has(effect): timed_effects[effect][0] = timed_effects[effect][0] + 1 else: @@ -51,7 +52,7 @@ func add_effect_timed(effect : PackedScene, time : float) -> void: var data : Array = [ 1, eff, time ] timed_effects[effect] = data -func remove_effect(effect : PackedScene) -> void: +func remove(effect : PackedScene) -> void: if effects.has(effect): var data : Array = effects[effect] diff --git a/game/project.godot b/game/project.godot index 42a1f0a..a74d124 100644 --- a/game/project.godot +++ b/game/project.godot @@ -29,7 +29,7 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://scripts/item_visuals/CharacterAtlasEntry2D.gd" }, { -"base": "Spatial", +"base": "Node2D", "class": "CharacterSkeketonAttachPoint", "language": "GDScript", "path": "res://player/CharacterSkeletonAttachPoint.gd" diff --git a/game/scenes/Main.tscn b/game/scenes/Main.tscn index 43dcdb4..88e9cfc 100644 --- a/game/scenes/Main.tscn +++ b/game/scenes/Main.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=7 format=2] +[gd_scene load_steps=8 format=2] [ext_resource path="res://scenes/MainScene.gd" type="Script" id=1] [ext_resource path="res://scenes/World.tscn" type="PackedScene" id=2] @@ -6,6 +6,7 @@ [ext_resource path="res://ui/theme/ui_theme.tres" type="Theme" id=4] [ext_resource path="res://ui/debug/DebugInfo.tscn" type="PackedScene" id=5] [ext_resource path="res://debug/FreeLookCam.tscn" type="PackedScene" id=6] +[ext_resource path="res://tilesets/db32/tplayer.tscn" type="PackedScene" id=7] [node name="Main" type="Node"] script = ExtResource( 1 ) @@ -13,6 +14,8 @@ menu_scene = ExtResource( 3 ) world_scene = ExtResource( 2 ) debug_camera_scene = ExtResource( 6 ) loading_screen_path = NodePath("LoadingScreen/PanelContainer") +bodies = [ ExtResource( 7 ) ] +tile_size = 1 [node name="LoadingScreen" type="CanvasLayer" parent="."] layer = 100 diff --git a/game/scenes/MainScene.gd b/game/scenes/MainScene.gd index 2f38b7d..093ea3b 100644 --- a/game/scenes/MainScene.gd +++ b/game/scenes/MainScene.gd @@ -27,6 +27,10 @@ export(PackedScene) var world_scene : PackedScene export(PackedScene) var debug_camera_scene : PackedScene export(NodePath) var loading_screen_path : NodePath +export(Vector2) var world_scale : Vector2 +export(Array, PackedScene) var bodies : Array +export(int) var tile_size : int + enum StartSceneTypes { NONE, MENU, WORLD } @@ -108,3 +112,14 @@ func show_loading_screen() -> void: func hide_loading_screen() -> void: _loading_screen.hide() +func get_world(): + return world_scene + +func get_world_scale(): + return world_scale + +func get_body(): + return bodies[randi() % bodies.size()] + +func get_tile_size(): + return tile_size diff --git a/game/tilesets/db32/tplayer.tscn b/game/tilesets/db32/tplayer.tscn new file mode 100644 index 0000000..df929c8 --- /dev/null +++ b/game/tilesets/db32/tplayer.tscn @@ -0,0 +1,8 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://tilesets/db32/db32_merged.png" type="Texture" id=1] + +[node name="Node2D" type="Sprite"] +texture = ExtResource( 1 ) +region_enabled = true +region_rect = Rect2( 19, 205.689, 8, 8 )