Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Knollewolle |
I have put some nodes in a list.
Those nodes are children of the node which i’m making a script for.
The parent node shall randomly choose one of its children and print it on the screen.
Then the children_node shall move to a direction and change it when a button is pressed (not in the script, yet).
extends Node2D
func _ready():
randomize()
#get_children()
pass # Replace with function body.
# Nodes arent found!
#var child_nodes = get_children()
var ls_food = [$fd_pizza, $fd_cocoa, $fd_schnitzel,
$fd_lasagna,$fd_energy, $fd_apple, $fd_cactus, $fd_burger,
$fd_wine, $fd_cake, $fd_icecone, $fd_ham, $fd_soup,
$fd_salad, $fd_chicken, $fd_fish, $fd_brokkoli, $fd_bcake, $fd_fruit, $fd_beer]
#var pts_food = {}
var food = ls_food[0]
const SCREEN_WIDTH = 360
const SCREEN_HEIGHT = 640
const MOVE_SPEED = 100
func choose_food():
food = ls_food[rand_range(0,20)]
pass
func _process(delta):
# var pos_food = food.position
food.position.x += (delta*MOVE_SPEED)
if food.position.x == (SCREEN_WIDTH - 32):
food.position.y += (delta*MOVE_SPEED)
if food.position >= 64:
food.position.x -= (delta*MOVE_SPEED)
# if food.position.x <= 0 and food.position.y >= 64:
# queue_free()
# score -= 10
pass