Adds growth value to fruit to allow for more rapid growth of the snake
parent
7de5b50884
commit
fefd1aa015
|
@ -16,3 +16,19 @@ shape = SubResource("RectangleShape2D_hf2pu")
|
||||||
|
|
||||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||||
texture = SubResource("PlaceholderTexture2D_kum7e")
|
texture = SubResource("PlaceholderTexture2D_kum7e")
|
||||||
|
|
||||||
|
[node name="Label" type="Label" parent="."]
|
||||||
|
anchors_preset = 8
|
||||||
|
anchor_left = 0.5
|
||||||
|
anchor_top = 0.5
|
||||||
|
anchor_right = 0.5
|
||||||
|
anchor_bottom = 0.5
|
||||||
|
offset_left = -20.0
|
||||||
|
offset_top = -11.5
|
||||||
|
offset_right = 20.0
|
||||||
|
offset_bottom = 11.5
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
text = "1"
|
||||||
|
horizontal_alignment = 1
|
||||||
|
vertical_alignment = 1
|
||||||
|
|
|
@ -5,6 +5,13 @@ const TILE_SIZE = 20
|
||||||
|
|
||||||
var all_positions : Array[Vector2] = []
|
var all_positions : Array[Vector2] = []
|
||||||
|
|
||||||
|
const possible_growth_amounts = [1,1,1,3,3,5,10]
|
||||||
|
|
||||||
|
var growth_amount : int = 1
|
||||||
|
|
||||||
|
@onready
|
||||||
|
var label : Label = $Label
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
var level : Area2D = get_tree().get_first_node_in_group("Level")
|
var level : Area2D = get_tree().get_first_node_in_group("Level")
|
||||||
var x_bounds : Vector2 = level.position.x * Vector2.ONE + Vector2(-TILE_SIZE, TILE_SIZE) * level.scale.x / 2
|
var x_bounds : Vector2 = level.position.x * Vector2.ONE + Vector2(-TILE_SIZE, TILE_SIZE) * level.scale.x / 2
|
||||||
|
@ -31,3 +38,5 @@ func respawn() -> void:
|
||||||
var chosen_position = possible_positions.pick_random()
|
var chosen_position = possible_positions.pick_random()
|
||||||
|
|
||||||
position = chosen_position
|
position = chosen_position
|
||||||
|
growth_amount = possible_growth_amounts.pick_random()
|
||||||
|
label.text = str(growth_amount)
|
||||||
|
|
|
@ -30,6 +30,7 @@ var timer_ref : Timer = $"../Timer"
|
||||||
|
|
||||||
var next_part : SnakePart = null
|
var next_part : SnakePart = null
|
||||||
var skip_next_move_propagation : bool = false
|
var skip_next_move_propagation : bool = false
|
||||||
|
var queued_growth : int = 0
|
||||||
|
|
||||||
signal do_movement(new_dir)
|
signal do_movement(new_dir)
|
||||||
|
|
||||||
|
@ -69,6 +70,8 @@ func process_movement(new_direction : Vector2) -> void:
|
||||||
# The head needs to check if we are about to collide with something
|
# The head needs to check if we are about to collide with something
|
||||||
if part_type == PartTypes.HEAD:
|
if part_type == PartTypes.HEAD:
|
||||||
check_movement()
|
check_movement()
|
||||||
|
if queued_growth:
|
||||||
|
extend()
|
||||||
|
|
||||||
# Update the position of this part
|
# Update the position of this part
|
||||||
position = (position + current_direction * TILE_SIZE).snapped(Vector2.ONE * TILE_SIZE)
|
position = (position + current_direction * TILE_SIZE).snapped(Vector2.ONE * TILE_SIZE)
|
||||||
|
@ -106,11 +109,13 @@ func check_movement() -> void:
|
||||||
match object_in_path.part_type:
|
match object_in_path.part_type:
|
||||||
PartTypes.BODY:
|
PartTypes.BODY:
|
||||||
lose_game()
|
lose_game()
|
||||||
|
PartTypes.DEAD:
|
||||||
|
lose_game()
|
||||||
PartTypes.TAIL:
|
PartTypes.TAIL:
|
||||||
ouroboros()
|
ouroboros()
|
||||||
if object_in_path is Fruit:
|
if object_in_path is Fruit:
|
||||||
|
queued_growth += object_in_path.growth_amount
|
||||||
object_in_path.respawn()
|
object_in_path.respawn()
|
||||||
extend()
|
|
||||||
|
|
||||||
func extend() -> void:
|
func extend() -> void:
|
||||||
# Remove old connection to previous next part
|
# Remove old connection to previous next part
|
||||||
|
@ -134,6 +139,9 @@ func extend() -> void:
|
||||||
# Mark the next movement to not propagate the movement down the chain
|
# Mark the next movement to not propagate the movement down the chain
|
||||||
skip_next_move_propagation = true
|
skip_next_move_propagation = true
|
||||||
|
|
||||||
|
# Mark the growth step as done
|
||||||
|
queued_growth -= 1
|
||||||
|
|
||||||
|
|
||||||
func lose_game() -> void:
|
func lose_game() -> void:
|
||||||
# You lose!
|
# You lose!
|
||||||
|
|
Loading…
Reference in New Issue