Refactored a bit. Punching improved, for example
This commit is contained in:
parent
1e24e0a59a
commit
f1d7c8968a
BIN
graphics/animations/Player Jab 48x48.png
Normal file
BIN
graphics/animations/Player Jab 48x48.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
40
graphics/animations/Player Jab 48x48.png.import
Normal file
40
graphics/animations/Player Jab 48x48.png.import
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://b27fd4xvrp2ov"
|
||||||
|
path="res://.godot/imported/Player Jab 48x48.png-a092fdd9a110293df667baca50431cc7.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://graphics/animations/Player Jab 48x48.png"
|
||||||
|
dest_files=["res://.godot/imported/Player Jab 48x48.png-a092fdd9a110293df667baca50431cc7.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/uastc_level=0
|
||||||
|
compress/rdo_quality_loss=0.0
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/channel_remap/red=0
|
||||||
|
process/channel_remap/green=1
|
||||||
|
process/channel_remap/blue=2
|
||||||
|
process/channel_remap/alpha=3
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
||||||
@ -60,7 +60,7 @@ jump={
|
|||||||
"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":0,"pressure":0.0,"pressed":true,"script":null)
|
"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":0,"pressure":0.0,"pressed":true,"script":null)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
shove={
|
punch={
|
||||||
"deadzone": 0.2,
|
"deadzone": 0.2,
|
||||||
"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":2,"pressure":0.0,"pressed":true,"script":null)
|
"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":2,"pressure":0.0,"pressed":true,"script":null)
|
||||||
]
|
]
|
||||||
|
|||||||
@ -511,18 +511,19 @@ intent = "powerup"
|
|||||||
|
|
||||||
[node name="Crates" type="Node" parent="."]
|
[node name="Crates" type="Node" parent="."]
|
||||||
|
|
||||||
[node name="SmallCrate" parent="Crates" groups=["explodable", "pushable"] instance=ExtResource("7_u5sy4")]
|
[node name="SmallCrate" parent="Crates" groups=["explodable", "punchable"] instance=ExtResource("7_u5sy4")]
|
||||||
z_index = 10
|
z_index = 10
|
||||||
|
position = Vector2(-86, 25)
|
||||||
|
|
||||||
[node name="SmallCrate2" parent="Crates" groups=["explodable", "pushable"] instance=ExtResource("7_u5sy4")]
|
[node name="SmallCrate2" parent="Crates" groups=["explodable", "punchable"] instance=ExtResource("7_u5sy4")]
|
||||||
z_index = 10
|
z_index = 10
|
||||||
position = Vector2(229, -140)
|
position = Vector2(229, -140)
|
||||||
|
|
||||||
[node name="SmallCrate3" parent="Crates" groups=["explodable", "pushable"] instance=ExtResource("7_u5sy4")]
|
[node name="SmallCrate3" parent="Crates" groups=["explodable", "punchable"] instance=ExtResource("7_u5sy4")]
|
||||||
z_index = 10
|
z_index = 10
|
||||||
position = Vector2(431, -222)
|
position = Vector2(431, -222)
|
||||||
|
|
||||||
[node name="SmallCrate4" parent="Crates" groups=["explodable", "pushable"] instance=ExtResource("7_u5sy4")]
|
[node name="SmallCrate4" parent="Crates" groups=["explodable", "punchable"] instance=ExtResource("7_u5sy4")]
|
||||||
z_index = 10
|
z_index = 10
|
||||||
position = Vector2(-7, -210)
|
position = Vector2(-7, -210)
|
||||||
|
|
||||||
|
|||||||
@ -511,19 +511,19 @@ intent = "powerup"
|
|||||||
|
|
||||||
[node name="Crates" type="Node" parent="."]
|
[node name="Crates" type="Node" parent="."]
|
||||||
|
|
||||||
[node name="SmallCrate" parent="Crates" groups=["explodable", "pushable"] instance=ExtResource("7_guvtl")]
|
[node name="SmallCrate" parent="Crates" groups=["explodable", "punchable"] instance=ExtResource("7_guvtl")]
|
||||||
z_index = 10
|
z_index = 10
|
||||||
position = Vector2(-146, -162)
|
position = Vector2(-146, -162)
|
||||||
|
|
||||||
[node name="SmallCrate2" parent="Crates" groups=["explodable", "pushable"] instance=ExtResource("7_guvtl")]
|
[node name="SmallCrate2" parent="Crates" groups=["explodable", "punchable"] instance=ExtResource("7_guvtl")]
|
||||||
z_index = 10
|
z_index = 10
|
||||||
position = Vector2(226, 60)
|
position = Vector2(226, 60)
|
||||||
|
|
||||||
[node name="SmallCrate3" parent="Crates" groups=["explodable", "pushable"] instance=ExtResource("7_guvtl")]
|
[node name="SmallCrate3" parent="Crates" groups=["explodable", "punchable"] instance=ExtResource("7_guvtl")]
|
||||||
z_index = 10
|
z_index = 10
|
||||||
position = Vector2(623, 7)
|
position = Vector2(623, 7)
|
||||||
|
|
||||||
[node name="SmallCrate4" parent="Crates" groups=["explodable", "pushable"] instance=ExtResource("7_guvtl")]
|
[node name="SmallCrate4" parent="Crates" groups=["explodable", "punchable"] instance=ExtResource("7_guvtl")]
|
||||||
z_index = 10
|
z_index = 10
|
||||||
position = Vector2(-433, -201)
|
position = Vector2(-433, -201)
|
||||||
|
|
||||||
|
|||||||
@ -511,18 +511,18 @@ intent = "powerup"
|
|||||||
|
|
||||||
[node name="Crates" type="Node" parent="."]
|
[node name="Crates" type="Node" parent="."]
|
||||||
|
|
||||||
[node name="SmallCrate" parent="Crates" groups=["explodable", "pushable"] instance=ExtResource("7_5xqnf")]
|
[node name="SmallCrate" parent="Crates" groups=["explodable", "punchable"] instance=ExtResource("7_5xqnf")]
|
||||||
z_index = 10
|
z_index = 10
|
||||||
|
|
||||||
[node name="SmallCrate2" parent="Crates" groups=["explodable", "pushable"] instance=ExtResource("7_5xqnf")]
|
[node name="SmallCrate2" parent="Crates" groups=["explodable", "punchable"] instance=ExtResource("7_5xqnf")]
|
||||||
z_index = 10
|
z_index = 10
|
||||||
position = Vector2(216, 52)
|
position = Vector2(216, 52)
|
||||||
|
|
||||||
[node name="SmallCrate3" parent="Crates" groups=["explodable", "pushable"] instance=ExtResource("7_5xqnf")]
|
[node name="SmallCrate3" parent="Crates" groups=["explodable", "punchable"] instance=ExtResource("7_5xqnf")]
|
||||||
z_index = 10
|
z_index = 10
|
||||||
position = Vector2(-253, 10)
|
position = Vector2(-253, 10)
|
||||||
|
|
||||||
[node name="SmallCrate4" parent="Crates" groups=["explodable", "pushable"] instance=ExtResource("7_5xqnf")]
|
[node name="SmallCrate4" parent="Crates" groups=["explodable", "punchable"] instance=ExtResource("7_5xqnf")]
|
||||||
z_index = 10
|
z_index = 10
|
||||||
position = Vector2(-82, -5)
|
position = Vector2(-82, -5)
|
||||||
|
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
[gd_scene load_steps=56 format=3 uid="uid://d3y1iqmpknpyo"]
|
[gd_scene load_steps=58 format=3 uid="uid://d3y1iqmpknpyo"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://d3hp5rjoph7hg" path="res://scripts/player.gd" id="1_3vyb7"]
|
[ext_resource type="Script" uid="uid://d3hp5rjoph7hg" path="res://scripts/player.gd" id="1_3vyb7"]
|
||||||
[ext_resource type="Texture2D" uid="uid://dr3rp5hv7rexv" path="res://graphics/animations/player_idle/Player Idle 48x48.png" id="2_g2els"]
|
[ext_resource type="Texture2D" uid="uid://dr3rp5hv7rexv" path="res://graphics/animations/player_idle/Player Idle 48x48.png" id="2_g2els"]
|
||||||
[ext_resource type="Texture2D" uid="uid://uxdt2cgxicmt" path="res://graphics/animations/player_jump/player jump 48x48.png" id="3_dqkch"]
|
[ext_resource type="Texture2D" uid="uid://uxdt2cgxicmt" path="res://graphics/animations/player_jump/player jump 48x48.png" id="3_dqkch"]
|
||||||
[ext_resource type="Texture2D" uid="uid://bnnj3lw3souky" path="res://graphics/animations/player_punch/Player Punch 64x64(1).png" id="4_fjrip"]
|
[ext_resource type="Texture2D" uid="uid://b27fd4xvrp2ov" path="res://graphics/animations/Player Jab 48x48.png" id="4_fjrip"]
|
||||||
[ext_resource type="Texture2D" uid="uid://bgp8oow6hgh5o" path="res://graphics/animations/player_run/player run 48x48.png" id="4_qlg0r"]
|
[ext_resource type="Texture2D" uid="uid://bgp8oow6hgh5o" path="res://graphics/animations/player_run/player run 48x48.png" id="4_qlg0r"]
|
||||||
[ext_resource type="Texture2D" uid="uid://dadvc8tsvmkb6" path="res://graphics/animations/player_shoot/Player Running Shooting 48x48.png" id="5_tuyoq"]
|
[ext_resource type="Texture2D" uid="uid://dadvc8tsvmkb6" path="res://graphics/animations/player_shoot/Player Running Shooting 48x48.png" id="5_tuyoq"]
|
||||||
[ext_resource type="Texture2D" uid="uid://crll0t2wjtsly" path="res://graphics/animations/player_shoot/player shoot 2H 48x48.png" id="6_fjrip"]
|
[ext_resource type="Texture2D" uid="uid://crll0t2wjtsly" path="res://graphics/animations/player_shoot/player shoot 2H 48x48.png" id="6_fjrip"]
|
||||||
@ -62,35 +62,43 @@ region = Rect2(0, 0, 48, 48)
|
|||||||
|
|
||||||
[sub_resource type="AtlasTexture" id="AtlasTexture_2dvfe"]
|
[sub_resource type="AtlasTexture" id="AtlasTexture_2dvfe"]
|
||||||
atlas = ExtResource("4_fjrip")
|
atlas = ExtResource("4_fjrip")
|
||||||
region = Rect2(0, 0, 64, 64)
|
region = Rect2(0, 0, 48, 48)
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id="AtlasTexture_giy8y"]
|
[sub_resource type="AtlasTexture" id="AtlasTexture_giy8y"]
|
||||||
atlas = ExtResource("4_fjrip")
|
atlas = ExtResource("4_fjrip")
|
||||||
region = Rect2(64, 0, 64, 64)
|
region = Rect2(48, 0, 48, 48)
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id="AtlasTexture_fdfoy"]
|
[sub_resource type="AtlasTexture" id="AtlasTexture_fdfoy"]
|
||||||
atlas = ExtResource("4_fjrip")
|
atlas = ExtResource("4_fjrip")
|
||||||
region = Rect2(128, 0, 64, 64)
|
region = Rect2(96, 0, 48, 48)
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id="AtlasTexture_hhpqf"]
|
[sub_resource type="AtlasTexture" id="AtlasTexture_hhpqf"]
|
||||||
atlas = ExtResource("4_fjrip")
|
atlas = ExtResource("4_fjrip")
|
||||||
region = Rect2(192, 0, 64, 64)
|
region = Rect2(144, 0, 48, 48)
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id="AtlasTexture_g5jhy"]
|
[sub_resource type="AtlasTexture" id="AtlasTexture_g5jhy"]
|
||||||
atlas = ExtResource("4_fjrip")
|
atlas = ExtResource("4_fjrip")
|
||||||
region = Rect2(256, 0, 64, 64)
|
region = Rect2(192, 0, 48, 48)
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id="AtlasTexture_holxr"]
|
[sub_resource type="AtlasTexture" id="AtlasTexture_holxr"]
|
||||||
atlas = ExtResource("4_fjrip")
|
atlas = ExtResource("4_fjrip")
|
||||||
region = Rect2(320, 0, 64, 64)
|
region = Rect2(240, 0, 48, 48)
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id="AtlasTexture_mx1m4"]
|
[sub_resource type="AtlasTexture" id="AtlasTexture_mx1m4"]
|
||||||
atlas = ExtResource("4_fjrip")
|
atlas = ExtResource("4_fjrip")
|
||||||
region = Rect2(384, 0, 64, 64)
|
region = Rect2(288, 0, 48, 48)
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id="AtlasTexture_4gjji"]
|
[sub_resource type="AtlasTexture" id="AtlasTexture_4gjji"]
|
||||||
atlas = ExtResource("4_fjrip")
|
atlas = ExtResource("4_fjrip")
|
||||||
region = Rect2(448, 0, 64, 64)
|
region = Rect2(336, 0, 48, 48)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_u2ulf"]
|
||||||
|
atlas = ExtResource("4_fjrip")
|
||||||
|
region = Rect2(384, 0, 48, 48)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_6e8lb"]
|
||||||
|
atlas = ExtResource("4_fjrip")
|
||||||
|
region = Rect2(432, 0, 48, 48)
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id="AtlasTexture_a8ls1"]
|
[sub_resource type="AtlasTexture" id="AtlasTexture_a8ls1"]
|
||||||
atlas = ExtResource("4_qlg0r")
|
atlas = ExtResource("4_qlg0r")
|
||||||
@ -273,6 +281,12 @@ animations = [{
|
|||||||
}, {
|
}, {
|
||||||
"duration": 1.0,
|
"duration": 1.0,
|
||||||
"texture": SubResource("AtlasTexture_4gjji")
|
"texture": SubResource("AtlasTexture_4gjji")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_u2ulf")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_6e8lb")
|
||||||
}],
|
}],
|
||||||
"loop": false,
|
"loop": false,
|
||||||
"name": &"punch",
|
"name": &"punch",
|
||||||
@ -399,7 +413,7 @@ position = Vector2(-16, -7)
|
|||||||
sprite_frames = SubResource("SpriteFrames_3vyb7")
|
sprite_frames = SubResource("SpriteFrames_3vyb7")
|
||||||
animation = &"punch"
|
animation = &"punch"
|
||||||
autoplay = "idle"
|
autoplay = "idle"
|
||||||
frame = 7
|
frame = 9
|
||||||
frame_progress = 1.0
|
frame_progress = 1.0
|
||||||
|
|
||||||
[node name="Camera2D" type="Camera2D" parent="."]
|
[node name="Camera2D" type="Camera2D" parent="."]
|
||||||
|
|||||||
@ -1,24 +1,36 @@
|
|||||||
class_name Player
|
class_name Player
|
||||||
extends CharacterBody2D
|
extends CharacterBody2D
|
||||||
## Character controller.
|
## Character controller.
|
||||||
## TODO: fix bullet cooldown timer
|
##
|
||||||
|
## Controls the player character in this 2D side-scrolling platformer
|
||||||
|
|
||||||
|
enum FaceDirection {
|
||||||
|
LEFT,
|
||||||
|
RIGHT
|
||||||
|
}
|
||||||
|
enum State {
|
||||||
|
IDLE,
|
||||||
|
RUN,
|
||||||
|
JUMP,
|
||||||
|
FALL,
|
||||||
|
SHOOT_STILL,
|
||||||
|
SHOOT_RUN,
|
||||||
|
PUNCH
|
||||||
|
}
|
||||||
|
|
||||||
const SPEED = 200.0
|
|
||||||
const JUMP_VELOCITY = -500.0
|
const JUMP_VELOCITY = -500.0
|
||||||
|
const SPEED = 200.0
|
||||||
|
|
||||||
enum FaceDirection{LEFT, RIGHT}
|
@export var BUMP_POWER := 50 ## Power from bumping into objects
|
||||||
enum State{IDLE, WALK, JUMP, FALLING, SHOOT_STILL, SHOOT_RUN, SHOVE}
|
@export var PUNCH_POWER := 300 ## Power from shoving objects
|
||||||
|
|
||||||
@export var BUMP_POWER := 50
|
|
||||||
@export var SHOVE_POWER := 300
|
|
||||||
@export var ACCELERATION := 10 ## Amount of "slide-y-ness" in side-to-side-movement
|
@export var ACCELERATION := 10 ## Amount of "slide-y-ness" in side-to-side-movement
|
||||||
@export var HARD_GRAVITY := 2
|
@export var HARD_GRAVITY := 2 ## Factor applied during FALL state
|
||||||
|
|
||||||
var current_state: State = State.IDLE
|
var current_state: State = State.IDLE
|
||||||
var facing : FaceDirection = FaceDirection.RIGHT
|
var facing : FaceDirection = FaceDirection.RIGHT
|
||||||
var direction : float = 0.0
|
var direction : float = 0.0
|
||||||
var push_target : RigidBody2D
|
var punch_target : RigidBody2D
|
||||||
var push_enabled : bool = false
|
var punch_enabled : bool = false
|
||||||
var jump_buffer_timer : Timer
|
var jump_buffer_timer : Timer
|
||||||
var shoot_cooldown_timer : Timer
|
var shoot_cooldown_timer : Timer
|
||||||
|
|
||||||
@ -62,18 +74,19 @@ func handle_input() -> void:
|
|||||||
facing = FaceDirection.RIGHT
|
facing = FaceDirection.RIGHT
|
||||||
|
|
||||||
# Handle shoving.
|
# Handle shoving.
|
||||||
if Input.is_action_just_pressed("shove"):
|
if Input.is_action_just_pressed("punch"):
|
||||||
print_debug("Shoving!")
|
print_debug("Trying to punch")
|
||||||
if push_enabled == true:
|
if punch_enabled == true:
|
||||||
var shove_direction : int
|
print_debug("Punching enabled")
|
||||||
|
var punch_direction : int
|
||||||
match facing:
|
match facing:
|
||||||
FaceDirection.RIGHT:
|
FaceDirection.RIGHT:
|
||||||
shove_direction = 1
|
punch_direction = 1
|
||||||
FaceDirection.LEFT:
|
FaceDirection.LEFT:
|
||||||
shove_direction = -1
|
punch_direction = -1
|
||||||
print_debug("Shoving %s" % push_target.name)
|
print_debug("Punching %s" % punch_target.name)
|
||||||
current_state = State.SHOVE
|
current_state = State.PUNCH
|
||||||
push_target.apply_central_impulse(Vector2(shove_direction, 0) * SHOVE_POWER)
|
punch_target.apply_central_impulse(Vector2(punch_direction, 0) * PUNCH_POWER)
|
||||||
|
|
||||||
# Handle shooting
|
# Handle shooting
|
||||||
if Input.is_action_just_pressed("shoot"):
|
if Input.is_action_just_pressed("shoot"):
|
||||||
@ -118,10 +131,10 @@ func handle_movement(delta) -> void:
|
|||||||
# Character is jumping; apply normal gravity
|
# Character is jumping; apply normal gravity
|
||||||
velocity += get_gravity() * delta
|
velocity += get_gravity() * delta
|
||||||
if velocity.y > 0:
|
if velocity.y > 0:
|
||||||
current_state = State.FALLING
|
current_state = State.FALL
|
||||||
else:
|
else:
|
||||||
# Character falling; apply hard gravity
|
# Character falling; apply hard gravity
|
||||||
current_state = State.FALLING
|
current_state = State.FALL
|
||||||
velocity += get_gravity() * HARD_GRAVITY * delta
|
velocity += get_gravity() * HARD_GRAVITY * delta
|
||||||
|
|
||||||
func handle_collisions() -> void:
|
func handle_collisions() -> void:
|
||||||
@ -132,46 +145,51 @@ func handle_collisions() -> void:
|
|||||||
c.get_collider().apply_central_impulse(-c.get_normal() * BUMP_POWER)
|
c.get_collider().apply_central_impulse(-c.get_normal() * BUMP_POWER)
|
||||||
|
|
||||||
if right_cast.is_colliding() and facing == FaceDirection.RIGHT:
|
if right_cast.is_colliding() and facing == FaceDirection.RIGHT:
|
||||||
|
#print_debug("Colliding with something to the right")
|
||||||
var collider = right_cast.get_collider()
|
var collider = right_cast.get_collider()
|
||||||
# check if this is OK
|
#print_debug("Colliding with %s " % collider.name)
|
||||||
if collider is Node and collider is RigidBody2D and collider.is_in_group("pushable"):
|
if collider is Node and collider is RigidBody2D and collider.is_in_group("punchable"):
|
||||||
push_target = collider
|
print_debug("We have a punch target")
|
||||||
push_enabled = true
|
punch_target = collider
|
||||||
|
punch_enabled = true
|
||||||
|
|
||||||
if left_cast.is_colliding() and facing == FaceDirection.LEFT:
|
if left_cast.is_colliding() and facing == FaceDirection.LEFT:
|
||||||
|
#print_debug("Colliding with something to the left")
|
||||||
var collider = left_cast.get_collider()
|
var collider = left_cast.get_collider()
|
||||||
if collider is Node and collider is RigidBody2D and collider.is_in_group("pushable"):
|
#print_debug("Colliding with %s " % collider.name)
|
||||||
push_target = collider
|
if collider is Node and collider is RigidBody2D and collider.is_in_group("punchable"):
|
||||||
push_enabled = true
|
print_debug("We have a punch target")
|
||||||
|
punch_target = collider
|
||||||
|
punch_enabled = true
|
||||||
|
|
||||||
if not right_cast.is_colliding() and not left_cast.is_colliding():
|
if not right_cast.is_colliding() and not left_cast.is_colliding():
|
||||||
push_enabled = false
|
punch_enabled = false
|
||||||
|
|
||||||
func update_state() -> void:
|
func update_state() -> void:
|
||||||
match current_state:
|
match current_state:
|
||||||
# If player is moving left or right
|
# If player is moving left or right
|
||||||
State.IDLE when velocity.x !=0:
|
State.IDLE when velocity.x !=0:
|
||||||
current_state = State.WALK
|
current_state = State.RUN
|
||||||
|
|
||||||
# If player stops walking, or starts falling
|
# If player stops walking, or starts falling
|
||||||
State.WALK:
|
State.RUN:
|
||||||
# If not moving left or right
|
# If not moving left or right
|
||||||
if velocity.x == 0:
|
if velocity.x == 0:
|
||||||
current_state = State.IDLE
|
current_state = State.IDLE
|
||||||
# If falling
|
# If falling
|
||||||
if not is_on_floor() and velocity.y > 0:
|
if not is_on_floor() and velocity.y > 0:
|
||||||
current_state = State.FALLING
|
current_state = State.FALL
|
||||||
|
|
||||||
# When jump peaks, we start to fall
|
# When jump peaks, we start to fall
|
||||||
State.JUMP when velocity.y > 0:
|
State.JUMP when velocity.y > 0:
|
||||||
current_state = State.FALLING
|
current_state = State.FALL
|
||||||
|
|
||||||
# Player lands, either still or moving
|
# Player lands, either still or moving
|
||||||
State.FALLING when is_on_floor():
|
State.FALL when is_on_floor():
|
||||||
if velocity.x == 0:
|
if velocity.x == 0:
|
||||||
current_state = State.IDLE
|
current_state = State.IDLE
|
||||||
else:
|
else:
|
||||||
current_state = State.WALK
|
current_state = State.RUN
|
||||||
|
|
||||||
# Player shooting
|
# Player shooting
|
||||||
State.SHOOT_STILL:
|
State.SHOOT_STILL:
|
||||||
@ -181,10 +199,10 @@ func update_state() -> void:
|
|||||||
# Player shooting while moving
|
# Player shooting while moving
|
||||||
State.SHOOT_RUN:
|
State.SHOOT_RUN:
|
||||||
await player_sprite.animation_finished
|
await player_sprite.animation_finished
|
||||||
current_state = State.WALK
|
current_state = State.RUN
|
||||||
|
|
||||||
# Player shoving
|
# Player shoving
|
||||||
State.SHOVE:
|
State.PUNCH:
|
||||||
await player_sprite.animation_finished
|
await player_sprite.animation_finished
|
||||||
current_state = State.IDLE
|
current_state = State.IDLE
|
||||||
|
|
||||||
@ -197,18 +215,18 @@ func update_animation() -> void:
|
|||||||
match current_state:
|
match current_state:
|
||||||
State.IDLE:
|
State.IDLE:
|
||||||
player_sprite.play("idle")
|
player_sprite.play("idle")
|
||||||
State.WALK:
|
State.RUN:
|
||||||
player_sprite.play("run")
|
player_sprite.play("run")
|
||||||
State.JUMP:
|
State.JUMP:
|
||||||
player_sprite.play("jump")
|
player_sprite.play("jump")
|
||||||
State.FALLING:
|
State.FALL:
|
||||||
player_sprite.play("fall")
|
player_sprite.play("fall")
|
||||||
State.SHOOT_STILL:
|
State.SHOOT_STILL:
|
||||||
player_sprite.play("shoot_still")
|
player_sprite.play("shoot_still")
|
||||||
State.SHOOT_RUN:
|
State.SHOOT_RUN:
|
||||||
player_sprite.play("shoot_run")
|
player_sprite.play("shoot_run")
|
||||||
State.SHOVE:
|
State.PUNCH:
|
||||||
player_sprite.play("punch")
|
player_sprite.play("punch")
|
||||||
|
|
||||||
func update_debug():
|
func update_debug():
|
||||||
%StateLabel.text = "Current state: %s" % current_state
|
%StateLabel.text = "Current state: %s" % State.keys()[current_state]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user