z-hack/src/Player.gd

108 lines
2.7 KiB
GDScript

extends KinematicBody2D
export(PackedScene) var weapons
signal restart
var speed = 200
var cheat = 0
var victory = 0
func _on_WeaponTimer_timeout():
$WeaponTimer.stop()
func player_die():
if victory == 0:
visible = false
$Camera2D/CanvasLayer/Lose.visible = true
$Camera2D/CanvasLayer/Restart.visible = true
pause_mode
func relic_left(number):
$Camera2D/CanvasLayer/Score.text = "Relics left " + str(number)
if number == 0:
$Camera2D/CanvasLayer/Victory.visible = true
$Camera2D/CanvasLayer/Restart.visible = true
victory = 1
$Light2D2.scale += Vector2(1.02,1.02)
func _input(event):
if cheat == 0 and event.as_text() == "C":
cheat = 1
if cheat == 1 and event.as_text() == "H":
cheat = 2
if cheat == 2 and event.as_text() == "E":
cheat = 3
if cheat == 3 and event.as_text() == "A":
cheat = 4
if cheat == 4 and event.as_text() == "T":
cheat = 5
$Camera2D/CanvasLayer/Cheater.visible = true
$Camera2D/CanvasLayer/CheatTimer.start()
# allow to restart using keyboard or controller
if event.is_action_pressed("ui_accept"):
if $Camera2D/CanvasLayer/Restart.visible:
_on_Button_pressed()
if $WeaponTimer.is_stopped():
if event.is_action_pressed("attack_up"):
var sword = weapons.instance()
$WeaponTimer.start()
add_child(sword)
sword.rotate(TAU)
if event.is_action_pressed("attack_right"):
var sword = weapons.instance()
$WeaponTimer.start()
add_child(sword)
sword.rotate(PI/2)
if event.is_action_pressed("attack_left"):
var sword = weapons.instance()
$WeaponTimer.start()
add_child(sword)
sword.rotate(-PI/2)
if event.is_action_pressed("attack_down"):
var sword = weapons.instance()
$WeaponTimer.start()
add_child(sword)
sword.rotate(PI)
if event.is_action_pressed("attack"):
$WeaponTimer.start()
var mouse_loc = get_global_mouse_position()
var sword = weapons.instance()
add_child(sword)
sword.look_at(mouse_loc)
sword.rotate(PI/2)
func _process(delta):
var velocity = Vector2.ZERO
var direction = Vector2.ZERO
if Input.is_action_pressed("ui_right"):
velocity.x += 1
direction = Vector2.RIGHT
if Input.is_action_pressed("ui_left"):
velocity.x -= 1
direction = Vector2.LEFT
if Input.is_action_pressed("ui_down"):
velocity.y += 1
direction = Vector2.DOWN
if Input.is_action_pressed("ui_up"):
velocity.y -= 1
direction = Vector2.UP
if cheat == 5 and Input.is_action_pressed("ui_select"):
var sword = weapons.instance()
add_child(sword)
if velocity.length() > 0:
velocity = velocity.normalized() * speed * delta
move_and_collide(velocity)
func light_increase():
$Light2D2.scale += Vector2(0.02,0.02)
func _on_Button_pressed():
emit_signal("restart")
func _on_CheatTimer_timeout():
$Camera2D/CanvasLayer/Cheater.visible = false