fix problems

This commit is contained in:
Fusselkater 2022-07-18 20:36:48 +02:00
parent c159e20937
commit 7ca8f03031
5 changed files with 30 additions and 12 deletions

View File

@ -80,9 +80,11 @@ func _ready():
$Camera2D.limit_bottom = level.camera_limit_bottom
func _physics_process(delta):
# Fall animation if not on floor
if velocity.y > 1 and not is_on_floor():
_set_player_state("fall_start")
# Movement
if Input.is_action_pressed("move_left") and not Input.is_action_pressed("move_right") \
and not player_state in ["striked_start", "striked", "striked_end"]:
move_left(SPEED)
@ -92,10 +94,12 @@ func _physics_process(delta):
elif player_state in ["idle", "run", "jump", "jump_end", "fall_end", "striked_end"]:
move_stop()
# On floor detection
if is_on_floor() and not player_state in ["striked", "striked_start"]:
snap = SNAP
_end_animation()
# Jump
if Input.is_action_just_pressed("jump"):
if $RayBottomLeft.is_colliding() or $RayBottomRight.is_colliding():
jump()
@ -114,12 +118,18 @@ func _set_player_state(new_state):
func move_right(delta):
_set_player_state("run")
get_node("Sprite").set_flip_h(false)
velocity.x = delta
if position.x < level.camera_limit_right:
velocity.x = delta
else:
velocity.x = 0
func move_left(delta):
_set_player_state("run")
get_node("Sprite").set_flip_h(true)
velocity.x = -delta
if position.x > level.camera_limit_left:
velocity.x = -delta
else:
velocity.x = 0
func move_stop():
_set_player_state("idle")
@ -148,8 +158,7 @@ func monster_hit(direction : int, damage: int):
if not invincible_hit:
invincible_hit = true
_set_player_state("striked_start")
health -= damage
GlobalState.health = health
_add_damage(damage)
snap = Vector2.ZERO
velocity.y = -300
velocity.x = direction * 5
@ -162,8 +171,12 @@ func _on_Enemy_Entered(body):
func coin_collected(value):
main.add_score(value)
func _add_damage(value):
health -= value
GlobalState.health = health
if health <= 0:
main.player_died()
func _on_screen_exited():
if velocity.y > 1:
health = 0
main.player_died()
_add_damage(100)

View File

@ -21,7 +21,7 @@ script = ExtResource( 11 )
[node name="Sprite" type="AnimatedSprite" parent="."]
frames = ExtResource( 1 )
animation = "idle"
frame = 1
frame = 2
playing = true
__meta__ = {
"_edit_lock_": true

View File

@ -14,6 +14,8 @@ func _ready():
$TypeSound.pitch_scale = pitch
func say(text : String):
var tree = get_tree()
$Label.visible_characters = 0
$Label.text = text
@ -23,7 +25,9 @@ func say(text : String):
for i in text.length() + 1:
$Label.visible_characters = i
$TypeSound.play()
yield(get_tree().create_timer(speed), "timeout")
if tree != null:
yield(tree.create_timer(speed), "timeout")
emit_signal("animation_ready")

View File

@ -24,4 +24,4 @@ format = 1
tile_data = PoolIntArray( 917505, 0, 1, 917506, 0, 2, 917507, 0, 2, 917508, 0, 2, 917509, 0, 2, 917510, 0, 2, 917511, 0, 2, 917512, 0, 2, 917513, 0, 2, 917514, 0, 2, 917515, 0, 2, 917516, 0, 2, 917517, 0, 2, 917518, 0, 2, 917519, 0, 2, 917520, 0, 2, 917521, 0, 2, 917522, 0, 2, 917523, 0, 2, 917524, 0, 2, 917525, 0, 2, 917526, 0, 2, 917527, 0, 2, 917528, 0, 2, 917529, 0, 2, 917530, 0, 2, 917531, 0, 2, 917532, 0, 2, 917533, 0, 2, 917534, 0, 2, 917535, 0, 2, 917536, 0, 2, 917537, 0, 2, 917538, 0, 2, 917539, 0, 2, 917540, 0, 2, 917541, 0, 2, 917542, 0, 2, 917543, 0, 2, 917544, 0, 0, 983080, 0, 0, 983081, 0, 2, 983082, 0, 2, 983083, 0, 2, 983084, 0, 3 )
[node name="CanvasModulate" type="CanvasModulate" parent="."]
color = Color( 0.5, 0.5, 0.5, 1 )
color = Color( 0.501961, 0.501961, 0.501961, 1 )

View File

@ -45,4 +45,5 @@ func play_bgm(bgm_path):
func player_died():
$HUD.scene_fadeout()
yield(get_tree().create_timer(1.0), "timeout")
GlobalState.health = 100
load_level()