instantiate ball
This commit is contained in:
parent
8f0d4b1b68
commit
e6053fdca9
2 changed files with 16 additions and 2 deletions
|
|
@ -12,6 +12,7 @@ class_name Level extends Node2D
|
|||
#@export var goal_layer: GoalTileLayer
|
||||
|
||||
@onready var player_scene: PackedScene = preload("res://scenes/player/player.tscn")
|
||||
@onready var ball_scene: PackedScene = preload("res://scenes/ball/ball.tscn")
|
||||
|
||||
var player_1: Player
|
||||
var player_2: Player
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ extends LevelState
|
|||
|
||||
|
||||
func _enter(_previous_state_path: String, _data: Dictionary = {"round": 0, "restart": false}) -> void:
|
||||
get_tree().paused = true
|
||||
assert((_data["round"] as int) in range(3), "round number is invalid")
|
||||
assert(
|
||||
(_data["restart"] as bool) == true or
|
||||
|
|
@ -10,6 +11,7 @@ func _enter(_previous_state_path: String, _data: Dictionary = {"round": 0, "rest
|
|||
)
|
||||
level.current_round = _data["round"]
|
||||
level.restarted = _data["restart"]
|
||||
|
||||
if level.restarted:
|
||||
level.current_round = 0
|
||||
level.scoreboard = Vector2i(0,0)
|
||||
|
|
@ -32,12 +34,13 @@ func _enter(_previous_state_path: String, _data: Dictionary = {"round": 0, "rest
|
|||
|
||||
level.player_1 = _instantiate_player(1)
|
||||
level.player_2 = _instantiate_player(2)
|
||||
level.ball = _instantiate_ball()
|
||||
|
||||
|
||||
func _instantiate_player(id: int) -> Player:
|
||||
var p: Player = level.player_1 if id == 1 else level.player_2
|
||||
var s: PlayerSpawnPoint = level.player_1_spawn if id == 1 else level.player_2_spawn
|
||||
var p: Player = level.player_scene.instantiate()
|
||||
|
||||
p = level.player_scene.instantiate()
|
||||
p.id = id
|
||||
p.name = "Player"+str(id)
|
||||
|
||||
|
|
@ -47,3 +50,13 @@ func _instantiate_player(id: int) -> Player:
|
|||
p.global_position = s.global_position
|
||||
|
||||
return p
|
||||
|
||||
|
||||
func _instantiate_ball() -> Ball:
|
||||
var b: Ball = level.ball_scene.instantiate()
|
||||
|
||||
level.add_child(b)
|
||||
|
||||
b.global_position = level.ball_spawn.global_position
|
||||
|
||||
return b
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue