Separate player and enemy from map storage
This commit is contained in:
parent
8cdd562c42
commit
878bfdd35a
14
Level.gd
14
Level.gd
@ -5,7 +5,6 @@ const BUFFER = 10
|
||||
|
||||
var state = null
|
||||
var State = load("State.gd")
|
||||
var Player = load("Player.gd")
|
||||
|
||||
var map_desc = {
|
||||
" " : preload("res://Empty.tscn"), # empty
|
||||
@ -17,6 +16,9 @@ var map_desc = {
|
||||
"#" : preload("res://Wall.tscn"), # wall
|
||||
}
|
||||
|
||||
var player = null
|
||||
var enemy = null
|
||||
|
||||
func load_level_file(filename):
|
||||
var lines = []
|
||||
var filestream = File.new()
|
||||
@ -30,12 +32,16 @@ func load_level_file(filename):
|
||||
for x in range(len(lines[0])):
|
||||
var tile_str = lines[y][x]
|
||||
var new_instance = map_desc[tile_str].instance()
|
||||
if new_instance.type == "Player":
|
||||
player = new_instance
|
||||
elif new_instance.type == "Enemy":
|
||||
enemy = new_instance
|
||||
else:
|
||||
row.append(new_instance)
|
||||
new_instance.global_position = Vector2(x * SPACE, y * SPACE)
|
||||
self.add_child(new_instance)
|
||||
row.append(new_instance)
|
||||
lvl_map.append(row)
|
||||
var plr = Player.new()
|
||||
state = State.new(lvl_map, plr)
|
||||
state = State.new(lvl_map, player, enemy)
|
||||
OS.window_size = Vector2((len(lines)*SPACE)-BUFFER, (len(lines[0])*SPACE)-BUFFER)
|
||||
|
||||
func _ready():
|
||||
|
@ -26,6 +26,7 @@ func _physics_process(_delta):
|
||||
pos = Vector2(pos.x+1, pos.y)
|
||||
if state.get_type(pos) == "Empty":
|
||||
self.translate(Vector2(speed, 0))
|
||||
state.player_pos = get_pos()
|
||||
|
||||
func get_pos():
|
||||
var pos = self.global_position
|
||||
|
7
State.gd
7
State.gd
@ -2,11 +2,16 @@ extends Node
|
||||
|
||||
var level_map = null
|
||||
var player = null
|
||||
var enemy = null
|
||||
var player_speed = 50
|
||||
|
||||
func _init(lvlmap, plr):
|
||||
var player_pos = Vector2()
|
||||
var enemy_pos = Vector2()
|
||||
|
||||
func _init(lvlmap, plr, enm):
|
||||
level_map = lvlmap
|
||||
player = plr
|
||||
enemy = enm
|
||||
|
||||
func get_type(pos):
|
||||
print(level_map[pos.y][pos.x].type)
|
||||
|
Loading…
x
Reference in New Issue
Block a user