working player death animation
This commit is contained in:
parent
5bd5a35d88
commit
723d677a81
@ -18,8 +18,9 @@ func resetPlayer():
|
|||||||
player.health = player.max_health
|
player.health = player.max_health
|
||||||
|
|
||||||
func playerDamage():
|
func playerDamage():
|
||||||
player.health -= 20
|
if player.health >0:
|
||||||
print("Player health is : "+str(player.health) )
|
player.health -= 20
|
||||||
|
|
||||||
#is the player dead?
|
#is the player dead?
|
||||||
if player.health <= 0:
|
if player.health <= 0:
|
||||||
#kill him
|
#kill him
|
||||||
|
@ -6,6 +6,8 @@ const JUMP_VELOCITY = -400.0
|
|||||||
const PUSH_FORCE = 700
|
const PUSH_FORCE = 700
|
||||||
|
|
||||||
var faceLeft = false
|
var faceLeft = false
|
||||||
|
var living = true
|
||||||
|
|
||||||
# can i push right or left
|
# can i push right or left
|
||||||
var pushLeftEnabled = false
|
var pushLeftEnabled = false
|
||||||
var pushRightEnabled = false
|
var pushRightEnabled = false
|
||||||
@ -21,87 +23,82 @@ var bullet = preload("res://scenes/bullet.tscn")
|
|||||||
|
|
||||||
func killPlayer():
|
func killPlayer():
|
||||||
print("kill the player")
|
print("kill the player")
|
||||||
#play death animation
|
if living:
|
||||||
playerSprite.play("death")
|
living = false
|
||||||
|
#play death animation
|
||||||
|
playerSprite.play("death")
|
||||||
|
|
||||||
func _physics_process(delta: float) -> void:
|
func _physics_process(delta: float) -> void:
|
||||||
# Add the gravity.
|
if living:
|
||||||
if not is_on_floor():
|
# Add the gravity.
|
||||||
velocity += get_gravity() * delta
|
if not is_on_floor():
|
||||||
|
velocity += get_gravity() * delta
|
||||||
|
|
||||||
# Handle jump.
|
# Handle jump.
|
||||||
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
|
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
|
||||||
velocity.y = JUMP_VELOCITY
|
velocity.y = JUMP_VELOCITY
|
||||||
|
|
||||||
if Input.is_action_just_pressed("Shove") && pushLeftEnabled && faceLeft:
|
|
||||||
print("shove a box on the left")
|
|
||||||
pushTarget.apply_central_impulse(Vector2(-1,0) * PUSH_FORCE * 1.5)
|
|
||||||
pushLeftEnabled = false
|
|
||||||
|
|
||||||
if Input.is_action_just_pressed("Shove") && pushRightEnabled && not faceLeft:
|
if Input.is_action_just_pressed("Shove") && pushLeftEnabled && faceLeft:
|
||||||
print("shove a box on the right")
|
pushTarget.apply_central_impulse(Vector2(-1,0) * PUSH_FORCE * 1.5)
|
||||||
pushTarget.apply_central_impulse(Vector2(1,0) * PUSH_FORCE * 1.5)
|
pushLeftEnabled = false
|
||||||
pushRightEnabled=false
|
|
||||||
|
|
||||||
if Input.is_action_just_pressed("shoot"):
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if faceLeft:
|
|
||||||
print("shoot left")
|
|
||||||
# mybullet.setSpeed(-700)
|
|
||||||
#mybullet.transform = marker_left.global_transform
|
|
||||||
%SceneManager.placeBullet(-700, marker_left.global_transform)
|
|
||||||
else:
|
|
||||||
print("shoot right")
|
|
||||||
#mybullet.transform = marker_right.global_transform
|
|
||||||
%SceneManager.placeBullet(700, marker_right.global_transform)
|
|
||||||
|
|
||||||
# Get the input direction and handle the movement/deceleration.
|
|
||||||
# As good practice, you should replace UI actions with custom gameplay actions.
|
|
||||||
var direction := Input.get_axis("ui_left", "ui_right")
|
|
||||||
if direction <0:
|
|
||||||
faceLeft = true
|
|
||||||
playerSprite.flip_h = true
|
|
||||||
if direction >0:
|
|
||||||
faceLeft = false
|
|
||||||
playerSprite.flip_h = false
|
|
||||||
|
|
||||||
if direction:
|
|
||||||
velocity.x = direction * SPEED
|
|
||||||
else:
|
|
||||||
velocity.x = move_toward(velocity.x, 0, SPEED)
|
|
||||||
if is_on_floor():
|
|
||||||
if direction == 0:
|
|
||||||
playerSprite.play("idle")
|
|
||||||
else:
|
|
||||||
playerSprite.play("run")
|
|
||||||
else:
|
|
||||||
playerSprite.play("jump")
|
|
||||||
|
|
||||||
move_and_slide()
|
if Input.is_action_just_pressed("Shove") && pushRightEnabled && not faceLeft:
|
||||||
for i in get_slide_collision_count():
|
pushTarget.apply_central_impulse(Vector2(1,0) * PUSH_FORCE * 1.5)
|
||||||
var c = get_slide_collision(i)
|
pushRightEnabled=false
|
||||||
if c.get_collider() is RigidBody2D:
|
|
||||||
c.get_collider().apply_central_impulse(-c.get_normal()* 100)
|
|
||||||
|
|
||||||
if left_ray.is_colliding():
|
|
||||||
print("left ray collision")
|
|
||||||
var collider = left_ray.get_collider()
|
|
||||||
if collider is Node:
|
|
||||||
if collider.is_in_group("pushables"):
|
|
||||||
pushLeftEnabled = true
|
|
||||||
pushTarget = collider
|
|
||||||
else:
|
|
||||||
#do something else
|
|
||||||
pushLeftEnabled = false
|
|
||||||
|
|
||||||
if right_ray.is_colliding():
|
if Input.is_action_just_pressed("shoot"):
|
||||||
print("right ray collision")
|
if faceLeft:
|
||||||
var collider = right_ray.get_collider()
|
# mybullet.setSpeed(-700)
|
||||||
if collider is Node:
|
#mybullet.transform = marker_left.global_transform
|
||||||
if collider.is_in_group("pushables"):
|
%SceneManager.placeBullet(-700, marker_left.global_transform)
|
||||||
pushRightEnabled = true
|
else:
|
||||||
pushTarget = collider
|
#mybullet.transform = marker_right.global_transform
|
||||||
else:
|
%SceneManager.placeBullet(700, marker_right.global_transform)
|
||||||
pushRightEnabled = false
|
|
||||||
|
# Get the input direction and handle the movement/deceleration.
|
||||||
|
# As good practice, you should replace UI actions with custom gameplay actions.
|
||||||
|
var direction := Input.get_axis("ui_left", "ui_right")
|
||||||
|
if direction <0:
|
||||||
|
faceLeft = true
|
||||||
|
playerSprite.flip_h = true
|
||||||
|
if direction >0:
|
||||||
|
faceLeft = false
|
||||||
|
playerSprite.flip_h = false
|
||||||
|
|
||||||
|
if direction:
|
||||||
|
velocity.x = direction * SPEED
|
||||||
|
else:
|
||||||
|
velocity.x = move_toward(velocity.x, 0, SPEED)
|
||||||
|
|
||||||
|
if is_on_floor():
|
||||||
|
if direction == 0:
|
||||||
|
playerSprite.play("idle")
|
||||||
|
else:
|
||||||
|
playerSprite.play("run")
|
||||||
|
else:
|
||||||
|
playerSprite.play("jump")
|
||||||
|
|
||||||
|
move_and_slide()
|
||||||
|
for i in get_slide_collision_count():
|
||||||
|
var c = get_slide_collision(i)
|
||||||
|
if c.get_collider() is RigidBody2D:
|
||||||
|
c.get_collider().apply_central_impulse(-c.get_normal()* 100)
|
||||||
|
|
||||||
|
if left_ray.is_colliding():
|
||||||
|
var collider = left_ray.get_collider()
|
||||||
|
if collider is Node:
|
||||||
|
if collider.is_in_group("pushables"):
|
||||||
|
pushLeftEnabled = true
|
||||||
|
pushTarget = collider
|
||||||
|
else:
|
||||||
|
#do something else
|
||||||
|
pushLeftEnabled = false
|
||||||
|
|
||||||
|
if right_ray.is_colliding():
|
||||||
|
var collider = right_ray.get_collider()
|
||||||
|
if collider is Node:
|
||||||
|
if collider.is_in_group("pushables"):
|
||||||
|
pushRightEnabled = true
|
||||||
|
pushTarget = collider
|
||||||
|
else:
|
||||||
|
pushRightEnabled = false
|
||||||
|
@ -66,7 +66,8 @@ func crateFactory():
|
|||||||
func killPlayer():
|
func killPlayer():
|
||||||
print("kill the player now")
|
print("kill the player now")
|
||||||
player.killPlayer()
|
player.killPlayer()
|
||||||
timer.start(3)
|
if timer.is_stopped():
|
||||||
|
timer.start(4)
|
||||||
|
|
||||||
|
|
||||||
func resetWorld():
|
func resetWorld():
|
||||||
|
Loading…
Reference in New Issue
Block a user