Skip to content

Commit

Permalink
#10 #16 #17 #18 and general refactoring (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
theaino authored Nov 13, 2024
1 parent d1c57b1 commit b85802a
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 57 deletions.
6 changes: 3 additions & 3 deletions art/fish/Anchovy.png.import
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://dk4otinrljxs5"
path="res://.godot/imported/anchovy.png-dd5a6a1477368f05dcb70d319607da11.ctex"
path="res://.godot/imported/Anchovy.png-55b03b36d32ea5bd0fa288a1e8d80881.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://art/fish/anchovy.png"
dest_files=["res://.godot/imported/anchovy.png-dd5a6a1477368f05dcb70d319607da11.ctex"]
source_file="res://art/fish/Anchovy.png"
dest_files=["res://.godot/imported/Anchovy.png-55b03b36d32ea5bd0fa288a1e8d80881.ctex"]

[params]

Expand Down
57 changes: 27 additions & 30 deletions fish.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var level:int = 1
var xp:int = 0
var birth:float = Time.get_unix_time_from_system()

const hungerSpeed = 60

var speed = maxSpeed

Expand Down Expand Up @@ -57,12 +58,13 @@ var lastFlip = 0

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):

if (state == IDLE): idle()
if (state == SWIM): swim()
if (state == FOOD): food()
{
IDLE: idle,
SWIM: swim,
FOOD: food
}[state].call()

hunger = hunger + 1
hunger = hunger + delta * hungerSpeed
if (hunger > hungerThreshold): hunger = hungerThreshold

if (lastFlip + 500 < Time.get_ticks_msec() && abs(direction.x) > 0.25):
Expand All @@ -80,10 +82,8 @@ func idle():
state = SWIM
boredom = 0
updateOutline()
pass

func swim():

if (hunger>hungerThreshold/2 && FoodGroup.get_children().size() > 0):
state = FOOD
return food()
Expand Down Expand Up @@ -160,7 +160,6 @@ func _on_fish_mouth_body_shape_entered(body_rid, collidedObject, body_shape_inde
if (self == FishInfoPanel.selectedFish):
FishInfoPanel.updateXP()


func _on_mouse_entered():
(sprite.material as ShaderMaterial).set("shader_param/enabled", true)
(sprite.material as ShaderMaterial).set("shader_param/line_color", Vector4(1,1,1,1))
Expand All @@ -175,12 +174,18 @@ func _on_mouse_exited():
print('unhover fish')

func _on_input_event(viewport, event, shape_idx):
if (event is InputEventMouseButton && !event.pressed && event.button_index==1):
FishInfoPanel.selectedFish = self
FishInfoPanel.revealInfo()
print("clicked fish")


if !(event is InputEventMouseButton) || event.pressed || event.button_index != 1:
return
var physicsSpace = get_world_2d().direct_space_state
var query_parameters = PhysicsPointQueryParameters2D.new()
query_parameters.collide_with_areas = true
query_parameters.position = event.position
var intersections = physicsSpace.intersect_point(query_parameters)
for i in intersections:
if i.collider.name in ["CoinClick"]: return
FishInfoPanel.selectedFish = self
FishInfoPanel.revealInfo()
print("clicked fish")

func _on_body_entered(collidedObject):
if (collidedObject.name == "Fish"):
Expand All @@ -195,22 +200,14 @@ func updateOutline():
(sprite.material as ShaderMaterial).set("shader_param/enabled", false)

func levelUpOutline():
outlineOn()
await get_tree().create_timer(0.15).timeout
outlineOff()
await get_tree().create_timer(0.15).timeout
outlineOn()
await get_tree().create_timer(0.15).timeout
outlineOff()
await get_tree().create_timer(0.15).timeout
outlineOn()
await get_tree().create_timer(0.15).timeout
outlineOff()
await get_tree().create_timer(0.15).timeout
outlineOn()
await get_tree().create_timer(0.15).timeout
outlineOff()
await get_tree().create_timer(1.0).timeout
var timeout = 0.15
for i in range(8):
if i % 2 == 0:
outlineOn()
else:
outlineOff()
await get_tree().create_timer(timeout).timeout
await get_tree().create_timer(1.0 - timeout).timeout
updateOutline()

func outlineOn():
Expand Down
2 changes: 0 additions & 2 deletions main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func remove_fish(fishNode):
var fish_data = fish.filter(func(f): return f.id == fishNode.id)
if fish_data.size() == 0:
push_error("tried to remove fish, but couldn't find the in the fish array", fishNode)
pass
print("okay im ghonna remove this fish with his data:", fish_data[0])
var fish_index = fish.find(fish_data[0])
print("removing fish at ",fish_index)
Expand Down Expand Up @@ -114,4 +113,3 @@ func updateFishData(fishy):
fishy.petName = f.petName
return
print("failed to find matching fish when saving fish data. id:",fishy.id)

1 change: 1 addition & 0 deletions main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ shape = SubResource("WorldBoundaryShape2D_gsbav")
shape = SubResource("WorldBoundaryShape2D_65aca")

[node name="TopWall" type="StaticBody2D" parent="Tank/Collisions"]
position = Vector2(0, 40)

[node name="CollisionShape2D" type="CollisionShape2D" parent="Tank/Collisions/TopWall"]
shape = SubResource("WorldBoundaryShape2D_8dguh")
Expand Down
2 changes: 0 additions & 2 deletions shop.gd
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,6 @@ func roomInTank():
print("tanksize: ",game.tankSize," | current fish: ",fishContainer.get_child_count(), " | room in tank: ",str(game.tankSize > fishContainer.get_child_count()))
return (game.tankSize > fishContainer.get_child_count())



func _on_buy_current_item_button_gui_input(event):
checkIfClickedShopButtonIsDisable(event, buyCurrentItemButton)

Expand Down
44 changes: 24 additions & 20 deletions tank.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,33 @@ extends Node2D
var food = load("res://food.tscn")
@onready var foodContainer = get_node("../Food")
@onready var game = get_node("/root/Node2D")

func _unhandled_input(event):
var size = get_viewport().get_visible_rect().size
if !(event is InputEventMouseButton) || event.pressed || event.button_index != 1:
return
var physicsSpace = get_world_2d().direct_space_state
var query_parameters = PhysicsPointQueryParameters2D.new()
query_parameters.collide_with_areas = true
query_parameters.position = event.position
var intersections = physicsSpace.intersect_point(query_parameters)
for i in intersections:
if i.collider.name in ["Fish", "CoinClick"]: return

var x = event.position.x
var y = event.position.y


if (event is InputEventMouseButton && !event.pressed && event.button_index==1):
var physicsSpace = get_world_2d().direct_space_state
var query_parameters = PhysicsPointQueryParameters2D.new()
query_parameters.collide_with_areas = true
query_parameters.position = event.position
var intersections = physicsSpace.intersect_point(query_parameters)
for i in intersections:
if (i.collider.name == "Fish"): return
if (i.collider.name == "CoinClick"): return
if (x < 0) || (y < 0) || (x >= size.x) || (y >= size.y):
return

var instance = food.instantiate()
instance.position.x = event.position.x
instance.position.y = event.position.y
foodContainer.add_child(instance)
game.money = game.money - 1
if game.money < 1: game.money = 1
print("fed")
var instance = food.instantiate()
instance.position.x = x
instance.position.y = y
foodContainer.add_child(instance)
game.money = game.money - 1
if game.money < 1: game.money = 1
print("fed")

func findCoinClick(c):
print("namey",c.collider.name)
if c.collider.name == "CoinClick": return true
else: return false
return c.collider.name == "CoinClick"

0 comments on commit b85802a

Please sign in to comment.