Skip to content

Commit bdce796

Browse files
committed
fish moves slower when hungry, food has unique value
1 parent 124fa7e commit bdce796

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

fish.gd

+20-17
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
extends RigidBody2D
22

3-
@export var speed = 100
3+
var maxSpeed = 100
4+
var speed = maxSpeed
45

56
enum {IDLE, SWIM, FOOD}
67
var state = IDLE
78

89
var boredom = 0
10+
var boredomThreshold = 800
911
var tired = 0
12+
var tiredThreshold = 2000
1013
var hunger = 5000
14+
var hungerThreshold = 5000
1115
var direction = Vector2.ZERO
1216

1317
var velocity = Vector2.ZERO
@@ -47,25 +51,29 @@ func _process(delta):
4751

4852
func idle():
4953
boredom = boredom + rng.randi_range(0,5)
50-
if (boredom > 800):
54+
if (boredom > boredomThreshold):
5155
state = SWIM
5256
boredom = 0
5357
pass
5458

5559
func swim():
5660

57-
if (hunger>5000 && FoodGroup.get_children().size() > 0):
61+
if (hunger>hungerThreshold/2 && FoodGroup.get_children().size() > 0):
5862
state = FOOD
5963
return food()
6064

61-
if (tired == 0): direction = Vector2(rng.randi_range(-1,1), rng.randi_range(-1,1))
65+
if (tired == 0):
66+
direction = Vector2(rng.randi_range(-1,1), rng.randi_range(-1,1))
67+
if (hunger > hungerThreshold/2): speed = maxSpeed / 5
68+
else: speed = maxSpeed
6269

63-
apply_impulse(Vector2(direction.x/2,direction.y/5), Vector2(0.5,0.5))
70+
apply_impulse(Vector2(direction.x/100*speed,direction.y/500*speed), Vector2(0.5,0.5))
6471

6572
tired = tired + rng.randi_range(0,5)
66-
if (tired > 2000):
73+
if (tired > tiredThreshold):
6774
state = IDLE
6875
tired = 0
76+
if (hunger > hungerThreshold/2): tired = tiredThreshold/2
6977
pass
7078

7179
func food():
@@ -85,22 +93,17 @@ func food():
8593
direction = mouthCol.get_global_position().direction_to(closest_food.get_global_position())
8694
apply_impulse(Vector2(direction.x/2,direction.y/3), Vector2(0.5,0.5))
8795

88-
89-
#func _on_body_entered(body):
90-
# if body.name == "Food":
91-
# print("entered body")
92-
# hunger = 0
93-
# body.queue_free()
94-
9596
var fishSprites = ['black-bass','carp','gargle','horse-mackerel','loach','pond-smelt','rainbow-trout','red-snapper','sockeye-salmon','yellow-tang']
9697

9798
func _input(event):
9899
if (event.is_action_released("ChangeFish")):
99100
var randomFishSprite = rng.randi_range(0,fishSprites.size()-1)
100101
sprite.texture = load("res://art/fish/"+fishSprites[randomFishSprite]+".png")
101102

102-
func _on_fish_mouth_body_shape_entered(body_rid, body, body_shape_index, local_shape_index):
103-
if body.name == "Food":
103+
func _on_fish_mouth_body_shape_entered(body_rid, collidedObject, body_shape_index, local_shape_index):
104+
if collidedObject.name == "Food":
104105
print("got good")
105-
#hunger = 0
106-
body.queue_free()
106+
hunger = hunger - collidedObject.value
107+
if (hunger < 0): hunger = 0
108+
print("healed fish hunger",collidedObject.value, "now", hunger)
109+
collidedObject.queue_free()

food.gd

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
extends RigidBody2D
22

3+
@export var value = 3000
4+
35
func _process(delta):
46
if (self.position.y > 270):
57
queue_free()

0 commit comments

Comments
 (0)