# Playerextends Area2D@onreadyvar screen_size =get_viewport_rect().sizevar speed =500var cooldown_active =falsevar cooldown =0.5funcmove(delta):var input_direction =Input.get_axis("ui_left","ui_right")var velocity =Vector2() # (0,0) velocity.x = input_direction position += speed * delta * velocity position.x =clamp(position.x, 0, screen_size.x)funcshoot():if cooldown_active:return cooldown_active =truevar cooldown_timer =Timer.new() cooldown_timer.wait_time = cooldown cooldown_timer.one_shot =trueadd_child(cooldown_timer) cooldown_timer.timeout.connect(_on_cooldown_timeout) cooldown_timer.start()var bullet =Bullet.generate_bullet()var current_scene =get_tree().get_current_scene() bullet.position =self.global_position current_scene.add_child(bullet)# Called when the node enters the scene tree for the first time.func_ready():pass# Replace with function body.# Called every frame. 'delta' is the elapsed time since the previous frame.func_process(delta):ifInput.is_action_pressed("ui_accept"):shoot()move(delta)func_on_cooldown_timeout(): cooldown_active =false
# Bulletclass_nameBulletextends Area2D@exportvar bullet_speed =-800const BulletScene =preload("res://scenes/bullet.tscn")staticfuncgenerate_bullet():var bullet =BulletScene.instantiate()return bulletfuncmove(delta):var velocity =Vector2.ZERO velocity.y +=1 position += velocity * bullet_speed * delta# Called when the node enters the scene tree for the first time.func_ready():pass# Replace with function body.# Called every frame. 'delta' is the elapsed time since the previous frame.func_process(delta):move(delta)
# PathFollow2Dextends PathFollow2Dvar reverse =1# Called when the node enters the scene tree for the first time.func_ready():pass# Replace with function body.# Called every frame. 'delta' is the elapsed time since the previous frame.func_process(delta): progress_ratio +=0.1* delta * reverseif (progress_ratio == 0or progress_ratio == 1): reverse = reverse *-1func_on_enemy_area_area_entered(area):print("hit")