Browse Source

Dynamically instance one player

DricomDragon 5 years ago
parent
commit
3bb2128d08
3 changed files with 18 additions and 18 deletions
  1. 13 2
      Game.gd
  2. 1 14
      Game.tscn
  3. 4 2
      Player.gd

+ 13 - 2
Game.gd

@@ -1,13 +1,24 @@
 extends Node2D
 
 onready var cam = $MainCamera
+onready var level = $Grid
 var players = []
 var dist_max = 900
 var zoom_rate = 0.001
 
+var playerScene = preload("res://Player.tscn")
+
 func _ready():
-	players.append($Player1)
-	players.append($Player2)
+	var player
+
+	# Player 1
+	player = playerScene.instance()
+	player.grid = level
+	player.turn_left_action = "player_1_turn_left"
+	player.turn_right_action = "player_1_turn_right"
+	player.position = Vector2(4 * 64 + 32, 8 * 64 + 32)
+	players.append(player) # TODO : use groups
+	add_child(player)
 
 func _process(d):
 	center_camera()

File diff suppressed because it is too large
+ 1 - 14
Game.tscn


+ 4 - 2
Player.gd

@@ -1,7 +1,6 @@
 extends Area2D
 
 # Nodes
-export (NodePath) var gridNode
 var grid:TileMap
 var tween
 var rayFront
@@ -38,7 +37,10 @@ export var turn_left_action:String
 export var turn_right_action:String
 
 func _ready():
-	grid = get_node(gridNode)
+	assert(grid)
+	assert(turn_left_action)
+	assert(turn_right_action)
+
 	cell_size = int (grid.get_cell_size().x)
 	cell_half_size = cell_size / 2