From 71cf76e9ef1a8db886ac6805b4a74c0c27af5b52 Mon Sep 17 00:00:00 2001 From: Jakob Feldmann Date: Thu, 2 Jun 2022 20:08:02 +0200 Subject: [PATCH] Rudimentary turning and player detecting turret --- src/Actors/Blobby/Blobby.gd | 10 +--------- src/Actors/Blobby/Blobby.tscn | 2 +- src/Actors/Enemy/Enemy.gd | 2 +- src/Actors/Enemy/Turret.gd | 19 ++++++++++++++++++ src/Actors/Enemy/Turret.tscn | 29 +++++++++++++++++++++++++--- src/Actors/Enemy/TurretRayCast.gd | 14 ++++++++++++++ src/Actors/Player.gd | 2 +- src/Contraptions/Platform/Track.tscn | 1 - src/Levels/Plattforms Level.tscn | 9 +++++++-- 9 files changed, 70 insertions(+), 18 deletions(-) create mode 100644 src/Actors/Enemy/Turret.gd create mode 100644 src/Actors/Enemy/TurretRayCast.gd diff --git a/src/Actors/Blobby/Blobby.gd b/src/Actors/Blobby/Blobby.gd index abd600b..6f9b9a2 100644 --- a/src/Actors/Blobby/Blobby.gd +++ b/src/Actors/Blobby/Blobby.gd @@ -10,14 +10,9 @@ onready var init_boost_type = player_state_machine.init_boost_type onready var camera_tween = $Camera2D/ShiftTween onready var camera = $Camera2D -# TODO Stuck to Wallslide on input -# TODO Too much speed reduction on landings # TODO Too much speed through midair boosting -# TODO Mini hopping through jump buffer(rare wallslide) -# TODO Think about how each component and feature would scale in the future -# TODO This is the worst thing since... you know # When the Enemy stomp AREA enters the enemy collision area -> stomp func _on_BlobbySkin_area_entered(area: Area2D) -> void: if area.is_in_group("weakpoint"): @@ -128,7 +123,6 @@ func is_reversing_horizontal_movement(direction: Vector2) -> bool: # Returns if the character is touching a wall with its whole body # Being able to touch a vertical surface over this length also makes it a qualified "wall" # Also sets wall_touch_direction -# TODO Walljumping sometimes catapults the player func is_touching_wall_completely() -> bool: for left_raycast in left_wall_raycasts.get_children(): wall_touch_direction = -1 @@ -141,8 +135,6 @@ func is_touching_wall_completely() -> bool: return true -# TODO Player gets stuck to a wall easily -# TODO Boosters should be able to fire while wallsliding # Attached to wall state is in the PlayerStateMachine func is_correct_walljump_input(direction: Vector2) -> bool: return ( @@ -247,7 +239,7 @@ func calculate_fall_velocity( func calculate_wallslide_velocity( linear_velocity: Vector2, delta: float, direction: Vector2 ) -> Vector2: - # Walljump mechanicsdd + # Walljump mechanics if is_correct_walljump_input(direction): linear_velocity.x = PhysicsFunc.two_step_euler( 0, acceleration_force["walljump"].x * direction.x, mass, delta diff --git a/src/Actors/Blobby/Blobby.tscn b/src/Actors/Blobby/Blobby.tscn index 115c682..94c1bc9 100644 --- a/src/Actors/Blobby/Blobby.tscn +++ b/src/Actors/Blobby/Blobby.tscn @@ -6,7 +6,7 @@ [ext_resource path="res://src/Actors/Blobby/Blobby.gd" type="Script" id=4] [ext_resource path="res://assets/meta/new_dynamicfont.tres" type="DynamicFont" id=5] -[node name="Blobby" type="KinematicBody2D"] +[node name="Blobby" type="KinematicBody2D" groups=["player"]] collision_mask = 120 script = ExtResource( 4 ) diff --git a/src/Actors/Enemy/Enemy.gd b/src/Actors/Enemy/Enemy.gd index ad29adb..cde48f8 100644 --- a/src/Actors/Enemy/Enemy.gd +++ b/src/Actors/Enemy/Enemy.gd @@ -8,7 +8,7 @@ func _ready() -> void: velocity.x = -30 -# TODO Unify areas of kinematic bodies to skin +# TODO adapt to groups func _on_StompDetector_body_entered(body: Node) -> void: if body.global_position.y > get_node("StompDetector").global_position.y: return diff --git a/src/Actors/Enemy/Turret.gd b/src/Actors/Enemy/Turret.gd new file mode 100644 index 0000000..bec67c2 --- /dev/null +++ b/src/Actors/Enemy/Turret.gd @@ -0,0 +1,19 @@ +extends KinematicBody2D + +# Declare member variables here. Examples: +# var a: int = 2 +# var b: String = "text" +onready var raycast: RayCast2D = $RayCast2D + + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + $AnimationPlayer.play("Turret Rotation") + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _physics_process(_delta: float) -> void: + if raycast.is_colliding(): + # The collider returns not the area or body it hit, but the parent of them + if raycast.get_collider().is_in_group("player"): + print_debug("player found") diff --git a/src/Actors/Enemy/Turret.tscn b/src/Actors/Enemy/Turret.tscn index 91b4b9f..9d121a5 100644 --- a/src/Actors/Enemy/Turret.tscn +++ b/src/Actors/Enemy/Turret.tscn @@ -1,13 +1,32 @@ -[gd_scene load_steps=3 format=2] +[gd_scene load_steps=5 format=2] [ext_resource path="res://assets/contraption/bumper.png" type="Texture" id=1] +[ext_resource path="res://src/Actors/Enemy/Turret.gd" type="Script" id=2] [sub_resource type="RectangleShape2D" id=1] extents = Vector2( 108.869, 37.2448 ) +[sub_resource type="Animation" id=2] +resource_name = "Turret Rotation" +length = 6.66 +loop = true +tracks/0/type = "value" +tracks/0/path = NodePath(".:rotation_degrees") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/keys = { +"times": PoolRealArray( 0, 3.2 ), +"transitions": PoolRealArray( 1, 1 ), +"update": 0, +"values": [ 0.0, 90.0 ] +} + [node name="Turret" type="KinematicBody2D"] collision_layer = 2 collision_mask = 3 +script = ExtResource( 2 ) [node name="Sprite" type="Sprite" parent="."] scale = Vector2( 0.612294, 1 ) @@ -19,5 +38,9 @@ shape = SubResource( 1 ) [node name="RayCast2D" type="RayCast2D" parent="."] enabled = true -collision_mask = 0 -collide_with_bodies = false +cast_to = Vector2( 0, 1e+07 ) + +[node name="AnimationPlayer" type="AnimationPlayer" parent="."] +pause_mode = 2 +playback_process_mode = 0 +"anims/Turret Rotation" = SubResource( 2 ) diff --git a/src/Actors/Enemy/TurretRayCast.gd b/src/Actors/Enemy/TurretRayCast.gd new file mode 100644 index 0000000..567a888 --- /dev/null +++ b/src/Actors/Enemy/TurretRayCast.gd @@ -0,0 +1,14 @@ +extends RayCast2D + +# Declare member variables here. Examples: +# var a: int = 2 +# var b: String = "text" + + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + pass # Replace with function body. + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + diff --git a/src/Actors/Player.gd b/src/Actors/Player.gd index 7bf3e47..ebc52c2 100644 --- a/src/Actors/Player.gd +++ b/src/Actors/Player.gd @@ -23,7 +23,7 @@ var acceleration_force := { "walk": Vector2(2000, 68000), "idle": Vector2(2000, 68000), "run": Vector2(2000, 68000), - "walljump": Vector2(50000, 58000), + "walljump": Vector2(36000, 58000), "air_strafe": Vector2(20000, 0) } # Gravity as m/s^2 diff --git a/src/Contraptions/Platform/Track.tscn b/src/Contraptions/Platform/Track.tscn index c82d4a7..66751aa 100644 --- a/src/Contraptions/Platform/Track.tscn +++ b/src/Contraptions/Platform/Track.tscn @@ -27,7 +27,6 @@ tracks/0/keys = { script = ExtResource( 2 ) [node name="KinematicBody2D" type="KinematicBody2D" parent="."] -position = Vector2( 19.2307, 0 ) collision_layer = 8 collision_mask = 0 motion/sync_to_physics = true diff --git a/src/Levels/Plattforms Level.tscn b/src/Levels/Plattforms Level.tscn index 6c6de09..588e185 100644 --- a/src/Levels/Plattforms Level.tscn +++ b/src/Levels/Plattforms Level.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=12 format=2] +[gd_scene load_steps=13 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] @@ -7,6 +7,7 @@ [ext_resource path="res://src/Contraptions/Platform/Track.tscn" type="PackedScene" id=5] [ext_resource path="res://src/HarmfulObjects/Bullet.tscn" type="PackedScene" id=6] [ext_resource path="res://src/UserInterface/Buttons/UI.tscn" type="PackedScene" id=7] +[ext_resource path="res://src/Actors/Enemy/Turret.tscn" type="PackedScene" id=8] [sub_resource type="NavigationPolygon" id=1] vertices = PoolVector2Array( 16, 16, 0, 16, 0, 0, 16, 0 ) @@ -79,7 +80,11 @@ scale = Vector2( 2.83999, 0.56 ) position = Vector2( 8, 0 ) [node name="Bullet" parent="." instance=ExtResource( 6 )] -position = Vector2( 237.856, 601.801 ) +position = Vector2( 901, 579 ) + +[node name="Turret" parent="." instance=ExtResource( 8 )] +position = Vector2( 958.501, 464 ) +scale = Vector2( 0.5, 0.5 ) [editable path="Spring4"] [editable path="Track"]