Matured flying enemy, cam fix, frog eats flying enemy
This commit is contained in:
parent
9bb25a7cbe
commit
62217c87fc
@ -160,6 +160,7 @@ click={
|
|||||||
2d_physics/layer_6="contraption"
|
2d_physics/layer_6="contraption"
|
||||||
2d_physics/layer_7="finnemajig"
|
2d_physics/layer_7="finnemajig"
|
||||||
2d_physics/layer_8="dropThrough"
|
2d_physics/layer_8="dropThrough"
|
||||||
|
2d_physics/layer_9="food"
|
||||||
|
|
||||||
[physics]
|
[physics]
|
||||||
|
|
||||||
|
|||||||
@ -4637,6 +4637,7 @@ cast_to = Vector2( 1.5, 0 )
|
|||||||
collision_mask = 56
|
collision_mask = 56
|
||||||
|
|
||||||
[node name="SlopeRaycastLeft" type="RayCast2D" parent="."]
|
[node name="SlopeRaycastLeft" type="RayCast2D" parent="."]
|
||||||
|
visible = false
|
||||||
position = Vector2( -9, 0 )
|
position = Vector2( -9, 0 )
|
||||||
enabled = true
|
enabled = true
|
||||||
cast_to = Vector2( 0, 24 )
|
cast_to = Vector2( 0, 24 )
|
||||||
@ -4644,11 +4645,13 @@ collision_mask = 8
|
|||||||
|
|
||||||
[node name="SlopeRaycast" type="RayCast2D" parent="."]
|
[node name="SlopeRaycast" type="RayCast2D" parent="."]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
|
visible = false
|
||||||
enabled = true
|
enabled = true
|
||||||
cast_to = Vector2( 0, 16 )
|
cast_to = Vector2( 0, 16 )
|
||||||
collision_mask = 8
|
collision_mask = 8
|
||||||
|
|
||||||
[node name="SlopeRaycastRight" type="RayCast2D" parent="."]
|
[node name="SlopeRaycastRight" type="RayCast2D" parent="."]
|
||||||
|
visible = false
|
||||||
position = Vector2( 10, 0 )
|
position = Vector2( 10, 0 )
|
||||||
enabled = true
|
enabled = true
|
||||||
cast_to = Vector2( 0, 24 )
|
cast_to = Vector2( 0, 24 )
|
||||||
|
|||||||
@ -3,7 +3,8 @@ extends Camera2D
|
|||||||
var horizontal_facing = 0
|
var horizontal_facing = 0
|
||||||
var vertical_facing = 0
|
var vertical_facing = 0
|
||||||
var camera_vertical_shift = 0
|
var camera_vertical_shift = 0
|
||||||
var move_time: float = 0
|
var right_move_time: float = 0
|
||||||
|
var left_move_time: float = 0
|
||||||
var slow_time: float = 0
|
var slow_time: float = 0
|
||||||
var original_limit_left: int
|
var original_limit_left: int
|
||||||
var original_limit_right: int
|
var original_limit_right: int
|
||||||
@ -13,8 +14,8 @@ var camera_is_panning: bool = false
|
|||||||
var target_offset: Vector2 = Vector2(0,0)
|
var target_offset: Vector2 = Vector2(0,0)
|
||||||
|
|
||||||
export var camera_horizontal_shift = 60
|
export var camera_horizontal_shift = 60
|
||||||
export var offset_reset_seconds := 0.9
|
export var offset_reset_seconds := 1
|
||||||
export var offset_adapt_seconds := 0.7
|
export var offset_adapt_seconds := 1
|
||||||
|
|
||||||
onready var shiftLeft = $CameraAnimationPlayer.get_animation("shiftingLeft")
|
onready var shiftLeft = $CameraAnimationPlayer.get_animation("shiftingLeft")
|
||||||
onready var shiftRight = $CameraAnimationPlayer.get_animation("shiftingRight")
|
onready var shiftRight = $CameraAnimationPlayer.get_animation("shiftingRight")
|
||||||
@ -44,14 +45,21 @@ func _physics_process(delta: float) -> void:
|
|||||||
if(!GlobalState.is_dead):
|
if(!GlobalState.is_dead):
|
||||||
var player_vel = (blobby.position - prev_pos)/delta
|
var player_vel = (blobby.position - prev_pos)/delta
|
||||||
# TODO Take average of velocity here
|
# TODO Take average of velocity here
|
||||||
if(abs(player_vel.x) >= blobby.max_velocity["walk"] * 0.97
|
if(abs(player_vel.x) >= blobby.max_velocity["walk"] * 0.97
|
||||||
&& (sign(player_vel.x) == sign(target_offset.x) || target_offset.x == 0)):
|
&& (sign(player_vel.x) == sign(target_offset.x) || target_offset.x == 0)):
|
||||||
move_time += delta
|
if(player_vel.x > 0):
|
||||||
elif(abs(player_vel.x) <= blobby.max_velocity["walk"] * 0.05
|
right_move_time += delta
|
||||||
|
left_move_time = max(0, left_move_time - delta)
|
||||||
|
slow_time = max(0, slow_time - delta)
|
||||||
|
else:
|
||||||
|
left_move_time += delta
|
||||||
|
right_move_time = max(0, right_move_time - delta)
|
||||||
|
slow_time = max(0, slow_time - delta)
|
||||||
|
elif(abs(player_vel.x) <= blobby.max_velocity["walk"] * 0.9
|
||||||
|| sign(player_vel.x) != sign(target_offset.x) || target_offset.x == 0):
|
|| sign(player_vel.x) != sign(target_offset.x) || target_offset.x == 0):
|
||||||
slow_time += delta
|
slow_time += delta
|
||||||
else:
|
left_move_time = max(0, left_move_time - delta)
|
||||||
move_time = max(0, move_time - delta)
|
right_move_time = max(0, right_move_time - delta)
|
||||||
|
|
||||||
if(!anim_player.is_playing()):
|
if(!anim_player.is_playing()):
|
||||||
_adapt_to_movement(player_vel)
|
_adapt_to_movement(player_vel)
|
||||||
@ -66,7 +74,7 @@ func _physics_process(delta: float) -> void:
|
|||||||
func _set_boundaries():
|
func _set_boundaries():
|
||||||
# This is ok, because it only happens on initialization
|
# This is ok, because it only happens on initialization
|
||||||
# But it is also quite fickle
|
# But it is also quite fickle
|
||||||
var tilemap = get_node("../%TileMap")
|
var tilemap = get_node("./%TileMap")
|
||||||
# TODO: This goes wrong when overwriting old tiles with new sprites
|
# TODO: This goes wrong when overwriting old tiles with new sprites
|
||||||
# New pngs -> completely new tiles and rebuild map
|
# New pngs -> completely new tiles and rebuild map
|
||||||
var rect = tilemap.get_used_rect()
|
var rect = tilemap.get_used_rect()
|
||||||
@ -98,33 +106,38 @@ func _adapt_to_movement(velocity: Vector2) -> void:
|
|||||||
var right_edge_pos = center.x + screen_rect.x/2 - camera_horizontal_shift
|
var right_edge_pos = center.x + screen_rect.x/2 - camera_horizontal_shift
|
||||||
# TODO: Blobby can go off screen, when shifting camera at level edge and returning i
|
# TODO: Blobby can go off screen, when shifting camera at level edge and returning i
|
||||||
# n the opposite direction slowly
|
# n the opposite direction slowly
|
||||||
if(move_time >= offset_adapt_seconds && !anim_player.is_playing()):
|
if(left_move_time >= offset_adapt_seconds && !anim_player.is_playing()):
|
||||||
move_time = 0
|
left_move_time = 0
|
||||||
target_offset.x = camera_horizontal_shift * sign(velocity.x)
|
target_offset.x = -camera_horizontal_shift
|
||||||
if(offset == target_offset ||
|
if(offset == target_offset ||
|
||||||
left_edge_pos + target_offset.x - 24 < limit_left ||
|
left_edge_pos + target_offset.x - 24 < limit_left ||
|
||||||
right_edge_pos + target_offset.x + 24 > limit_right ):
|
right_edge_pos + target_offset.x + 24 > limit_right ):
|
||||||
return
|
return
|
||||||
if(sign(velocity.x) < 0):
|
offset_track = shiftLeft.find_track(".:offset")
|
||||||
offset_track = shiftLeft.find_track(".:offset")
|
shiftLeft.track_set_key_value(offset_track, 0, offset)
|
||||||
shiftLeft.track_set_key_value(offset_track, 0, offset)
|
shiftLeft.track_set_key_value(offset_track, 1, target_offset)
|
||||||
shiftLeft.track_set_key_value(offset_track, 1, target_offset)
|
# limit_left = original_limit_left + camera_horizontal_shift
|
||||||
# limit_left = original_limit_left + camera_horizontal_shift
|
var limit_left_track = shiftLeft.find_track(".:limit_left")
|
||||||
var limit_left_track = shiftLeft.find_track(".:limit_left")
|
var new_limit_left = original_limit_left + camera_horizontal_shift
|
||||||
var new_limit_left = original_limit_left + camera_horizontal_shift
|
shiftLeft.track_set_key_value(limit_left_track, 0, limit_left)
|
||||||
shiftLeft.track_set_key_value(limit_left_track, 0, limit_left)
|
shiftLeft.track_set_key_value(limit_left_track, 1, new_limit_left)
|
||||||
shiftLeft.track_set_key_value(limit_left_track, 1, new_limit_left)
|
anim_player.play("shiftingLeft")
|
||||||
anim_player.play("shiftingLeft")
|
elif(right_move_time >= offset_adapt_seconds && !anim_player.is_playing()):
|
||||||
else:
|
right_move_time = 0
|
||||||
offset_track = shiftRight.find_track(".:offset")
|
target_offset.x = camera_horizontal_shift
|
||||||
shiftRight.track_set_key_value(offset_track, 0, offset)
|
if(offset == target_offset ||
|
||||||
shiftRight.track_set_key_value(offset_track, 1, target_offset)
|
left_edge_pos + target_offset.x - 24 < limit_left ||
|
||||||
# limit_right = original_limit_right - camera_horizontal_shift
|
right_edge_pos + target_offset.x + 24 > limit_right ):
|
||||||
var limit_right_track = shiftRight.find_track(".:limit_right")
|
return
|
||||||
var new_limit_right = original_limit_right - camera_horizontal_shift
|
offset_track = shiftRight.find_track(".:offset")
|
||||||
shiftRight.track_set_key_value(limit_right_track, 0, limit_right)
|
shiftRight.track_set_key_value(offset_track, 0, offset)
|
||||||
shiftRight.track_set_key_value(limit_right_track, 1, new_limit_right)
|
shiftRight.track_set_key_value(offset_track, 1, target_offset)
|
||||||
anim_player.play("shiftingRight")
|
# limit_right = original_limit_right - camera_horizontal_shift
|
||||||
|
var limit_right_track = shiftRight.find_track(".:limit_right")
|
||||||
|
var new_limit_right = original_limit_right - camera_horizontal_shift
|
||||||
|
shiftRight.track_set_key_value(limit_right_track, 0, limit_right)
|
||||||
|
shiftRight.track_set_key_value(limit_right_track, 1, new_limit_right)
|
||||||
|
anim_player.play("shiftingRight")
|
||||||
elif(slow_time >= offset_reset_seconds):
|
elif(slow_time >= offset_reset_seconds):
|
||||||
slow_time = 0
|
slow_time = 0
|
||||||
target_offset.x = 0
|
target_offset.x = 0
|
||||||
@ -173,7 +186,6 @@ func _update_lighting_shader():
|
|||||||
# var top_left = -vtrans.origin / vtrans.get_scale()
|
# var top_left = -vtrans.origin / vtrans.get_scale()
|
||||||
# var vsize = get_viewport_rect().size
|
# var vsize = get_viewport_rect().size
|
||||||
# var t = Transform2D(0, (top_left + 0.5*vsize/vtrans.get_scale()).rotated(rotation))
|
# var t = Transform2D(0, (top_left + 0.5*vsize/vtrans.get_scale()).rotated(rotation))
|
||||||
|
|
||||||
image.set_pixel(i, 0, Color(
|
image.set_pixel(i, 0, Color(
|
||||||
light.position.x, light.position.y,
|
light.position.x, light.position.y,
|
||||||
light.strength, light.radius
|
light.strength, light.radius
|
||||||
|
|||||||
@ -532,7 +532,7 @@ drag_margin_v_enabled = true
|
|||||||
drag_margin_left = 0.05
|
drag_margin_left = 0.05
|
||||||
drag_margin_top = 0.0
|
drag_margin_top = 0.0
|
||||||
drag_margin_right = 0.05
|
drag_margin_right = 0.05
|
||||||
drag_margin_bottom = 0.01
|
drag_margin_bottom = 0.0
|
||||||
editor_draw_drag_margin = true
|
editor_draw_drag_margin = true
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
|
|
||||||
@ -633,10 +633,10 @@ texture = ExtResource( 8 )
|
|||||||
[node name="AnimatedSprite" type="AnimatedSprite" parent="ParallaxBackground/ParallaxLayer5"]
|
[node name="AnimatedSprite" type="AnimatedSprite" parent="ParallaxBackground/ParallaxLayer5"]
|
||||||
visible = false
|
visible = false
|
||||||
frames = SubResource( 7 )
|
frames = SubResource( 7 )
|
||||||
frame = 10
|
frame = 6
|
||||||
playing = true
|
playing = true
|
||||||
|
|
||||||
[node name="AnimatedSprite2" type="AnimatedSprite" parent="ParallaxBackground/ParallaxLayer5"]
|
[node name="AnimatedSprite2" type="AnimatedSprite" parent="ParallaxBackground/ParallaxLayer5"]
|
||||||
frames = SubResource( 8 )
|
frames = SubResource( 8 )
|
||||||
frame = 1
|
frame = 11
|
||||||
playing = true
|
playing = true
|
||||||
|
|||||||
@ -3,37 +3,116 @@ const PhysicsFunc = preload("res://src/Utilities/Physic/PhysicsFunc.gd")
|
|||||||
|
|
||||||
onready var players = get_tree().get_nodes_in_group("player")
|
onready var players = get_tree().get_nodes_in_group("player")
|
||||||
|
|
||||||
onready var nav_agent: NavigationAgent2D = $NavigationAgent2D
|
onready var vision_raycast: RayCast2D = $VisionRayCast
|
||||||
|
onready var orientation: RayCast2D = $Orientation
|
||||||
onready var feeler_raycast: RayCast2D = $FeelerRayCast
|
onready var feeler_raycast: RayCast2D = $FeelerRayCast
|
||||||
|
onready var nav_agent: NavigationAgent2D = $NavigationAgent2D
|
||||||
onready var tilemap: TileMap = $"../%TileMap"
|
onready var tilemap: TileMap = $"../%TileMap"
|
||||||
|
onready var target_lost_timer: Timer
|
||||||
|
onready var update_navigation_timer: Timer
|
||||||
onready var rng = RandomNumberGenerator.new()
|
onready var rng = RandomNumberGenerator.new()
|
||||||
|
|
||||||
export var score := 100
|
export var score := 100
|
||||||
# Is given in blocks
|
# Is given in blocks
|
||||||
export var vision_distance := 6.0
|
export var vision_distance := 6.0
|
||||||
|
export var blindspot_angle := 20
|
||||||
|
export var loose_target_seconds := 3.0
|
||||||
|
export var patrolling := false
|
||||||
|
export var aggressive := true
|
||||||
|
export var acceleration := 50
|
||||||
|
export var patrolling_slowdown := 0.80
|
||||||
|
export var max_speed := 90
|
||||||
|
export var weight := 0.15
|
||||||
|
|
||||||
|
var path_direction: Vector2 = Vector2()
|
||||||
var target: Object = null
|
var target: Object = null
|
||||||
|
var patrol_waypoints := []
|
||||||
|
var patrol_waypoint_index := 0
|
||||||
|
var next_waypoint: Vector2
|
||||||
var is_hurt := false
|
var is_hurt := false
|
||||||
var has_reversed := false
|
var has_reversed := false
|
||||||
var avoidance_raycasts := []
|
var avoidance_raycasts := []
|
||||||
|
var slow_down_factor := 1.0
|
||||||
|
|
||||||
|
var detect_timer := 0.0
|
||||||
|
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
spawn_avoidance_raycasts(32, 20)
|
spawn_avoidance_raycasts(32, 24)
|
||||||
|
target_lost_timer = Timer.new()
|
||||||
|
target_lost_timer.set_one_shot(true)
|
||||||
|
target_lost_timer.connect("timeout", self, "lose_target")
|
||||||
|
add_child(target_lost_timer)
|
||||||
|
update_navigation_timer = Timer.new()
|
||||||
|
update_navigation_timer.connect("timeout", self, "update_navigation")
|
||||||
|
add_child(update_navigation_timer)
|
||||||
|
update_navigation_timer.start(0.5)
|
||||||
|
# TODO Hat immer den Spawn im Patrolpath
|
||||||
|
patrol_waypoints.append(global_position)
|
||||||
|
for waypoint in $PatrolPath.get_children():
|
||||||
|
patrol_waypoints.append(waypoint.global_position)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func searching() -> Vector2:
|
func searching() -> Vector2:
|
||||||
# TODO Less often!
|
slow_down_factor = patrolling_slowdown
|
||||||
|
if(aggressive && detect_timer > 0.33):
|
||||||
|
detect_player()
|
||||||
|
detect_timer = 0.0
|
||||||
|
if(patrolling && nav_agent.is_target_reached()):
|
||||||
|
next_waypoint = get_next_patrol_target()
|
||||||
|
update_navigation()
|
||||||
|
elif(patrolling):
|
||||||
|
next_waypoint = patrol_waypoints[patrol_waypoint_index]
|
||||||
|
else:
|
||||||
|
# Spawn location
|
||||||
|
return patrol_waypoints[0]
|
||||||
return nav_agent.get_next_location()
|
return nav_agent.get_next_location()
|
||||||
|
|
||||||
func execute_movement(_delta: float) -> void:
|
func get_next_patrol_target() -> Vector2:
|
||||||
nav_agent.set_target_location(players[0].global_position)
|
var waypoint_count = patrol_waypoints.size()
|
||||||
var next_pos = velocity - global_position
|
for wp in patrol_waypoints:
|
||||||
|
if next_waypoint == wp:
|
||||||
|
patrol_waypoint_index = patrol_waypoint_index + 1 if patrol_waypoint_index < waypoint_count - 1 else 0
|
||||||
|
return patrol_waypoints[patrol_waypoint_index]
|
||||||
|
patrol_waypoint_index = 0
|
||||||
|
return patrol_waypoints[0]
|
||||||
|
|
||||||
|
func hunting() -> Vector2:
|
||||||
|
slow_down_factor = 1.0
|
||||||
|
if(detect_timer > 0.33):
|
||||||
|
detect_player()
|
||||||
|
detect_timer = 0.0
|
||||||
|
next_waypoint = players[0].global_position - Vector2(0,9)
|
||||||
|
return nav_agent.get_next_location()
|
||||||
|
|
||||||
|
func detect_player() -> void:
|
||||||
|
var player
|
||||||
|
if(players.empty()):
|
||||||
|
print("no player found")
|
||||||
|
return
|
||||||
|
player = players[0]
|
||||||
|
#TODO Depends on height of blobby sprite since blobbys bottom and not his middle is on y=0
|
||||||
|
vision_raycast.cast_to = (player.global_position - global_position - Vector2(0,9)).normalized() * 24 * vision_distance
|
||||||
|
var ray_angle_to_facing = vision_raycast.cast_to.angle_to(orientation.cast_to)
|
||||||
|
vision_raycast.force_raycast_update()
|
||||||
|
var collider = vision_raycast.get_collider()
|
||||||
|
if(abs(ray_angle_to_facing) < PI/2-deg2rad(blindspot_angle) && collider != null && collider.is_in_group("player")):
|
||||||
|
target_lost_timer.stop()
|
||||||
|
target = collider
|
||||||
|
print("target found")
|
||||||
|
elif(target != null && target_lost_timer.is_stopped()):
|
||||||
|
target_lost_timer.start(loose_target_seconds)
|
||||||
|
|
||||||
|
func execute_movement(delta: float) -> void:
|
||||||
|
detect_timer += delta
|
||||||
|
var next_direction = path_direction - global_position
|
||||||
|
orientation.cast_to = Vector2(sign(next_direction.x),0)*50
|
||||||
var avoidance_obstacle_distance = average_collision_vector(avoidance_raycasts)
|
var avoidance_obstacle_distance = average_collision_vector(avoidance_raycasts)
|
||||||
next_pos = next_pos.normalized() + avoidance_obstacle_distance.rotated(PI).normalized()
|
next_direction = next_direction.normalized() + avoidance_obstacle_distance.rotated(PI).normalized()
|
||||||
check_feeler((next_pos * 100))
|
# TODO Make parameters more tunable
|
||||||
#TODO
|
velocity = move_and_slide(PhysicsFunc.two_step_euler_vec(velocity, next_direction.normalized() * acceleration * slow_down_factor, weight, delta)
|
||||||
velocity = move_and_slide(next_pos.normalized() * 50, FLOOR_NORMAL, false, 4, 0.785398,false)
|
,FLOOR_NORMAL, false, 4, 0.785398,false)
|
||||||
|
velocity = velocity/max((velocity.length()/(max_speed*slow_down_factor)),1)
|
||||||
|
|
||||||
func average_collision_vector(var raycasts: Array) -> Vector2:
|
func average_collision_vector(var raycasts: Array) -> Vector2:
|
||||||
var total_distances = Vector2()
|
var total_distances = Vector2()
|
||||||
@ -44,11 +123,6 @@ func average_collision_vector(var raycasts: Array) -> Vector2:
|
|||||||
total_distances += collision_point
|
total_distances += collision_point
|
||||||
return total_distances/raycasts.size()
|
return total_distances/raycasts.size()
|
||||||
|
|
||||||
func can_reverse_facing_direction() -> bool:
|
|
||||||
if(is_on_floor() && !has_reversed):
|
|
||||||
return true
|
|
||||||
return false
|
|
||||||
|
|
||||||
func spawn_avoidance_raycasts(var raycount: int, var length: float = 24) -> void:
|
func spawn_avoidance_raycasts(var raycount: int, var length: float = 24) -> void:
|
||||||
var direction: float = 0
|
var direction: float = 0
|
||||||
while direction <= 2*PI:
|
while direction <= 2*PI:
|
||||||
@ -72,3 +146,14 @@ func check_feeler(v: Vector2, _offset = Vector2(0,0)) -> Object:
|
|||||||
feeler_raycast.force_raycast_update()
|
feeler_raycast.force_raycast_update()
|
||||||
feeler_raycast.position = prev_position
|
feeler_raycast.position = prev_position
|
||||||
return feeler_raycast.get_collider()
|
return feeler_raycast.get_collider()
|
||||||
|
|
||||||
|
func lose_target() -> void:
|
||||||
|
print("flyer target lost")
|
||||||
|
target = null
|
||||||
|
|
||||||
|
func update_navigation() -> void:
|
||||||
|
nav_agent.set_target_location(next_waypoint)
|
||||||
|
|
||||||
|
func die() -> void:
|
||||||
|
GlobalState.score += score
|
||||||
|
queue_free()
|
||||||
|
|||||||
@ -3,10 +3,10 @@
|
|||||||
[ext_resource path="res://src/Actors/Enemies/Beings/Flyer.gd" type="Script" id=1]
|
[ext_resource path="res://src/Actors/Enemies/Beings/Flyer.gd" type="Script" id=1]
|
||||||
[ext_resource path="res://src/Actors/Enemies/Beings/FlyerStateMachine.gd" type="Script" id=2]
|
[ext_resource path="res://src/Actors/Enemies/Beings/FlyerStateMachine.gd" type="Script" id=2]
|
||||||
[ext_resource path="res://assets/meta/new_dynamicfont.tres" type="DynamicFont" id=3]
|
[ext_resource path="res://assets/meta/new_dynamicfont.tres" type="DynamicFont" id=3]
|
||||||
[ext_resource path="res://assets/blobby/idle/blobby1.png" type="Texture" id=4]
|
[ext_resource path="res://assets/for testing/Adventurer Sprite Sheet v1.1.png" type="Texture" id=4]
|
||||||
|
|
||||||
[sub_resource type="RectangleShape2D" id=1]
|
[sub_resource type="RectangleShape2D" id=1]
|
||||||
extents = Vector2( 12, 9 )
|
extents = Vector2( 11, 9 )
|
||||||
|
|
||||||
[sub_resource type="RectangleShape2D" id=2]
|
[sub_resource type="RectangleShape2D" id=2]
|
||||||
extents = Vector2( 15, 5.12039 )
|
extents = Vector2( 15, 5.12039 )
|
||||||
@ -14,16 +14,19 @@ extents = Vector2( 15, 5.12039 )
|
|||||||
[sub_resource type="RectangleShape2D" id=3]
|
[sub_resource type="RectangleShape2D" id=3]
|
||||||
extents = Vector2( 18.2143, 14.3338 )
|
extents = Vector2( 18.2143, 14.3338 )
|
||||||
|
|
||||||
[node name="Flyer" type="KinematicBody2D" groups=["harmful"]]
|
[node name="Flyer" type="KinematicBody2D" groups=["frogfood", "harmful"]]
|
||||||
collision_layer = 2
|
collision_layer = 258
|
||||||
collision_mask = 9
|
collision_mask = 9
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
|
vision_distance = 8.0
|
||||||
|
blindspot_angle = 30
|
||||||
|
loose_target_seconds = 5.0
|
||||||
|
patrolling = true
|
||||||
|
|
||||||
[node name="Statemachine" type="Node2D" parent="."]
|
[node name="Statemachine" type="Node2D" parent="."]
|
||||||
script = ExtResource( 2 )
|
script = ExtResource( 2 )
|
||||||
|
|
||||||
[node name="StateLabel" type="Label" parent="."]
|
[node name="StateLabel" type="Label" parent="."]
|
||||||
visible = false
|
|
||||||
show_behind_parent = true
|
show_behind_parent = true
|
||||||
margin_left = -36.0
|
margin_left = -36.0
|
||||||
margin_top = -30.0
|
margin_top = -30.0
|
||||||
@ -37,9 +40,12 @@ align = 1
|
|||||||
valign = 1
|
valign = 1
|
||||||
|
|
||||||
[node name="FlyerSprite" type="Sprite" parent="."]
|
[node name="FlyerSprite" type="Sprite" parent="."]
|
||||||
position = Vector2( -1, -1 )
|
position = Vector2( 2, -8 )
|
||||||
scale = Vector2( 1, 1.34375 )
|
scale = Vector2( 1, 1.34375 )
|
||||||
texture = ExtResource( 4 )
|
texture = ExtResource( 4 )
|
||||||
|
hframes = 13
|
||||||
|
vframes = 16
|
||||||
|
frame = 81
|
||||||
|
|
||||||
[node name="VisibilityEnabler2D" type="VisibilityEnabler2D" parent="."]
|
[node name="VisibilityEnabler2D" type="VisibilityEnabler2D" parent="."]
|
||||||
position = Vector2( 954, 0 )
|
position = Vector2( 954, 0 )
|
||||||
@ -58,7 +64,9 @@ collide_with_areas = true
|
|||||||
shape = SubResource( 1 )
|
shape = SubResource( 1 )
|
||||||
|
|
||||||
[node name="NavigationAgent2D" type="NavigationAgent2D" parent="."]
|
[node name="NavigationAgent2D" type="NavigationAgent2D" parent="."]
|
||||||
path_max_distance = 100.0
|
path_desired_distance = 4.0
|
||||||
|
target_desired_distance = 8.0
|
||||||
|
path_max_distance = 50.0
|
||||||
|
|
||||||
[node name="cshape" type="Node2D" parent="."]
|
[node name="cshape" type="Node2D" parent="."]
|
||||||
position = Vector2( 0, -3.8147e-06 )
|
position = Vector2( 0, -3.8147e-06 )
|
||||||
@ -89,5 +97,24 @@ collision_mask = 126
|
|||||||
[node name="CollisionPolygon2D" type="CollisionShape2D" parent="EnemySkin"]
|
[node name="CollisionPolygon2D" type="CollisionShape2D" parent="EnemySkin"]
|
||||||
shape = SubResource( 3 )
|
shape = SubResource( 3 )
|
||||||
|
|
||||||
|
[node name="PatrolPath" type="Node2D" parent="."]
|
||||||
|
|
||||||
|
[node name="Position2D2" type="Position2D" parent="PatrolPath"]
|
||||||
|
position = Vector2( 72, 0 )
|
||||||
|
|
||||||
|
[node name="Position2D3" type="Position2D" parent="PatrolPath"]
|
||||||
|
position = Vector2( -72, 0 )
|
||||||
|
|
||||||
|
[node name="Orientation" type="RayCast2D" parent="."]
|
||||||
|
cast_to = Vector2( -1, 0 )
|
||||||
|
collision_mask = 0
|
||||||
|
collide_with_bodies = false
|
||||||
|
|
||||||
|
[node name="VisionRayCast" type="RayCast2D" parent="."]
|
||||||
|
enabled = true
|
||||||
|
cast_to = Vector2( 0, -1 )
|
||||||
|
collision_mask = 9
|
||||||
|
collide_with_areas = true
|
||||||
|
|
||||||
[connection signal="body_entered" from="StompDetector" to="." method="_on_StompDetector_body_entered"]
|
[connection signal="body_entered" from="StompDetector" to="." method="_on_StompDetector_body_entered"]
|
||||||
[connection signal="area_entered" from="EnemySkin" to="." method="_on_EnemySkin_area_entered"]
|
[connection signal="area_entered" from="EnemySkin" to="." method="_on_EnemySkin_area_entered"]
|
||||||
|
|||||||
@ -20,7 +20,7 @@ func _ready() -> void:
|
|||||||
# Game logic consequences of state
|
# Game logic consequences of state
|
||||||
func _state_logic(delta):
|
func _state_logic(delta):
|
||||||
var state_action_ref = funcref(parent, self.state)
|
var state_action_ref = funcref(parent, self.state)
|
||||||
parent.velocity = state_action_ref.call_func()
|
parent.path_direction = state_action_ref.call_func()
|
||||||
parent.execute_movement(delta)
|
parent.execute_movement(delta)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -3,10 +3,12 @@ const PhysicsFunc = preload("res://src/Utilities/Physic/PhysicsFunc.gd")
|
|||||||
|
|
||||||
onready var players = get_tree().get_nodes_in_group("player")
|
onready var players = get_tree().get_nodes_in_group("player")
|
||||||
|
|
||||||
|
|
||||||
onready var vision_raycast: RayCast2D = $VisionRayCast
|
onready var vision_raycast: RayCast2D = $VisionRayCast
|
||||||
onready var orientation: RayCast2D = $Orientation
|
onready var orientation: RayCast2D = $Orientation
|
||||||
onready var feeler_raycast: RayCast2D = $FeelerRayCast
|
onready var feeler_raycast: RayCast2D = $FeelerRayCast
|
||||||
onready var tilemap: TileMap = $"../%TileMap"
|
onready var tilemap: TileMap = $"../%TileMap"
|
||||||
|
onready var state_machine = $Statemachine
|
||||||
onready var jump_timer: Timer
|
onready var jump_timer: Timer
|
||||||
onready var target_lost_timer: Timer
|
onready var target_lost_timer: Timer
|
||||||
onready var rng = RandomNumberGenerator.new()
|
onready var rng = RandomNumberGenerator.new()
|
||||||
@ -14,6 +16,8 @@ onready var rng = RandomNumberGenerator.new()
|
|||||||
export var score := 100
|
export var score := 100
|
||||||
# Is given in blocks
|
# Is given in blocks
|
||||||
export var vision_distance := 6.0
|
export var vision_distance := 6.0
|
||||||
|
export var attack_jump_range := 6.0
|
||||||
|
export var loose_target_seconds := 3.0
|
||||||
# Jump distance in blocks
|
# Jump distance in blocks
|
||||||
export var default_jump_distance := 3.0
|
export var default_jump_distance := 3.0
|
||||||
export var default_jump_angle := 70.0
|
export var default_jump_angle := 70.0
|
||||||
@ -27,9 +31,12 @@ var movement_radius: float
|
|||||||
var anchor: Node2D
|
var anchor: Node2D
|
||||||
var is_bound := false
|
var is_bound := false
|
||||||
var was_restricted := false
|
var was_restricted := false
|
||||||
|
var barely_held_back_counter := 0
|
||||||
var has_reversed := false
|
var has_reversed := false
|
||||||
|
|
||||||
|
var food_sources = []
|
||||||
var target: Object = null
|
var target: Object = null
|
||||||
|
var food_target: Object = null
|
||||||
|
|
||||||
var start_x := 0.0
|
var start_x := 0.0
|
||||||
var in_air := false
|
var in_air := false
|
||||||
@ -37,6 +44,7 @@ var is_hurt := false
|
|||||||
var stored_x_vel = 0.0
|
var stored_x_vel = 0.0
|
||||||
|
|
||||||
var current_delta = 0.0
|
var current_delta = 0.0
|
||||||
|
var detect_timer := 0.0
|
||||||
|
|
||||||
var reversing_possible_searching := true
|
var reversing_possible_searching := true
|
||||||
|
|
||||||
@ -48,7 +56,7 @@ func _ready():
|
|||||||
jump_timer.connect("timeout", self, "jump")
|
jump_timer.connect("timeout", self, "jump")
|
||||||
target_lost_timer = Timer.new()
|
target_lost_timer = Timer.new()
|
||||||
target_lost_timer.set_one_shot(true)
|
target_lost_timer.set_one_shot(true)
|
||||||
target_lost_timer.connect("timeout", self, "lose_target")
|
target_lost_timer.connect("timeout", self, "loose_target")
|
||||||
add_child(jump_timer)
|
add_child(jump_timer)
|
||||||
add_child(target_lost_timer)
|
add_child(target_lost_timer)
|
||||||
|
|
||||||
@ -70,6 +78,7 @@ func _on_StompDetector_body_entered(body: Node) -> void:
|
|||||||
func execute_movement(delta: float) -> void:
|
func execute_movement(delta: float) -> void:
|
||||||
# Navigation2DServer.map_get_path()
|
# Navigation2DServer.map_get_path()
|
||||||
current_delta = delta
|
current_delta = delta
|
||||||
|
detect_timer += delta
|
||||||
velocity.y += _gravity * delta
|
velocity.y += _gravity * delta
|
||||||
if(is_bound):
|
if(is_bound):
|
||||||
var next_position = global_position + velocity * current_delta
|
var next_position = global_position + velocity * current_delta
|
||||||
@ -99,9 +108,16 @@ func _on_EnemySkin_area_entered(area:Area2D) -> void:
|
|||||||
die()
|
die()
|
||||||
|
|
||||||
|
|
||||||
func searching() -> Vector2:
|
func _on_EnemySkin_body_entered(body: Node) -> void:
|
||||||
detect_player()
|
if body.is_in_group("frogfood"):
|
||||||
|
loose_target()
|
||||||
|
body.die()
|
||||||
|
|
||||||
|
|
||||||
|
func searching() -> Vector2:
|
||||||
|
if(detect_timer > 0.333):
|
||||||
|
search_next_target()
|
||||||
|
detect_timer = 0.0
|
||||||
if(is_on_floor()):
|
if(is_on_floor()):
|
||||||
if(jump_timer.is_stopped()):
|
if(jump_timer.is_stopped()):
|
||||||
jump_timer.start(rng.randfn(jump_time_search, jump_time_standard_deviation))
|
jump_timer.start(rng.randfn(jump_time_search, jump_time_standard_deviation))
|
||||||
@ -113,18 +129,37 @@ func searching() -> Vector2:
|
|||||||
reversing_possible_searching = true
|
reversing_possible_searching = true
|
||||||
jump_timer.stop()
|
jump_timer.stop()
|
||||||
in_air = true
|
in_air = true
|
||||||
|
|
||||||
return velocity
|
return velocity
|
||||||
|
|
||||||
|
|
||||||
func hunting() -> Vector2:
|
func search_next_target():
|
||||||
detect_player()
|
if(target != null && !weakref(target).get_ref()):
|
||||||
|
return
|
||||||
|
detect_food()
|
||||||
|
if(food_target == null):
|
||||||
|
detect_player()
|
||||||
|
|
||||||
|
|
||||||
|
func hunting() -> Vector2:
|
||||||
|
var was_target_freed = !weakref(target).get_ref()
|
||||||
|
if(detect_timer > 0.333):
|
||||||
|
search_next_target()
|
||||||
|
detect_timer = 0.0
|
||||||
|
#TODO Dependent on block size
|
||||||
|
elif(is_on_floor() && food_target != null && !was_target_freed &&
|
||||||
|
global_position.distance_to(food_target.global_position) <= attack_jump_range * 24):
|
||||||
|
|
||||||
|
var collider = check_feeler(food_target.global_position - global_position)
|
||||||
|
if(barely_held_back_counter == 0 && collider != null && collider.is_in_group("frogfood")):
|
||||||
|
jump_timer.stop()
|
||||||
|
return attack_jump(food_target.global_position)
|
||||||
|
|
||||||
if(is_on_floor()):
|
if(is_on_floor()):
|
||||||
if(jump_timer.is_stopped()):
|
if(jump_timer.is_stopped()):
|
||||||
jump_timer.start(rng.randfn(jump_time_hunt, jump_time_standard_deviation))
|
jump_timer.start(rng.randfn(jump_time_hunt, jump_time_standard_deviation))
|
||||||
if(in_air):
|
if(in_air):
|
||||||
in_air = false
|
in_air = false
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if(!in_air):
|
if(!in_air):
|
||||||
start_x = global_position.x
|
start_x = global_position.x
|
||||||
@ -132,25 +167,61 @@ func hunting() -> Vector2:
|
|||||||
jump_timer.stop()
|
jump_timer.stop()
|
||||||
in_air = true
|
in_air = true
|
||||||
|
|
||||||
|
if(barely_held_back_counter > 1):
|
||||||
|
barely_held_back_counter = 0
|
||||||
|
loose_target()
|
||||||
|
|
||||||
|
if(target != null && !was_target_freed &&
|
||||||
|
sign((target.global_position - global_position).x) != get_facing_direction()):
|
||||||
|
reverse_facing_direction()
|
||||||
|
|
||||||
return velocity
|
return velocity
|
||||||
|
|
||||||
|
|
||||||
|
func detect_food() -> void:
|
||||||
|
# TODO What if food spawns in
|
||||||
|
food_sources = get_tree().get_nodes_in_group("frogfood")
|
||||||
|
if(food_sources.empty()):
|
||||||
|
return
|
||||||
|
var i = 0
|
||||||
|
var min_dist_f_index = 0
|
||||||
|
var min_dist = (food_sources[0].global_position - global_position).length()
|
||||||
|
var food_node = null
|
||||||
|
for f in food_sources:
|
||||||
|
var new_dist = (food_sources[i].global_position - global_position).length()
|
||||||
|
min_dist = new_dist if new_dist < min_dist else min_dist
|
||||||
|
min_dist_f_index = i if new_dist < min_dist else min_dist_f_index
|
||||||
|
i += 1
|
||||||
|
food_node = food_sources[min_dist_f_index]
|
||||||
|
#TODO Depends on height of blobby sprite since blobbys bottom and not his middle is on y=0
|
||||||
|
vision_raycast.cast_to = (food_node.global_position - global_position).normalized() * 24 * vision_distance
|
||||||
|
var ray_angle_to_facing = vision_raycast.cast_to.angle_to(orientation.cast_to)
|
||||||
|
vision_raycast.force_raycast_update()
|
||||||
|
var collider = vision_raycast.get_collider()
|
||||||
|
if(abs(ray_angle_to_facing) < PI/3 && collider != null && collider.is_in_group("frogfood")):
|
||||||
|
target_lost_timer.stop()
|
||||||
|
target = collider
|
||||||
|
food_target = collider
|
||||||
|
elif(target != null && target_lost_timer.is_stopped()):
|
||||||
|
target_lost_timer.start(loose_target_seconds)
|
||||||
|
|
||||||
|
|
||||||
func detect_player() -> void:
|
func detect_player() -> void:
|
||||||
var player
|
var player
|
||||||
if(players.empty()):
|
if(players.empty()):
|
||||||
print("no player found")
|
print("no player found")
|
||||||
return
|
return
|
||||||
player = players[0]
|
player = players[0]
|
||||||
vision_raycast.cast_to = (player.global_position - global_position).normalized() * 24 * vision_distance
|
#TODO Depends on height of blobby sprite since blobbys bottom and not his middle is on y=0
|
||||||
|
vision_raycast.cast_to = (player.global_position - global_position - Vector2(0, 9)).normalized() * 24 * vision_distance
|
||||||
var ray_angle_to_facing = vision_raycast.cast_to.angle_to(orientation.cast_to)
|
var ray_angle_to_facing = vision_raycast.cast_to.angle_to(orientation.cast_to)
|
||||||
vision_raycast.force_raycast_update()
|
vision_raycast.force_raycast_update()
|
||||||
var collider = vision_raycast.get_collider()
|
var collider = vision_raycast.get_collider()
|
||||||
if(target == null && abs(ray_angle_to_facing) < PI/4 && collider != null && collider.is_in_group("player")):
|
if(abs(ray_angle_to_facing) < PI/4 && collider != null && collider.is_in_group("player")):
|
||||||
target_lost_timer.stop()
|
target_lost_timer.stop()
|
||||||
target = collider
|
target = collider
|
||||||
print("target found")
|
|
||||||
elif(target != null && target_lost_timer.is_stopped()):
|
elif(target != null && target_lost_timer.is_stopped()):
|
||||||
target_lost_timer.start(3.0)
|
target_lost_timer.start(loose_target_seconds)
|
||||||
|
|
||||||
|
|
||||||
func sleeping() -> Vector2:
|
func sleeping() -> Vector2:
|
||||||
@ -159,9 +230,10 @@ func sleeping() -> Vector2:
|
|||||||
return velocity
|
return velocity
|
||||||
|
|
||||||
|
|
||||||
func lose_target() -> void:
|
func loose_target() -> void:
|
||||||
print("target lost")
|
print("frog target lost")
|
||||||
target = null
|
target = null
|
||||||
|
food_target = null
|
||||||
|
|
||||||
|
|
||||||
func jump():
|
func jump():
|
||||||
@ -178,8 +250,11 @@ func jump():
|
|||||||
var new_distance = next_position.distance_to(anchor.global_position)
|
var new_distance = next_position.distance_to(anchor.global_position)
|
||||||
# print(current_distance)
|
# print(current_distance)
|
||||||
# print(new_distance)
|
# print(new_distance)
|
||||||
|
# Would go out of distance
|
||||||
if((new_distance >= movement_radius && new_distance > current_distance) || (new_distance > current_distance && was_restricted)):
|
if((new_distance >= movement_radius && new_distance > current_distance) || (new_distance > current_distance && was_restricted)):
|
||||||
if can_reverse_facing_direction():
|
if(state_machine.state == "hunting"):
|
||||||
|
barely_held_back_counter += 1
|
||||||
|
if can_reverse_facing_direction() && (barely_held_back_counter == 0 || barely_held_back_counter > 1):
|
||||||
reverse_facing_direction()
|
reverse_facing_direction()
|
||||||
was_restricted = false
|
was_restricted = false
|
||||||
|
|
||||||
@ -228,10 +303,9 @@ func consider_jump_headspace(v: Vector2) -> Vector2:
|
|||||||
var new_distance = default_jump_distance * (0.66 if target_height > -26 else 0.75)
|
var new_distance = default_jump_distance * (0.66 if target_height > -26 else 0.75)
|
||||||
v = velocity_for_jump_distance(new_distance, abs(new_angle))
|
v = velocity_for_jump_distance(new_distance, abs(new_angle))
|
||||||
v = correct_jump_direction(v)
|
v = correct_jump_direction(v)
|
||||||
height = calculate_jump_height(v)
|
height = calculate_jump_height(v) * -1
|
||||||
distance = calculate_jump_distance(v) * get_facing_direction()
|
distance = calculate_jump_distance(v) * get_facing_direction()
|
||||||
height_collider = check_feeler(Vector2(get_facing_direction()*(distance/2), (-height)), Vector2(0,-23))
|
if(height < target_height && can_reverse_facing_direction()):
|
||||||
if(height_collider != null && can_reverse_facing_direction()):
|
|
||||||
print("no safe height for frog jump")
|
print("no safe height for frog jump")
|
||||||
return Vector2(0,0)
|
return Vector2(0,0)
|
||||||
return v
|
return v
|
||||||
@ -263,6 +337,7 @@ func consider_jump_landing_space(v: Vector2) -> Vector2:
|
|||||||
return Vector2(0,0)
|
return Vector2(0,0)
|
||||||
return v
|
return v
|
||||||
|
|
||||||
|
|
||||||
func consider_jumping_on_top() -> Vector2:
|
func consider_jumping_on_top() -> Vector2:
|
||||||
var collider = check_feeler(Vector2(42 * get_facing_direction(),0))
|
var collider = check_feeler(Vector2(42 * get_facing_direction(),0))
|
||||||
var facing = 0 if get_facing_direction() >= 0 else - 1
|
var facing = 0 if get_facing_direction() >= 0 else - 1
|
||||||
@ -358,8 +433,9 @@ func change_jump_distance(target_distance: float, v: Vector2) -> Vector2:
|
|||||||
var initial_distance = calculate_jump_distance(v)
|
var initial_distance = calculate_jump_distance(v)
|
||||||
return v.normalized() * sqrt(pow(v.length(),2)/(initial_distance/target_distance))
|
return v.normalized() * sqrt(pow(v.length(),2)/(initial_distance/target_distance))
|
||||||
|
|
||||||
|
|
||||||
# Takes an angle and a distance to calculate a jump launching at that angle and covering the distance
|
# Takes an angle and a distance to calculate a jump launching at that angle and covering the distance
|
||||||
func velocity_for_jump_distance(distance: float = 3*24, angle: float = deg2rad(65)) -> Vector2:
|
func velocity_for_jump_distance(distance: float = default_jump_distance*24, angle: float = deg2rad(default_jump_angle)) -> 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)
|
||||||
|
|
||||||
@ -370,14 +446,31 @@ func can_reverse_facing_direction() -> bool:
|
|||||||
return false
|
return false
|
||||||
|
|
||||||
|
|
||||||
# Checks the feeler ray for collisions and returns collision or null
|
# Returns a jump velocity that has the target_position in it's path
|
||||||
|
func attack_jump(target_position: Vector2) -> Vector2:
|
||||||
|
var target_vector = target_position - global_position
|
||||||
|
target_vector = Vector2(abs(target_vector.x), target_vector.y)
|
||||||
|
var jump_angle = target_vector.angle()
|
||||||
|
var v = Vector2()
|
||||||
|
# TODO Tunable parameters
|
||||||
|
if jump_angle < deg2rad(-30):
|
||||||
|
v = velocity_for_jump_distance(target_vector.x, deg2rad(default_jump_angle))
|
||||||
|
v = jump_height_to_velocity(abs(target_vector.y), v)
|
||||||
|
else:
|
||||||
|
v = velocity_for_jump_distance(target_vector.x * 1.5,deg2rad(45))
|
||||||
|
v = correct_jump_direction(v)
|
||||||
|
return v
|
||||||
|
|
||||||
|
|
||||||
|
# Checks the feeler ray for collisions and returns collider or null
|
||||||
func check_feeler(v: Vector2, _offset = Vector2(0,0)) -> Object:
|
func check_feeler(v: Vector2, _offset = Vector2(0,0)) -> Object:
|
||||||
var prev_position = feeler_raycast.position
|
var prev_position = feeler_raycast.position
|
||||||
feeler_raycast.position += _offset
|
feeler_raycast.position += _offset
|
||||||
feeler_raycast.cast_to = v
|
feeler_raycast.cast_to = v
|
||||||
feeler_raycast.force_raycast_update()
|
feeler_raycast.force_raycast_update()
|
||||||
|
var collider = feeler_raycast.get_collider()
|
||||||
feeler_raycast.position = prev_position
|
feeler_raycast.position = prev_position
|
||||||
return feeler_raycast.get_collider()
|
return collider
|
||||||
|
|
||||||
|
|
||||||
func reverse_facing_direction() -> void:
|
func reverse_facing_direction() -> void:
|
||||||
|
|||||||
@ -410,15 +410,17 @@ physics_process_parent = true
|
|||||||
[node name="FeelerRayCast" type="RayCast2D" parent="."]
|
[node name="FeelerRayCast" type="RayCast2D" parent="."]
|
||||||
enabled = true
|
enabled = true
|
||||||
cast_to = Vector2( 0, -1 )
|
cast_to = Vector2( 0, -1 )
|
||||||
collision_mask = 56
|
collision_mask = 312
|
||||||
collide_with_areas = true
|
collide_with_areas = true
|
||||||
|
|
||||||
[node name="Orientation" type="RayCast2D" parent="."]
|
[node name="Orientation" type="RayCast2D" parent="."]
|
||||||
|
visible = false
|
||||||
cast_to = Vector2( -1, 0 )
|
cast_to = Vector2( -1, 0 )
|
||||||
collision_mask = 0
|
collision_mask = 0
|
||||||
collide_with_bodies = false
|
collide_with_bodies = false
|
||||||
|
|
||||||
[node name="Left_Wallcast" type="RayCast2D" parent="."]
|
[node name="Left_Wallcast" type="RayCast2D" parent="."]
|
||||||
|
visible = false
|
||||||
position = Vector2( -10, 6 )
|
position = Vector2( -10, 6 )
|
||||||
enabled = true
|
enabled = true
|
||||||
cast_to = Vector2( -5, 0 )
|
cast_to = Vector2( -5, 0 )
|
||||||
@ -426,6 +428,7 @@ collision_mask = 56
|
|||||||
collide_with_areas = true
|
collide_with_areas = true
|
||||||
|
|
||||||
[node name="Right_Wallcast" type="RayCast2D" parent="."]
|
[node name="Right_Wallcast" type="RayCast2D" parent="."]
|
||||||
|
visible = false
|
||||||
position = Vector2( 10, 6 )
|
position = Vector2( 10, 6 )
|
||||||
enabled = true
|
enabled = true
|
||||||
cast_to = Vector2( 5, 0 )
|
cast_to = Vector2( 5, 0 )
|
||||||
@ -433,9 +436,10 @@ collision_mask = 56
|
|||||||
collide_with_areas = true
|
collide_with_areas = true
|
||||||
|
|
||||||
[node name="VisionRayCast" type="RayCast2D" parent="."]
|
[node name="VisionRayCast" type="RayCast2D" parent="."]
|
||||||
|
visible = false
|
||||||
enabled = true
|
enabled = true
|
||||||
cast_to = Vector2( 0, -1 )
|
cast_to = Vector2( 0, -1 )
|
||||||
collision_mask = 9
|
collision_mask = 265
|
||||||
collide_with_areas = true
|
collide_with_areas = true
|
||||||
|
|
||||||
[node name="EnemyBody" type="CollisionShape2D" parent="." groups=["harmful"]]
|
[node name="EnemyBody" type="CollisionShape2D" parent="." groups=["harmful"]]
|
||||||
@ -473,3 +477,4 @@ shape = SubResource( 3 )
|
|||||||
|
|
||||||
[connection signal="body_entered" from="StompDetector" to="." method="_on_StompDetector_body_entered"]
|
[connection signal="body_entered" from="StompDetector" to="." method="_on_StompDetector_body_entered"]
|
||||||
[connection signal="area_entered" from="EnemySkin" to="." method="_on_EnemySkin_area_entered"]
|
[connection signal="area_entered" from="EnemySkin" to="." method="_on_EnemySkin_area_entered"]
|
||||||
|
[connection signal="body_entered" from="EnemySkin" to="." method="_on_EnemySkin_body_entered"]
|
||||||
|
|||||||
@ -20,7 +20,7 @@ func _ready() -> void:
|
|||||||
|
|
||||||
|
|
||||||
# Game logic consequences of state
|
# Game logic consequences of state
|
||||||
func _state_logic(delta):
|
func _state_logic(delta):
|
||||||
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)
|
||||||
|
|||||||
@ -7,7 +7,7 @@ radius = 2.0
|
|||||||
|
|
||||||
[node name="RopeAnchor" type="RigidBody2D"]
|
[node name="RopeAnchor" type="RigidBody2D"]
|
||||||
z_index = -1
|
z_index = -1
|
||||||
collision_layer = 256
|
collision_layer = 0
|
||||||
collision_mask = 8
|
collision_mask = 8
|
||||||
input_pickable = true
|
input_pickable = true
|
||||||
mode = 1
|
mode = 1
|
||||||
|
|||||||
@ -7,7 +7,7 @@ radius = 1.0
|
|||||||
height = 1.0
|
height = 1.0
|
||||||
|
|
||||||
[node name="RigidBody2D" type="RigidBody2D"]
|
[node name="RigidBody2D" type="RigidBody2D"]
|
||||||
collision_layer = 256
|
collision_layer = 0
|
||||||
collision_mask = 8
|
collision_mask = 8
|
||||||
gravity_scale = 3.0
|
gravity_scale = 3.0
|
||||||
linear_damp = 1.0
|
linear_damp = 1.0
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -18,3 +18,8 @@ static func two_step_euler(v0, force, mass, delta) -> float:
|
|||||||
var v1 = v0 + force / mass * delta
|
var v1 = v0 + force / mass * delta
|
||||||
var v2 = v1 + force / mass * delta
|
var v2 = v1 + force / mass * delta
|
||||||
return (v1 + v2) / 2
|
return (v1 + v2) / 2
|
||||||
|
|
||||||
|
static func two_step_euler_vec(v0: Vector2, force: Vector2, mass: float, delta: float) -> Vector2:
|
||||||
|
var v1 = v0 + force / mass * delta
|
||||||
|
var v2 = v1 + force / mass * delta
|
||||||
|
return (v1 + v2) / 2
|
||||||
Loading…
Reference in New Issue
Block a user