shine-runners-test/player.gd

55 lines
1.3 KiB
GDScript3
Raw Permalink Normal View History

2025-04-20 16:15:26 +10:00
extends RigidBody2D
class_name Player
var id : int = 0
var score : int = 0
var scorecard : Scorecard
2025-04-20 17:31:40 +10:00
var alive : bool = true
var lifetime : float = 0
2025-04-20 16:15:26 +10:00
@export var start_speed = 100
@export var animated_sprite : AnimatedSprite2D
func _ready() -> void:
var frame : int = randi_range(0, animated_sprite.sprite_frames.get_frame_count("default")-1)
2025-04-20 20:52:48 +10:00
2025-04-20 16:15:26 +10:00
#animated_sprite.frame = frame
func start_engine():
var direction : Vector2 = Vector2 (randf_range(-1,1), randf_range(-1,1))
apply_force( direction.normalized() * start_speed)
2025-04-20 20:52:48 +10:00
2025-04-20 16:15:26 +10:00
func setup():
animated_sprite.frame = id
2025-04-20 17:31:40 +10:00
func respawn_shiny():
var shiny = load("res://shiny.tscn").instantiate()
var ranPos = randi_range(0,GM.shine_spawns.size()-1)
shiny.position = GM.shine_spawns[ranPos].position
2025-04-21 01:11:27 +10:00
get_tree().get_root().get_node("Game").add_child(shiny)
2025-04-20 17:31:40 +10:00
func _process(delta: float) -> void:
scorecard.score = score
scorecard.alive = alive
lifetime += delta
2025-04-20 21:24:12 +10:00
if(linear_velocity.length() < 50 and lifetime > 5):
linear_velocity *= 1.4
2025-04-20 17:31:40 +10:00
if(not alive):
modulate = Color("ffffff42")
contact_monitor = false
scorecard.alive = false
for i in range(score):
respawn_shiny()
process_mode = Node.PROCESS_MODE_DISABLED
func _on_body_entered(body: Node) -> void:
#print("mew")
if body.is_in_group("player") :
2025-04-21 01:11:27 +10:00
#print("playersHit")
2025-04-20 17:31:40 +10:00
if(score > 0):
2025-04-20 20:52:48 +10:00
#score -= 1
#respawn_shiny()
pass