first commit

This commit is contained in:
zman27 2022-01-20 23:33:07 -05:00
commit 3d1a4019e9
38 changed files with 701 additions and 0 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

1
.import/.gdignore Normal file
View File

@ -0,0 +1 @@

View File

@ -0,0 +1,3 @@
source_md5="850709b0d0e7d8fe81d33219d626ea29"
dest_md5="783bcec70fa44da2dd6b4ff4c9583b9c"

Binary file not shown.

View File

@ -0,0 +1,3 @@
source_md5="ebfebe3f0c5a78c8ace93517cfa3dccc"
dest_md5="0c0e4c0c7af86b5a536b6f61c645c9f7"

View File

@ -0,0 +1,3 @@
source_md5="b74c4398dc267c1662c70b37259bfc07"
dest_md5="42052ea1a3189df986255e736614620e"

View File

@ -0,0 +1,3 @@
source_md5="14115228e2292e7cbf50d5599a0be86c"
dest_md5="1e4414700c1bb4fa1cab9f9913cfe14a"

View File

@ -0,0 +1,3 @@
source_md5="33b89e2d9d2d22647326e006ba0b78da"
dest_md5="216e054cc3523302149ddfaa337b0c21"

View File

@ -0,0 +1,3 @@
source_md5="47313fa4c47a9963fddd764e1ec6e4a8"
dest_md5="26ea799ea0a3da9e753b3ebe822e0570"

Binary file not shown.

152
Actors/Fish.gd Normal file
View File

@ -0,0 +1,152 @@
extends KinematicBody2D
# external settings
export var swim_speed: float = 30.0
export var swim_up_down_variance = 0.75
# variables
var velocity = Vector2()
var dropping := true
var turningright := false
var turningleft := false
var nearest_food : Node
var hungry := true
var canseefood := false
func _ready() -> void:
randomize() # generate random seed to randomize each fish
# SETTINGS
var swim_speed_variance = 0.25
# CONNECT SIGNAL
var edgeL = get_tree().get_root().find_node("TankEdgeL", true, false)
edgeL.connect("edgehit", self, "handle_edgehit")
var edgeR = get_tree().get_root().find_node("TankEdgeR", true, false)
edgeR.connect("edgehit", self, "handle_edgehit")
# ACTUAL CODE
swim_speed = swim_speed * (1 + rand_range(-swim_speed_variance, swim_speed_variance)) # give the fish a random speed in range
$DropTimer.wait_time = rand_range(0.5,2) # drop the fish to a random depth in range
$AnimatedSprite.play()
if randf() >= 0.5:
$AnimatedSprite.animation = "left"
else:
$AnimatedSprite.animation = "right"
func handle_edgehit(action: String):
if action == "turn right":
turningright = true
elif action == "turn left":
turningleft = true
func _process(delta: float) -> void:
#print(velocity)
if dropping:
velocity = Vector2(0,175)
if get_tree().get_nodes_in_group("Food").size() > 0:
canseefood = true
nearest_food = find_nearest_food()
# $Line2D.set_point_position(1, nearest_food.get_global_position() - get_global_position())
else:
canseefood = false
if hungry and canseefood:
velocity = position.direction_to(nearest_food.get_global_position()) * 100 # idk why i need to x100 this but i do
# THIS ALWAYS CONTROLS WHERE THE FISH IS MOVING
move_and_slide(velocity)
# func _on_Vision_body_entered(body: Node) -> void:
# if body.is_in_group("Food"):
# print("Yummy! I see some food!")
# var hungry: bool
# var angle_toward_food: float
# if hungry:
# angle_toward_food = get_angle(me, nearest_food)
# natural_movement_angle = random(-15, 15)
# natural_movement = angle_toward_food + natural_movement_angle
#
# random_speed = random(0, 5) + 3
#
# move_and_slide(vector2(random_speed, natural_movement))
func _on_SwimTimer_timeout() -> void:
if not canseefood:
var direction = randf()
var swimdirection = 0
if direction >= .75 or turningright:
swimdirection = 1
$AnimatedSprite.animation = "right"
turningright = false
if direction <= .25 or turningleft:
swimdirection = -1
$AnimatedSprite.animation = "left"
turningleft = false
velocity = Vector2(1, rand_range(-swim_up_down_variance, swim_up_down_variance))
velocity = velocity * swim_speed * swimdirection
# rotate correctly for both directions & sprite animations
$AnimatedSprite.rotation = Vector2(0,0).angle_to_point(velocity) + deg2rad(90 * (swimdirection + 1) * swimdirection)
func _on_DropTimer_timeout():
dropping = false
# identify and record the nearest food
func find_nearest_food() -> Node:
var all_food = get_tree().get_nodes_in_group("Food")
if get_tree().get_nodes_in_group("Food").size() > 0:
nearest_food = all_food[0] # assume the first food is closest
# look through spawn nodes to see if any are closer
for food in all_food:
if food.global_position.distance_to(global_position) < nearest_food.global_position.distance_to(global_position):
nearest_food = food
return nearest_food
else:
return null
func _on_FishHitbox_body_entered(body: Node) -> void:
if body.is_in_group("Food") and hungry:
body.queue_free()
hungry = false
$HungerTimer.start()
func _on_HungerTimer_timeout():
if hungry:
queue_free()
else:
hungry = true

80
Actors/Fish.tscn Normal file
View File

@ -0,0 +1,80 @@
[gd_scene load_steps=7 format=2]
[ext_resource path="res://Actors/Fish.gd" type="Script" id=1]
[ext_resource path="res://fish.png" type="Texture" id=2]
[ext_resource path="res://fish2.png" type="Texture" id=3]
[sub_resource type="CapsuleShape2D" id=1]
radius = 25.4989
height = 59.0012
[sub_resource type="RectangleShape2D" id=2]
extents = Vector2( 253, 195 )
[sub_resource type="SpriteFrames" id=3]
animations = [ {
"frames": [ ExtResource( 3 ) ],
"loop": true,
"name": "left",
"speed": 5.0
}, {
"frames": [ ExtResource( 2 ) ],
"loop": true,
"name": "right",
"speed": 5.0
} ]
[node name="Fish" type="KinematicBody2D" groups=["Fish"]]
position = Vector2( 56.4995, 307.501 )
script = ExtResource( 1 )
__meta__ = {
"_edit_group_": true
}
swim_speed = 90.0
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2( -1, 0 )
rotation = 1.5708
shape = SubResource( 1 )
[node name="Vision" type="Area2D" parent="."]
[node name="VisionRadius" type="CollisionShape2D" parent="Vision"]
shape = SubResource( 2 )
[node name="SwimTimer" type="Timer" parent="."]
autostart = true
[node name="DropTimer" type="Timer" parent="."]
wait_time = 2.0
one_shot = true
autostart = true
[node name="HungerTimer" type="Timer" parent="."]
wait_time = 10.0
autostart = true
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
frames = SubResource( 3 )
animation = "left"
[node name="FishHitbox" type="Area2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="FishHitbox"]
position = Vector2( -1, 0 )
rotation = 1.5708
shape = SubResource( 1 )
[node name="Line2D" type="Line2D" parent="."]
points = PoolVector2Array( 0, 0, 0, 0 )
[node name="Timer2" type="Timer" parent="."]
wait_time = 60.0
one_shot = true
autostart = true
[connection signal="body_entered" from="Vision" to="." method="_on_Vision_body_entered"]
[connection signal="timeout" from="SwimTimer" to="." method="_on_SwimTimer_timeout"]
[connection signal="timeout" from="DropTimer" to="." method="_on_DropTimer_timeout"]
[connection signal="timeout" from="HungerTimer" to="." method="_on_HungerTimer_timeout"]
[connection signal="body_entered" from="FishHitbox" to="." method="_on_FishHitbox_body_entered"]

BIN
Art/food0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

34
Art/food0.png.import Normal file
View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/food0.png-4190a40b216d2306867a0c3dad72d3da.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Art/food0.png"
dest_files=[ "res://.import/food0.png-4190a40b216d2306867a0c3dad72d3da.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

BIN
Art/food1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

34
Art/food1.png.import Normal file
View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/food1.png-16771573ec176a96051d844379b63b8b.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Art/food1.png"
dest_files=[ "res://.import/food1.png-16771573ec176a96051d844379b63b8b.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

BIN
Art/food2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

34
Art/food2.png.import Normal file
View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/food2.png-a0aa0ff5aa74157d0c1656e29d64956b.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Art/food2.png"
dest_files=[ "res://.import/food2.png-a0aa0ff5aa74157d0c1656e29d64956b.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

21
Button.gd Normal file
View File

@ -0,0 +1,21 @@
extends Button
func _on_Button_pressed():
var scene = load("res://Actors/Fish.tscn")
var fish = scene.instance()
fish.position = Vector2(rand_range(300,get_viewport().size.x-300),-100)
add_child(fish)
func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed("Spawn Fish"):
var scene = load("res://Actors/Fish.tscn")
var fish = scene.instance()
fish.position = Vector2(get_global_mouse_position().x, -100)
add_child(fish)

42
Food.tscn Normal file
View File

@ -0,0 +1,42 @@
[gd_scene load_steps=7 format=2]
[ext_resource path="res://Art/food0.png" type="Texture" id=1]
[ext_resource path="res://Art/food2.png" type="Texture" id=2]
[ext_resource path="res://Art/food1.png" type="Texture" id=3]
[ext_resource path="res://FoodSprites.gd" type="Script" id=4]
[sub_resource type="SpriteFrames" id=1]
animations = [ {
"frames": [ ExtResource( 3 ) ],
"loop": true,
"name": "1",
"speed": 5.0
}, {
"frames": [ ExtResource( 2 ) ],
"loop": true,
"name": "2",
"speed": 5.0
}, {
"frames": [ ExtResource( 1 ) ],
"loop": true,
"name": "0",
"speed": 5.0
} ]
[sub_resource type="CircleShape2D" id=2]
radius = 16.0182
[node name="Food" type="RigidBody2D" groups=["Food"]]
collision_layer = 2
mass = 0.2
linear_damp = 1.0
[node name="FoodSprites" type="AnimatedSprite" parent="."]
scale = Vector2( 0.5, 0.5 )
frames = SubResource( 1 )
animation = "2"
script = ExtResource( 4 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2( 0, -0.235703 )
shape = SubResource( 2 )

11
FoodSprites.gd Normal file
View File

@ -0,0 +1,11 @@
extends AnimatedSprite
func _ready():
randomize()
play_random_animation()
func play_random_animation():
var animations = frames.get_animation_names()
var animation_id = randi() % animations.size()
var animation_name = animations[animation_id]
play(animation_name)

13
TankEdge.gd Normal file
View File

@ -0,0 +1,13 @@
extends Area2D
signal edgehit
func _on_TankEdge_body_entered(body: Node) -> void:
if body.is_in_group("Fish"):
print("This bitch ass fish just crossed the line at " + str(body.position.x))
if body.position.x < get_viewport().size.x/2:
emit_signal("edgehit", "turn right")
print("Turning the " + body.name + " right.")
else:
emit_signal("edgehit", "turn left")
print("Turning the " + body.name + " left.")

14
TankEdge.tscn Normal file
View File

@ -0,0 +1,14 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://TankEdge.gd" type="Script" id=1]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 135, 455 )
[node name="TankEdge" type="Area2D"]
script = ExtResource( 1 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource( 1 )
[connection signal="body_entered" from="." to="." method="_on_TankEdge_body_entered"]

9
World.gd Normal file
View File

@ -0,0 +1,9 @@
extends Node2D
func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed("Spawn Food"):
var food = load("res://Food.tscn").instance()
food.position = Vector2(get_global_mouse_position().x, -25)
food.rotation = deg2rad(360)
add_child(food)

43
World.tscn Normal file
View File

@ -0,0 +1,43 @@
[gd_scene load_steps=5 format=2]
[ext_resource path="res://Button.gd" type="Script" id=1]
[ext_resource path="res://TankEdge.tscn" type="PackedScene" id=2]
[ext_resource path="res://World.gd" type="Script" id=4]
[sub_resource type="LineShape2D" id=1]
[node name="World" type="Node2D"]
script = ExtResource( 4 )
[node name="ColorRect" type="ColorRect" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
color = Color( 0.137255, 0.352941, 0.764706, 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Button" type="Button" parent="."]
margin_left = 54.0
margin_top = 41.0
margin_right = 124.0
margin_bottom = 61.0
text = "New Fish"
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="TankEdgeL" parent="." instance=ExtResource( 2 )]
position = Vector2( 135.334, 453.28 )
[node name="TankEdgeR" parent="." instance=ExtResource( 2 )]
position = Vector2( 1464.51, 450 )
[node name="StaticBody2D" type="StaticBody2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"]
position = Vector2( 800, 900 )
shape = SubResource( 1 )
[connection signal="pressed" from="Button" to="Button" method="_on_Button_pressed"]

7
default_env.tres Normal file
View File

@ -0,0 +1,7 @@
[gd_resource type="Environment" load_steps=2 format=2]
[sub_resource type="ProceduralSky" id=1]
[resource]
background_mode = 2
background_sky = SubResource( 1 )

31
export_presets.cfg Normal file
View File

@ -0,0 +1,31 @@
[preset.0]
name="Mac OSX"
platform="Mac OSX"
runnable=true
custom_features=""
export_filter="all_resources"
include_filter=""
exclude_filter=""
export_path="./Fish20220119.zip"
script_export_mode=1
script_encryption_key=""
[preset.0.options]
custom_template/debug=""
custom_template/release=""
application/name="Fish!!"
application/info="Made by Josh and Skip"
application/icon="res://fish.png"
application/identifier=""
application/signature=""
application/short_version="0.0.1"
application/version="0.0.1"
application/copyright=""
display/high_res=false
privacy/camera_usage_description=""
privacy/microphone_usage_description=""
texture_format/s3tc=true
texture_format/etc=false
texture_format/etc2=false

BIN
fish.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

35
fish.png.import Normal file
View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/fish.png-373349fe5906fa24a595247b3fc0d517.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://fish.png"
dest_files=[ "res://.import/fish.png-373349fe5906fa24a595247b3fc0d517.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

BIN
fish2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

35
fish2.png.import Normal file
View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/fish2.png-5f2e622985802cf154a9485121f4ce36.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://fish2.png"
dest_files=[ "res://.import/fish2.png-5f2e622985802cf154a9485121f4ce36.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

BIN
icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

35
icon.png.import Normal file
View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://icon.png"
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

52
project.godot Normal file
View File

@ -0,0 +1,52 @@
; Engine configuration file.
; It's best edited using the editor UI and not directly,
; since the parameters that go here are not all obvious.
;
; Format:
; [section] ; section goes between []
; param=value ; assign values to parameters
config_version=4
[application]
config/name="Fish"
config/description="FISH!!!!"
run/main_scene="res://World.tscn"
config/icon="res://icon.png"
[display]
window/size/width=1600
window/size/height=900
window/stretch/mode="2d"
window/stretch/aspect="expand"
[input]
ui_end={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":0,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
]
}
"Spawn Food"={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":32,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":1,"pressed":false,"doubleclick":false,"script":null)
]
}
"Spawn Fish"={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777234,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":2,"pressed":false,"doubleclick":false,"script":null)
]
}
[physics]
common/enable_pause_aware_picking=true
[rendering]
environment/default_environment="res://default_env.tres"