Added laserpoint to turret scene & move testlevel

This commit is contained in:
Jakob Feldmann 2022-06-20 23:00:43 +02:00
parent 9cef352fe2
commit 68511984c7
15 changed files with 282 additions and 41 deletions

Binary file not shown.

View File

@ -0,0 +1,26 @@
[remap]
importer="aseprite.wizard.plugin"
type="SpriteFrames"
path="res://.import/laserpoint.aseprite-bee1cba4b556a9418f3b7b1cd6c0be3e.res"
[deps]
source_file="res://assets/enemy/laserpoint.aseprite"
dest_files=[ "res://.import/laserpoint.aseprite-bee1cba4b556a9418f3b7b1cd6c0be3e.res" ]
[params]
split_layers=false
exclude_layers_pattern=""
only_visible_layers=false
sheet_type="Packed"
sprite_filename_pattern="{basename}.{layer}.{extension}"
texture_strip/import_texture_strip=false
texture_strip/filename_pattern="{basename}.{layer}.Strip.{extension}"
texture_atlas/import_texture_atlas=false
texture_atlas/filename_pattern="{basename}.{layer}.Atlas.{extension}"
texture_atlas/frame_filename_pattern="{basename}.{layer}.{animation}.{frame}.Atlas.{extension}"
animated_texture/import_animated_texture=false
animated_texture/filename_pattern="{basename}.{layer}.{animation}.Texture.{extension}"
animated_texture/frame_filename_pattern="{basename}.{layer}.{animation}.{frame}.Texture.{extension}"

BIN
assets/enemy/laserpoint.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 151 B

View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/laserpoint.png-b228f3d4dcfe8d6476e6068a85a04524.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/enemy/laserpoint.png"
dest_files=[ "res://.import/laserpoint.png-b228f3d4dcfe8d6476e6068a85a04524.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=false
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 628 B

View File

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/background tile.png-f280c3bf572e5293d0867d12a982e05d.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/environment/background/background tile.png"
dest_files=[ "res://.import/background tile.png-f280c3bf572e5293d0867d12a982e05d.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=false
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

View File

@ -3,7 +3,9 @@ extends KinematicBody2D
# Declare member variables here. Examples:
# var a: int = 2
# var b: String = "text"
onready var sightline: RayCast2D = $Sightline
onready var sightcone: Node2D = $SightCone
onready var aimline: RayCast2D = $Aimline
onready var laserpoint: Sprite = $Laserpoint
onready var turret_state_machine = $TurretStateMachine
onready var lock_on_timer = $LockOnTimer
onready var sight_lost_timer = $SightLostTimer
@ -27,17 +29,24 @@ var target_ray
func prey():
return prey_ref.get_ref()
func searching():
if sightline.is_colliding():
# The collider returns not the area or body it hit, but the parent of them
var collider = sightline.get_collider()
if collider.is_in_group("player"):
prey_ref = weakref(collider)
func position_laserpoint():
if aimline.is_colliding():
laserpoint.global_position = aimline.get_collision_point()
func searching():
position_laserpoint()
for sightline in sightcone.get_children():
if sightline.is_colliding():
# The collider returns not the area or body it hit, but the parent of them
var collider = sightline.get_collider()
if collider.is_in_group("player"):
prey_ref = weakref(collider)
# TODO should this stand still?
# TODO Use yield and coroutine instead
func start_locking():
position_laserpoint()
target_ray = RayCast2D.new()
add_child(target_ray)
target_ray.enabled = true
@ -54,7 +63,7 @@ func is_tracking_prey():
return true if(prey() != null) else false
func aiming():
var target_angle = target_ray.cast_to.angle_to(sightline.cast_to)
var target_angle = target_ray.cast_to.angle_to(aimline.cast_to)
var rotation_speed = max(
min_rotation_speed, abs(target_angle / rotation_speed_divider)
)
@ -66,28 +75,29 @@ func aiming():
rotation, original_rotation, original_rotation + angle_of_freedom
)
# Shoots and can loose the target
func shooting():
aiming()
if sightline.is_colliding():
# The collider returns not the area or body it hit, but the parent of them
# TODO Sight should be a cone instead of a ray
# This could be done with a permanent target ray and the angle between it and the sightline
var collider = sightline.get_collider()
if collider.is_in_group("player"):
sight_lost_timer.stop()
target_ray.cast_to = to_local(prey().position)
else:
if (
sight_lost_timer.get_time_left() < 0.1
&& sight_lost_timer.get_time_left() > 0
):
prey_ref = weakref(null)
target_ray.queue_free()
return
if sight_lost_timer.is_stopped():
sight_lost_timer.start()
elif(prey() != null):
for sightline in sightcone.get_children():
if sightline.is_colliding():
# The collider returns not the area or body it hit, but the parent of them
var collider = sightline.get_collider()
if collider.is_in_group("player"):
sight_lost_timer.stop()
target_ray.cast_to = to_local(prey().position)
else:
if (
sight_lost_timer.get_time_left() < 0.1
&& sight_lost_timer.get_time_left() > 0
):
prey_ref = weakref(null)
target_ray.queue_free()
return
if sight_lost_timer.is_stopped():
sight_lost_timer.start()
elif(prey() != null):
target_ray.cast_to = to_local(prey().position)
return
func spawn_projectile():
var b = Bullet.instance()

View File

@ -1,9 +1,10 @@
[gd_scene load_steps=8 format=2]
[gd_scene load_steps=9 format=2]
[ext_resource path="res://assets/contraption/bumper.png" type="Texture" id=1]
[ext_resource path="res://assets/meta/new_dynamicfont.tres" type="DynamicFont" id=2]
[ext_resource path="res://src/Actors/Enemies/Machines/Turret.gd" type="Script" id=3]
[ext_resource path="res://src/Actors/Enemies/Machines/TurretStateMachine.gd" type="Script" id=4]
[ext_resource path="res://assets/enemy/laserpoint.png" type="Texture" id=5]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 108.869, 37.8566 )
@ -26,7 +27,7 @@ tracks/0/keys = {
[sub_resource type="Animation" id=2]
resource_name = "Turret Rotation"
length = 6.66
length = 12.2
loop = true
tracks/0/type = "value"
tracks/0/path = NodePath(".:rotation_degrees")
@ -35,18 +36,18 @@ tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 3.2 ),
"times": PoolRealArray( 0, 6.1 ),
"transitions": PoolRealArray( 0.9, 1.1 ),
"update": 0,
"values": [ 0.0, 90.0 ]
}
[node name="Turret" type="KinematicBody2D"]
[node name="Turret" type="KinematicBody2D" groups=["enemy"]]
collision_layer = 2
collision_mask = 3
script = ExtResource( 3 )
[node name="Sprite" type="Sprite" parent="."]
[node name="Turret" type="Sprite" parent="."]
scale = Vector2( 0.612294, 1 )
texture = ExtResource( 1 )
@ -55,11 +56,6 @@ position = Vector2( 0, -0.103346 )
scale = Vector2( 0.310271, 1.02855 )
shape = SubResource( 1 )
[node name="Sightline" type="RayCast2D" parent="."]
enabled = true
cast_to = Vector2( 0, 1e+07 )
collision_mask = 59
[node name="TurretStateMachine" type="Node" parent="."]
script = ExtResource( 4 )
@ -94,4 +90,27 @@ playback_process_mode = 0
[node name="FiringRateTimer" type="Timer" parent="."]
wait_time = 0.1
[node name="Aimline" type="RayCast2D" parent="."]
enabled = true
cast_to = Vector2( 0, 100000 )
collision_mask = 123
[node name="SightCone" type="Node2D" parent="."]
[node name="Sightline1" type="RayCast2D" parent="SightCone"]
rotation = 0.0698132
enabled = true
cast_to = Vector2( 0, 100000 )
collision_mask = 123
[node name="Sightline2" type="RayCast2D" parent="SightCone"]
rotation = -0.0698132
enabled = true
cast_to = Vector2( 0, 100000 )
collision_mask = 121
[node name="Laserpoint" type="Sprite" parent="."]
z_index = -1
texture = ExtResource( 5 )
[connection signal="timeout" from="FiringRateTimer" to="." method="_on_FiringRateTimer_timeout"]

View File

@ -1,6 +1,7 @@
extends StateMachine
onready var anim_player = parent.get_node("AnimationPlayer")
onready var laserpoint: Sprite = parent.get_node("Laserpoint")
# Adds the intial states
func _ready():
@ -53,11 +54,14 @@ func _get_transition(_delta):
parent.get_node("StateLabel").text = self.state
var new_state
if parent.is_tracking_prey() && self.state == "searching":
laserpoint.visible = true
new_state = "locking"
# TODO Helper function with null check and reference check
if !parent.is_tracking_prey() && self.state == "shooting":
laserpoint.visible = true
new_state = "searching"
if self.state == "locking" && parent.is_locked_on_target():
laserpoint.visible = false
new_state = "shooting"
if new_state != self.state:
return new_state

View File

@ -64,7 +64,6 @@ func _Kinematic_Body_on_Spring() -> void:
y_velocity += PhysicsFunc.complete_unelastic_shock(
a_velocity, b_velocity, a_mass, b_mass
)
print(y_velocity)
stored_incoming_velocity = 0
shock_ready = false

View File

@ -1,10 +1,11 @@
[gd_scene load_steps=11 format=2]
[gd_scene load_steps=12 format=2]
[ext_resource path="res://src/Actors/Blobby/Blobby.tscn" type="PackedScene" id=1]
[ext_resource path="res://assets/environment/blocks/Basic stone block.png" type="Texture" id=2]
[ext_resource path="res://src/Contraptions/Platform/Spring.tscn" type="PackedScene" id=3]
[ext_resource path="res://src/Environment/Background.tscn" type="PackedScene" id=4]
[ext_resource path="res://src/Contraptions/Platform/Track.tscn" type="PackedScene" id=5]
[ext_resource path="res://src/Actors/Enemies/Machines/Turret.tscn" type="PackedScene" id=6]
[ext_resource path="res://src/UserInterface/Buttons/UI.tscn" type="PackedScene" id=7]
[sub_resource type="NavigationPolygon" id=1]
@ -63,6 +64,14 @@ collision_mask = 2147483648
format = 1
tile_data = PoolIntArray( 0, 0, 0, 1, 0, 0, 2, 0, 0, 3, 0, 0, 4, 0, 0, 5, 0, 0, 6, 0, 0, 7, 0, 0, 8, 0, 0, 9, 0, 0, 10, 0, 0, 11, 0, 0, 12, 0, 0, 13, 0, 0, 14, 0, 0, 15, 0, 0, 16, 0, 0, 17, 0, 0, 18, 0, 0, 19, 0, 0, 20, 0, 0, 21, 0, 0, 22, 0, 0, 23, 0, 0, 24, 0, 0, 25, 0, 0, 26, 0, 0, 27, 0, 0, 28, 0, 0, 29, 0, 0, 30, 0, 0, 65536, 0, 0, 65566, 0, 0, 131072, 0, 0, 131102, 0, 0, 196608, 0, 0, 196638, 0, 0, 262144, 0, 0, 262174, 0, 0, 327680, 0, 0, 327710, 0, 0, 393216, 0, 0, 393246, 0, 0, 458752, 0, 0, 458782, 0, 0, 524288, 0, 0, 524318, 0, 0, 589824, 0, 0, 589854, 0, 0, 655360, 0, 0, 655390, 0, 0, 720896, 0, 0, 720926, 0, 0, 786432, 0, 0, 786462, 0, 0, 851968, 0, 0, 851998, 0, 0, 917504, 0, 0, 917534, 0, 0, 983040, 0, 0, 983070, 0, 0, 1048576, 0, 0, 1048606, 0, 0, 1114112, 0, 0, 1114142, 0, 0, 1179648, 0, 0, 1179678, 0, 0, 1245184, 0, 0, 1245214, 0, 0, 1310720, 0, 0, 1310750, 0, 0, 1376256, 0, 0, 1376286, 0, 0, 1441792, 0, 0, 1441822, 0, 0, 1507328, 0, 0, 1507358, 0, 0, 1572864, 0, 0, 1572894, 0, 0, 1638400, 0, 0, 1638430, 0, 0, 1703936, 0, 0, 1703966, 0, 0, 1769472, 0, 0, 1769502, 0, 0, 1835008, 0, 0, 1835038, 0, 0, 1900544, 0, 0, 1900574, 0, 0, 1966080, 0, 0, 1966110, 0, 0, 2031616, 0, 0, 2031646, 0, 0, 2097152, 0, 0, 2097182, 0, 0, 2162688, 0, 0, 2162718, 0, 0, 2228224, 0, 0, 2228254, 0, 0, 2293760, 0, 0, 2293790, 0, 0, 2359296, 0, 0, 2359326, 0, 0, 2424832, 0, 0, 2424862, 0, 0, 2490368, 0, 0, 2490398, 0, 0, 2555904, 0, 0, 2555905, 0, 0, 2555906, 0, 0, 2555907, 0, 0, 2555908, 0, 0, 2555909, 0, 0, 2555910, 0, 0, 2555911, 0, 0, 2555912, 0, 0, 2555913, 0, 0, 2555914, 0, 0, 2555915, 0, 0, 2555916, 0, 0, 2555917, 0, 0, 2555918, 0, 0, 2555919, 0, 0, 2555920, 0, 0, 2555921, 0, 0, 2555922, 0, 0, 2555923, 0, 0, 2555924, 0, 0, 2555925, 0, 0, 2555926, 0, 0, 2555927, 0, 0, 2555928, 0, 0, 2555929, 0, 0, 2555930, 0, 0, 2555931, 0, 0, 2555932, 0, 0, 2555933, 0, 0, 2555934, 0, 0 )
[node name="Turret" parent="." instance=ExtResource( 6 )]
position = Vector2( 479, 430 )
scale = Vector2( 0.354, 0.354 )
[node name="Laserpoint" parent="Turret" index="11"]
position = Vector2( -8.71185, 539.311 )
scale = Vector2( 2.08898, 2.08898 )
[node name="Blobby" parent="." instance=ExtResource( 1 )]
position = Vector2( 50.7867, 604.063 )
@ -83,5 +92,6 @@ scale = Vector2( 2.83999, 0.56 )
[node name="KinematicBody2D" parent="Track" index="0"]
position = Vector2( 25.0812, 0 )
[editable path="Turret"]
[editable path="Spring4"]
[editable path="Track"]

View File

@ -4,7 +4,7 @@
[ext_resource path="res://assets/environment/blocks/Basic stone block.png" type="Texture" id=2]
[ext_resource path="res://src/Contraptions/Platform/Track.tscn" type="PackedScene" id=3]
[ext_resource path="res://assets/environment/background/background.png" type="Texture" id=4]
[ext_resource path="res://src/UserInterface/Portal.tscn" type="PackedScene" id=5]
[ext_resource path="res://src/Contraptions/Portal/Portal.tscn" type="PackedScene" id=5]
[sub_resource type="NavigationPolygon" id=1]
vertices = PoolVector2Array( 16, 16, 0, 16, 0, 0, 16, 0 )

File diff suppressed because one or more lines are too long

View File

@ -54,7 +54,7 @@ __meta__ = {
[node name="PlayButton" parent="ViewportContainer/MenuContainer" instance=ExtResource( 3 )]
margin_right = 97.0
margin_bottom = 38.0
next_scene_path = "res://src/Levels/Plattforms Level.tscn"
next_scene_path = "res://src/Levels/WalkNJumpTesterLevel.tscn"
[node name="QuitButton" parent="ViewportContainer/MenuContainer" instance=ExtResource( 1 )]
anchor_left = 0.0