tp work and first steep for menu
This commit is contained in:
@@ -3,6 +3,8 @@ extends RigidBody2D
|
||||
var SPEED : float
|
||||
var direction : Vector2
|
||||
var type:= 1
|
||||
var is_in := false
|
||||
var delay_dup := 0.0
|
||||
|
||||
@export var particles := load("res://scene/destroy.tscn")
|
||||
|
||||
@@ -16,7 +18,10 @@ func _ready() -> void:
|
||||
SPEED = randf() / 50 +50
|
||||
rotation = randf_range(0.0, 360.0)
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
func _process(delta: float) -> void:
|
||||
|
||||
if delay_dup < 1:
|
||||
delay_dup += delta
|
||||
linear_velocity = direction * SPEED
|
||||
|
||||
func split():
|
||||
@@ -58,7 +63,6 @@ func _on_body_entered(body: Node) -> void:
|
||||
if body.is_in_group("asteroid"):
|
||||
get_parent()._add_collision(body, self)
|
||||
elif body.is_in_group("shoot"):
|
||||
body.destroy = true
|
||||
body.queue_free()
|
||||
split()
|
||||
else:
|
||||
direction = -direction
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
extends CharacterBody2D
|
||||
|
||||
class_name Ship
|
||||
|
||||
@export var MAX_SPEED: float = 200
|
||||
@export var SHOOT_NODE: PackedScene
|
||||
|
||||
@@ -11,6 +13,7 @@ var horizontal : float
|
||||
var vertical : float
|
||||
var rota_temp: float
|
||||
var delay := 0.0
|
||||
var is_in = true
|
||||
|
||||
func _input(event):
|
||||
pass
|
||||
@@ -47,5 +50,5 @@ func _physics_process(delta: float) -> void:
|
||||
func shoot()->void:
|
||||
var new = SHOOT_NODE.instantiate()
|
||||
new.direction = direction
|
||||
new.position = position + (18 * direction.normalized())
|
||||
new.position = position + (32 * direction.normalized())
|
||||
get_parent().add_child(new)
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
extends RigidBody2D
|
||||
|
||||
class_name Shoot
|
||||
@export var SPEED : float = 100.0
|
||||
var destroy = false
|
||||
var is_in := true
|
||||
var direction: Vector2:
|
||||
set(val):
|
||||
direction = val.normalized() * SPEED
|
||||
@@ -13,5 +16,5 @@ func _process(delta: float) -> void:
|
||||
linear_velocity = direction
|
||||
|
||||
time += delta
|
||||
#if time >= 2:
|
||||
# self.queue_free()
|
||||
if time >= 2:
|
||||
self.queue_free()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
extends Node2D
|
||||
|
||||
class_name Spawner
|
||||
@export var asteroidx1 : PackedScene
|
||||
@export var asteroidx2 : PackedScene
|
||||
@export var asteroidx3 : PackedScene
|
||||
@@ -7,8 +8,9 @@ extends Node2D
|
||||
@export var player : CharacterBody2D
|
||||
@export var distance:= 600.0
|
||||
@export var delay_spawn := 3.0
|
||||
@export var load_screen:= false
|
||||
|
||||
var current_time := 50.0
|
||||
var current_time := 0.0
|
||||
|
||||
signal add_collision
|
||||
|
||||
@@ -17,7 +19,7 @@ var list_of_collision_2 : Array[Node]
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
pass
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
@@ -32,14 +34,17 @@ func _process(delta: float) -> void:
|
||||
list_of_collision_1 = []
|
||||
list_of_collision_2 = []
|
||||
current_time += delta
|
||||
if current_time >= 2.0:
|
||||
if current_time >= delay_spawn and ((load_screen and get_children().size() < 10) or not load_screen):
|
||||
current_time = 0
|
||||
spawn()
|
||||
|
||||
func spawn_duplicate(asteroid: Node2D):
|
||||
var dup = asteroid.duplicate(DUPLICATE_USE_INSTANTIATION)
|
||||
dup.currently_in = true
|
||||
dup.position = (asteroid.position - Vector2(320, 320)).rotated(PI) + Vector2(320, 320)
|
||||
dup.type = asteroid.type
|
||||
dup.is_in = false
|
||||
var new_pos = (asteroid.position ).rotated(PI)
|
||||
dup.position = new_pos
|
||||
dup.rotation = asteroid.rotation
|
||||
dup.direction = asteroid.direction
|
||||
call_deferred("add_child", dup)
|
||||
|
||||
@@ -58,7 +63,7 @@ func spawn():
|
||||
elif choice == 4:
|
||||
new = asteroidx4.instantiate()
|
||||
new.type = 4
|
||||
var new_global_position = Vector2(distance,0).rotated(randf_range(0.0, 360)) + Vector2(320, 320)
|
||||
var new_global_position = Vector2(distance,0).rotated(randf_range(0.0, 360))
|
||||
new.global_position = new_global_position
|
||||
new.direction = (player.global_position - new_global_position).normalized()
|
||||
add_child(new)
|
||||
|
||||
@@ -1,8 +1,44 @@
|
||||
extends Node2D
|
||||
|
||||
|
||||
@export var spawner : Spawner
|
||||
var ship_scene = load("res://scene/ship.tscn")
|
||||
var shoot_scene = load("res://scene/shoot.tscn")
|
||||
|
||||
func _on_area_2d_body_exited(body: Node2D) -> void:
|
||||
if body.is_in_group("asteroid") and not body.is_in and body.delay_dup > 0.5:
|
||||
spawner.spawn_duplicate(body)
|
||||
body.queue_free()
|
||||
|
||||
|
||||
func _on_area_2d_body_entered(body: Node2D) -> void:
|
||||
pass
|
||||
|
||||
func _is_in_true(body: Node2D) -> void:
|
||||
|
||||
if body.is_in_group("asteroid") or body is Ship:
|
||||
body.is_in = true
|
||||
|
||||
|
||||
func _is_in_false(body: Node2D) -> void:
|
||||
if body.is_in_group("asteroid"):
|
||||
body.set_collision_layer(3)
|
||||
body.set_collision_mask(3)
|
||||
body.is_in = false
|
||||
elif body is Ship:
|
||||
body.is_in = false
|
||||
var new_ship = ship_scene.instantiate()
|
||||
new_ship.position = body.position.rotated(PI) *.95
|
||||
new_ship.rotation = body.rotation
|
||||
get_parent().call_deferred("add_child",new_ship)
|
||||
spawner.player = new_ship
|
||||
body.queue_free()
|
||||
elif body is Shoot and not body.destroy:
|
||||
body.is_in = false
|
||||
var new_shoot = shoot_scene.instantiate()
|
||||
new_shoot.position = body.position.rotated(PI)
|
||||
new_shoot.direction = body.direction
|
||||
new_shoot.rotation = body.rotation
|
||||
new_shoot.time = body.time
|
||||
get_parent().call_deferred("add_child",new_shoot)
|
||||
|
||||
|
||||
func _on_wall_destroy_body_entered(body: Node2D) -> void:
|
||||
body.queue_free()
|
||||
|
||||
Reference in New Issue
Block a user