got tilting and flipping finished
This commit is contained in:
parent
6df55c5e89
commit
093ed20a0b
34
debug_object.gd
Normal file
34
debug_object.gd
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#@tool
|
||||||
|
#@icon(icon_path: String)
|
||||||
|
class_name DebugObject
|
||||||
|
extends HBoxContainer
|
||||||
|
## Documentation comments
|
||||||
|
|
||||||
|
#signal
|
||||||
|
#enum
|
||||||
|
#const
|
||||||
|
var target: Node
|
||||||
|
var variable: StringName
|
||||||
|
|
||||||
|
#@onready var
|
||||||
|
@onready var debug_label: Label = $DebugLabel
|
||||||
|
@onready var debug_value: Label = $DebugValue
|
||||||
|
|
||||||
|
## OVERRIDES
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
if target and variable:
|
||||||
|
debug_label.text = variable.to_pascal_case() + ": "
|
||||||
|
|
||||||
|
func _process(_delta: float) -> void:
|
||||||
|
if target:
|
||||||
|
debug_value.text = str(target.get(variable))
|
||||||
|
|
||||||
|
|
||||||
|
## CORE
|
||||||
|
|
||||||
|
## PRIVATE/HELPER
|
||||||
|
|
||||||
|
## RECEIVERS
|
||||||
|
|
||||||
|
## SETTERS/GETTERS
|
||||||
1
debug_object.gd.uid
Normal file
1
debug_object.gd.uid
Normal file
@ -0,0 +1 @@
|
|||||||
|
uid://dnw30w3hpedur
|
||||||
14
debug_object.tscn
Normal file
14
debug_object.tscn
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
[gd_scene format=3 uid="uid://ctpm1isydoxy"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://dnw30w3hpedur" path="res://debug_object.gd" id="1_vr84h"]
|
||||||
|
|
||||||
|
[node name="DebugObject" type="HBoxContainer" unique_id=670838278]
|
||||||
|
script = ExtResource("1_vr84h")
|
||||||
|
|
||||||
|
[node name="DebugLabel" type="Label" parent="." unique_id=204413732]
|
||||||
|
layout_mode = 2
|
||||||
|
text = "SomeVariable: "
|
||||||
|
|
||||||
|
[node name="DebugValue" type="Label" parent="." unique_id=1444599920]
|
||||||
|
layout_mode = 2
|
||||||
|
text = "SomeValue"
|
||||||
37
debug_section.gd
Normal file
37
debug_section.gd
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
@tool
|
||||||
|
#@icon(icon_path: String)
|
||||||
|
#class_name MyNode
|
||||||
|
extends VBoxContainer
|
||||||
|
## Documentation comments
|
||||||
|
|
||||||
|
#signal
|
||||||
|
#enum
|
||||||
|
#const
|
||||||
|
const DEBUG_OBJECT = preload("uid://ctpm1isydoxy")
|
||||||
|
|
||||||
|
@export var target_node: Node
|
||||||
|
@export var variables_to_track: Array[StringName]
|
||||||
|
#var
|
||||||
|
|
||||||
|
@onready var debug_title: Label = $DebugTitle
|
||||||
|
|
||||||
|
## OVERRIDES
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
if target_node:
|
||||||
|
debug_title.text = "Debug info for %s" % target_node.name
|
||||||
|
if variables_to_track:
|
||||||
|
for variable in variables_to_track:
|
||||||
|
var new_debug_object: DebugObject = DEBUG_OBJECT.instantiate()
|
||||||
|
new_debug_object.target = target_node
|
||||||
|
new_debug_object.variable = variable
|
||||||
|
add_child(new_debug_object)
|
||||||
|
|
||||||
|
|
||||||
|
## CORE
|
||||||
|
|
||||||
|
## PRIVATE/HELPER
|
||||||
|
|
||||||
|
## RECEIVERS
|
||||||
|
|
||||||
|
## SETTERS/GETTERS
|
||||||
1
debug_section.gd.uid
Normal file
1
debug_section.gd.uid
Normal file
@ -0,0 +1 @@
|
|||||||
|
uid://4tr1rjqc0ebl
|
||||||
12
debug_section.tscn
Normal file
12
debug_section.tscn
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
[gd_scene format=3 uid="uid://dr4342v00t7ei"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://4tr1rjqc0ebl" path="res://debug_section.gd" id="1_ut6yq"]
|
||||||
|
|
||||||
|
[node name="DebugSection" type="VBoxContainer" unique_id=305062788]
|
||||||
|
offset_right = 40.0
|
||||||
|
offset_bottom = 40.0
|
||||||
|
script = ExtResource("1_ut6yq")
|
||||||
|
|
||||||
|
[node name="DebugTitle" type="Label" parent="." unique_id=1354024129]
|
||||||
|
layout_mode = 2
|
||||||
|
text = "Debug info for SomeNode"
|
||||||
@ -18,26 +18,22 @@ config/icon="res://icon.svg"
|
|||||||
|
|
||||||
up={
|
up={
|
||||||
"deadzone": 0.2,
|
"deadzone": 0.2,
|
||||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null)
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194320,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194320,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
down={
|
down={
|
||||||
"deadzone": 0.2,
|
"deadzone": 0.2,
|
||||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"location":0,"echo":false,"script":null)
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194322,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194322,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
left={
|
left={
|
||||||
"deadzone": 0.2,
|
"deadzone": 0.2,
|
||||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"location":0,"echo":false,"script":null)
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194319,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194319,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
right={
|
right={
|
||||||
"deadzone": 0.2,
|
"deadzone": 0.2,
|
||||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null)
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
bite={
|
bite={
|
||||||
@ -45,6 +41,11 @@ bite={
|
|||||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":66,"key_label":0,"unicode":98,"location":0,"echo":false,"script":null)
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":66,"key_label":0,"unicode":98,"location":0,"echo":false,"script":null)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
swim={
|
||||||
|
"deadzone": 0.2,
|
||||||
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"location":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
[physics]
|
[physics]
|
||||||
|
|
||||||
|
|||||||
59
shark.gd
59
shark.gd
@ -9,11 +9,13 @@ enum FaceDirection {LEFT, RIGHT}
|
|||||||
#const
|
#const
|
||||||
@export_range(0, 360, 1.0, "radians_as_degrees") var rotation_speed: float = 0.0 ## degrees per second
|
@export_range(0, 360, 1.0, "radians_as_degrees") var rotation_speed: float = 0.0 ## degrees per second
|
||||||
|
|
||||||
var current_direction: FaceDirection = FaceDirection.LEFT: set = set_direction
|
|
||||||
var input_vector: Vector2
|
var input_vector: Vector2
|
||||||
|
var facing_right: bool = true: set = set_facing_right
|
||||||
|
var tilt: float = 0.0
|
||||||
|
var tilt_power: float = 0.0
|
||||||
|
|
||||||
@onready var shark_sprite: AnimatedSprite2D = $SharkSprite
|
@onready var shark_sprite: AnimatedSprite2D = $SharkSprite
|
||||||
@onready var shark_collider: CollisionPolygon2D = $SharkCollider
|
@onready var shark_collider: CollisionShape2D = $SharkCollider
|
||||||
@onready var shark_cam: Camera2D = $SharkCam
|
@onready var shark_cam: Camera2D = $SharkCam
|
||||||
|
|
||||||
## OVERRIDES
|
## OVERRIDES
|
||||||
@ -22,16 +24,38 @@ func _ready() -> void:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
func _process(_delta: float) -> void:
|
func _process(_delta: float) -> void:
|
||||||
pass
|
if facing_right:
|
||||||
|
tilt = clamp(rotation, -1.0, 1.0)
|
||||||
|
else:
|
||||||
|
tilt = -clamp(rotation, -1.0, 1.0)
|
||||||
|
|
||||||
func _physics_process(delta: float) -> void:
|
func _physics_process(delta: float) -> void:
|
||||||
input_vector = Input.get_vector("left", "right", "up", "down")
|
# handle left-right movement
|
||||||
if input_vector.x > 0:
|
input_vector.x = Input.get_axis("left", "right")
|
||||||
current_direction = FaceDirection.RIGHT
|
# flip sprite if needed
|
||||||
elif input_vector.x < 0:
|
if abs(input_vector.x) > 0: # moving horizontally
|
||||||
current_direction = FaceDirection.LEFT
|
if input_vector.x > 0: # moving right
|
||||||
|
facing_right = true
|
||||||
rotate(deg_to_rad(input_vector.y * rotation_speed * delta))
|
elif input_vector.x < 0: # moving left
|
||||||
|
facing_right = false
|
||||||
|
# handle up/down tilt
|
||||||
|
input_vector.y = Input.get_axis("up", "down")
|
||||||
|
if abs(input_vector.y) > 0: # attempting to tilt
|
||||||
|
if input_vector.y < 0: # attempting to tilt up (up is negative)
|
||||||
|
if tilt > -1.0: # able to tilt further up
|
||||||
|
#tilt = rotate_toward(tilt, (-PI/2), rotation_speed * delta)
|
||||||
|
if facing_right: # tilting up means negative rotation
|
||||||
|
rotate(-rotation_speed * delta)
|
||||||
|
else: # tilting up means positive rotation
|
||||||
|
rotate(rotation_speed * delta)
|
||||||
|
elif input_vector.y > 0: # attempting to tilt down (up is negative)
|
||||||
|
if tilt < 1.0: # able to tilt further down
|
||||||
|
#tilt = rotate_toward(tilt, (PI/2), rotation_speed * delta)
|
||||||
|
if facing_right: # tilting down means positive rotation
|
||||||
|
rotate(rotation_speed * delta)
|
||||||
|
else: # tilting down means negative rotation
|
||||||
|
rotate(-rotation_speed * delta)
|
||||||
|
|
||||||
|
|
||||||
## CORE
|
## CORE
|
||||||
|
|
||||||
@ -40,9 +64,12 @@ func _physics_process(delta: float) -> void:
|
|||||||
## RECEIVERS
|
## RECEIVERS
|
||||||
|
|
||||||
## SETTERS/GETTERS
|
## SETTERS/GETTERS
|
||||||
func set_direction(new_direction: FaceDirection) -> void:
|
func set_facing_right(is_facing_right: bool) -> void:
|
||||||
if new_direction == FaceDirection.LEFT:
|
if facing_right != is_facing_right:
|
||||||
shark_sprite.flip_h = false
|
rotation = -rotation
|
||||||
else:
|
if is_facing_right == true:
|
||||||
shark_sprite.flip_h = true
|
shark_sprite.flip_h = true
|
||||||
current_direction = new_direction
|
else:
|
||||||
|
shark_sprite.flip_h = false
|
||||||
|
facing_right = is_facing_right
|
||||||
|
|
||||||
|
|||||||
14
shark.tscn
14
shark.tscn
@ -4,6 +4,7 @@
|
|||||||
[ext_resource type="Script" uid="uid://c2phpu1wyi63u" path="res://shark.gd" id="1_uce6o"]
|
[ext_resource type="Script" uid="uid://c2phpu1wyi63u" path="res://shark.gd" id="1_uce6o"]
|
||||||
[ext_resource type="Texture2D" uid="uid://b62iwqkbendj3" path="res://spritesheets/__dark_blue_shark_swim_snapping.png" id="2_26j10"]
|
[ext_resource type="Texture2D" uid="uid://b62iwqkbendj3" path="res://spritesheets/__dark_blue_shark_swim_snapping.png" id="2_26j10"]
|
||||||
[ext_resource type="Texture2D" uid="uid://b8uwcr02vroko" path="res://spritesheets/__dark_blue_shark_swim.png" id="3_mdx7w"]
|
[ext_resource type="Texture2D" uid="uid://b8uwcr02vroko" path="res://spritesheets/__dark_blue_shark_swim.png" id="3_mdx7w"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://dr4342v00t7ei" path="res://debug_section.tscn" id="5_l26on"]
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id="AtlasTexture_odtda"]
|
[sub_resource type="AtlasTexture" id="AtlasTexture_odtda"]
|
||||||
atlas = ExtResource("2_26j10")
|
atlas = ExtResource("2_26j10")
|
||||||
@ -337,7 +338,7 @@ height = 500.0
|
|||||||
|
|
||||||
[node name="Shark" type="CharacterBody2D" unique_id=868425079]
|
[node name="Shark" type="CharacterBody2D" unique_id=868425079]
|
||||||
script = ExtResource("1_uce6o")
|
script = ExtResource("1_uce6o")
|
||||||
rotation_speed = 6.283185307179586
|
rotation_speed = 1.5707963267948966
|
||||||
|
|
||||||
[node name="SharkSprite" type="AnimatedSprite2D" parent="." unique_id=1862357568]
|
[node name="SharkSprite" type="AnimatedSprite2D" parent="." unique_id=1862357568]
|
||||||
sprite_frames = SubResource("SpriteFrames_odtda")
|
sprite_frames = SubResource("SpriteFrames_odtda")
|
||||||
@ -347,6 +348,15 @@ flip_h = true
|
|||||||
|
|
||||||
[node name="SharkCam" type="Camera2D" parent="." unique_id=692363117]
|
[node name="SharkCam" type="Camera2D" parent="." unique_id=692363117]
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1437907772]
|
[node name="SharkCollider" type="CollisionShape2D" parent="." unique_id=1437907772]
|
||||||
rotation = 1.5707964
|
rotation = 1.5707964
|
||||||
shape = SubResource("CapsuleShape2D_uce6o")
|
shape = SubResource("CapsuleShape2D_uce6o")
|
||||||
|
|
||||||
|
[node name="RayCast2D" type="RayCast2D" parent="." unique_id=1636588841]
|
||||||
|
target_position = Vector2(500, 0)
|
||||||
|
|
||||||
|
[node name="SharkDebugLayer" type="CanvasLayer" parent="." unique_id=359221405]
|
||||||
|
|
||||||
|
[node name="DebugSection" parent="SharkDebugLayer" unique_id=305062788 node_paths=PackedStringArray("target_node") instance=ExtResource("5_l26on")]
|
||||||
|
target_node = NodePath("../..")
|
||||||
|
variables_to_track = Array[StringName]([&"input_vector", &"facing_right", &"tilt", &"rotation_speed", &"rotation"])
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user