Always start players at a base

This commit is contained in:
DeathByDenim 2023-05-17 21:18:17 -04:00
parent a09a2b2235
commit b0d5b6d906
Signed by: DeathByDenim
GPG Key ID: 4A475283D925365B
2 changed files with 12 additions and 7 deletions

View File

@ -1,7 +1,7 @@
extends Node2D
var options = {}
var base_pos = Vector2i(0,0)
var base_positions: Array[Vector2i]
# Called when the node enters the scene tree for the first time.
func _ready():
@ -32,9 +32,8 @@ func add_player(id: int):
var player_ship = preload("res://World/PlayerShip.tscn").instantiate()
# Set player id.
player_ship.player = id
player_ship.position = Vector2(600, 600)
if id == 1:
player_ship.position = Vector2(800, 600)
player_ship.position = 64*base_positions[randi() % base_positions.size()] + Vector2i(32, 32)
player_ship.rotation_degrees = -90
player_ship.name = str(id)
$Players.add_child(player_ship, true)
@ -121,6 +120,13 @@ func parse_map_file(file_name):
var letter_code = data[iy * width + ix]
if tile_dictionary.has(letter_code):
$TileMap.set_cell(0, Vector2i(ix, iy), 0, tile_dictionary[letter_code])
if "_0123456789".contains(letter_code):
base_positions.push_back(Vector2i(ix, iy))
if edge_wrap:
if ix < width / 2:
base_positions[-1].x += width
if iy < height / 2:
base_positions[-1].y += height
if edge_wrap:
$TileMap.set_cell(0, Vector2i(ix + width, iy), 0, tile_dictionary[letter_code])
$TileMap.set_cell(0, Vector2i(ix + width, iy + height), 0, tile_dictionary[letter_code])
@ -132,8 +138,8 @@ func parse_map_file(file_name):
func apply_options():
var width = int(options["mapwidth"])
var height = int(options["mapheight"])
get_node("Map boundaries/CollisionShape2D").shape.size = 64 * Vector2i(width, height)
get_node("Map boundaries").position = 64 * Vector2i(width, height) / 2
$"Map boundaries/CollisionShape2D".shape.size = 64 * Vector2i(width, height)
$"Map boundaries".position = 64 * Vector2i(width, height)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):

View File

@ -172,7 +172,6 @@ format = 2
[node name="Map boundaries" type="Area2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="Map boundaries"]
position = Vector2(3200, 3200)
shape = SubResource("RectangleShape2D_hjo0t")
[node name="Players" type="Node2D" parent="."]