Ver código fonte

Player now have a script control (incomplete). World scene modified to test new player controller.

master
Bryan Miller 4 anos atrás
pai
commit
f74ccbfbb3
4 arquivos alterados com 180 adições e 92 exclusões
  1. +93
    -90
      Data/Objects/Player.tscn
  2. +40
    -0
      Data/Scripts/Player.gd
  3. +17
    -1
      Data/World.tscn
  4. +30
    -1
      project.godot

+ 93
- 90
Data/Objects/Player.tscn Ver arquivo

@@ -1,7 +1,8 @@
[gd_scene load_steps=45 format=2]
[gd_scene load_steps=46 format=2]

[ext_resource path="res://Data/Graphics/SS_001.png" type="Texture" id=1]
[ext_resource path="res://icon.png" type="Texture" id=2]
[ext_resource path="res://Data/Scripts/Player.gd" type="Script" id=3]

[sub_resource type="CapsuleShape2D" id=1]
radius = 6.0
@@ -326,7 +327,7 @@ tracks/3/keys = {
"times": PoolRealArray( 0, 0.7, 0.9, 1.6 )
}

[sub_resource type="Animation" id=6]
[sub_resource type="Animation" id=5]
length = 0.6
tracks/0/type = "value"
tracks/0/path = NodePath("Body/Head/Sprite:frame")
@@ -341,7 +342,7 @@ tracks/0/keys = {
"values": [ 0, 1, 4 ]
}

[sub_resource type="Animation" id=21]
[sub_resource type="Animation" id=6]
resource_name = "FootShuffleA"
length = 0.8
tracks/0/type = "bezier"
@@ -405,7 +406,7 @@ tracks/5/keys = {
"times": PoolRealArray( 0, 0.1, 0.6, 0.8 )
}

[sub_resource type="Animation" id=22]
[sub_resource type="Animation" id=7]
resource_name = "HandsShuffleA"
length = 0.9
tracks/0/type = "bezier"
@@ -469,7 +470,7 @@ tracks/5/keys = {
"times": PoolRealArray( 0 )
}

[sub_resource type="Animation" id=23]
[sub_resource type="Animation" id=8]
resource_name = "HandsShuffleB"
length = 2.8
tracks/0/type = "bezier"
@@ -493,7 +494,7 @@ tracks/1/keys = {
"times": PoolRealArray( 0, 0.2, 0.4, 0.6, 0.8, 1, 2, 2.2, 2.4, 2.6, 2.8 )
}

[sub_resource type="Animation" id=26]
[sub_resource type="Animation" id=9]
resource_name = "LookAtCamera"
length = 0.4
tracks/0/type = "value"
@@ -509,7 +510,7 @@ tracks/0/keys = {
"values": [ 0, 9, 10, 11 ]
}

[sub_resource type="Animation" id=27]
[sub_resource type="Animation" id=10]
resource_name = "LookDown"
length = 0.1
tracks/0/type = "value"
@@ -525,7 +526,7 @@ tracks/0/keys = {
"values": [ 12 ]
}

[sub_resource type="Animation" id=28]
[sub_resource type="Animation" id=11]
resource_name = "LookFromCamera"
length = 0.4
tracks/0/type = "value"
@@ -541,8 +542,7 @@ tracks/0/keys = {
"values": [ 11, 10, 9, 0 ]
}

[sub_resource type="Animation" id=7]
resource_name = "Run"
[sub_resource type="Animation" id=12]
length = 1.2
loop = true
step = 0.02
@@ -687,7 +687,7 @@ tracks/13/keys = {
"times": PoolRealArray( 0, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.2 )
}

[sub_resource type="Animation" id=29]
[sub_resource type="Animation" id=13]
resource_name = "Walk"
length = 1.6
loop = true
@@ -788,48 +788,48 @@ tracks/7/keys = {
"values": [ 30.2969, 101.405, 101.405, 49.9436, -33.5517, 0.0, 0.0, 49.7383 ]
}

[sub_resource type="AnimationNodeAnimation" id=46]
[sub_resource type="AnimationNodeAnimation" id=14]
animation = "Walk"

[sub_resource type="AnimationNodeAnimation" id=8]
[sub_resource type="AnimationNodeAnimation" id=15]
animation = "Run"

[sub_resource type="AnimationNodeAnimation" id=9]
[sub_resource type="AnimationNodeAnimation" id=16]
animation = "Breath"

[sub_resource type="AnimationNodeTimeScale" id=10]
[sub_resource type="AnimationNodeTimeScale" id=17]

[sub_resource type="AnimationNodeBlendTree" id=11]
nodes/Animation/node = SubResource( 9 )
[sub_resource type="AnimationNodeBlendTree" id=18]
nodes/Animation/node = SubResource( 16 )
nodes/Animation/position = Vector2( 60, 120 )
nodes/BreathRate/node = SubResource( 10 )
nodes/BreathRate/node = SubResource( 17 )
nodes/BreathRate/position = Vector2( 280, 120 )
nodes/output/position = Vector2( 680, 140 )
node_connections = [ "output", 0, "BreathRate", "BreathRate", 0, "Animation" ]

[sub_resource type="AnimationNodeBlend2" id=12]
[sub_resource type="AnimationNodeBlend2" id=19]

[sub_resource type="AnimationNodeAnimation" id=13]
[sub_resource type="AnimationNodeAnimation" id=20]
animation = "Blink"

[sub_resource type="AnimationNodeAnimation" id=24]
[sub_resource type="AnimationNodeAnimation" id=21]
animation = "Eyebrow"

[sub_resource type="AnimationNodeAnimation" id=30]
[sub_resource type="AnimationNodeAnimation" id=22]
animation = "HandsShuffleA"

[sub_resource type="AnimationNodeAnimation" id=31]
[sub_resource type="AnimationNodeAnimation" id=23]
animation = "HandsShuffleB"

[sub_resource type="AnimationNodeAnimation" id=32]
[sub_resource type="AnimationNodeAnimation" id=24]
animation = "FootShuffleA"

[sub_resource type="AnimationNodeAnimation" id=15]
[sub_resource type="AnimationNodeAnimation" id=25]
animation = "Base"

[sub_resource type="AnimationNodeOneShot" id=33]
[sub_resource type="AnimationNodeOneShot" id=26]

[sub_resource type="AnimationNodeTransition" id=34]
[sub_resource type="AnimationNodeTransition" id=27]
input_count = 3
input_0/name = "Blink"
input_0/auto_advance = false
@@ -838,85 +838,85 @@ input_1/auto_advance = false
input_2/name = "ShakeHead"
input_2/auto_advance = false

[sub_resource type="AnimationNodeOneShot" id=35]
[sub_resource type="AnimationNodeOneShot" id=28]

[sub_resource type="AnimationNodeTransition" id=36]
[sub_resource type="AnimationNodeTransition" id=29]
input_count = 2
input_0/name = "Fidget"
input_0/auto_advance = false
input_1/name = "Contemplate"
input_1/auto_advance = false

[sub_resource type="AnimationNodeOneShot" id=25]
[sub_resource type="AnimationNodeOneShot" id=30]

[sub_resource type="AnimationNodeAnimation" id=38]
[sub_resource type="AnimationNodeAnimation" id=31]
animation = "LookAtCamera"

[sub_resource type="AnimationNodeAnimation" id=47]
[sub_resource type="AnimationNodeAnimation" id=32]
animation = "LookAtCamera"

[sub_resource type="AnimationNodeAnimation" id=39]
[sub_resource type="AnimationNodeAnimation" id=33]
animation = "LookFromCamera"

[sub_resource type="AnimationNodeAnimation" id=40]
[sub_resource type="AnimationNodeAnimation" id=34]
animation = "LookFromCamera"

[sub_resource type="AnimationNodeStateMachineTransition" id=41]
[sub_resource type="AnimationNodeStateMachineTransition" id=35]
switch_mode = 2
auto_advance = true

[sub_resource type="AnimationNodeStateMachineTransition" id=42]
[sub_resource type="AnimationNodeStateMachineTransition" id=36]
switch_mode = 2
auto_advance = true

[sub_resource type="AnimationNodeStateMachineTransition" id=48]
[sub_resource type="AnimationNodeStateMachineTransition" id=37]
switch_mode = 2
auto_advance = true

[sub_resource type="AnimationNodeStateMachine" id=44]
states/LookAtCamera/node = SubResource( 47 )
[sub_resource type="AnimationNodeStateMachine" id=38]
states/LookAtCamera/node = SubResource( 32 )
states/LookAtCamera/position = Vector2( 382, 12 )
"states/LookAtCamera 2/node" = SubResource( 38 )
"states/LookAtCamera 2/node" = SubResource( 31 )
"states/LookAtCamera 2/position" = Vector2( 338, 257 )
states/LookFromCamera/node = SubResource( 39 )
states/LookFromCamera/node = SubResource( 33 )
states/LookFromCamera/position = Vector2( 601, 135 )
states/ShakeHead/node = SubResource( 40 )
states/ShakeHead/node = SubResource( 34 )
states/ShakeHead/position = Vector2( 122, 143 )
transitions = [ "LookFromCamera", "LookAtCamera 2", SubResource( 41 ), "LookAtCamera 2", "ShakeHead", SubResource( 42 ), "LookAtCamera", "LookFromCamera", SubResource( 48 ) ]
transitions = [ "LookFromCamera", "LookAtCamera 2", SubResource( 35 ), "LookAtCamera 2", "ShakeHead", SubResource( 36 ), "LookAtCamera", "LookFromCamera", SubResource( 37 ) ]
start_node = "LookAtCamera"
end_node = "ShakeHead"
graph_offset = Vector2( -163, -106 )

[sub_resource type="AnimationNodeBlendTree" id=18]
[sub_resource type="AnimationNodeBlendTree" id=39]
graph_offset = Vector2( -40.5663, 152.619 )
nodes/Animation/node = SubResource( 15 )
nodes/Animation/node = SubResource( 25 )
nodes/Animation/position = Vector2( 400, 160 )
"nodes/Animation 2/node" = SubResource( 13 )
"nodes/Animation 2/node" = SubResource( 20 )
"nodes/Animation 2/position" = Vector2( 120, 300 )
"nodes/Animation 3/node" = SubResource( 24 )
"nodes/Animation 3/node" = SubResource( 21 )
"nodes/Animation 3/position" = Vector2( 120, 420 )
"nodes/Animation 4/node" = SubResource( 30 )
"nodes/Animation 4/node" = SubResource( 22 )
"nodes/Animation 4/position" = Vector2( 580, 380 )
"nodes/Animation 5/node" = SubResource( 31 )
"nodes/Animation 5/node" = SubResource( 23 )
"nodes/Animation 5/position" = Vector2( 580, 500 )
"nodes/Animation 6/node" = SubResource( 32 )
"nodes/Animation 6/node" = SubResource( 24 )
"nodes/Animation 6/position" = Vector2( 1100, 80 )
nodes/Expression/node = SubResource( 33 )
nodes/Expression/node = SubResource( 26 )
nodes/Expression/position = Vector2( 600, 160 )
nodes/FaceState/node = SubResource( 34 )
nodes/FaceState/node = SubResource( 27 )
nodes/FaceState/position = Vector2( 380, 340 )
nodes/Feet/node = SubResource( 35 )
nodes/Feet/node = SubResource( 28 )
nodes/Feet/position = Vector2( 1400, 80 )
nodes/HandState/node = SubResource( 36 )
nodes/HandState/node = SubResource( 29 )
nodes/HandState/position = Vector2( 860, 400 )
nodes/Hands/node = SubResource( 25 )
nodes/Hands/node = SubResource( 30 )
nodes/Hands/position = Vector2( 1080, 200 )
nodes/ShakeHead/node = SubResource( 44 )
nodes/ShakeHead/node = SubResource( 38 )
nodes/ShakeHead/position = Vector2( 120, 540 )
nodes/output/position = Vector2( 1820, 120 )
node_connections = [ "output", 0, "Feet", "Expression", 0, "Animation", "Expression", 1, "FaceState", "FaceState", 0, "Animation 2", "FaceState", 1, "Animation 3", "FaceState", 2, "ShakeHead", "HandState", 0, "Animation 4", "HandState", 1, "Animation 5", "Hands", 0, "Expression", "Hands", 1, "HandState", "Feet", 0, "Hands", "Feet", 1, "Animation 6" ]
node_connections = [ "output", 0, "Feet", "Expression", 0, "Animation", "Expression", 1, "FaceState", "FaceState", 0, "Animation 2", "FaceState", 1, "Animation 3", "FaceState", 2, "ShakeHead", "Feet", 0, "Hands", "Feet", 1, "Animation 6", "HandState", 0, "Animation 4", "HandState", 1, "Animation 5", "Hands", 0, "Expression", "Hands", 1, "HandState" ]

[sub_resource type="AnimationNodeTransition" id=19]
[sub_resource type="AnimationNodeTransition" id=40]
input_count = 4
input_0/name = "Idle"
input_0/auto_advance = false
@@ -927,37 +927,38 @@ input_2/auto_advance = false
input_3/name = "Jump"
input_3/auto_advance = false

[sub_resource type="AnimationNodeBlendTree" id=20]
graph_offset = Vector2( 162, 134 )
nodes/Animation/node = SubResource( 8 )
nodes/Animation/position = Vector2( 140, 280 )
"nodes/Animation 2/node" = SubResource( 46 )
[sub_resource type="AnimationNodeBlendTree" id=41]
graph_offset = Vector2( 3.22357, 70.3737 )
nodes/Animation/node = SubResource( 15 )
nodes/Animation/position = Vector2( 160, 260 )
"nodes/Animation 2/node" = SubResource( 14 )
"nodes/Animation 2/position" = Vector2( 140, 400 )
nodes/Breath/node = SubResource( 11 )
nodes/Breath/node = SubResource( 18 )
nodes/Breath/position = Vector2( 640, 340 )
nodes/BreathCtrl/node = SubResource( 12 )
nodes/BreathCtrl/node = SubResource( 19 )
nodes/BreathCtrl/position = Vector2( 900, 220 )
nodes/Idle/node = SubResource( 18 )
nodes/Idle/node = SubResource( 39 )
nodes/Idle/position = Vector2( 140, 160 )
nodes/State/node = SubResource( 19 )
nodes/State/node = SubResource( 40 )
nodes/State/position = Vector2( 660, 120 )
nodes/output/position = Vector2( 1460, 160 )
node_connections = [ "output", 0, "BreathCtrl", "State", 0, "Idle", "State", 1, "Animation", "State", 2, "Animation 2", "BreathCtrl", 0, "State", "BreathCtrl", 1, "Breath" ]
nodes/output/position = Vector2( 1180, 240 )
node_connections = [ "output", 0, "BreathCtrl", "BreathCtrl", 0, "State", "BreathCtrl", 1, "Breath", "State", 0, "Idle", "State", 1, "Animation", "State", 2, "Animation 2" ]

[sub_resource type="AnimationNodeStateMachinePlayback" id=45]
[sub_resource type="AnimationNodeStateMachinePlayback" id=42]

[node name="Player" type="KinematicBody2D"]
position = Vector2( 0, -0.174824 )
script = ExtResource( 3 )

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource( 1 )

[node name="Body" type="Position2D" parent="."]
position = Vector2( -0.75, 1.60819 )
position = Vector2( -0.75, 0.75 )

[node name="Sprite" type="Sprite" parent="Body"]
position = Vector2( 0.348317, 0 )
scale = Vector2( 1.00226, 1 )
position = Vector2( 0.424996, 0 )
scale = Vector2( 1.07694, 1 )
texture = ExtResource( 1 )
vframes = 16
hframes = 16
@@ -965,7 +966,7 @@ frame = 16

[node name="Head" type="Position2D" parent="Body"]
position = Vector2( 0.291992, -5.2558 )
rotation = 0.0950778
rotation = -0.014155

[node name="Sprite" type="Sprite" parent="Body/Head"]
position = Vector2( 0.291992, -2.04392 )
@@ -974,7 +975,7 @@ vframes = 16
hframes = 16

[node name="Right Hand" type="Position2D" parent="Body"]
position = Vector2( 6.38461, 1.3514 )
position = Vector2( -2.83482, -0.404972 )

[node name="Sprite" type="Sprite" parent="Body/Right Hand"]
position = Vector2( 0.404972, 0.728954 )
@@ -984,7 +985,7 @@ region_rect = Rect2( 5, 32, 5, 5 )

[node name="Left Hand" type="Position2D" parent="Body"]
show_behind_parent = true
position = Vector2( -5.3208, 1.31172 )
position = Vector2( 6.0746, -0.728951 )

[node name="Sprite" type="Sprite" parent="Body/Left Hand"]
position = Vector2( 0.404972, 0.728954 )
@@ -993,7 +994,7 @@ region_enabled = true
region_rect = Rect2( 5, 36, 5, 5 )

[node name="Right Foot" type="Position2D" parent="Body"]
position = Vector2( -4.16048, 9.55858 )
position = Vector2( -1.29591, 9.47638 )

[node name="Sprite" type="Sprite" parent="Body/Right Foot"]
position = Vector2( 0.485966, 0.890942 )
@@ -1003,7 +1004,7 @@ region_rect = Rect2( 0, 32, 5, 4 )

[node name="Left Foot" type="Position2D" parent="Body"]
show_behind_parent = true
position = Vector2( 5.8789, 7.84067 )
position = Vector2( 2.26785, 9.31439 )

[node name="Sprite" type="Sprite" parent="Body/Left Foot"]
position = Vector2( 0.485966, 0.890942 )
@@ -1012,6 +1013,7 @@ region_enabled = true
region_rect = Rect2( 0, 36, 5, 4 )

[node name="icon" type="Sprite" parent="."]
visible = false
position = Vector2( 0.0053978, 44.3479 )
texture = ExtResource( 2 )

@@ -1019,19 +1021,20 @@ texture = ExtResource( 2 )
anims/Base = SubResource( 2 )
anims/Blink = SubResource( 3 )
anims/Breath = SubResource( 4 )
anims/Eyebrow = SubResource( 6 )
anims/FootShuffleA = SubResource( 21 )
anims/HandsShuffleA = SubResource( 22 )
anims/HandsShuffleB = SubResource( 23 )
anims/LookAtCamera = SubResource( 26 )
anims/LookDown = SubResource( 27 )
anims/LookFromCamera = SubResource( 28 )
anims/Run = SubResource( 7 )
anims/Walk = SubResource( 29 )
anims/Eyebrow = SubResource( 5 )
anims/FootShuffleA = SubResource( 6 )
anims/HandsShuffleA = SubResource( 7 )
anims/HandsShuffleB = SubResource( 8 )
anims/LookAtCamera = SubResource( 9 )
anims/LookDown = SubResource( 10 )
anims/LookFromCamera = SubResource( 11 )
anims/Run = SubResource( 12 )
anims/Walk = SubResource( 13 )

[node name="AnimationTree" type="AnimationTree" parent="."]
tree_root = SubResource( 20 )
tree_root = SubResource( 41 )
anim_player = NodePath("../AnimationPlayer")
active = true
parameters/Breath/BreathRate/scale = 1.0
parameters/BreathCtrl/blend_amount = 0.5
parameters/Idle/Expression/active = false
@@ -1039,5 +1042,5 @@ parameters/Idle/FaceState/current = 2
parameters/Idle/Feet/active = false
parameters/Idle/HandState/current = 0
parameters/Idle/Hands/active = false
parameters/Idle/ShakeHead/playback = SubResource( 45 )
parameters/State/current = 1
parameters/Idle/ShakeHead/playback = SubResource( 42 )
parameters/State/current = 0

+ 40
- 0
Data/Scripts/Player.gd Ver arquivo

@@ -0,0 +1,40 @@
extends KinematicBody2D


onready var _anim_tree = $AnimationTree

export var max_velocity = 150
export var base_lateral_friction_coeff = 1.0

var movement_velocity = Vector2.ZERO
var grav_velocity = Vector2.ZERO

var component_h = 0
var component_v = 0
var on_floor = false

func _ready():
self.set_physics_process(true)


func _physics_process(delta):
var gravity_vector = ProjectSettings.get_setting("physics/2d/default_gravity_vector")
var gravity_magnitude = ProjectSettings.get_setting("physics/2d/default_gravity") * 10 * delta
var up_vector = gravity_vector * -1
if on_floor == false:
grav_velocity += (gravity_vector * gravity_magnitude)
var velocity = movement_velocity + grav_velocity
if velocity.length() > max_velocity:
velocity = velocity.normalized() * max_velocity
move_and_slide(velocity, up_vector)
if is_on_floor() and on_floor == false:
grav_velocity = Vector2.ZERO
on_floor = true



func _input(event):
pass

+ 17
- 1
Data/World.tscn Ver arquivo

@@ -1,7 +1,23 @@
[gd_scene load_steps=2 format=2]
[gd_scene load_steps=4 format=2]

[ext_resource path="res://Data/Objects/Player.tscn" type="PackedScene" id=1]
[ext_resource path="res://icon.png" type="Texture" id=2]

[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 32, 32 )

[node name="World" type="Node2D"]

[node name="Player" parent="." instance=ExtResource( 1 )]
position = Vector2( 229.364, 26.4181 )

[node name="Floor" type="StaticBody2D" parent="."]
position = Vector2( 226.876, 126.076 )

[node name="CollisionShape2D" type="CollisionShape2D" parent="Floor"]
shape = SubResource( 1 )

[node name="Sprite" type="Sprite" parent="Floor"]
modulate = Color( 0, 0, 0, 1 )
position = Vector2( 0, -1.10803 )
texture = ExtResource( 2 )

+ 30
- 1
project.godot Ver arquivo

@@ -24,10 +24,39 @@ config/icon="res://icon.png"

[display]

window/size/width=800
window/size/width=640
window/size/height=480
window/stretch/mode="2d"
window/stretch/aspect="keep"

[input]

move_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)
]
}
move_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)
]
}
move_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)
]
}
move_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)
]
}
action={
"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":69,"unicode":0,"echo":false,"script":null)
]
}

[rendering]

environment/default_environment="res://default_env.tres"

Carregando…
Cancelar
Salvar