WIP scene loading fixes

This commit is contained in:
archfan 2020-04-18 19:34:41 -04:00
parent 34b476cf6a
commit e6cd47de5a
5 changed files with 25 additions and 34 deletions

View File

@ -1,3 +1,5 @@
extends Node2D
var map_desc = {
" " : preload("res://Obstacle.tscn"),
"." : preload("res://Obstacle.tscn"),
@ -5,22 +7,23 @@ var map_desc = {
"G" : preload("res://Obstacle.tscn"),
"P" : preload("res://Obstacle.tscn"),
"I" : preload("res://Obstacle.tscn"),
"#" : preload("res://Obstacle.tscn"),
}
func load_level_file(filename):
var lines = []
var filestream = File.new()
filestream.open("res://levels/" + filename)
while not filestream.end_of_file():
filestream.open("res://levels/" + filename, File.READ)
while not filestream.eof_reached():
lines.append(filestream.get_line())
filestream.close()
for y in range(len(lines)):
for x in range(len(lines[0])):
var tile_str = lines[y][x]
var new_instance = map_desc[tile_str].instance()
new_instance.Translation = Vector2(x * 3000, y * 3000)
self.get_root.add_child(new_instance)
new_instance.global_position = Vector2(x * 3000, y * 3000)
self.add_child(new_instance)
# This doesn't seem to work, please fix.
func _on_Level_ready():
func _ready():
load_level_file("test_level_2.txt")

View File

@ -1,17 +1,15 @@
[gd_scene load_steps=5 format=2]
[ext_resource path="res://Player.gd" type="Script" id=1]
[ext_resource path="res://icon.png" type="Texture" id=2]
[sub_resource type="RectangleShape2D" id=1]
[gd_scene load_steps=6 format=2]
[ext_resource path="res://Level.gd" type="Script" id=1]
[ext_resource path="res://Player.gd" type="Script" id=2]
[ext_resource path="res://icon.png" type="Texture" id=3]
[sub_resource type="RectangleShape2D" id=2]
[sub_resource type="RectangleShape2D" id=3]
[sub_resource type="RectangleShape2D" id=1]
[node name="Level" type="Node2D"]
script = ExtResource( 1 )
[node name="Background" type="TextureRect" parent="."]
margin_right = 1030.0
@ -30,11 +28,11 @@ margin_right = 40.0
margin_bottom = 40.0
[node name="EnemyCollision" type="CollisionShape2D" parent="Enemy"]
shape = SubResource( 1 )
shape = SubResource( 2 )
[node name="Player" type="KinematicBody2D" parent="."]
position = Vector2( 100, 100 )
script = ExtResource( 1 )
script = ExtResource( 2 )
__meta__ = {
"_edit_group_": true
}
@ -42,21 +40,8 @@ __meta__ = {
[node name="PlayerTexture" type="TextureRect" parent="Player"]
margin_right = 40.0
margin_bottom = 40.0
texture = ExtResource( 2 )
texture = ExtResource( 3 )
[node name="PlayerCollision" type="CollisionShape2D" parent="Player"]
shape = SubResource( 2 )
[node name="Obstacle" type="StaticBody2D" parent="."]
__meta__ = {
"_edit_group_": true
}
[node name="ObstacleTexture" type="TextureRect" parent="Obstacle"]
margin_right = 40.0
margin_bottom = 40.0
[node name="ObstacleCollision" type="CollisionShape2D" parent="Obstacle"]
shape = SubResource( 3 )
shape = SubResource( 1 )

View File

@ -1,6 +1,8 @@
[gd_scene load_steps=2 format=2]
[gd_scene load_steps=3 format=2]
[sub_resource type="RectangleShape2D" id=3]
[ext_resource path="res://icon.png" type="Texture" id=1]
[sub_resource type="RectangleShape2D" id=1]
[node name="Obstacle" type="StaticBody2D"]
__meta__ = {
@ -10,7 +12,8 @@ __meta__ = {
[node name="ObstacleTexture" type="TextureRect" parent="."]
margin_right = 40.0
margin_bottom = 40.0
texture = ExtResource( 1 )
[node name="ObstacleCollision" type="CollisionShape2D" parent="."]
shape = SubResource( 3 )
shape = SubResource( 1 )

View File

@ -5,3 +5,4 @@
[resource]
background_mode = 2
background_sky = SubResource( 1 )

View File

@ -16,7 +16,6 @@ _global_script_class_icons={
[application]
config/name="LD46"
run/main_scene="res://Level.tscn"
config/icon="res://icon.png"
[input]