2024-04-16 20:29:45 -04:00
|
|
|
extends RigidBody2D
|
|
|
|
|
|
|
|
var speed = 1000 # move speed in pixels/sec
|
|
|
|
var rotation_speed = 3 # turning speed in radians/sec
|
|
|
|
var quare = preload("res://quare.tscn")
|
|
|
|
var exagon = preload("res://exagon.tscn")
|
|
|
|
@onready var notifier = $"../Notification"
|
|
|
|
var num_quares = 0
|
|
|
|
var max_quares = 3
|
2024-04-26 16:32:56 -04:00
|
|
|
var exagons = 0
|
2024-04-17 15:00:20 -04:00
|
|
|
var absolute_movement = false
|
2024-04-17 18:39:03 -04:00
|
|
|
var config = ConfigFile.new()
|
2024-04-16 20:29:45 -04:00
|
|
|
|
2024-04-18 19:45:52 -04:00
|
|
|
const idle_anim = preload("res://player_idle.gif")
|
|
|
|
const moving_anim = preload("res://player_moving.gif")
|
|
|
|
var moving = false
|
|
|
|
|
2024-04-16 20:29:45 -04:00
|
|
|
func _ready():
|
|
|
|
update_display()
|
2024-04-18 19:45:52 -04:00
|
|
|
update_animation()
|
2024-04-17 18:39:03 -04:00
|
|
|
if config.load("user://settings.cfg") == OK:
|
|
|
|
absolute_movement = not config.get_value("config", "relative_controls")
|
2024-04-16 20:29:45 -04:00
|
|
|
|
2024-04-18 19:45:52 -04:00
|
|
|
func update_animation():
|
|
|
|
if moving:
|
|
|
|
$AnimatedSprite2D.sprite_frames = moving_anim
|
|
|
|
else:
|
|
|
|
$AnimatedSprite2D.sprite_frames = idle_anim
|
|
|
|
|
|
|
|
$AnimatedSprite2D.play("gif")
|
|
|
|
|
2024-04-16 20:29:45 -04:00
|
|
|
func _physics_process(delta):
|
|
|
|
look_at(get_global_mouse_position())
|
|
|
|
var move_input = Input.get_axis("down", "up")
|
2024-04-17 19:14:46 -04:00
|
|
|
var side_input = Input.get_axis("right", "left")
|
2024-04-18 19:45:52 -04:00
|
|
|
if move_input > 0 and not moving:
|
|
|
|
moving = true
|
|
|
|
update_animation()
|
|
|
|
elif move_input <= 0 and moving:
|
|
|
|
moving = false
|
|
|
|
update_animation()
|
|
|
|
|
2024-04-17 15:00:20 -04:00
|
|
|
if absolute_movement:
|
|
|
|
apply_central_force(Vector2(side_input * speed, move_input * speed) * -1)
|
|
|
|
else:
|
2024-04-17 19:14:46 -04:00
|
|
|
apply_central_force(transform.y * side_input * speed / -2 + transform.x * move_input * speed)
|
2024-04-16 20:29:45 -04:00
|
|
|
|
|
|
|
func _input(event):
|
|
|
|
if event.is_action_pressed("jump"):
|
|
|
|
global_position = get_global_mouse_position()
|
|
|
|
if event.is_action_pressed("quare"):
|
|
|
|
if num_quares >= max_quares:
|
|
|
|
notifier.notify("All Quares in Use!")
|
|
|
|
return
|
|
|
|
|
2024-04-19 17:59:19 -04:00
|
|
|
if not $"../CollisionCheck".is_clear(get_global_mouse_position(), 60):
|
2024-04-16 20:29:45 -04:00
|
|
|
$"../CollisionCheck".flash()
|
|
|
|
notifier.notify("Too Close!")
|
|
|
|
return
|
|
|
|
num_quares += 1
|
|
|
|
var new_quare = quare.instantiate()
|
|
|
|
new_quare.position = get_global_mouse_position()
|
|
|
|
$/root/Node2D.add_child(new_quare)
|
|
|
|
new_quare.name = "Quare"
|
|
|
|
update_display()
|
|
|
|
if event.is_action_pressed("exagon"):
|
2024-04-18 19:45:52 -04:00
|
|
|
if exagons > 1:
|
|
|
|
exagons = 1
|
2024-04-16 20:29:45 -04:00
|
|
|
if exagons <= 0:
|
|
|
|
notifier.notify("No Exagons!")
|
|
|
|
return
|
|
|
|
|
|
|
|
if not $"../CollisionCheck".is_clear(get_global_mouse_position()):
|
|
|
|
$"../CollisionCheck".flash()
|
|
|
|
notifier.notify("Too Close!")
|
|
|
|
return
|
|
|
|
exagons -= 1
|
|
|
|
var new_exagon = exagon.instantiate()
|
|
|
|
new_exagon.position = get_global_mouse_position()
|
|
|
|
$/root/Node2D.add_child(new_exagon)
|
|
|
|
new_exagon.name = "Exagon"
|
|
|
|
update_display()
|
|
|
|
#$Gun.shoot()
|
|
|
|
|
|
|
|
func aquire_quare():
|
|
|
|
await get_tree().create_timer(3).timeout
|
|
|
|
num_quares -= 1
|
2024-04-20 09:45:17 -04:00
|
|
|
$QuareFX.play()
|
2024-04-16 20:29:45 -04:00
|
|
|
update_display()
|
|
|
|
|
|
|
|
func aquire_exagon():
|
|
|
|
await get_tree().create_timer(15).timeout
|
|
|
|
exagons += 1
|
2024-04-20 09:45:17 -04:00
|
|
|
$ExagonFX.play()
|
2024-04-16 20:29:45 -04:00
|
|
|
update_display()
|
|
|
|
|
|
|
|
func update_display():
|
2024-04-26 16:32:56 -04:00
|
|
|
$"../UI/Quare Count".text = "%d Quares\n" % [(max_quares - num_quares)]
|
2024-04-16 20:29:45 -04:00
|
|
|
|
|
|
|
func destroy():
|
2024-04-20 09:45:17 -04:00
|
|
|
$DeathFX.play()
|
2024-04-16 20:29:45 -04:00
|
|
|
get_tree().paused = true
|
|
|
|
$"../GameOver".visible = true
|