mirror of
https://github.com/Dariasteam/Cows-Revenge.git
synced 2026-01-23 02:15:17 +00:00
Refactorización movimiento
This commit is contained in:
parent
ef0376a717
commit
997b084b31
3 changed files with 58 additions and 59 deletions
|
|
@ -157,7 +157,7 @@ trigger = true
|
|||
transform/pos = Vector2( 3.8147e-06, 0 )
|
||||
frames = SubResource( 8 )
|
||||
animation = "walking"
|
||||
frame = 6
|
||||
frame = 8
|
||||
playing = true
|
||||
|
||||
[node name="hit_ray_particle" type="Particles2D" parent="."]
|
||||
|
|
|
|||
112
player.gd
112
player.gd
|
|
@ -25,9 +25,13 @@ onready var foots = get_node("foots")
|
|||
var can_jump = true
|
||||
var jumping = false
|
||||
var velocity = Vector2()
|
||||
var final_velocity = Vector2()
|
||||
var jump_time = 0
|
||||
var jump_key_pressed = false
|
||||
|
||||
var right = false
|
||||
var left = false
|
||||
|
||||
var receive_damage = true
|
||||
|
||||
export(int) var max_milk = 500
|
||||
|
|
@ -105,51 +109,26 @@ func _fixed_process(delta):
|
|||
if (jumping):
|
||||
jump_time -= altitude
|
||||
|
||||
|
||||
velocity.y += delta * GRAVITY
|
||||
|
||||
# Salto
|
||||
if (Input.is_action_pressed("ui_jump")):
|
||||
if (jumping and can_jump_more() and jump_key_pressed):
|
||||
velocity.y = - JUMP_SPEED + (MAX_JUMP_TIME - jump_time) * 20
|
||||
sprite.stop()
|
||||
jumping = true
|
||||
elif(can_jump and !jump_key_pressed):
|
||||
velocity.y = - JUMP_SPEED
|
||||
jump_time = MAX_JUMP_TIME
|
||||
can_jump = false
|
||||
jumping = true
|
||||
jump_key_pressed = true
|
||||
else:
|
||||
jump_key_pressed = false
|
||||
if (jumping and can_jump_more() and jump_key_pressed):
|
||||
velocity.y = - JUMP_SPEED + (MAX_JUMP_TIME - jump_time) * 20
|
||||
sprite.stop()
|
||||
jumping = true
|
||||
|
||||
|
||||
# Movimiento horizontal
|
||||
if (Input.is_action_pressed("ui_left")):
|
||||
sprite.set_animation("walk")
|
||||
emit_signal("looking_left");
|
||||
velocity.x = - horizontal_movement_amount()
|
||||
sprite.set_flip_h(true)
|
||||
elif (Input.is_action_pressed("ui_right")):
|
||||
sprite.set_animation("walk")
|
||||
velocity.x = horizontal_movement_amount()
|
||||
emit_signal("looking_right");
|
||||
sprite.set_flip_h(false)
|
||||
else:
|
||||
sprite.set_animation("Idle")
|
||||
if (velocity.x > SLIDE_LEVEL):
|
||||
# Movimiento horizontal
|
||||
if (!right and !left):
|
||||
sprite.set_animatiºon("Idle")
|
||||
if (velocity.x > SLIDE_LEVEL):
|
||||
velocity.x -= SLIDE_LEVEL
|
||||
elif (velocity.x < -SLIDE_LEVEL):
|
||||
velocity.x += SLIDE_LEVEL
|
||||
else:
|
||||
else:
|
||||
velocity.x = 0
|
||||
walk_speed = 0
|
||||
# Agacharse
|
||||
if (Input.is_action_pressed("ui_down")):
|
||||
get_node("Collision_Normal").set_trigger(true)
|
||||
get_node("Collision_Agachado").set_trigger(false)
|
||||
else:
|
||||
get_node("Collision_Normal").set_trigger(false)
|
||||
get_node("Collision_Agachado").set_trigger(true)
|
||||
|
||||
|
||||
var motion = velocity * delta
|
||||
|
||||
if (jumping and test_move(motion)):
|
||||
|
|
@ -160,29 +139,30 @@ func _fixed_process(delta):
|
|||
|
||||
motion = move(motion)
|
||||
|
||||
# Control de colisiones
|
||||
# Control de colisiones
|
||||
|
||||
if (is_colliding()):
|
||||
sprite.play("")
|
||||
var normal = get_collision_normal()
|
||||
jumping = false
|
||||
if (normal.y > 0.5 and jumping):
|
||||
# Está chocandose contra el techo
|
||||
jumping = false
|
||||
# Está chocandose contra el techo
|
||||
can_jump = false
|
||||
jump_time = 0
|
||||
else:
|
||||
# Está en el suelo
|
||||
else:
|
||||
# Está en el suelo
|
||||
|
||||
if (normal.y < -0.25):
|
||||
can_jump = true
|
||||
jumping = false
|
||||
motion.y = 0
|
||||
motion = normal.slide(motion)
|
||||
velocity = normal.slide(velocity)
|
||||
final_velocity = normal.slide(final_velocity)
|
||||
velocity.y = 0
|
||||
else:
|
||||
else:
|
||||
motion = normal.slide(motion)
|
||||
velocity = normal.slide(velocity)
|
||||
final_velocity = normal.slide(final_velocity)
|
||||
move(motion)
|
||||
|
||||
|
||||
else:
|
||||
can_jump = false
|
||||
|
||||
|
|
@ -197,28 +177,46 @@ func _ready():
|
|||
|
||||
|
||||
func _input(ev):
|
||||
|
||||
|
||||
if (ev.is_action_pressed("ui_left")):
|
||||
print("ui_left on")
|
||||
left = true
|
||||
sprite.set_animation("walk")
|
||||
emit_signal("looking_left")
|
||||
velocity.x = -450
|
||||
sprite.set_flip_h(true)
|
||||
elif (ev.is_action_released("ui_left")):
|
||||
print("ui_left off")
|
||||
left = false
|
||||
|
||||
if (ev.is_action_pressed("ui_right")):
|
||||
print("ui_right on")
|
||||
right = true
|
||||
sprite.set_animation("walk")
|
||||
velocity.x = 450
|
||||
emit_signal("looking_right")
|
||||
sprite.set_flip_h(false)
|
||||
elif (ev.is_action_released("ui_right")):
|
||||
print("ui_right off")
|
||||
right = false
|
||||
|
||||
|
||||
|
||||
|
||||
if (ev.is_action_pressed("ui_up")):
|
||||
print("ui_up on")
|
||||
elif (ev.is_action_released("ui_up")):
|
||||
print("ui_up off")
|
||||
|
||||
|
||||
# Agacharse
|
||||
if (ev.is_action_pressed("ui_down")):
|
||||
print("ui_down on")
|
||||
get_node("Collision_Normal").set_trigger(true)
|
||||
get_node("Collision_Agachado").set_trigger(false)
|
||||
elif (ev.is_action_released("ui_down")):
|
||||
print("ui_down off")
|
||||
get_node("Collision_Normal").set_trigger(false)
|
||||
get_node("Collision_Agachado").set_trigger(true)
|
||||
|
||||
if (ev.is_action_pressed("ui_jump")):
|
||||
print("ui_jump on")
|
||||
jump_key_pressed = true
|
||||
velocity.y = - JUMP_SPEED
|
||||
jumping = true
|
||||
jump_time = MAX_JUMP_TIME
|
||||
can_jump = false
|
||||
elif (ev.is_action_released("ui_jump")):
|
||||
print("ui_jump off")
|
||||
jump_key_pressed = false
|
||||
|
|
@ -69,7 +69,7 @@ altitude = 0.5
|
|||
MAX_WALK_SPEED = 450
|
||||
max_milk = 500
|
||||
milk_level = 0
|
||||
invulneravility_time = 2
|
||||
invulneravility_time = 1
|
||||
|
||||
[node name="shooter" type="Node2D" parent="."]
|
||||
|
||||
|
|
@ -104,6 +104,7 @@ _update_shape_index = 1
|
|||
|
||||
frames = SubResource( 3 )
|
||||
animation = "walk"
|
||||
frame = 3
|
||||
playing = true
|
||||
|
||||
[node name="Camera2D" type="Camera2D" parent="sprite"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue