summaryrefslogtreecommitdiff
path: root/src/entities/food/scripts/food_manager.gd
diff options
context:
space:
mode:
Diffstat (limited to 'src/entities/food/scripts/food_manager.gd')
-rw-r--r--src/entities/food/scripts/food_manager.gd19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/entities/food/scripts/food_manager.gd b/src/entities/food/scripts/food_manager.gd
index 426677c..4196806 100644
--- a/src/entities/food/scripts/food_manager.gd
+++ b/src/entities/food/scripts/food_manager.gd
@@ -1,7 +1,7 @@
class_name FoodManager
extends Node2D
-export(PackedScene) var FOOD: PackedScene
+export(PackedScene) var FOOD_BASIC: PackedScene
export(NodePath) var WORLD_GENERATOR_NP: NodePath
onready var world_generator: Node2D = get_node(WORLD_GENERATOR_NP)
onready var possible_food_locations: Array = world_generator.get_valid_map_coords()
@@ -21,17 +21,21 @@ func _process(delta) -> void:
func _place_new_food() -> void:
- var food: Area2D = FOOD.instance()
- Event.emit_signal("food_placing_new_food", food.TYPE)
+ var food: FoodBasic = FOOD_BASIC.instance()
+ var type: int = FoodBasic.Type.APPLE
+ Event.emit_signal("food_placing_new_food", type)
var pos_loc: Array = _get_random_pos()
var pos: Vector2 = pos_loc[0]
var loc: Vector2 = pos_loc[1]
+ # need to set the position first, else it will spawn on the middle and the moved
food.global_position = pos
- food.location = loc
add_child(food)
+ food.set_type(FoodBasic.Type.APPLE)
+ food.set_location(loc)
+ food.properties["points"] = 1
current_food.append(loc)
- Event.emit_signal("food_placed_new_food", food.TYPE, loc)
+ Event.emit_signal("food_placed_new_food", food.properties["type"], food.properties["location"])
func _get_random_pos() -> Array:
@@ -40,7 +44,6 @@ func _get_random_pos() -> Array:
var location: Vector2
while not found_valid_loc:
- print("trying")
index = randi() % possible_food_locations.size()
location = possible_food_locations[index]
if current_food.find(location) == -1:
@@ -49,6 +52,6 @@ func _get_random_pos() -> Array:
return [world_generator.get_centered_world_position(location), location]
-func _on_food_eaten(type: int, location: Vector2) -> void:
- var index: int = current_food.find(location)
+func _on_food_eaten(properties: Dictionary) -> void:
+ var index: int = current_food.find(properties["location"])
current_food.remove(index)