final is here
This commit is contained in:
@@ -8,6 +8,7 @@ var delay_dup := 0.0
|
||||
|
||||
@export var particles := load("res://scene/destroy.tscn")
|
||||
|
||||
|
||||
@export var asteroidx1 : = load("res://scene/asteroidx1.tscn")
|
||||
@export var asteroidx2 : = load("res://scene/asteroidx2.tscn")
|
||||
@export var asteroidx3 : = load("res://scene/asteroidx3.tscn")
|
||||
@@ -65,10 +66,12 @@ func _on_body_entered(body: Node) -> void:
|
||||
elif body.is_in_group("shoot"):
|
||||
body.destroy = true
|
||||
body.queue_free()
|
||||
GameController.emit_signal("point_gain", type)
|
||||
GameController.emit_signal("point_gain", type, global_position)
|
||||
split()
|
||||
elif body is Ship and !body.is_inv():
|
||||
body.is_currently_hit = true
|
||||
direction = (global_position - body.global_position).normalized()
|
||||
body.velocity += direction * 10
|
||||
#GameController.emit_signal("player_hit")
|
||||
|
||||
|
||||
|
||||
14
script/score_particles.gd
Normal file
14
script/score_particles.gd
Normal file
@@ -0,0 +1,14 @@
|
||||
extends CPUParticles2D
|
||||
|
||||
|
||||
@export var label := Label
|
||||
|
||||
var score := 0
|
||||
|
||||
func _ready() -> void:
|
||||
emitting = true
|
||||
label.text = "+" + str(score)
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if not emitting:
|
||||
queue_free()
|
||||
1
script/score_particles.gd.uid
Normal file
1
script/score_particles.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://5cghvv2m23uq
|
||||
@@ -5,18 +5,28 @@ var player_name := ""
|
||||
@export var label_name := Label
|
||||
|
||||
|
||||
func _on_item_list_item_selected(index: int) -> void:
|
||||
pass
|
||||
func _ready() -> void:
|
||||
if GameController.is_multiplayer:
|
||||
label_name.text = "Team Name 0/8:"
|
||||
else:
|
||||
label_name.text = "Player Name 0/8:"
|
||||
|
||||
|
||||
func _on_item_list_item_activated(index: int) -> void:
|
||||
var temp = $Control/ItemList.get_item_text(index)
|
||||
var nbr = player_name.length()
|
||||
if temp == "Back":
|
||||
player_name[-1] = ""
|
||||
elif temp == "Enter" and player_name.length() > 0:
|
||||
GameController.emit_signal("go_to_menu", player_name)
|
||||
elif nbr < 10:
|
||||
if player_name.length() > 0:
|
||||
player_name[-1] = ""
|
||||
elif temp == "Enter" :
|
||||
if player_name.length() > 0:
|
||||
GameController.emit_signal("go_to_menu", player_name)
|
||||
elif nbr < 8:
|
||||
player_name += temp
|
||||
nbr = player_name.length()
|
||||
label_name.text = "Player Name " + str(nbr) +"/10:\n" + player_name
|
||||
if GameController.is_multiplayer:
|
||||
label_name.text = "Team Name "
|
||||
else:
|
||||
label_name.text = "Player Name "
|
||||
label_name.text += str(nbr) +"/8:\n" + player_name
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ class_name Ship
|
||||
@export var TIME_INVUL := 1.0
|
||||
@export var animation : AnimationPlayer
|
||||
@export var target : Node2D
|
||||
@export var player_2 := false
|
||||
|
||||
const SPEED = 25.0
|
||||
const JUMP_VELOCITY = -400.0
|
||||
@@ -20,13 +21,12 @@ var is_in = true
|
||||
var delay_inv := 0.0
|
||||
var is_currently_hit := false
|
||||
|
||||
func _input(event):
|
||||
pass
|
||||
|
||||
func _ready() -> void:
|
||||
delay_inv = TIME_INVUL +1
|
||||
GameController.connect("player_hit", start_inv)
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
delay += delta
|
||||
if is_inv():
|
||||
@@ -34,29 +34,32 @@ func _physics_process(delta: float) -> void:
|
||||
animation.play("blink")
|
||||
else:
|
||||
animation.play("RESET")
|
||||
|
||||
horizontal = Input.get_axis("ui_up", "ui_down")
|
||||
vertical = Input.get_axis("ui_left", "ui_right")
|
||||
if vertical != 0:
|
||||
velocity.x = move_toward(velocity.x, MAX_SPEED * vertical, SPEED)
|
||||
if ! player_2:
|
||||
horizontal = Input.get_axis("ui_up", "ui_down")
|
||||
vertical = Input.get_axis("ui_left", "ui_right")
|
||||
else:
|
||||
horizontal = Input.get_axis("up_player_2", "down_player_2")
|
||||
vertical = Input.get_axis("left_player_2", "right_player_2")
|
||||
direction = Vector2(vertical, horizontal).normalized()
|
||||
if direction.x != 0:
|
||||
velocity.x = move_toward(velocity.x, MAX_SPEED * direction.x, SPEED)
|
||||
else:
|
||||
velocity.x = move_toward(velocity.x, 0, SPEED)
|
||||
|
||||
if horizontal != 0:
|
||||
velocity.y = move_toward(velocity.y, MAX_SPEED * horizontal, SPEED)
|
||||
if direction.y != 0:
|
||||
velocity.y = move_toward(velocity.y, MAX_SPEED * direction.y, SPEED)
|
||||
else:
|
||||
velocity.y = move_toward(velocity.y, 0, SPEED)
|
||||
|
||||
if horizontal != 0 or vertical != 0:
|
||||
direction = Vector2(vertical, horizontal)
|
||||
rotation = rotate_toward(rotation ,atan2(horizontal, vertical), 0.5)
|
||||
|
||||
rotation = rotate_toward(rotation ,atan2(horizontal, vertical), 0.4)
|
||||
|
||||
if Input.is_action_pressed("ui_accept") and delay >= 0.5:
|
||||
if (( not player_2 and Input.is_action_pressed("ui_accept")) or ( player_2 and Input.is_action_pressed("accept_player_2"))) and delay >= 0.5:
|
||||
shoot()
|
||||
delay = 0
|
||||
if !is_inv() and is_currently_hit:
|
||||
GameController.emit_signal("player_hit")
|
||||
GameController.emit_signal("player_hit", player_2)
|
||||
|
||||
move_and_slide()
|
||||
|
||||
@@ -71,5 +74,6 @@ func shoot()->void:
|
||||
func is_inv() -> bool:
|
||||
return delay_inv <= TIME_INVUL
|
||||
|
||||
func start_inv()->void:
|
||||
delay_inv = 0.0
|
||||
func start_inv(type : bool)->void:
|
||||
if type == player_2 :
|
||||
delay_inv = 0.0
|
||||
|
||||
@@ -18,8 +18,3 @@ func _process(delta: float) -> void:
|
||||
time += delta
|
||||
if time >= 2:
|
||||
self.queue_free()
|
||||
|
||||
|
||||
func _on_body_entered(body: Node) -> void:
|
||||
if body is Shoot:
|
||||
self.queue_free()
|
||||
|
||||
17
script/ui.gd
17
script/ui.gd
@@ -5,7 +5,7 @@ extends CanvasLayer
|
||||
var player_life:= 3
|
||||
var score := 0
|
||||
var time := 0.0
|
||||
|
||||
@export var show_score :PackedScene = load("res://scene/score_particles.tscn")
|
||||
|
||||
func _ready() -> void:
|
||||
GameController.connect("player_hit", update_player)
|
||||
@@ -14,12 +14,21 @@ func _ready() -> void:
|
||||
func _process(delta: float) -> void:
|
||||
time += delta
|
||||
|
||||
func update_score(add : int)->void:
|
||||
score += 2 ** (5-add) * (1 + (time / 100))
|
||||
func update_score(add : int, ast_pos: Vector2)->void:
|
||||
var temp = 2 ** (5-add) * (1 + (time / 100))
|
||||
spawn_score(temp,ast_pos)
|
||||
score += temp
|
||||
label_score.text = str(score)
|
||||
|
||||
func update_player() -> void:
|
||||
func update_player(_type:bool) -> void:
|
||||
player_life -= 1
|
||||
if player_life < 0:
|
||||
GameController.emit_signal("go_to_score_saver", score)
|
||||
box_player1.get_children(false)[player_life].visible = false
|
||||
|
||||
|
||||
func spawn_score(score: int,pos : Vector2)->void:
|
||||
var new = show_score.instantiate()
|
||||
new.global_position = pos
|
||||
new.score = score
|
||||
get_parent().add_child(new)
|
||||
|
||||
Reference in New Issue
Block a user