summaryrefslogtreecommitdiff
path: root/src/entities/food/scripts
diff options
context:
space:
mode:
authorDavid Luevano Alvarado <david@luevano.xyz>2022-06-04 23:00:58 -0600
committerDavid Luevano Alvarado <david@luevano.xyz>2022-06-04 23:00:58 -0600
commit36abc689d783774ce4f2d7b5a1bb621d8684be45 (patch)
treea3dbed6069fbd8d9a588c7510ce581af3e847af0 /src/entities/food/scripts
parent9a2bcf02c2623c8f3e8f5e74e70b3c0333790484 (diff)
added more ui for after gameplay, generalized basic food
Diffstat (limited to 'src/entities/food/scripts')
-rw-r--r--src/entities/food/scripts/food.gd2
-rw-r--r--src/entities/food/scripts/food_basic.gd6
-rw-r--r--src/entities/food/scripts/food_manager.gd27
3 files changed, 20 insertions, 15 deletions
diff --git a/src/entities/food/scripts/food.gd b/src/entities/food/scripts/food.gd
index ca27acc..aa5207f 100644
--- a/src/entities/food/scripts/food.gd
+++ b/src/entities/food/scripts/food.gd
@@ -47,7 +47,7 @@ func _set_properties() -> void:
func randomize_stats() -> void:
- points = int(rand_range(1, 30))
+ points = int(rand_range(1, 10))
func _on_body_entered(body: Node) -> void:
diff --git a/src/entities/food/scripts/food_basic.gd b/src/entities/food/scripts/food_basic.gd
index 0a56208..032ec23 100644
--- a/src/entities/food/scripts/food_basic.gd
+++ b/src/entities/food/scripts/food_basic.gd
@@ -2,9 +2,11 @@ class_name FoodBasic
extends Food
enum Type {
- APPLE
+ APPLE,
+ BANANA
}
func _ready():
- texture[Type.APPLE] = preload("res://entities/food/sprites/apple.png") \ No newline at end of file
+ texture[Type.APPLE] = preload("res://entities/food/sprites/apple.png")
+ texture[Type.BANANA] = preload("res://entities/food/sprites/banana.png") \ No newline at end of file
diff --git a/src/entities/food/scripts/food_manager.gd b/src/entities/food/scripts/food_manager.gd
index 4196806..bbe27be 100644
--- a/src/entities/food/scripts/food_manager.gd
+++ b/src/entities/food/scripts/food_manager.gd
@@ -6,8 +6,7 @@ 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()
-var max_apples: int = 10
-var current_food: Array = []
+var current_basic_food: Array = []
func _ready():
@@ -16,13 +15,13 @@ func _ready():
func _process(delta) -> void:
- if current_food.size() < max_apples:
- _place_new_food()
+ if current_basic_food.size() < Global.MAX_BASIC_FOOD:
+ _place_new_basic_food()
-func _place_new_food() -> void:
+func _place_new_basic_food() -> void:
var food: FoodBasic = FOOD_BASIC.instance()
- var type: int = FoodBasic.Type.APPLE
+ var type: int = _get_random_food_type(FoodBasic.Type)
Event.emit_signal("food_placing_new_food", type)
var pos_loc: Array = _get_random_pos()
var pos: Vector2 = pos_loc[0]
@@ -31,13 +30,17 @@ func _place_new_food() -> void:
# need to set the position first, else it will spawn on the middle and the moved
food.global_position = pos
add_child(food)
- food.set_type(FoodBasic.Type.APPLE)
+ food.set_type(type)
food.set_location(loc)
- food.properties["points"] = 1
- current_food.append(loc)
+ # food.properties["points"] = 1
+ current_basic_food.append(loc)
Event.emit_signal("food_placed_new_food", food.properties["type"], food.properties["location"])
+func _get_random_food_type(type) -> int:
+ return randi() % type.size()
+
+
func _get_random_pos() -> Array:
var found_valid_loc: bool = false
var index: int
@@ -46,12 +49,12 @@ func _get_random_pos() -> Array:
while not found_valid_loc:
index = randi() % possible_food_locations.size()
location = possible_food_locations[index]
- if current_food.find(location) == -1:
+ if current_basic_food.find(location) == -1:
found_valid_loc = true
return [world_generator.get_centered_world_position(location), location]
func _on_food_eaten(properties: Dictionary) -> void:
- var index: int = current_food.find(properties["location"])
- current_food.remove(index)
+ var index: int = current_basic_food.find(properties["location"])
+ current_basic_food.remove(index)