all the things

This commit is contained in:
zoe 2021-12-04 01:20:48 +01:00
parent ea85953f61
commit 612cb6652b
6 changed files with 36 additions and 12 deletions

View file

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

8
World/Pixel.gd Normal file
View file

@ -0,0 +1,8 @@
extends ColorRect
var empty = true
var position = Vector2()
export var lighter_green = Color("#91e369")
export var light_green = Color("#56c157")
export var medium_green = Color("#46a65c")
export var dark_green = Color("#358859")

View file

@ -1,9 +1,11 @@
[gd_scene format=2]
[gd_scene load_steps=2 format=2]
[ext_resource path="res://World/Pixel.gd" type="Script" id=1]
[node name="Pixel" type="ColorRect"]
margin_right = 1.0
margin_bottom = 1.0
color = Color( 0, 0, 0, 0 )
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}

View file

@ -1,23 +1,31 @@
extends Node2D
export var size = Vector2(128, 144)
# 2 dimensional array y and x
var pixels_y = []
var pixels_x = []
func _ready():
call_deferred("spawn_pixels")
call_deferred("plant_seed")
func spawn_pixels():
for n in size.x:
var pixels_x = []
var pixels_y = []
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)
pixel.position = Vector2(n, i)
# show in scene
Main.add_child(pixel)
# initilize array
pixels_y.append(pixel)
pixels_x.append(pixels_y)
func plant_seed():
var rect = pixels_x[size.x / 2][size.y - 8]
rect.color = rect.light_green
func grow():
pass

12
World/Plant.tscn Normal file
View file

@ -0,0 +1,12 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://World/Plant.gd" type="Script" id=2]
[node name="Plant" type="Node2D"]
script = ExtResource( 2 )
[node name="Timer" type="Timer" parent="."]
wait_time = 0.25
autostart = true
[connection signal="timeout" from="Timer" to="." method="grow"]

View file

@ -1,6 +0,0 @@
[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 )