1
1
extends RigidBody2D
2
2
3
- @export var speed = 100
3
+ var maxSpeed = 100
4
+ var speed = maxSpeed
4
5
5
6
enum {IDLE , SWIM , FOOD }
6
7
var state = IDLE
7
8
8
9
var boredom = 0
10
+ var boredomThreshold = 800
9
11
var tired = 0
12
+ var tiredThreshold = 2000
10
13
var hunger = 5000
14
+ var hungerThreshold = 5000
11
15
var direction = Vector2 .ZERO
12
16
13
17
var velocity = Vector2 .ZERO
@@ -47,25 +51,29 @@ func _process(delta):
47
51
48
52
func idle ():
49
53
boredom = boredom + rng .randi_range (0 ,5 )
50
- if (boredom > 800 ):
54
+ if (boredom > boredomThreshold ):
51
55
state = SWIM
52
56
boredom = 0
53
57
pass
54
58
55
59
func swim ():
56
60
57
- if (hunger > 5000 && FoodGroup .get_children ().size () > 0 ):
61
+ if (hunger > hungerThreshold / 2 && FoodGroup .get_children ().size () > 0 ):
58
62
state = FOOD
59
63
return food ()
60
64
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
62
69
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 ))
64
71
65
72
tired = tired + rng .randi_range (0 ,5 )
66
- if (tired > 2000 ):
73
+ if (tired > tiredThreshold ):
67
74
state = IDLE
68
75
tired = 0
76
+ if (hunger > hungerThreshold / 2 ): tired = tiredThreshold / 2
69
77
pass
70
78
71
79
func food ():
@@ -85,22 +93,17 @@ func food():
85
93
direction = mouthCol .get_global_position ().direction_to (closest_food .get_global_position ())
86
94
apply_impulse (Vector2 (direction .x / 2 ,direction .y / 3 ), Vector2 (0.5 ,0.5 ))
87
95
88
-
89
- # func _on_body_entered(body):
90
- # if body.name == "Food":
91
- # print("entered body")
92
- # hunger = 0
93
- # body.queue_free()
94
-
95
96
var fishSprites = ['black-bass' ,'carp' ,'gargle' ,'horse-mackerel' ,'loach' ,'pond-smelt' ,'rainbow-trout' ,'red-snapper' ,'sockeye-salmon' ,'yellow-tang' ]
96
97
97
98
func _input (event ):
98
99
if (event .is_action_released ("ChangeFish" )):
99
100
var randomFishSprite = rng .randi_range (0 ,fishSprites .size ()- 1 )
100
101
sprite .texture = load ("res://art/fish/" + fishSprites [randomFishSprite ]+ ".png" )
101
102
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" :
104
105
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 ()
0 commit comments