Frog can be knocked out and also die

If the frog sleeps it will drop down and not move,
it's also rendered unharmful.
When it dies, a new Rope attached to an empty
collar is spawned :(
This commit is contained in:
Jakob Feldmann 2023-01-04 23:07:13 +01:00
parent d710219cfd
commit 7a7c1638ba
12 changed files with 126 additions and 49 deletions

View File

@ -437,5 +437,6 @@ func _on_GameplaySignalManager_getback_timer_up() -> void:
func _on_BlobbySkin_body_exited(body:Node) -> void:
# This is for drop through platforms
if body.get_collision_mask_bit(7):
set_collision_mask_bit(7, true)

View File

@ -2,17 +2,53 @@ extends Node2D
var Rope = preload("res://src/Contraptions/Rope/Rope.tscn")
var start_pos := Vector2.ZERO
var end_pos := Vector2.ZERO
func _ready() -> void:
pass
var RopeAnchor = preload("res://src/Contraptions/Rope/RopeAnchor.tscn")
var rope
var is_first_signal = true
func _on_LevelTemplate_ready() -> void:
var rope = Rope.instance()
rope = Rope.instance()
# For some reason the rope only can be instanced in the parent scene
# The scene also has to be ready beforehand
get_parent().add_child(rope)
rope.rope_end = get_node("RopeAnchor")
rope.rope_start = get_node("WhatAreFrog")
rope.rope_end_joint = get_node("RopeAnchor/cshape/pjoint")
rope.rope_start_joint = get_node("WhatAreFrog/cshape/pjoint")
rope.spawn_rope($RopeAnchor.global_position, $RopeAnchor.global_position, false)
rope.spawn_rope($WhatAreFrog.global_position, $WhatAreFrog.global_position + Vector2(100,0), false)
pass
# Executes on frog death
# The old switchero
func _on_WhatAreFrog_child_exiting_tree(node:Node) -> void:
if(is_first_signal):
var anchor = RopeAnchor.instance()
anchor.mode = 0
add_child(anchor)
anchor.global_position = rope.rope_start_joint.global_position
rope.queue_free()
rope = Rope.instance()
# For some reason the rope only can be instanced in the parent scene
# The scene also has to be ready beforehand
get_parent().add_child(rope)
rope.rope_end = get_node("RopeAnchor")
rope.rope_start = anchor
rope.rope_end_joint = get_node("RopeAnchor/cshape/pjoint")
rope.rope_start_joint = anchor.get_node("cshape/pjoint")
rope.spawn_rope(anchor.global_position, $RopeAnchor.global_position, false)
is_first_signal = false
# rope.rope_start = anchor
# anchor.global_position = rope.rope_start_joint.global_position
# rope.rope_start_joint = anchor.get_node("cshape/pjoint")
# rope.rope_pieces[0] = anchor
# var first_piece = rope.rope_pieces[1]
# rope.rope_start_joint.node_a = anchor.get_path
# rope.rope_start_joint.node_b = first_piece.get_path()
# first_piece.get_node("cshape/pjoint").node_b = anchor.get_path()
else:
pass
# var lastPiecePath: NodePath = $WhatAreFrog/cshape/pjoint.node_b
# print(lastPiecePath)
# var lastPiece: Node = get_node(lastPiecePath)
# print(lastPiece)
# lastPiece.get_node("cshape/pjoint").node_a = anchor.get_path()

View File

@ -12,4 +12,6 @@ script = ExtResource( 3 )
[node name="RopeAnchor" parent="." instance=ExtResource( 2 )]
position = Vector2( -136, 11 )
[connection signal="child_exiting_tree" from="WhatAreFrog" to="." method="_on_WhatAreFrog_child_exiting_tree"]
[editable path="RopeAnchor"]

View File

@ -1,8 +1,6 @@
extends Player
const PhysicsFunc = preload("res://src/Utilities/Physic/PhysicsFunc.gd")
var Rope = preload("res://src/Contraptions/Rope/Rope.tscn")
onready var orientation: RayCast2D = $Orientation
onready var jump_timer: Timer
@ -10,10 +8,11 @@ export var score := 100
var start_x = 0
var in_air = false
var died = false
var is_hurt = false
func _ready():
jump_timer = Timer.new()
jump_timer.set_one_shot(true)
jump_timer.connect("timeout", self, "jump")
add_child(jump_timer)
@ -22,8 +21,10 @@ func _ready():
func _on_StompDetector_body_entered(body: Node) -> void:
if body.global_position.y > get_node("StompDetector").global_position.y:
return
get_node("EnemyBody").disabled = true
die()
if body.is_in_group("player"):
remove_from_group("harmful")
is_hurt = true
func execute_movement(delta: float) -> void:
velocity.y += _gravity * delta
@ -37,10 +38,9 @@ func execute_movement(delta: float) -> void:
func die() -> void:
if(!died):
GlobalState.score += score
died = true
#queue_free()
GlobalState.score += score
queue_free()
func _on_EnemySkin_area_entered(area:Area2D) -> void:
@ -48,6 +48,7 @@ func _on_EnemySkin_area_entered(area:Area2D) -> void:
get_node("EnemyBody").disabled = true
die()
func searching() -> Vector2:
if(is_on_floor()):
if(jump_timer.is_stopped()):
@ -58,9 +59,16 @@ func searching() -> Vector2:
else:
if(!in_air):
start_x = global_position.x
jump_timer.stop()
in_air = true
return velocity
func sleeping() -> Vector2:
jump_timer.stop()
return velocity
func jump():
var v: Vector2 = velocity_for_jump_distance()
var jump_height = (pow(v.length(), 2) * pow(sin(deg2rad(65)),2))/(2*_gravity)
@ -68,6 +76,7 @@ func jump():
$CeilingRayCast.cast_to = Vector2(1.5*24 * sign(orientation.cast_to.x), - jump_height)
velocity = v
func velocity_for_jump_distance(distance: float = 3*24, angle: float = deg2rad(65)) -> Vector2:
var abs_velocity = sqrt((distance * _gravity)/sin(2*angle))
return Vector2(abs_velocity,0).rotated(-1*angle)

View File

@ -1,8 +1,9 @@
[gd_scene load_steps=7 format=2]
[gd_scene load_steps=8 format=2]
[ext_resource path="res://assets/enemy/enemy.png" type="Texture" id=1]
[ext_resource path="res://src/Actors/Enemies/Beings/WhatAreFrog.gd" type="Script" id=2]
[ext_resource path="res://src/Actors/Enemies/Beings/WhatAreFrogStateMachine.gd" type="Script" id=3]
[ext_resource path="res://assets/meta/new_dynamicfont.tres" type="DynamicFont" id=4]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 2.72463, 1.17848 )
@ -22,6 +23,19 @@ script = ExtResource( 2 )
[node name="Statemachine" type="Node2D" parent="."]
script = ExtResource( 3 )
[node name="StateLabel" type="Label" parent="."]
show_behind_parent = true
margin_left = -36.0
margin_top = -30.0
margin_right = 37.0
margin_bottom = -16.0
custom_colors/font_color = Color( 1, 1, 1, 1 )
custom_colors/font_outline_modulate = Color( 0, 0, 0, 1 )
custom_fonts/font = ExtResource( 4 )
text = "Ihre Werbung"
align = 1
valign = 1
[node name="FrogSprite" type="Sprite" parent="."]
position = Vector2( 0, -1.90735e-06 )
scale = Vector2( 0.286789, 0.276348 )
@ -67,7 +81,7 @@ scale = Vector2( 0.1, 0.1 )
[node name="pjoint" type="PinJoint2D" parent="cshape"]
scale = Vector2( 0.3, 0.3 )
bias = 0.9
bias = 0.108
softness = 0.1
[node name="StompDetector" type="Area2D" parent="." groups=["weakpoint"]]

View File

@ -19,13 +19,24 @@ func _ready() -> void:
# Game logic consequences of state
func _state_logic(delta):
if(!(parent.died && parent.is_on_floor())):
var state_action_ref = funcref(parent, self.state)
parent.velocity = state_action_ref.call_func()
parent.execute_movement(delta)
var state_action_ref = funcref(parent, self.state)
parent.velocity = state_action_ref.call_func()
parent.execute_movement(delta)
func _get_transition(_delta):
parent.get_node("StateLabel").text = (
self.state
# + " x vel:"
# + String(round(parent.velocity.x))
# + " y vel/10:"
# + String(round(parent.velocity.y / 10))
)
var new_state
if parent.is_hurt:
new_state = states.sleeping
if new_state != self.state:
return new_state
return null

View File

@ -33,8 +33,6 @@ func spawn_rope(start_pos: Vector2, end_pos: Vector2, new_anchors: bool = true):
add_child(rope_end, true)
rope_start.global_position = start_pos
rope_end.global_position = end_pos
start_pos = rope_start_joint.global_position
end_pos = rope_end_joint.global_position
var dist = start_pos.distance_to(end_pos)
var pieces_amount = round(dist / piece_length)
var spawn_angle = (end_pos-start_pos).angle() - PI/2
@ -54,16 +52,16 @@ func create_rope(pieces_amount: int, last_piece: Object, end_pos: Vector2, spawn
rope_end_joint.node_b = rope_pieces[-1].get_path()
func add_piece(prev_link: Object, id: int, spawn_angle:float) -> Object:
var joint: PinJoint2D = prev_link.get_node("cshape/pjoint") as PinJoint2D
func add_piece(prev_piece: Object, id: int, spawn_angle:float) -> Object:
var prev_joint: PinJoint2D = prev_piece.get_node("cshape/pjoint") as PinJoint2D
var new_piece: Object = RopePiece.instance() as Object
new_piece.global_position = joint.global_position
new_piece.global_position = prev_joint.global_position
new_piece.rotation = spawn_angle
new_piece.prev_link = prev_link
new_piece.prev_piece = prev_piece
new_piece.id = id
add_child(new_piece)
joint.node_a = prev_link.get_path()
joint.node_b = new_piece.get_path()
add_child(new_piece, true)
prev_joint.node_a = prev_piece.get_path()
prev_joint.node_b = new_piece.get_path()
return new_piece

View File

@ -11,6 +11,7 @@ collision_layer = 256
collision_mask = 8
input_pickable = true
mode = 1
mass = 0.01
linear_damp = 1.0
angular_damp = 1.0

View File

@ -2,4 +2,4 @@ extends RigidBody2D
var id := -1
var prev_link: Object = null
var prev_piece: Object = null

View File

@ -9,7 +9,6 @@ height = 1.0
[node name="RigidBody2D" type="RigidBody2D"]
collision_layer = 256
collision_mask = 8
gravity_scale = 0.2
linear_damp = 1.0
angular_damp = 1.0
script = ExtResource( 1 )
@ -21,5 +20,4 @@ shape = SubResource( 1 )
[node name="pjoint" type="PinJoint2D" parent="cshape"]
position = Vector2( 0, 1.5 )
scale = Vector2( 0.3, 0.3 )
bias = 0.1
softness = 0.1

View File

@ -15,17 +15,17 @@ func _ready() -> void:
# rope.rope_end_joint = get_node("BoundFrog/WhatAreFrog/cshape/pjoint")
# rope.spawn_rope($BoundFrog/RopeAnchor.global_position, $BoundFrog.global_position, false)
func _input(event):
if event is InputEventMouseButton && !event.is_pressed():
if start_pos == Vector2.ZERO:
start_pos = get_global_mouse_position()
elif end_pos == Vector2.ZERO:
end_pos = get_global_mouse_position()
rope = Rope.instance()
add_child(rope)
rope.spawn_rope(start_pos, end_pos)
start_pos = Vector2.ZERO
end_pos = Vector2.ZERO
# func _input(event):
# if event is InputEventMouseButton && !event.is_pressed():
# if start_pos == Vector2.ZERO:
# start_pos = get_global_mouse_position()
# elif end_pos == Vector2.ZERO:
# end_pos = get_global_mouse_position()
# rope = Rope.instance()
# add_child(rope)
# rope.spawn_rope(start_pos, end_pos)
# start_pos = Vector2.ZERO
# end_pos = Vector2.ZERO
# if rope != null && event.is_action_pressed("click"):
# rope.mouse_follow = true
# if event.is_action_released("click"):

File diff suppressed because one or more lines are too long