110 lines
1.9 KiB
GDScript
110 lines
1.9 KiB
GDScript
extends KinematicBody2D
|
|
|
|
var speed = Vector2.ZERO
|
|
|
|
export var jump_speed = 1100.0
|
|
export var gravity = 45.0
|
|
export var max_lives = 1
|
|
|
|
enum {
|
|
RUN,
|
|
JUMP,
|
|
IDLE
|
|
}
|
|
|
|
enum {
|
|
SCORE,
|
|
TIME
|
|
}
|
|
|
|
var jump_key = "dialogic_next"
|
|
|
|
var player_enabled = false
|
|
|
|
var state = RUN
|
|
var au_sol = true
|
|
|
|
var current_lives = max_lives
|
|
|
|
onready var animation = $AnimatedSprite
|
|
onready var bonus_texture = $BonusControl/TextureRect
|
|
onready var bonus_tween = $BonusControl/Tween
|
|
onready var bonus_timer = $BonusControl/Timer
|
|
|
|
signal hit()
|
|
signal die()
|
|
signal score()
|
|
|
|
func _ready():
|
|
stop()
|
|
|
|
|
|
func _physics_process(delta):
|
|
if player_enabled:
|
|
match state:
|
|
RUN:
|
|
animation.play("man_run")
|
|
JUMP:
|
|
speed = Vector2.ZERO
|
|
speed.y -= jump_speed
|
|
animation.play("man_jump")
|
|
state = IDLE
|
|
IDLE:
|
|
pass
|
|
speed.y += gravity
|
|
move_and_collide(speed*delta)
|
|
|
|
|
|
func _input(event):
|
|
if player_enabled and state == RUN and event.is_action_pressed(jump_key):
|
|
state = JUMP
|
|
|
|
|
|
func _on_Area2D_body_entered(body):
|
|
if body is StaticBody2D:
|
|
state = RUN
|
|
|
|
|
|
func _on_Area2D_body_exited(body):
|
|
if body is StaticBody2D:
|
|
state = JUMP
|
|
|
|
|
|
func start():
|
|
show()
|
|
player_enabled = true
|
|
|
|
|
|
func stop():
|
|
hide()
|
|
bonus_texture.modulate = Color(1, 1, 1, 0)
|
|
player_enabled = false
|
|
|
|
|
|
func hit():
|
|
current_lives -= 1
|
|
if current_lives > 0:
|
|
emit_signal("hit")
|
|
else:
|
|
current_lives = 0
|
|
emit_signal("die")
|
|
|
|
|
|
func play_bonus_anim():
|
|
bonus_texture.show()
|
|
bonus_tween.stop_all()
|
|
bonus_timer.stop()
|
|
bonus_tween.interpolate_property(bonus_texture, "modulate", null, Color(1, 1, 1, 1), 0.3, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT)
|
|
bonus_tween.start()
|
|
bonus_timer.start()
|
|
|
|
|
|
func bonus():
|
|
play_bonus_anim()
|
|
emit_signal("score")
|
|
|
|
|
|
func _on_Timer_timeout() -> void:
|
|
bonus_tween.stop_all()
|
|
bonus_tween.interpolate_property(bonus_texture, "modulate", null, Color(1, 1, 1, 0), 0.3, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT)
|
|
bonus_tween.start()
|