summaryrefslogtreecommitdiff
path: root/src/entities/food
diff options
context:
space:
mode:
Diffstat (limited to 'src/entities/food')
-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
-rw-r--r--src/entities/food/sprites/apple.pngbin135 -> 155 bytes
-rw-r--r--src/entities/food/sprites/banana.pngbin0 -> 184 bytes
-rw-r--r--src/entities/food/sprites/banana.png.import35
6 files changed, 55 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)
diff --git a/src/entities/food/sprites/apple.png b/src/entities/food/sprites/apple.png
index 7111450..2eb9080 100644
--- a/src/entities/food/sprites/apple.png
+++ b/src/entities/food/sprites/apple.png
Binary files differ
diff --git a/src/entities/food/sprites/banana.png b/src/entities/food/sprites/banana.png
new file mode 100644
index 0000000..afe7b51
--- /dev/null
+++ b/src/entities/food/sprites/banana.png
Binary files differ
diff --git a/src/entities/food/sprites/banana.png.import b/src/entities/food/sprites/banana.png.import
new file mode 100644
index 0000000..e4da833
--- /dev/null
+++ b/src/entities/food/sprites/banana.png.import
@@ -0,0 +1,35 @@
+[remap]
+
+importer="texture"
+type="StreamTexture"
+path="res://.import/banana.png-790b92b84b3b62d7a7828565ae8ed4ec.stex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://entities/food/sprites/banana.png"
+dest_files=[ "res://.import/banana.png-790b92b84b3b62d7a7828565ae8ed4ec.stex" ]
+
+[params]
+
+compress/mode=0
+compress/lossy_quality=0.7
+compress/hdr_mode=0
+compress/bptc_ldr=0
+compress/normal_map=0
+flags/repeat=0
+flags/filter=false
+flags/mipmaps=false
+flags/anisotropic=false
+flags/srgb=2
+process/fix_alpha_border=false
+process/premult_alpha=false
+process/HDR_as_SRGB=false
+process/invert_color=false
+process/normal_map_invert_y=false
+stream=false
+size_limit=0
+detect_3d=false
+svg/scale=1.0