add pixel array

This commit is contained in:
zoe 2021-12-04 00:12:22 +01:00
parent 27aeeb275f
commit 93a206dd8b
6 changed files with 56 additions and 0 deletions

7
World/Main.tscn Normal file
View file

@ -0,0 +1,7 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://World/Tree.tscn" type="PackedScene" id=1]
[node name="Main" type="Node2D"]
[node name="Tree" parent="." instance=ExtResource( 1 )]

9
World/Pixel.tscn Normal file
View file

@ -0,0 +1,9 @@
[gd_scene format=2]
[node name="Pixel" type="ColorRect"]
margin_right = 1.0
margin_bottom = 1.0
color = Color( 0, 0, 0, 0 )
__meta__ = {
"_edit_use_anchors_": false
}

23
World/Tree.gd Normal file
View file

@ -0,0 +1,23 @@
extends Node2D
export var size = Vector2(128, 144)
# 2 dimensional array y and x
var pixels_y = []
func _ready():
call_deferred("spawn_pixels")
func spawn_pixels():
for n in size.x:
var pixels_x = []
for i in size.y:
var Main = get_tree().current_scene
var Pixel = preload("res://World/Pixel.tscn")
var pixel = Pixel.instance()
# set position
pixel.rect_global_position = Vector2(n, i)
# show in scene
Main.add_child(pixel)
# initilize array
pixels_y.append(pixel)
pixels_x.append(pixels_y)

6
World/Tree.tscn Normal file
View file

@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://World/Tree.gd" type="Script" id=2]
[node name="Tree" type="Node2D"]
script = ExtResource( 2 )

View file

@ -1,5 +1,7 @@
[gd_resource type="Environment" load_steps=2 format=2]
[sub_resource type="ProceduralSky" id=1]
[resource]
background_mode = 2
background_sky = SubResource( 1 )

View file

@ -11,12 +11,21 @@ config_version=4
[application]
config/name="Untitled Plant Game"
run/main_scene="res://World/Main.tscn"
config/icon="res://icon.png"
[display]
window/size/width=256
window/size/height=144
window/stretch/mode="2d"
window/stretch/aspect="keep"
[physics]
common/enable_pause_aware_picking=true
[rendering]
environment/default_clear_color=Color( 0.94902, 0.988235, 0.878431, 1 )
environment/default_environment="res://default_env.tres"