apples om nom

This commit is contained in:
Tabby 2025-08-15 15:12:02 +10:00
parent 2c512d5764
commit ba4ede05fa
6 changed files with 68 additions and 2 deletions

View file

@ -4,3 +4,11 @@ Snake jam for SXSW Jam 2025
- make the z-order of the current room higher
- disable colliders (and maybe darken?) the non-active rooms
- [x] snake movement
- [x] eat apples
- [ ] grow snake
- [ ] apples go inisde
- [ ] inside stuff
- [ ] hunger/fuel system
- [ ] apple collsion detection

40
fieldManager.gd Normal file
View file

@ -0,0 +1,40 @@
extends Node2D
var apple_path : String = "res://prefabs/apple.tscn"
@export var map_size : Vector2 = Vector2(10,10)
@export var tile_size : Vector2 = Vector2(320,320)
@export var top_left : Vector2
@export var test_area : Area2D
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
Router.eat_apple.connect(spawn_apple)
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
#spawn_apple()
pass
func spawn_apple():
var new_apple : Area2D = load(apple_path).instantiate()
var spot_found : bool = false
var rand_pos : Vector2
rand_pos = Vector2(randi_range(0,map_size.x-1),randi_range(0,map_size.y-1))
## apple spawning collsion detection
#while (!spot_found):
#rand_pos = Vector2(randi_range(0,map_size.x-1),randi_range(0,map_size.y-1))
#test_area.global_position = Vector2(top_left.x + rand_pos.x * tile_size.x,top_left.y + rand_pos.y * tile_size.y)
#if test_area.has_overlapping_areas():
#print("possible collision")
#for i in test_area.get_overlapping_areas():
#if (i.is_in_group("apple") or i.is_in_group("wall")):
#spot_found = false
#else:
#spot_found = true
#else:
#spot_found = true
new_apple.global_position = Vector2(top_left.x + rand_pos.x * tile_size.x,top_left.y + rand_pos.y * tile_size.y)
add_child(new_apple)
pass

1
fieldManager.gd.uid Normal file
View file

@ -0,0 +1 @@
uid://cvsonvlgpi43g

View file

@ -67,6 +67,7 @@ func _on_eat_die_box_area_entered(area: Area2D) -> void:
if(area.is_in_group("apple")):
area.queue_free()
print("mmm tasty apple")
Router.eat_apple.emit()
if(area.is_in_group("wall")):
print("i die")
get_tree().get_root().process_mode = Node.PROCESS_MODE_DISABLED

View file

@ -1,6 +1,7 @@
extends Node
signal activate_seg(int)
signal eat_apple
var current_seg : Node2D
var cur_id : int = 0

View file

@ -1,14 +1,21 @@
[gd_scene load_steps=8 format=3 uid="uid://daqqurdrnk61h"]
[gd_scene load_steps=10 format=3 uid="uid://daqqurdrnk61h"]
[ext_resource type="Script" uid="uid://bue4xxejdsmqh" path="res://snakeManager.gd" id="1_6uqi0"]
[ext_resource type="PackedScene" uid="uid://bwoeu7ask0fck" path="res://prefabs/snake_segment.tscn" id="1_8uh7m"]
[ext_resource type="Script" uid="uid://cvsonvlgpi43g" path="res://fieldManager.gd" id="1_ehkex"]
[ext_resource type="Texture2D" uid="uid://b1sese4p8sck3" path="res://assets/smallMap.png" id="1_vbegm"]
[ext_resource type="PackedScene" uid="uid://cusdydgg4b1bo" path="res://prefabs/braincell.tscn" id="2_6uqi0"]
[ext_resource type="Script" uid="uid://b0djy8fmq4qjq" path="res://camera_2d.gd" id="5_ykrsh"]
[ext_resource type="PackedScene" uid="uid://qpjwodeafyno" path="res://prefabs/apple.tscn" id="6_g14j6"]
[ext_resource type="PackedScene" uid="uid://bl5py87o1qbgr" path="res://prefabs/wall.tscn" id="7_vbegm"]
[node name="Node2D" type="Node2D"]
[sub_resource type="CircleShape2D" id="CircleShape2D_ehkex"]
radius = 50.0
[node name="Node2D" type="Node2D" node_paths=PackedStringArray("test_area")]
script = ExtResource("1_ehkex")
top_left = Vector2(-1600, -1600)
test_area = NodePath("TestArea")
[node name="Sprite2D" type="Sprite2D" parent="."]
position = Vector2(-160, -160)
@ -69,3 +76,11 @@ rotation = 1.5708
[node name="Wall4" parent="." instance=ExtResource("7_vbegm")]
position = Vector2(1600, -160)
rotation = 1.5708
[node name="Marker2D" type="Marker2D" parent="."]
position = Vector2(-1600, -1600)
[node name="TestArea" type="Area2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="TestArea"]
shape = SubResource("CircleShape2D_ehkex")