Tut19 Complete: Camera

This commit is contained in:
Alan Youngblood 2024-11-30 15:43:01 -05:00
parent 54f9772836
commit d103dac31a
13 changed files with 55 additions and 5 deletions

BIN
.DS_Store vendored

Binary file not shown.

Binary file not shown.

View File

@ -21,6 +21,7 @@ onready var sprite = $AnimatedSprite
onready var stats = $Stats onready var stats = $Stats
onready var playerDetectionZone = $PlayerDetectionZone onready var playerDetectionZone = $PlayerDetectionZone
onready var hurtbox = $Hurtbox onready var hurtbox = $Hurtbox
onready var softCollision = $SoftCollision
func _physics_process(delta): func _physics_process(delta):
knockback = knockback.move_toward(Vector2.ZERO, 200 * delta) knockback = knockback.move_toward(Vector2.ZERO, 200 * delta)
@ -43,8 +44,11 @@ func _physics_process(delta):
state = IDLE state = IDLE
sprite.flip_h = velocity.x < 0 sprite.flip_h = velocity.x < 0
if softCollision.is_colliding():
velocity += softCollision.get_push_vector() * delta * 400
velocity = move_and_slide(velocity) velocity = move_and_slide(velocity)
func seek_player(): func seek_player():
if playerDetectionZone.can_see_player(): if playerDetectionZone.can_see_player():
state = CHASE state = CHASE

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=18 format=2] [gd_scene load_steps=20 format=2]
[ext_resource path="res://Enemies/Bat.png" type="Texture" id=1] [ext_resource path="res://Enemies/Bat.png" type="Texture" id=1]
[ext_resource path="res://Shadows/SmallShadow.png" type="Texture" id=2] [ext_resource path="res://Shadows/SmallShadow.png" type="Texture" id=2]
@ -7,6 +7,7 @@
[ext_resource path="res://Stats.tscn" type="PackedScene" id=5] [ext_resource path="res://Stats.tscn" type="PackedScene" id=5]
[ext_resource path="res://Enemies/PlayerDetectionZone.tscn" type="PackedScene" id=6] [ext_resource path="res://Enemies/PlayerDetectionZone.tscn" type="PackedScene" id=6]
[ext_resource path="res://Overlap/Hitbox.tscn" type="PackedScene" id=7] [ext_resource path="res://Overlap/Hitbox.tscn" type="PackedScene" id=7]
[ext_resource path="res://Overlap/SoftCollision.tscn" type="PackedScene" id=8]
[sub_resource type="AtlasTexture" id=1] [sub_resource type="AtlasTexture" id=1]
atlas = ExtResource( 1 ) atlas = ExtResource( 1 )
@ -49,6 +50,9 @@ radius = 61.0328
[sub_resource type="CircleShape2D" id=10] [sub_resource type="CircleShape2D" id=10]
radius = 5.0 radius = 5.0
[sub_resource type="CircleShape2D" id=11]
radius = 5.0
[node name="Bat" type="KinematicBody2D"] [node name="Bat" type="KinematicBody2D"]
collision_layer = 16 collision_layer = 16
script = ExtResource( 4 ) script = ExtResource( 4 )
@ -56,7 +60,6 @@ script = ExtResource( 4 )
[node name="AnimatedSprite" type="AnimatedSprite" parent="."] [node name="AnimatedSprite" type="AnimatedSprite" parent="."]
frames = SubResource( 6 ) frames = SubResource( 6 )
animation = "Fly" animation = "Fly"
frame = 1
playing = true playing = true
offset = Vector2( 0, -12 ) offset = Vector2( 0, -12 )
@ -64,9 +67,11 @@ offset = Vector2( 0, -12 )
texture = ExtResource( 2 ) texture = ExtResource( 2 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] [node name="CollisionShape2D" type="CollisionShape2D" parent="."]
visible = false
shape = SubResource( 7 ) shape = SubResource( 7 )
[node name="Hurtbox" parent="." instance=ExtResource( 3 )] [node name="Hurtbox" parent="." instance=ExtResource( 3 )]
visible = false
collision_layer = 8 collision_layer = 8
[node name="CollisionShape2D" parent="Hurtbox" index="0"] [node name="CollisionShape2D" parent="Hurtbox" index="0"]
@ -77,21 +82,29 @@ shape = SubResource( 8 )
max_health = 2 max_health = 2
[node name="PlayerDetectionZone" parent="." instance=ExtResource( 6 )] [node name="PlayerDetectionZone" parent="." instance=ExtResource( 6 )]
visible = false
[node name="CollisionShape2D" parent="PlayerDetectionZone" index="0"] [node name="CollisionShape2D" parent="PlayerDetectionZone" index="0"]
modulate = Color( 1, 1, 1, 0.258824 ) modulate = Color( 1, 1, 1, 0.258824 )
shape = SubResource( 9 ) shape = SubResource( 9 )
[node name="Hitbox" parent="." instance=ExtResource( 7 )] [node name="Hitbox" parent="." instance=ExtResource( 7 )]
visible = false
collision_mask = 4 collision_mask = 4
[node name="CollisionShape2D" parent="Hitbox" index="0"] [node name="CollisionShape2D" parent="Hitbox" index="0"]
position = Vector2( 0, -15 ) position = Vector2( 0, -15 )
shape = SubResource( 10 ) shape = SubResource( 10 )
[node name="SoftCollision" parent="." instance=ExtResource( 8 )]
[node name="CollisionShape2D" parent="SoftCollision" index="0"]
shape = SubResource( 11 )
[connection signal="area_entered" from="Hurtbox" to="." method="_on_Hurtbox_area_entered"] [connection signal="area_entered" from="Hurtbox" to="." method="_on_Hurtbox_area_entered"]
[connection signal="no_health" from="Stats" to="." method="_on_Stats_no_health"] [connection signal="no_health" from="Stats" to="." method="_on_Stats_no_health"]
[editable path="Hurtbox"] [editable path="Hurtbox"]
[editable path="PlayerDetectionZone"] [editable path="PlayerDetectionZone"]
[editable path="Hitbox"] [editable path="Hitbox"]
[editable path="SoftCollision"]

View File

@ -0,0 +1,14 @@
extends Area2D
func is_colliding():
var areas = get_overlapping_areas()
return areas.size() > 0
func get_push_vector():
var areas = get_overlapping_areas()
var push_vector = Vector2.ZERO
if is_colliding():
var area = areas[0]
push_vector = area.global_position.direction_to(global_position)
push_vector = push_vector.normalized()
return push_vector

View File

@ -0,0 +1,8 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://Overlap/SoftCollision.gd" type="Script" id=1]
[node name="SoftCollision" type="Area2D"]
script = ExtResource( 1 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]

View File

@ -527,7 +527,7 @@ points = PoolVector2Array( 0, 0, 32, 0, 32, 32, 0, 32 )
position = Vector2( 160, 90 ) position = Vector2( 160, 90 )
texture = ExtResource( 3 ) texture = ExtResource( 3 )
region_enabled = true region_enabled = true
region_rect = Rect2( 0, 0, 320, 180 ) region_rect = Rect2( 0, 0, 880, 448 )
[node name="DirtPathTileMap" type="TileMap" parent="."] [node name="DirtPathTileMap" type="TileMap" parent="."]
tile_set = SubResource( 1 ) tile_set = SubResource( 1 )
@ -542,6 +542,11 @@ collision_mask = 0
format = 1 format = 1
tile_data = PoolIntArray( 0, 0, 4, 1, 0, 196609, 2, 0, 196609, 3, 0, 196610, 7, 0, 196608, 8, 0, 196609, 9, 0, 7, 65536, 0, 131075, 65545, 0, 131075, 196611, 0, 3, 196617, 0, 3, 262144, 0, 0, 262145, 0, 1, 262146, 0, 1, 262147, 0, 131079, 262152, 0, 196608, 262153, 0, 262151, 327680, 0, 131072, 327681, 0, 131073, 327682, 0, 131073, 327683, 0, 131074, 327689, 0, 131075 ) tile_data = PoolIntArray( 0, 0, 4, 1, 0, 196609, 2, 0, 196609, 3, 0, 196610, 7, 0, 196608, 8, 0, 196609, 9, 0, 7, 65536, 0, 131075, 65545, 0, 131075, 196611, 0, 3, 196617, 0, 3, 262144, 0, 0, 262145, 0, 1, 262146, 0, 1, 262147, 0, 131079, 262152, 0, 196608, 262153, 0, 262151, 327680, 0, 131072, 327681, 0, 131073, 327682, 0, 131073, 327683, 0, 131074, 327689, 0, 131075 )
[node name="Camera2D" type="Camera2D" parent="."]
position = Vector2( 111, 71 )
current = true
smoothing_enabled = true
[node name="YSort" type="YSort" parent="."] [node name="YSort" type="YSort" parent="."]
[node name="Player" parent="YSort" instance=ExtResource( 2 )] [node name="Player" parent="YSort" instance=ExtResource( 2 )]
@ -550,6 +555,9 @@ __meta__ = {
"_edit_group_": true "_edit_group_": true
} }
[node name="RemoteTransform2D" type="RemoteTransform2D" parent="YSort/Player"]
remote_path = NodePath("../../../Camera2D")
[node name="Bushes" type="YSort" parent="YSort"] [node name="Bushes" type="YSort" parent="YSort"]
[node name="Bush" parent="YSort/Bushes" instance=ExtResource( 1 )] [node name="Bush" parent="YSort/Bushes" instance=ExtResource( 1 )]
@ -616,4 +624,6 @@ margin_bottom = 40.0
[node name="TouchControls" parent="Control" instance=ExtResource( 7 )] [node name="TouchControls" parent="Control" instance=ExtResource( 7 )]
[node name="HealthUI" parent="." instance=ExtResource( 9 )] [node name="CanvasLayer" type="CanvasLayer" parent="."]
[node name="HealthUI" parent="CanvasLayer" instance=ExtResource( 9 )]

Binary file not shown.

Binary file not shown.

View File

@ -139,7 +139,7 @@
<script type='text/javascript' src='index.js'></script> <script type='text/javascript' src='index.js'></script>
<script type='text/javascript'>//<![CDATA[ <script type='text/javascript'>//<![CDATA[
const GODOT_CONFIG = {"args":[],"canvasResizePolicy":2,"executable":"index","experimentalVK":false,"fileSizes":{"index.pck":2289520,"index.wasm":13790961},"focusCanvas":true,"gdnativeLibs":[]}; const GODOT_CONFIG = {"args":[],"canvasResizePolicy":2,"executable":"index","experimentalVK":false,"fileSizes":{"index.pck":2291520,"index.wasm":13790961},"focusCanvas":true,"gdnativeLibs":[]};
var engine = new Engine(GODOT_CONFIG); var engine = new Engine(GODOT_CONFIG);
(function() { (function() {

View File

@ -109,6 +109,7 @@ pointing/emulate_mouse_from_touch=false
2d_physics/layer_3="PlayerHurtbox" 2d_physics/layer_3="PlayerHurtbox"
2d_physics/layer_4="EnemyHurtbox" 2d_physics/layer_4="EnemyHurtbox"
2d_physics/layer_5="Enemy" 2d_physics/layer_5="Enemy"
2d_physics/layer_6="SoftCollisions"
[physics] [physics]