PRIDE SNAKES!
							parent
							
								
									e5d6f3d786
								
							
						
					
					
						commit
						ab7721f1fa
					
				| 
						 | 
				
			
			@ -1,13 +1,11 @@
 | 
			
		|||
[gd_scene load_steps=4 format=3 uid="uid://d0okbjqyaoe0w"]
 | 
			
		||||
 | 
			
		||||
[ext_resource type="Script" uid="uid://cn4hlmm4qa8fg" path="res://Scripts/snake_part.gd" id="1_iuiyg"]
 | 
			
		||||
[ext_resource type="Texture2D" uid="uid://b0can5myhke8s" path="res://Sprites/snake_straight.png" id="2_hf2pu"]
 | 
			
		||||
 | 
			
		||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_hf2pu"]
 | 
			
		||||
size = Vector2(18, 18)
 | 
			
		||||
 | 
			
		||||
[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_kum7e"]
 | 
			
		||||
size = Vector2(40, 40)
 | 
			
		||||
 | 
			
		||||
[node name="SnakePart" type="Area2D" groups=["BlocksSpawn"]]
 | 
			
		||||
script = ExtResource("1_iuiyg")
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -15,7 +13,7 @@ script = ExtResource("1_iuiyg")
 | 
			
		|||
shape = SubResource("RectangleShape2D_hf2pu")
 | 
			
		||||
 | 
			
		||||
[node name="Sprite2D" type="Sprite2D" parent="."]
 | 
			
		||||
texture = SubResource("PlaceholderTexture2D_kum7e")
 | 
			
		||||
texture = ExtResource("2_hf2pu")
 | 
			
		||||
 | 
			
		||||
[node name="DownRayCast2D" type="RayCast2D" parent="."]
 | 
			
		||||
target_position = Vector2(0, 60)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,9 +4,11 @@ class_name SnakePart
 | 
			
		|||
const TILE_SIZE = 40
 | 
			
		||||
enum PartTypes {HEAD, BODY, TAIL}
 | 
			
		||||
enum States {ALIVE, DEAD, OUROBOROS, OLD_OUROBOROS}
 | 
			
		||||
const COLOURS = [Color.DARK_RED, Color.ORANGE_RED, Color.YELLOW, Color.WEB_GREEN, Color.BLUE, Color.REBECCA_PURPLE]
 | 
			
		||||
 | 
			
		||||
var part_type : PartTypes = PartTypes.HEAD
 | 
			
		||||
var state : States = States.ALIVE
 | 
			
		||||
var colour_index : int = 0
 | 
			
		||||
var current_direction : Vector2 = Vector2.RIGHT
 | 
			
		||||
var old_direction : Vector2 = Vector2.RIGHT
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -83,6 +85,7 @@ func _ready() -> void:
 | 
			
		|||
		# Set up a body part
 | 
			
		||||
		var body = snake_part_obj.instantiate()
 | 
			
		||||
		body.part_type = PartTypes.BODY
 | 
			
		||||
		body.colour_index = colour_index
 | 
			
		||||
		body.position = (position - current_direction * TILE_SIZE).snapped(Vector2.ONE * TILE_SIZE)
 | 
			
		||||
		next_part = body
 | 
			
		||||
		get_parent().add_child.call_deferred(body)
 | 
			
		||||
| 
						 | 
				
			
			@ -93,6 +96,7 @@ func _ready() -> void:
 | 
			
		|||
		# Set up a tail part
 | 
			
		||||
		var tail = snake_part_obj.instantiate()
 | 
			
		||||
		tail.part_type = PartTypes.TAIL
 | 
			
		||||
		tail.colour_index = colour_index
 | 
			
		||||
		tail.position = (position - current_direction * TILE_SIZE * 2).snapped(Vector2.ONE * TILE_SIZE)
 | 
			
		||||
		body.next_part = tail
 | 
			
		||||
		get_parent().add_child.call_deferred(tail)
 | 
			
		||||
| 
						 | 
				
			
			@ -107,6 +111,7 @@ func _ready() -> void:
 | 
			
		|||
		raycast_up.queue_free()
 | 
			
		||||
		raycast_left.queue_free()
 | 
			
		||||
		raycast_right.queue_free()
 | 
			
		||||
	update_sprite()
 | 
			
		||||
 | 
			
		||||
# TODO: Optimise this!
 | 
			
		||||
func generate_spawn_grid() -> Array[Vector2]:
 | 
			
		||||
| 
						 | 
				
			
			@ -197,6 +202,8 @@ func process_movement(new_direction : Vector2, prevent_movment : bool = false) -
 | 
			
		|||
 | 
			
		||||
func update_sprite() -> void:
 | 
			
		||||
	
 | 
			
		||||
	sprite.modulate = COLOURS[colour_index]
 | 
			
		||||
	
 | 
			
		||||
	# Set the sprite based on state and part type
 | 
			
		||||
	match part_type:
 | 
			
		||||
		PartTypes.HEAD:
 | 
			
		||||
| 
						 | 
				
			
			@ -287,6 +294,7 @@ func extend() -> void:
 | 
			
		|||
	var new_body = snake_part_obj.instantiate()
 | 
			
		||||
	new_body.part_type = PartTypes.BODY
 | 
			
		||||
	new_body.position = (position).snapped(Vector2.ONE * TILE_SIZE)
 | 
			
		||||
	new_body.colour_index = colour_index
 | 
			
		||||
	get_parent().add_child(new_body)
 | 
			
		||||
	on_movement.connect(new_body.process_movement)
 | 
			
		||||
	new_body.on_movement.connect(next_part.process_movement)
 | 
			
		||||
| 
						 | 
				
			
			@ -377,6 +385,7 @@ func spawn_new_snake() -> void:
 | 
			
		|||
	# Spawn in the new snake
 | 
			
		||||
	var new_head = snake_part_obj.instantiate()
 | 
			
		||||
	new_head.position = chosen_position.snapped(Vector2.ONE * TILE_SIZE)
 | 
			
		||||
	new_head.colour_index = colour_index + 1
 | 
			
		||||
	get_parent().add_child(new_head)
 | 
			
		||||
	new_head.on_ouroboros.connect(ouroboros)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue