fix problems
This commit is contained in:
parent
c159e20937
commit
7ca8f03031
5 changed files with 30 additions and 12 deletions
|
@ -80,9 +80,11 @@ func _ready():
|
||||||
$Camera2D.limit_bottom = level.camera_limit_bottom
|
$Camera2D.limit_bottom = level.camera_limit_bottom
|
||||||
|
|
||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
|
# Fall animation if not on floor
|
||||||
if velocity.y > 1 and not is_on_floor():
|
if velocity.y > 1 and not is_on_floor():
|
||||||
_set_player_state("fall_start")
|
_set_player_state("fall_start")
|
||||||
|
|
||||||
|
# Movement
|
||||||
if Input.is_action_pressed("move_left") and not Input.is_action_pressed("move_right") \
|
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"]:
|
and not player_state in ["striked_start", "striked", "striked_end"]:
|
||||||
move_left(SPEED)
|
move_left(SPEED)
|
||||||
|
@ -92,10 +94,12 @@ func _physics_process(delta):
|
||||||
elif player_state in ["idle", "run", "jump", "jump_end", "fall_end", "striked_end"]:
|
elif player_state in ["idle", "run", "jump", "jump_end", "fall_end", "striked_end"]:
|
||||||
move_stop()
|
move_stop()
|
||||||
|
|
||||||
|
# On floor detection
|
||||||
if is_on_floor() and not player_state in ["striked", "striked_start"]:
|
if is_on_floor() and not player_state in ["striked", "striked_start"]:
|
||||||
snap = SNAP
|
snap = SNAP
|
||||||
_end_animation()
|
_end_animation()
|
||||||
|
|
||||||
|
# Jump
|
||||||
if Input.is_action_just_pressed("jump"):
|
if Input.is_action_just_pressed("jump"):
|
||||||
if $RayBottomLeft.is_colliding() or $RayBottomRight.is_colliding():
|
if $RayBottomLeft.is_colliding() or $RayBottomRight.is_colliding():
|
||||||
jump()
|
jump()
|
||||||
|
@ -114,12 +118,18 @@ func _set_player_state(new_state):
|
||||||
func move_right(delta):
|
func move_right(delta):
|
||||||
_set_player_state("run")
|
_set_player_state("run")
|
||||||
get_node("Sprite").set_flip_h(false)
|
get_node("Sprite").set_flip_h(false)
|
||||||
|
if position.x < level.camera_limit_right:
|
||||||
velocity.x = delta
|
velocity.x = delta
|
||||||
|
else:
|
||||||
|
velocity.x = 0
|
||||||
|
|
||||||
func move_left(delta):
|
func move_left(delta):
|
||||||
_set_player_state("run")
|
_set_player_state("run")
|
||||||
get_node("Sprite").set_flip_h(true)
|
get_node("Sprite").set_flip_h(true)
|
||||||
|
if position.x > level.camera_limit_left:
|
||||||
velocity.x = -delta
|
velocity.x = -delta
|
||||||
|
else:
|
||||||
|
velocity.x = 0
|
||||||
|
|
||||||
func move_stop():
|
func move_stop():
|
||||||
_set_player_state("idle")
|
_set_player_state("idle")
|
||||||
|
@ -148,8 +158,7 @@ func monster_hit(direction : int, damage: int):
|
||||||
if not invincible_hit:
|
if not invincible_hit:
|
||||||
invincible_hit = true
|
invincible_hit = true
|
||||||
_set_player_state("striked_start")
|
_set_player_state("striked_start")
|
||||||
health -= damage
|
_add_damage(damage)
|
||||||
GlobalState.health = health
|
|
||||||
snap = Vector2.ZERO
|
snap = Vector2.ZERO
|
||||||
velocity.y = -300
|
velocity.y = -300
|
||||||
velocity.x = direction * 5
|
velocity.x = direction * 5
|
||||||
|
@ -163,7 +172,11 @@ func _on_Enemy_Entered(body):
|
||||||
func coin_collected(value):
|
func coin_collected(value):
|
||||||
main.add_score(value)
|
main.add_score(value)
|
||||||
|
|
||||||
func _on_screen_exited():
|
func _add_damage(value):
|
||||||
if velocity.y > 1:
|
health -= value
|
||||||
health = 0
|
GlobalState.health = health
|
||||||
|
if health <= 0:
|
||||||
main.player_died()
|
main.player_died()
|
||||||
|
|
||||||
|
func _on_screen_exited():
|
||||||
|
_add_damage(100)
|
||||||
|
|
|
@ -21,7 +21,7 @@ script = ExtResource( 11 )
|
||||||
[node name="Sprite" type="AnimatedSprite" parent="."]
|
[node name="Sprite" type="AnimatedSprite" parent="."]
|
||||||
frames = ExtResource( 1 )
|
frames = ExtResource( 1 )
|
||||||
animation = "idle"
|
animation = "idle"
|
||||||
frame = 1
|
frame = 2
|
||||||
playing = true
|
playing = true
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
"_edit_lock_": true
|
"_edit_lock_": true
|
||||||
|
|
|
@ -14,6 +14,8 @@ func _ready():
|
||||||
$TypeSound.pitch_scale = pitch
|
$TypeSound.pitch_scale = pitch
|
||||||
|
|
||||||
func say(text : String):
|
func say(text : String):
|
||||||
|
var tree = get_tree()
|
||||||
|
|
||||||
$Label.visible_characters = 0
|
$Label.visible_characters = 0
|
||||||
$Label.text = text
|
$Label.text = text
|
||||||
|
|
||||||
|
@ -23,7 +25,9 @@ func say(text : String):
|
||||||
for i in text.length() + 1:
|
for i in text.length() + 1:
|
||||||
$Label.visible_characters = i
|
$Label.visible_characters = i
|
||||||
$TypeSound.play()
|
$TypeSound.play()
|
||||||
yield(get_tree().create_timer(speed), "timeout")
|
|
||||||
|
if tree != null:
|
||||||
|
yield(tree.create_timer(speed), "timeout")
|
||||||
|
|
||||||
emit_signal("animation_ready")
|
emit_signal("animation_ready")
|
||||||
|
|
||||||
|
|
|
@ -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 )
|
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="."]
|
[node name="CanvasModulate" type="CanvasModulate" parent="."]
|
||||||
color = Color( 0.5, 0.5, 0.5, 1 )
|
color = Color( 0.501961, 0.501961, 0.501961, 1 )
|
||||||
|
|
|
@ -45,4 +45,5 @@ func play_bgm(bgm_path):
|
||||||
func player_died():
|
func player_died():
|
||||||
$HUD.scene_fadeout()
|
$HUD.scene_fadeout()
|
||||||
yield(get_tree().create_timer(1.0), "timeout")
|
yield(get_tree().create_timer(1.0), "timeout")
|
||||||
|
GlobalState.health = 100
|
||||||
load_level()
|
load_level()
|
||||||
|
|
Loading…
Reference in a new issue