summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Luevano Alvarado <david@luevano.xyz>2022-06-05 04:38:44 -0600
committerDavid Luevano Alvarado <david@luevano.xyz>2022-06-05 04:38:44 -0600
commite4423cc8490b7f5ec3449f568bf64e81f4d03248 (patch)
tree167f178e1197c21260f70eaffd0a3375742f3447 /src
parent36abc689d783774ce4f2d7b5a1bb621d8684be45 (diff)
add more food types, refactored code and tidy up stuff
Diffstat (limited to 'src')
-rw-r--r--src/entities/actors/snake/scripts/snake.gd23
-rw-r--r--src/entities/food/scenes/FoodManager.tscn4
-rw-r--r--src/entities/food/scenes/FoodSpecial.tscn16
-rw-r--r--src/entities/food/scripts/food.gd39
-rw-r--r--src/entities/food/scripts/food_basic.gd2
-rw-r--r--src/entities/food/scripts/food_manager.gd52
-rw-r--r--src/entities/food/scripts/food_special.gd16
-rw-r--r--src/entities/food/sprites/bunny.pngbin0 -> 242 bytes
-rw-r--r--src/entities/food/sprites/bunny.png.import35
-rw-r--r--src/entities/food/sprites/frog.pngbin0 -> 246 bytes
-rw-r--r--src/entities/food/sprites/frog.png.import35
-rw-r--r--src/entities/food/sprites/rat.pngbin0 -> 277 bytes
-rw-r--r--src/entities/food/sprites/rat.png.import35
-rw-r--r--src/entities/food/sprites/turtle.pngbin0 -> 258 bytes
-rw-r--r--src/entities/food/sprites/turtle.png.import35
-rw-r--r--src/event.gd5
-rw-r--r--src/game.gd2
-rw-r--r--src/global.gd4
-rw-r--r--src/project.godot14
-rw-r--r--src/stats.gd17
-rw-r--r--src/tools/score_manager/scenes/ScoreLabel.tscn2
-rw-r--r--src/tools/score_manager/scripts/score_label.gd3
-rw-r--r--src/tools/score_manager/scripts/score_manager.gd26
-rw-r--r--src/tools/world_generator/scenes/WorldGenerator.tscn1
-rw-r--r--src/tools/world_generator/scripts/walker_head.gd42
-rw-r--r--src/tools/world_generator/scripts/world_generator.gd10
-rw-r--r--src/ui/stats_display/scripts/stats_display.gd1
27 files changed, 340 insertions, 79 deletions
diff --git a/src/entities/actors/snake/scripts/snake.gd b/src/entities/actors/snake/scripts/snake.gd
index bae6e83..e5dfd08 100644
--- a/src/entities/actors/snake/scripts/snake.gd
+++ b/src/entities/actors/snake/scripts/snake.gd
@@ -15,12 +15,14 @@ var tail_segment: PathFollow2D
# didn't konw how to name this, basically holds the current path lenght
# whenever the add body segment, and we use this stack to add body parts
var body_segment_queue: Array
-# var distance_to_first_segment: float
+
+var debug: bool = false
func _ready():
set_physics_process(false)
set_process_input(false)
+ Event.connect("toggle_debug", self, "_on_toggle_debug")
Event.connect("snake_path_new_point", self, "_on_snake_path_new_point")
Event.connect("snake_add_new_segment", self, "_on_snake_add_new_segment")
Event.connect("snake_added_new_segment", self, "_on_snake_added_new_segment")
@@ -41,14 +43,10 @@ func _physics_process(delta: float) -> void:
# print(distance_to_first_segment)
-func _input(event: InputEvent) -> void:
- if event.is_action_pressed("add_body_part"):
- _add_segment_to_queue()
-
-
-# func _draw() -> void:
-# if path.curve.get_baked_points().size() >= 2:
-# draw_polyline(path.curve.get_baked_points(), Color.aquamarine, 1, true)
+func _draw() -> void:
+ if debug:
+ if path.curve.get_baked_points().size() >= 2:
+ draw_polyline(path.curve.get_baked_points(), Color.aquamarine, 1, true)
func _add_new_segment() -> void:
@@ -95,7 +93,8 @@ func _add_segment_to_queue() -> void:
func _on_snake_path_new_point(coordinates: Vector2) -> void:
path.curve.add_point(coordinates)
# update call is to draw curve as there are new points to the path's curve
- # update()
+ if debug:
+ update()
if not finished_adding_initial_segments:
if current_body_segments < Global.SNAKE_INITIAL_SEGMENTS:
@@ -119,3 +118,7 @@ func _on_snake_added_initial_segments() -> void:
func _on_snake_add_new_segment(amount: int) -> void:
for i in amount:
_add_segment_to_queue()
+
+
+func _on_toggle_debug() -> void:
+ debug = !debug
diff --git a/src/entities/food/scenes/FoodManager.tscn b/src/entities/food/scenes/FoodManager.tscn
index e56b9de..73bde55 100644
--- a/src/entities/food/scenes/FoodManager.tscn
+++ b/src/entities/food/scenes/FoodManager.tscn
@@ -1,8 +1,10 @@
-[gd_scene load_steps=3 format=2]
+[gd_scene load_steps=4 format=2]
[ext_resource path="res://entities/food/scenes/FoodBasic.tscn" type="PackedScene" id=1]
[ext_resource path="res://entities/food/scripts/food_manager.gd" type="Script" id=2]
+[ext_resource path="res://entities/food/scenes/FoodSpecial.tscn" type="PackedScene" id=3]
[node name="FoodManager" type="Node2D"]
script = ExtResource( 2 )
FOOD_BASIC = ExtResource( 1 )
+FOOD_SPECIAL = ExtResource( 3 )
diff --git a/src/entities/food/scenes/FoodSpecial.tscn b/src/entities/food/scenes/FoodSpecial.tscn
new file mode 100644
index 0000000..1b8c4e6
--- /dev/null
+++ b/src/entities/food/scenes/FoodSpecial.tscn
@@ -0,0 +1,16 @@
+[gd_scene load_steps=3 format=2]
+
+[ext_resource path="res://entities/food/scripts/food_special.gd" type="Script" id=2]
+
+[sub_resource type="CircleShape2D" id=1]
+radius = 8.0
+
+[node name="FoodSpecial" type="Area2D"]
+collision_layer = 256
+collision_mask = 0
+script = ExtResource( 2 )
+
+[node name="Sprite" type="Sprite" parent="."]
+
+[node name="Collision" type="CollisionShape2D" parent="."]
+shape = SubResource( 1 )
diff --git a/src/entities/food/scripts/food.gd b/src/entities/food/scripts/food.gd
index aa5207f..386f0e5 100644
--- a/src/entities/food/scripts/food.gd
+++ b/src/entities/food/scripts/food.gd
@@ -7,13 +7,9 @@ var texture: Dictionary
var timer: Timer
var properties: Dictionary
-var points: int = 1
-var time_to_live: float = -1.0
func _ready():
- randomize_stats()
- _set_properties()
timer = Timer.new()
timer.one_shot = true
@@ -21,35 +17,24 @@ func _ready():
connect("body_entered", self, "_on_body_entered")
-func set_type(type: int) -> void:
- set_property("type", type)
- _sprite.texture = texture[type]
+func update_texture() -> void:
+ _sprite.texture = texture[properties["type"]]
-func set_location(loc: Vector2) -> void:
- set_property("location", loc)
+func set_properties(pos: Vector2, loc: Vector2, special: bool, type: int, points: int=1, ttl: float = -1.0) -> void:
+ properties["global_position"] = pos
+ global_position = pos
+ properties["location"] = loc
+ properties["special"] = special
+ properties["type"] = type
-
-func set_timer(time: float) -> void:
- time_to_live = time
- if time_to_live != -1.0:
- timer.wait_time = time_to_live
+ properties["points"] = points
+ properties["ttl"] = ttl
+ if properties["ttl"] != -1.0:
+ timer.wait_time = properties["ttl"]
timer.start()
-func set_property(property: String, value) -> void:
- properties[property] = value
-
-
-func _set_properties() -> void:
- set_property("points", points)
- set_property("global_position", global_position)
-
-
-func randomize_stats() -> void:
- points = int(rand_range(1, 10))
-
-
func _on_body_entered(body: Node) -> void:
Event.emit_signal("food_eaten", properties)
queue_free()
diff --git a/src/entities/food/scripts/food_basic.gd b/src/entities/food/scripts/food_basic.gd
index 032ec23..8090cdc 100644
--- a/src/entities/food/scripts/food_basic.gd
+++ b/src/entities/food/scripts/food_basic.gd
@@ -9,4 +9,4 @@ enum Type {
func _ready():
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
+ texture[Type.BANANA] = preload("res://entities/food/sprites/banana.png")
diff --git a/src/entities/food/scripts/food_manager.gd b/src/entities/food/scripts/food_manager.gd
index bbe27be..a605f9e 100644
--- a/src/entities/food/scripts/food_manager.gd
+++ b/src/entities/food/scripts/food_manager.gd
@@ -2,39 +2,66 @@ class_name FoodManager
extends Node2D
export(PackedScene) var FOOD_BASIC: PackedScene
+export(PackedScene) var FOOD_SPECIAL: 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()
+# needed to know what food is available to setup
+var stats: Stats = SaveData.get_stats()
+
var current_basic_food: Array = []
+var current_special_food: Array = []
+var max_basic_food: int
+var max_special_food: int
func _ready():
randomize()
+ max_basic_food = int(possible_food_locations.size() * Global.MAX_BASIC_FOOD)
+ max_special_food = int(possible_food_locations.size() * Global.MAX_SPECIAL_FOOD)
Event.connect("food_eaten", self, "_on_food_eaten")
func _process(delta) -> void:
- if current_basic_food.size() < Global.MAX_BASIC_FOOD:
+ if current_basic_food.size() < max_basic_food:
_place_new_basic_food()
+ if current_special_food.size() < max_special_food:
+ _place_new_special_food()
+
func _place_new_basic_food() -> void:
var food: FoodBasic = FOOD_BASIC.instance()
var type: int = _get_random_food_type(FoodBasic.Type)
- Event.emit_signal("food_placing_new_food", type)
+ Event.emit_signal("food_placing_new_food", false, 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.set_properties(pos, loc, false, type)
add_child(food)
- food.set_type(type)
- food.set_location(loc)
- # food.properties["points"] = 1
+ food.update_texture()
current_basic_food.append(loc)
- Event.emit_signal("food_placed_new_food", food.properties["type"], food.properties["location"])
+ Event.emit_signal("food_placed_new_food", food.properties)
+
+
+func _place_new_special_food() -> void:
+ var food: FoodSpecial = FOOD_SPECIAL.instance()
+ var type: int = _get_random_food_type(FoodSpecial.Type)
+ Event.emit_signal("food_placing_new_food", true, 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.set_properties(pos, loc, true, type, Global.POINTS_TO_GROW)
+ add_child(food)
+ food.update_texture()
+ current_special_food.append(loc)
+ Event.emit_signal("food_placed_new_food", food.properties)
func _get_random_food_type(type) -> int:
@@ -49,12 +76,17 @@ func _get_random_pos() -> Array:
while not found_valid_loc:
index = randi() % possible_food_locations.size()
location = possible_food_locations[index]
- if current_basic_food.find(location) == -1:
+ if current_basic_food.find(location) == -1 and current_special_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_basic_food.find(properties["location"])
- current_basic_food.remove(index)
+ var index: int
+ if properties["special"]:
+ index = current_special_food.find(properties["location"])
+ current_special_food.remove(index)
+ else:
+ index = current_basic_food.find(properties["location"])
+ current_basic_food.remove(index)
diff --git a/src/entities/food/scripts/food_special.gd b/src/entities/food/scripts/food_special.gd
new file mode 100644
index 0000000..c2fde78
--- /dev/null
+++ b/src/entities/food/scripts/food_special.gd
@@ -0,0 +1,16 @@
+class_name FoodSpecial
+extends Food
+
+enum Type {
+ BUNNY,
+ FROG,
+ TURTLE,
+ RAT
+}
+
+
+func _ready():
+ texture[Type.BUNNY] = preload("res://entities/food/sprites/bunny.png")
+ texture[Type.FROG] = preload("res://entities/food/sprites/frog.png")
+ texture[Type.TURTLE] = preload("res://entities/food/sprites/turtle.png")
+ texture[Type.RAT] = preload("res://entities/food/sprites/rat.png")
diff --git a/src/entities/food/sprites/bunny.png b/src/entities/food/sprites/bunny.png
new file mode 100644
index 0000000..900ab6c
--- /dev/null
+++ b/src/entities/food/sprites/bunny.png
Binary files differ
diff --git a/src/entities/food/sprites/bunny.png.import b/src/entities/food/sprites/bunny.png.import
new file mode 100644
index 0000000..435f4b3
--- /dev/null
+++ b/src/entities/food/sprites/bunny.png.import
@@ -0,0 +1,35 @@
+[remap]
+
+importer="texture"
+type="StreamTexture"
+path="res://.import/bunny.png-98d2abf876bf5ec1713a2e3b2c3305b3.stex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://entities/food/sprites/bunny.png"
+dest_files=[ "res://.import/bunny.png-98d2abf876bf5ec1713a2e3b2c3305b3.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
diff --git a/src/entities/food/sprites/frog.png b/src/entities/food/sprites/frog.png
new file mode 100644
index 0000000..4057647
--- /dev/null
+++ b/src/entities/food/sprites/frog.png
Binary files differ
diff --git a/src/entities/food/sprites/frog.png.import b/src/entities/food/sprites/frog.png.import
new file mode 100644
index 0000000..ea33961
--- /dev/null
+++ b/src/entities/food/sprites/frog.png.import
@@ -0,0 +1,35 @@
+[remap]
+
+importer="texture"
+type="StreamTexture"
+path="res://.import/frog.png-f3af79da776ffc12de65d12bcff92073.stex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://entities/food/sprites/frog.png"
+dest_files=[ "res://.import/frog.png-f3af79da776ffc12de65d12bcff92073.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
diff --git a/src/entities/food/sprites/rat.png b/src/entities/food/sprites/rat.png
new file mode 100644
index 0000000..b63923f
--- /dev/null
+++ b/src/entities/food/sprites/rat.png
Binary files differ
diff --git a/src/entities/food/sprites/rat.png.import b/src/entities/food/sprites/rat.png.import
new file mode 100644
index 0000000..92456c9
--- /dev/null
+++ b/src/entities/food/sprites/rat.png.import
@@ -0,0 +1,35 @@
+[remap]
+
+importer="texture"
+type="StreamTexture"
+path="res://.import/rat.png-efc63e12fde232a4cdae97b805791ec6.stex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://entities/food/sprites/rat.png"
+dest_files=[ "res://.import/rat.png-efc63e12fde232a4cdae97b805791ec6.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
diff --git a/src/entities/food/sprites/turtle.png b/src/entities/food/sprites/turtle.png
new file mode 100644
index 0000000..e901da8
--- /dev/null
+++ b/src/entities/food/sprites/turtle.png
Binary files differ
diff --git a/src/entities/food/sprites/turtle.png.import b/src/entities/food/sprites/turtle.png.import
new file mode 100644
index 0000000..cc452c7
--- /dev/null
+++ b/src/entities/food/sprites/turtle.png.import
@@ -0,0 +1,35 @@
+[remap]
+
+importer="texture"
+type="StreamTexture"
+path="res://.import/turtle.png-fd98564ac1dff9497a69b2772482c676.stex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://entities/food/sprites/turtle.png"
+dest_files=[ "res://.import/turtle.png-fd98564ac1dff9497a69b2772482c676.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
diff --git a/src/event.gd b/src/event.gd
index cc15684..6c817c8 100644
--- a/src/event.gd
+++ b/src/event.gd
@@ -3,6 +3,7 @@ extends Node
signal game_start
signal game_restart
signal game_over
+signal toggle_debug
signal snake_path_new_point(coordinates)
signal snake_add_new_segment(amount)
@@ -13,8 +14,8 @@ signal snake_segment_body_entered(body)
signal snake_rotated
signal snake_growth_progress(progress)
-signal food_placing_new_food(type)
-signal food_placed_new_food(type, location)
+signal food_placing_new_food(special, type)
+signal food_placed_new_food(properties)
signal food_eaten(properties)
signal food_timed_out(properties)
diff --git a/src/game.gd b/src/game.gd
index 218d975..0135b76 100644
--- a/src/game.gd
+++ b/src/game.gd
@@ -12,6 +12,8 @@ func _ready() -> void:
func _input(event: InputEvent) -> void:
if event.is_action_pressed("restart"):
Event.emit_signal("game_restart")
+ if event.is_action_pressed("debug"):
+ Event.emit_signal("toggle_debug")
func _on_snake_segment_body_entered(body: Node) -> void:
diff --git a/src/global.gd b/src/global.gd
index 01d3388..112f16c 100644
--- a/src/global.gd
+++ b/src/global.gd
@@ -16,4 +16,6 @@ var SNAKE_SEGMENT_SIZE: float = 6.0
var POINTS_TO_GROW: int = 10
-var MAX_BASIC_FOOD: int = 30
+# percentage of the available tiles
+var MAX_BASIC_FOOD: float = 0.05
+var MAX_SPECIAL_FOOD: float = 0.01
diff --git a/src/project.godot b/src/project.godot
index eb70498..7ad8041 100644
--- a/src/project.godot
+++ b/src/project.godot
@@ -24,6 +24,11 @@ _global_script_classes=[ {
"language": "GDScript",
"path": "res://entities/food/scripts/food_manager.gd"
}, {
+"base": "Food",
+"class": "FoodSpecial",
+"language": "GDScript",
+"path": "res://entities/food/scripts/food_special.gd"
+}, {
"base": "Node",
"class": "GifDecoder",
"language": "GDScript",
@@ -68,6 +73,7 @@ _global_script_class_icons={
"Food": "",
"FoodBasic": "",
"FoodManager": "",
+"FoodSpecial": "",
"GifDecoder": "",
"GifRecorder": "res://addons/GifMaker/gif.svg",
"GifRectangle": "res://addons/GifMaker/GifRectangle.svg",
@@ -159,14 +165,14 @@ move_right={
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":0,"physical_scancode":68,"unicode":0,"echo":false,"script":null)
]
}
-add_body_part={
+restart={
"deadzone": 0.5,
-"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":0,"physical_scancode":32,"unicode":0,"echo":false,"script":null)
+"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":82,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
]
}
-restart={
+debug={
"deadzone": 0.5,
-"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":82,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
+"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":80,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
]
}
diff --git a/src/stats.gd b/src/stats.gd
index 6906221..d789341 100644
--- a/src/stats.gd
+++ b/src/stats.gd
@@ -46,6 +46,17 @@ func get_stats() -> Dictionary:
func set_stats(stats: Dictionary) -> void:
- var current_stats: Dictionary = get_stats()
- for i in stats:
- current_stats[i] = stats[i]
+ points = stats["points"]
+ segments = stats["segments"]
+ dash_points = stats["dash_points"]
+ slow_points = stats["slow_points"]
+ jump_points = stats["jump_points"]
+ dash_segments = stats["dash_segments"]
+ slow_segments = stats["slow_segments"]
+ jump_segments = stats["jump_segments"]
+ dash_percentage = stats["dash_percentage"]
+ slow_percentage = stats["slow_percentage"]
+ jump_lenght = stats["jump_lenght"]
+ trait_dash = stats["trait_dash"]
+ trait_slow = stats["trait_slow"]
+ trait_jump = stats["trait_jump"]
diff --git a/src/tools/score_manager/scenes/ScoreLabel.tscn b/src/tools/score_manager/scenes/ScoreLabel.tscn
index 365aff1..0a078e1 100644
--- a/src/tools/score_manager/scenes/ScoreLabel.tscn
+++ b/src/tools/score_manager/scenes/ScoreLabel.tscn
@@ -18,7 +18,7 @@ margin_right = 12.0
margin_bottom = 13.0
custom_colors/font_color_shadow = Color( 0, 0, 0, 1 )
custom_fonts/font = ExtResource( 1 )
-text = "x1"
+text = "+1"
[node name="Timer" type="Timer" parent="Hbox/Label"]
one_shot = true
diff --git a/src/tools/score_manager/scripts/score_label.gd b/src/tools/score_manager/scripts/score_label.gd
index f1ccb9d..13a34c8 100644
--- a/src/tools/score_manager/scripts/score_label.gd
+++ b/src/tools/score_manager/scripts/score_label.gd
@@ -14,7 +14,7 @@ var texture: Dictionary = {
}
var alive_time: float = 2.0
-var fmt: String = "x%s"
+var fmt: String = "+%s"
var points: int
@@ -25,7 +25,6 @@ func _ready():
func set_properties(_points: int, color: Color, location: Vector2, type: int=-1) -> void:
- print("Constructing")
points = _points
label.text = fmt % points
label.add_color_override("font_color", color)
diff --git a/src/tools/score_manager/scripts/score_manager.gd b/src/tools/score_manager/scripts/score_manager.gd
index 27a8dd4..492ceb5 100644
--- a/src/tools/score_manager/scripts/score_manager.gd
+++ b/src/tools/score_manager/scripts/score_manager.gd
@@ -11,6 +11,7 @@ var mutation_stats: Array = [
]
var last_snake_pos: Vector2 = Vector2.ZERO
+var snake_location_offset: Vector2 = Vector2(8.0, 8.0)
func _ready():
@@ -55,7 +56,7 @@ func _spawn_added_segment_text(amount: int) -> void:
if amount > 0:
var label: ScoreLabel = SCORE_LABEL.instance()
add_child(label)
- label.set_properties(amount, Color.green, last_snake_pos, ScoreLabel.Type.BODY_SEGMENT)
+ label.set_properties(amount, Color.green, last_snake_pos + snake_location_offset, ScoreLabel.Type.BODY_SEGMENT)
func _on_snake_path_new_point(coordinates: Vector2) -> void:
@@ -63,5 +64,26 @@ func _on_snake_path_new_point(coordinates: Vector2) -> void:
func _on_game_over() -> void:
- print("Show comparison.")
+ var max_stats: Stats = _get_max_stats()
+ SaveData.save_data(max_stats)
Event.emit_signal("display_stats", initial_stats, stats, mutation_stats)
+
+
+func _get_max_stats() -> Stats:
+ var old_stats_dict: Dictionary = initial_stats.get_stats()
+ var new_stats_dict: Dictionary = stats.get_stats()
+ var max_stats: Stats = Stats.new()
+ var max_stats_dict: Dictionary = max_stats.get_stats()
+ var bool_stats: Array = [
+ "trait_dash",
+ "trait_slow",
+ "trait_jump"
+ ]
+
+ for i in old_stats_dict:
+ if bool_stats.has(i):
+ max_stats_dict[i] = old_stats_dict[i] or new_stats_dict[i]
+ else:
+ max_stats_dict[i] = max(old_stats_dict[i], new_stats_dict[i])
+ max_stats.set_stats(max_stats_dict)
+ return max_stats
diff --git a/src/tools/world_generator/scenes/WorldGenerator.tscn b/src/tools/world_generator/scenes/WorldGenerator.tscn
index 32ed939..824d298 100644
--- a/src/tools/world_generator/scenes/WorldGenerator.tscn
+++ b/src/tools/world_generator/scenes/WorldGenerator.tscn
@@ -48,7 +48,6 @@ points = PoolVector2Array( 16, 16, 0, 16, 0, 0, 16, 0 )
[node name="WorldGenerator" type="Node2D"]
script = ExtResource( 5 )
-TILEMAP_NP = NodePath("TileMap")
[node name="TileMap" type="TileMap" parent="."]
tile_set = SubResource( 1 )
diff --git a/src/tools/world_generator/scripts/walker_head.gd b/src/tools/world_generator/scripts/walker_head.gd
index dc71db1..2ad9650 100644
--- a/src/tools/world_generator/scripts/walker_head.gd
+++ b/src/tools/world_generator/scripts/walker_head.gd
@@ -2,8 +2,8 @@ extends Node2D
export(NodePath) var TILEMAP_NP: NodePath
export(PackedScene) var WALKER_UNIT_NP: PackedScene
-export(int, 5, 100, 1) var STARTING_UNIT_COUNT: int = 5
-export(int, 3, 10, 1) var INITIAL_SAFE_ZONE_SIZE: int = 3
+export(int, 4, 100, 1) var STARTING_UNIT_COUNT: int = 6
+export(int, 2, 10, 1) var INITIAL_SAFE_ZONE_SIZE: int = 2
onready var tilemap: TileMap = get_node(TILEMAP_NP)
@@ -23,6 +23,15 @@ func _ready() -> void:
_fill_empty_space()
+func get_cells_around(size: int=INITIAL_SAFE_ZONE_SIZE) -> Array:
+ var locations: Array = []
+ for i in range(-size, size):
+ for j in range(-size, size):
+ locations.append(Vector2(i, j))
+
+ return locations
+
+
func _place_safe_zone() -> void:
var size: int = INITIAL_SAFE_ZONE_SIZE
for i in range(-size, size):
@@ -44,27 +53,40 @@ func _spawn_walker_unit(spawn_position: Vector2) -> void:
func _fill_empty_space() -> void:
+ var locations: Array = _get_empty_cells_location()
+ for location in locations:
+ tilemap.set_cellv(location, Global.WORLD_TILE_WALL)
+
+
+func _get_empty_cells_location() -> Array:
+ var locations: Array = []
var rect: Rect2 = tilemap.get_used_rect()
var margin: int = map_margin
for x in range(-margin, rect.size.x + margin):
- for y in range (-margin, rect.size.y + margin ):
- var poses: Vector2= Vector2(rect.position.x + x, rect.position.y + y)
- if tilemap.get_cell(int(poses.x), int(poses.y)) == TileMap.INVALID_CELL:
- tilemap.set_cellv(poses, Global.WORLD_TILE_WALL)
+ for y in range (-margin, rect.size.y + margin):
+ var location: Vector2 = Vector2(rect.position.x + x, rect.position.y + y)
+ if tilemap.get_cell(int(location.x), int(location.y)) == TileMap.INVALID_CELL:
+ locations.append(location)
+
+ return locations
func _on_world_gen_walker_started(id: int) -> void:
- print("Walker unit %s started." % id)
+ # print("Walker unit %s started." % id)
+ pass
func _on_world_gen_walker_finished(id: int) -> void:
- print("Walker unit %s finished." % id)
+ # print("Walker unit %s finished." % id)
+ pass
func _on_world_gen_walker_died(id: int) -> void:
- print("Walker unit %s died." % id)
+ # print("Walker unit %s died." % id)
+ pass
func _on_world_gen_spawn_walker_unit(location: Vector2) -> void:
- print("Spawning new walking unit.")
+ # print("Spawning new walking unit.")
+ pass
_spawn_walker_unit(location)
diff --git a/src/tools/world_generator/scripts/world_generator.gd b/src/tools/world_generator/scripts/world_generator.gd
index 5e8626b..5de84ea 100644
--- a/src/tools/world_generator/scripts/world_generator.gd
+++ b/src/tools/world_generator/scripts/world_generator.gd
@@ -1,11 +1,15 @@
extends Node2D
-export(NodePath) var TILEMAP_NP: NodePath
-onready var tilemap: TileMap = get_node(TILEMAP_NP)
+onready var tilemap: TileMap = $TileMap
+onready var walker_head: Node2D = $WalkerHead
func get_valid_map_coords() -> Array:
- return tilemap.get_used_cells_by_id(Global.WORLD_TILE_PATH)
+ var safe_area: Array = walker_head.get_cells_around()
+ var cells_used: Array = tilemap.get_used_cells_by_id(Global.WORLD_TILE_PATH)
+ for location in safe_area:
+ cells_used.erase(location)
+ return cells_used
func get_centered_world_position(location: Vector2) -> Vector2:
diff --git a/src/ui/stats_display/scripts/stats_display.gd b/src/ui/stats_display/scripts/stats_display.gd
index f1f77ef..f1f17e8 100644
--- a/src/ui/stats_display/scripts/stats_display.gd
+++ b/src/ui/stats_display/scripts/stats_display.gd
@@ -17,7 +17,6 @@ func _on_display_stats(old_stats: Stats, new_stats: Stats, mut_stats: Array) ->
var mut_stats_dict: Array = []
for i in mut_stats:
mut_stats_dict.append(i)
- print(i)
var type: int
var prefix: String