summaryrefslogtreecommitdiff
path: root/player.gd
blob: 9743b4c423c54e002e925563593abb8202c16256 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
extends Area2D

@export var speed := 2.0
@onready var primogemmes = get_node("../CanvasUI/UI/Primogemmes")
@onready var sfxs = [ $SfxOO, $SfxEE, $SfxOO2 ]
@onready var sfx = 0


func type() -> String: return "player"


# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	SignalHub.select_character.connect(select_character)
	select_character("venti")


func get_input() -> Vector2:
	var vec := Vector2.ZERO
	if Input.is_action_pressed("ui_left"): vec.x -= 1
	if Input.is_action_pressed("ui_right"): vec.x += 1
	if Input.is_action_pressed("ui_up"): vec.y -= 1
	if Input.is_action_pressed("ui_down"): vec.y += 1
	return vec


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(_delta2: float) -> void:
	position += get_local_mouse_position().normalized() * speed
	position = position.clamp(Globals.LIMITS_MIN, Globals.LIMITS_MAX)
	#var color := Color()
	#color.r = randi() % 2
	#color.g = randi() % 2
	#color.b = randi() % 2
	#material.set_shader_parameter("color", color)
	


func _on_area_entered(area: Area2D) -> void:
	match area.type():
		"coin":
			area.queue_free()
			sfxs[sfx].play()
			sfx = (sfx + 1) % len(sfxs)
			primogemmes.count += 1
			$Sprite2D.rotation_degrees += 90


func select_character(s: String) -> void:
	match s:
		"venti":
			$Sprite2D.frame = 0
		"luigi":
			$Sprite2D.frame = 1