dev-base #36

Merged
Snoweuph merged 54 commits from dev-base into nightly 2023-04-05 21:01:03 +00:00
7 changed files with 162 additions and 68 deletions
Showing only changes of commit 502d0c440d - Show all commits

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 B

View file

@ -16,9 +16,9 @@ dest_files=["res://.godot/imported/basic_enemy.png-86528a00f666ed79fdb26797653ef
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/bptc_ldr=0
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false

View file

@ -28,7 +28,7 @@ texture = ExtResource("1")
0:1/0/terrains_peering_bit/top_right_corner = 0
0:2/size_in_atlas = Vector2i(1, 2)
0:2/0 = 0
0:2/0/texture_offset = Vector2i(0, -8)
0:2/0/texture_origin = Vector2i(0, -8)
0:2/0/terrain_set = 0
0:2/0/terrain = 0
0:2/0/physics_layer_0/linear_velocity = Vector2(0, 0)
@ -40,7 +40,7 @@ texture = ExtResource("1")
0:2/0/terrains_peering_bit/top_right_corner = 0
1:2/size_in_atlas = Vector2i(1, 2)
1:2/0 = 0
1:2/0/texture_offset = Vector2i(0, -8)
1:2/0/texture_origin = Vector2i(0, -8)
1:2/0/terrain_set = 0
1:2/0/terrain = 0
1:2/0/physics_layer_0/linear_velocity = Vector2(0, 0)
@ -99,7 +99,7 @@ texture = ExtResource("1")
2:1/0/terrains_peering_bit/top_side = 0
2:2/size_in_atlas = Vector2i(1, 2)
2:2/0 = 0
2:2/0/texture_offset = Vector2i(0, -8)
2:2/0/texture_origin = Vector2i(0, -8)
2:2/0/terrain_set = 0
2:2/0/terrain = 0
2:2/0/physics_layer_0/linear_velocity = Vector2(0, 0)
@ -198,7 +198,7 @@ texture = ExtResource("1")
5:1/0/terrains_peering_bit/top_side = 0
5:2/size_in_atlas = Vector2i(1, 2)
5:2/0 = 0
5:2/0/texture_offset = Vector2i(0, -8)
5:2/0/texture_origin = Vector2i(0, -8)
5:2/0/terrain_set = 0
5:2/0/terrain = 0
5:2/0/physics_layer_0/linear_velocity = Vector2(0, 0)
@ -259,7 +259,7 @@ texture = ExtResource("1")
7:1/0/terrains_peering_bit/left_side = 0
7:2/size_in_atlas = Vector2i(1, 2)
7:2/0 = 0
7:2/0/texture_offset = Vector2i(0, -8)
7:2/0/texture_origin = Vector2i(0, -8)
7:2/0/terrain_set = 0
7:2/0/terrain = 0
7:2/0/physics_layer_0/linear_velocity = Vector2(0, 0)
@ -271,7 +271,7 @@ texture = ExtResource("1")
7:2/0/terrains_peering_bit/top_side = 0
6:2/size_in_atlas = Vector2i(1, 2)
6:2/0 = 0
6:2/0/texture_offset = Vector2i(0, -8)
6:2/0/texture_origin = Vector2i(0, -8)
6:2/0/terrain_set = 0
6:2/0/terrain = 0
6:2/0/physics_layer_0/linear_velocity = Vector2(0, 0)
@ -283,7 +283,7 @@ texture = ExtResource("1")
6:2/0/terrains_peering_bit/top_side = 0
19:2/size_in_atlas = Vector2i(1, 2)
19:2/0 = 0
19:2/0/texture_offset = Vector2i(0, -8)
19:2/0/texture_origin = Vector2i(0, -8)
19:2/0/terrain_set = 0
19:2/0/terrain = 1
19:2/0/physics_layer_0/linear_velocity = Vector2(0, 0)
@ -295,7 +295,7 @@ texture = ExtResource("1")
19:2/0/terrains_peering_bit/top_side = 1
18:2/size_in_atlas = Vector2i(1, 2)
18:2/0 = 0
18:2/0/texture_offset = Vector2i(0, -8)
18:2/0/texture_origin = Vector2i(0, -8)
18:2/0/terrain_set = 0
18:2/0/terrain = 1
18:2/0/physics_layer_0/linear_velocity = Vector2(0, 0)
@ -307,7 +307,7 @@ texture = ExtResource("1")
18:2/0/terrains_peering_bit/top_side = 1
17:2/size_in_atlas = Vector2i(1, 2)
17:2/0 = 0
17:2/0/texture_offset = Vector2i(0, -8)
17:2/0/texture_origin = Vector2i(0, -8)
17:2/0/terrain_set = 0
17:2/0/terrain = 1
17:2/0/physics_layer_0/linear_velocity = Vector2(0, 0)
@ -344,7 +344,7 @@ texture = ExtResource("1")
15:2/0/terrains_peering_bit/top_right_corner = 1
14:2/size_in_atlas = Vector2i(1, 2)
14:2/0 = 0
14:2/0/texture_offset = Vector2i(0, -8)
14:2/0/texture_origin = Vector2i(0, -8)
14:2/0/terrain_set = 0
14:2/0/terrain = 1
14:2/0/physics_layer_0/linear_velocity = Vector2(0, 0)
@ -382,7 +382,7 @@ texture = ExtResource("1")
15:3/0/terrains_peering_bit/top_right_corner = 1
13:2/size_in_atlas = Vector2i(1, 2)
13:2/0 = 0
13:2/0/texture_offset = Vector2i(0, -8)
13:2/0/texture_origin = Vector2i(0, -8)
13:2/0/terrain_set = 0
13:2/0/terrain = 1
13:2/0/physics_layer_0/linear_velocity = Vector2(0, 0)
@ -395,7 +395,7 @@ texture = ExtResource("1")
13:2/0/terrains_peering_bit/top_right_corner = 1
12:2/size_in_atlas = Vector2i(1, 2)
12:2/0 = 0
12:2/0/texture_offset = Vector2i(0, -8)
12:2/0/texture_origin = Vector2i(0, -8)
12:2/0/terrain_set = 0
12:2/0/terrain = 1
12:2/0/physics_layer_0/linear_velocity = Vector2(0, 0)
@ -559,7 +559,7 @@ texture = ExtResource("1")
12:1/0/terrains_peering_bit/top_right_corner = 1
8:2/size_in_atlas = Vector2i(1, 2)
8:2/0 = 0
8:2/0/texture_offset = Vector2i(0, -8)
8:2/0/texture_origin = Vector2i(0, -8)
8:2/0/terrain_set = 0
8:2/0/terrain = 0
8:2/0/physics_layer_0/linear_velocity = Vector2(0, 0)
@ -765,7 +765,7 @@ texture = ExtResource("1")
20:1/0/terrains_peering_bit/top_side = 1
20:2/size_in_atlas = Vector2i(1, 2)
20:2/0 = 0
20:2/0/texture_offset = Vector2i(0, -8)
20:2/0/texture_origin = Vector2i(0, -8)
20:2/0/terrain_set = 0
20:2/0/terrain = 1
20:2/0/physics_layer_0/linear_velocity = Vector2(0, 0)
@ -874,7 +874,7 @@ texture = ExtResource("1")
0:4/0/terrains_peering_bit/bottom_side = 0
1:4/size_in_atlas = Vector2i(1, 2)
1:4/0 = 0
1:4/0/texture_offset = Vector2i(0, -8)
1:4/0/texture_origin = Vector2i(0, -8)
1:4/0/terrain_set = 0
1:4/0/terrain = 0
1:4/0/physics_layer_0/linear_velocity = Vector2(0, 0)
@ -883,7 +883,7 @@ texture = ExtResource("1")
1:4/0/terrains_peering_bit/top_side = 0
2:4/size_in_atlas = Vector2i(1, 2)
2:4/0 = 0
2:4/0/texture_offset = Vector2i(0, -8)
2:4/0/texture_origin = Vector2i(0, -8)
2:4/0/terrain_set = 0
2:4/0/terrain = 0
2:4/0/physics_layer_0/linear_velocity = Vector2(0, 0)
@ -892,7 +892,7 @@ texture = ExtResource("1")
2:4/0/terrains_peering_bit/right_side = 0
3:4/size_in_atlas = Vector2i(1, 2)
3:4/0 = 0
3:4/0/texture_offset = Vector2i(0, -8)
3:4/0/texture_origin = Vector2i(0, -8)
3:4/0/terrain_set = 0
3:4/0/terrain = 0
3:4/0/physics_layer_0/linear_velocity = Vector2(0, 0)
@ -912,7 +912,7 @@ texture = ExtResource("1")
4:4/0/terrains_peering_bit/left_side = 0
5:4/size_in_atlas = Vector2i(1, 2)
5:4/0 = 0
5:4/0/texture_offset = Vector2i(0, -8)
5:4/0/texture_origin = Vector2i(0, -8)
5:4/0/terrain_set = 0
5:4/0/terrain = 0
5:4/0/physics_layer_0/linear_velocity = Vector2(0, 0)
@ -954,7 +954,7 @@ texture = ExtResource("1")
12:4/0/terrains_peering_bit/bottom_side = 1
13:4/size_in_atlas = Vector2i(1, 2)
13:4/0 = 0
13:4/0/texture_offset = Vector2i(0, -8)
13:4/0/texture_origin = Vector2i(0, -8)
13:4/0/terrain_set = 0
13:4/0/terrain = 1
13:4/0/physics_layer_0/linear_velocity = Vector2(0, 0)
@ -963,7 +963,7 @@ texture = ExtResource("1")
13:4/0/terrains_peering_bit/top_side = 1
14:4/size_in_atlas = Vector2i(1, 2)
14:4/0 = 0
14:4/0/texture_offset = Vector2i(0, -8)
14:4/0/texture_origin = Vector2i(0, -8)
14:4/0/terrain_set = 0
14:4/0/terrain = 1
14:4/0/physics_layer_0/linear_velocity = Vector2(0, 0)
@ -972,7 +972,7 @@ texture = ExtResource("1")
14:4/0/terrains_peering_bit/right_side = 1
15:4/size_in_atlas = Vector2i(1, 2)
15:4/0 = 0
15:4/0/texture_offset = Vector2i(0, -8)
15:4/0/texture_origin = Vector2i(0, -8)
15:4/0/terrain_set = 0
15:4/0/terrain = 1
15:4/0/physics_layer_0/linear_velocity = Vector2(0, 0)
@ -992,7 +992,7 @@ texture = ExtResource("1")
16:4/0/terrains_peering_bit/left_side = 1
17:4/size_in_atlas = Vector2i(1, 2)
17:4/0 = 0
17:4/0/texture_offset = Vector2i(0, -8)
17:4/0/texture_origin = Vector2i(0, -8)
17:4/0/terrain_set = 0
17:4/0/terrain = 1
17:4/0/physics_layer_0/linear_velocity = Vector2(0, 0)
@ -1140,7 +1140,7 @@ texture = ExtResource("1")
0:6/0/terrains_peering_bit/left_side = 0
1:6/size_in_atlas = Vector2i(1, 2)
1:6/0 = 0
1:6/0/texture_offset = Vector2i(0, -8)
1:6/0/texture_origin = Vector2i(0, -8)
1:6/0/terrain_set = 0
1:6/0/terrain = 0
1:6/0/physics_layer_0/linear_velocity = Vector2(0, 0)
@ -1178,7 +1178,7 @@ texture = ExtResource("1")
4:6/0/terrains_peering_bit/left_side = 0
5:6/size_in_atlas = Vector2i(1, 2)
5:6/0 = 0
5:6/0/texture_offset = Vector2i(0, -8)
5:6/0/texture_origin = Vector2i(0, -8)
5:6/0/terrain_set = 0
5:6/0/terrain = 0
5:6/0/physics_layer_0/linear_velocity = Vector2(0, 0)
@ -1216,7 +1216,7 @@ texture = ExtResource("1")
12:6/0/terrains_peering_bit/left_side = 1
13:6/size_in_atlas = Vector2i(1, 2)
13:6/0 = 0
13:6/0/texture_offset = Vector2i(0, -8)
13:6/0/texture_origin = Vector2i(0, -8)
13:6/0/terrain_set = 0
13:6/0/terrain = 1
13:6/0/physics_layer_0/linear_velocity = Vector2(0, 0)
@ -1254,7 +1254,7 @@ texture = ExtResource("1")
16:6/0/terrains_peering_bit/left_side = 1
17:6/size_in_atlas = Vector2i(1, 2)
17:6/0 = 0
17:6/0/texture_offset = Vector2i(0, -8)
17:6/0/texture_origin = Vector2i(0, -8)
17:6/0/terrain_set = 0
17:6/0/terrain = 1
17:6/0/physics_layer_0/linear_velocity = Vector2(0, 0)
@ -1804,6 +1804,7 @@ texture = ExtResource("1")
[resource]
physics_layer_0/collision_layer = 1
physics_layer_0/collision_mask = 0
terrain_set_0/mode = 0
terrain_set_0/terrain_0/name = "Colony Blue"
terrain_set_0/terrain_0/color = Color(0, 0.384314, 0.721569, 1)

File diff suppressed because one or more lines are too long

108
Scripts/Enemy/EnemyLook.gd Normal file
View file

@ -0,0 +1,108 @@
extends Node2D
@export_group("Movement Properties")
@export var speed = 25
@export var turn_speed = 25
@export_group("Vision Properties")
@export var ray : RayCast2D
@export_flags_2d_physics var player_collision_layer := 2
@export var max_view_distance := 50
@export_range(0.0, 360.0) var angle_cone_of_vision : float = 120
@export_range(0, 72) var sweeping_steps : int = 24
@export var debug_vision := false
var sees_player : bool
var player_positions : Array
func _ready():
# Set Raycast into view Direction
ray.target_position = Vector2(max_view_distance, 0)
pass
func view():
# Swipe the Raycast instead of using a lot to get better performance
# Set Raycast to starting position
ray.rotation_degrees = -angle_cone_of_vision / 2
# Create Array to Store Angles of Hits
var hit_angles : Array
# Clear Player Positions Array
player_positions.clear()
for step in sweeping_steps + 1:
# Check Ray
ray.force_raycast_update()
if ray.is_colliding():
# Get Collider
var collider = ray.get_collider()
var collider_class = collider.get_class()
var collision_layer : int
# Get Collision Layer
if collider_class == "TileMap":
collider = collider as TileMap
collision_layer = collider.tile_set.get_physics_layer_collision_layer(0)
else:
collision_layer = collider.get_collision_layer()
# Checking Collision Layer
if collision_layer & player_collision_layer > 0:
hit_angles.append(ray.rotation_degrees)
player_positions.append(to_local(ray.get_collision_point()))
# Rotate Ray
ray.rotation_degrees += angle_cone_of_vision / sweeping_steps
return hit_angles
func rotate_to_player(delta : float):
# Get All Angles at which the Player can be seen
var hit_angles = view()
# If The Player cant be seen, return and do nothing
if hit_angles.size() <= 0:
sees_player = false
return
sees_player = true
# Calculate Average Angle Of Player
var average_angle : float
for angle in hit_angles:
average_angle += angle
average_angle /= hit_angles.size()
# Rotate towards Player, but limit it by rotation speed
self.rotation_degrees += clampf(average_angle, -2 * PI * delta * turn_speed, 2 * PI * delta * turn_speed)
pass
func _physics_process(delta):
rotate_to_player(delta)
pass
func _process(delta):
if debug_vision:
queue_redraw()
pass
func _draw():
# Draw a Debug Arc in case that Debug Vision is enabled
if debug_vision:
# Draw All Ray Positions
var angle = -angle_cone_of_vision / 2
for step in sweeping_steps + 1:
self.draw_line(Vector2(), Vector2(max_view_distance,0).rotated(deg_to_rad(angle)), Color.DARK_RED, 0.5, false)
angle += angle_cone_of_vision / sweeping_steps
# Draw Ray Arc
self.draw_arc(Vector2(), max_view_distance, deg_to_rad(-angle_cone_of_vision / 2), deg_to_rad(angle_cone_of_vision / 2), sweeping_steps + 1, Color.RED, 0.5, false)
# Draw A Circle Around the Player if hes seen
if sees_player:
for pos in player_positions:
self.draw_circle(pos, 4, Color.ORANGE_RED)
pass

View file

@ -1,19 +0,0 @@
extends CharacterBody2D
@export var speed = 25
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(delta):
var sprite = self.get_child(1)
self.velocity = Vector2(cos(sprite.get_rotation() - PI / 2), sin(sprite.get_rotation() - PI / 2)).normalized() * speed
if self.move_and_slide():
sprite.rotate(PI)

View file

@ -65,6 +65,12 @@ do_shake={
]
}
[layer_names]
2d_physics/layer_1="Map"
2d_physics/layer_2="Player"
2d_physics/layer_3="Enemys"
[physics]
common/enable_pause_aware_picking=true