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:
parent
d710219cfd
commit
7a7c1638ba
@ -437,5 +437,6 @@ func _on_GameplaySignalManager_getback_timer_up() -> void:
|
|||||||
|
|
||||||
|
|
||||||
func _on_BlobbySkin_body_exited(body:Node) -> void:
|
func _on_BlobbySkin_body_exited(body:Node) -> void:
|
||||||
|
# This is for drop through platforms
|
||||||
if body.get_collision_mask_bit(7):
|
if body.get_collision_mask_bit(7):
|
||||||
set_collision_mask_bit(7, true)
|
set_collision_mask_bit(7, true)
|
||||||
|
|||||||
@ -2,17 +2,53 @@ extends Node2D
|
|||||||
|
|
||||||
|
|
||||||
var Rope = preload("res://src/Contraptions/Rope/Rope.tscn")
|
var Rope = preload("res://src/Contraptions/Rope/Rope.tscn")
|
||||||
var start_pos := Vector2.ZERO
|
var RopeAnchor = preload("res://src/Contraptions/Rope/RopeAnchor.tscn")
|
||||||
var end_pos := Vector2.ZERO
|
var rope
|
||||||
|
var is_first_signal = true
|
||||||
func _ready() -> void:
|
|
||||||
pass
|
|
||||||
|
|
||||||
func _on_LevelTemplate_ready() -> void:
|
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)
|
get_parent().add_child(rope)
|
||||||
rope.rope_end = get_node("RopeAnchor")
|
rope.rope_end = get_node("RopeAnchor")
|
||||||
rope.rope_start = get_node("WhatAreFrog")
|
rope.rope_start = get_node("WhatAreFrog")
|
||||||
rope.rope_end_joint = get_node("RopeAnchor/cshape/pjoint")
|
rope.rope_end_joint = get_node("RopeAnchor/cshape/pjoint")
|
||||||
rope.rope_start_joint = get_node("WhatAreFrog/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()
|
||||||
|
|||||||
@ -12,4 +12,6 @@ script = ExtResource( 3 )
|
|||||||
[node name="RopeAnchor" parent="." instance=ExtResource( 2 )]
|
[node name="RopeAnchor" parent="." instance=ExtResource( 2 )]
|
||||||
position = Vector2( -136, 11 )
|
position = Vector2( -136, 11 )
|
||||||
|
|
||||||
|
[connection signal="child_exiting_tree" from="WhatAreFrog" to="." method="_on_WhatAreFrog_child_exiting_tree"]
|
||||||
|
|
||||||
[editable path="RopeAnchor"]
|
[editable path="RopeAnchor"]
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
extends Player
|
extends Player
|
||||||
const PhysicsFunc = preload("res://src/Utilities/Physic/PhysicsFunc.gd")
|
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 orientation: RayCast2D = $Orientation
|
||||||
onready var jump_timer: Timer
|
onready var jump_timer: Timer
|
||||||
|
|
||||||
@ -10,10 +8,11 @@ export var score := 100
|
|||||||
|
|
||||||
var start_x = 0
|
var start_x = 0
|
||||||
var in_air = false
|
var in_air = false
|
||||||
var died = false
|
var is_hurt = false
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
jump_timer = Timer.new()
|
jump_timer = Timer.new()
|
||||||
|
jump_timer.set_one_shot(true)
|
||||||
jump_timer.connect("timeout", self, "jump")
|
jump_timer.connect("timeout", self, "jump")
|
||||||
add_child(jump_timer)
|
add_child(jump_timer)
|
||||||
|
|
||||||
@ -22,8 +21,10 @@ func _ready():
|
|||||||
func _on_StompDetector_body_entered(body: Node) -> void:
|
func _on_StompDetector_body_entered(body: Node) -> void:
|
||||||
if body.global_position.y > get_node("StompDetector").global_position.y:
|
if body.global_position.y > get_node("StompDetector").global_position.y:
|
||||||
return
|
return
|
||||||
get_node("EnemyBody").disabled = true
|
if body.is_in_group("player"):
|
||||||
die()
|
remove_from_group("harmful")
|
||||||
|
is_hurt = true
|
||||||
|
|
||||||
|
|
||||||
func execute_movement(delta: float) -> void:
|
func execute_movement(delta: float) -> void:
|
||||||
velocity.y += _gravity * delta
|
velocity.y += _gravity * delta
|
||||||
@ -37,10 +38,9 @@ func execute_movement(delta: float) -> void:
|
|||||||
|
|
||||||
|
|
||||||
func die() -> void:
|
func die() -> void:
|
||||||
if(!died):
|
|
||||||
GlobalState.score += score
|
GlobalState.score += score
|
||||||
died = true
|
|
||||||
#queue_free()
|
queue_free()
|
||||||
|
|
||||||
|
|
||||||
func _on_EnemySkin_area_entered(area:Area2D) -> void:
|
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
|
get_node("EnemyBody").disabled = true
|
||||||
die()
|
die()
|
||||||
|
|
||||||
|
|
||||||
func searching() -> Vector2:
|
func searching() -> Vector2:
|
||||||
if(is_on_floor()):
|
if(is_on_floor()):
|
||||||
if(jump_timer.is_stopped()):
|
if(jump_timer.is_stopped()):
|
||||||
@ -58,9 +59,16 @@ func searching() -> Vector2:
|
|||||||
else:
|
else:
|
||||||
if(!in_air):
|
if(!in_air):
|
||||||
start_x = global_position.x
|
start_x = global_position.x
|
||||||
|
jump_timer.stop()
|
||||||
in_air = true
|
in_air = true
|
||||||
return velocity
|
return velocity
|
||||||
|
|
||||||
|
|
||||||
|
func sleeping() -> Vector2:
|
||||||
|
jump_timer.stop()
|
||||||
|
return velocity
|
||||||
|
|
||||||
|
|
||||||
func jump():
|
func jump():
|
||||||
var v: Vector2 = velocity_for_jump_distance()
|
var v: Vector2 = velocity_for_jump_distance()
|
||||||
var jump_height = (pow(v.length(), 2) * pow(sin(deg2rad(65)),2))/(2*_gravity)
|
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)
|
$CeilingRayCast.cast_to = Vector2(1.5*24 * sign(orientation.cast_to.x), - jump_height)
|
||||||
velocity = v
|
velocity = v
|
||||||
|
|
||||||
|
|
||||||
func velocity_for_jump_distance(distance: float = 3*24, angle: float = deg2rad(65)) -> Vector2:
|
func velocity_for_jump_distance(distance: float = 3*24, angle: float = deg2rad(65)) -> Vector2:
|
||||||
var abs_velocity = sqrt((distance * _gravity)/sin(2*angle))
|
var abs_velocity = sqrt((distance * _gravity)/sin(2*angle))
|
||||||
return Vector2(abs_velocity,0).rotated(-1*angle)
|
return Vector2(abs_velocity,0).rotated(-1*angle)
|
||||||
|
|||||||
@ -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://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/WhatAreFrog.gd" type="Script" id=2]
|
||||||
[ext_resource path="res://src/Actors/Enemies/Beings/WhatAreFrogStateMachine.gd" type="Script" id=3]
|
[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]
|
[sub_resource type="RectangleShape2D" id=1]
|
||||||
extents = Vector2( 2.72463, 1.17848 )
|
extents = Vector2( 2.72463, 1.17848 )
|
||||||
@ -22,6 +23,19 @@ script = ExtResource( 2 )
|
|||||||
[node name="Statemachine" type="Node2D" parent="."]
|
[node name="Statemachine" type="Node2D" parent="."]
|
||||||
script = ExtResource( 3 )
|
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="."]
|
[node name="FrogSprite" type="Sprite" parent="."]
|
||||||
position = Vector2( 0, -1.90735e-06 )
|
position = Vector2( 0, -1.90735e-06 )
|
||||||
scale = Vector2( 0.286789, 0.276348 )
|
scale = Vector2( 0.286789, 0.276348 )
|
||||||
@ -67,7 +81,7 @@ scale = Vector2( 0.1, 0.1 )
|
|||||||
|
|
||||||
[node name="pjoint" type="PinJoint2D" parent="cshape"]
|
[node name="pjoint" type="PinJoint2D" parent="cshape"]
|
||||||
scale = Vector2( 0.3, 0.3 )
|
scale = Vector2( 0.3, 0.3 )
|
||||||
bias = 0.9
|
bias = 0.108
|
||||||
softness = 0.1
|
softness = 0.1
|
||||||
|
|
||||||
[node name="StompDetector" type="Area2D" parent="." groups=["weakpoint"]]
|
[node name="StompDetector" type="Area2D" parent="." groups=["weakpoint"]]
|
||||||
|
|||||||
@ -19,13 +19,24 @@ func _ready() -> void:
|
|||||||
|
|
||||||
# Game logic consequences of state
|
# Game logic consequences of state
|
||||||
func _state_logic(delta):
|
func _state_logic(delta):
|
||||||
if(!(parent.died && parent.is_on_floor())):
|
|
||||||
var state_action_ref = funcref(parent, self.state)
|
var state_action_ref = funcref(parent, self.state)
|
||||||
parent.velocity = state_action_ref.call_func()
|
parent.velocity = state_action_ref.call_func()
|
||||||
parent.execute_movement(delta)
|
parent.execute_movement(delta)
|
||||||
|
|
||||||
|
|
||||||
func _get_transition(_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
|
return null
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -33,8 +33,6 @@ func spawn_rope(start_pos: Vector2, end_pos: Vector2, new_anchors: bool = true):
|
|||||||
add_child(rope_end, true)
|
add_child(rope_end, true)
|
||||||
rope_start.global_position = start_pos
|
rope_start.global_position = start_pos
|
||||||
rope_end.global_position = end_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 dist = start_pos.distance_to(end_pos)
|
||||||
var pieces_amount = round(dist / piece_length)
|
var pieces_amount = round(dist / piece_length)
|
||||||
var spawn_angle = (end_pos-start_pos).angle() - PI/2
|
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()
|
rope_end_joint.node_b = rope_pieces[-1].get_path()
|
||||||
|
|
||||||
|
|
||||||
func add_piece(prev_link: Object, id: int, spawn_angle:float) -> Object:
|
func add_piece(prev_piece: Object, id: int, spawn_angle:float) -> Object:
|
||||||
var joint: PinJoint2D = prev_link.get_node("cshape/pjoint") as PinJoint2D
|
var prev_joint: PinJoint2D = prev_piece.get_node("cshape/pjoint") as PinJoint2D
|
||||||
var new_piece: Object = RopePiece.instance() as Object
|
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.rotation = spawn_angle
|
||||||
new_piece.prev_link = prev_link
|
new_piece.prev_piece = prev_piece
|
||||||
new_piece.id = id
|
new_piece.id = id
|
||||||
add_child(new_piece)
|
add_child(new_piece, true)
|
||||||
joint.node_a = prev_link.get_path()
|
prev_joint.node_a = prev_piece.get_path()
|
||||||
joint.node_b = new_piece.get_path()
|
prev_joint.node_b = new_piece.get_path()
|
||||||
|
|
||||||
return new_piece
|
return new_piece
|
||||||
|
|
||||||
|
|||||||
@ -11,6 +11,7 @@ collision_layer = 256
|
|||||||
collision_mask = 8
|
collision_mask = 8
|
||||||
input_pickable = true
|
input_pickable = true
|
||||||
mode = 1
|
mode = 1
|
||||||
|
mass = 0.01
|
||||||
linear_damp = 1.0
|
linear_damp = 1.0
|
||||||
angular_damp = 1.0
|
angular_damp = 1.0
|
||||||
|
|
||||||
|
|||||||
@ -2,4 +2,4 @@ extends RigidBody2D
|
|||||||
|
|
||||||
|
|
||||||
var id := -1
|
var id := -1
|
||||||
var prev_link: Object = null
|
var prev_piece: Object = null
|
||||||
|
|||||||
@ -9,7 +9,6 @@ height = 1.0
|
|||||||
[node name="RigidBody2D" type="RigidBody2D"]
|
[node name="RigidBody2D" type="RigidBody2D"]
|
||||||
collision_layer = 256
|
collision_layer = 256
|
||||||
collision_mask = 8
|
collision_mask = 8
|
||||||
gravity_scale = 0.2
|
|
||||||
linear_damp = 1.0
|
linear_damp = 1.0
|
||||||
angular_damp = 1.0
|
angular_damp = 1.0
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
@ -21,5 +20,4 @@ shape = SubResource( 1 )
|
|||||||
[node name="pjoint" type="PinJoint2D" parent="cshape"]
|
[node name="pjoint" type="PinJoint2D" parent="cshape"]
|
||||||
position = Vector2( 0, 1.5 )
|
position = Vector2( 0, 1.5 )
|
||||||
scale = Vector2( 0.3, 0.3 )
|
scale = Vector2( 0.3, 0.3 )
|
||||||
bias = 0.1
|
|
||||||
softness = 0.1
|
softness = 0.1
|
||||||
|
|||||||
@ -15,17 +15,17 @@ func _ready() -> void:
|
|||||||
# rope.rope_end_joint = get_node("BoundFrog/WhatAreFrog/cshape/pjoint")
|
# rope.rope_end_joint = get_node("BoundFrog/WhatAreFrog/cshape/pjoint")
|
||||||
# rope.spawn_rope($BoundFrog/RopeAnchor.global_position, $BoundFrog.global_position, false)
|
# rope.spawn_rope($BoundFrog/RopeAnchor.global_position, $BoundFrog.global_position, false)
|
||||||
|
|
||||||
func _input(event):
|
# func _input(event):
|
||||||
if event is InputEventMouseButton && !event.is_pressed():
|
# if event is InputEventMouseButton && !event.is_pressed():
|
||||||
if start_pos == Vector2.ZERO:
|
# if start_pos == Vector2.ZERO:
|
||||||
start_pos = get_global_mouse_position()
|
# start_pos = get_global_mouse_position()
|
||||||
elif end_pos == Vector2.ZERO:
|
# elif end_pos == Vector2.ZERO:
|
||||||
end_pos = get_global_mouse_position()
|
# end_pos = get_global_mouse_position()
|
||||||
rope = Rope.instance()
|
# rope = Rope.instance()
|
||||||
add_child(rope)
|
# add_child(rope)
|
||||||
rope.spawn_rope(start_pos, end_pos)
|
# rope.spawn_rope(start_pos, end_pos)
|
||||||
start_pos = Vector2.ZERO
|
# start_pos = Vector2.ZERO
|
||||||
end_pos = Vector2.ZERO
|
# end_pos = Vector2.ZERO
|
||||||
# if rope != null && event.is_action_pressed("click"):
|
# if rope != null && event.is_action_pressed("click"):
|
||||||
# rope.mouse_follow = true
|
# rope.mouse_follow = true
|
||||||
# if event.is_action_released("click"):
|
# if event.is_action_released("click"):
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user