Tut19 Complete: Camera
This commit is contained in:
parent
54f9772836
commit
d103dac31a
BIN
ActionRPG-HeartBeast/.DS_Store
vendored
BIN
ActionRPG-HeartBeast/.DS_Store
vendored
Binary file not shown.
@ -21,6 +21,7 @@ onready var sprite = $AnimatedSprite
|
||||
onready var stats = $Stats
|
||||
onready var playerDetectionZone = $PlayerDetectionZone
|
||||
onready var hurtbox = $Hurtbox
|
||||
onready var softCollision = $SoftCollision
|
||||
|
||||
func _physics_process(delta):
|
||||
knockback = knockback.move_toward(Vector2.ZERO, 200 * delta)
|
||||
@ -43,8 +44,11 @@ func _physics_process(delta):
|
||||
state = IDLE
|
||||
sprite.flip_h = velocity.x < 0
|
||||
|
||||
if softCollision.is_colliding():
|
||||
velocity += softCollision.get_push_vector() * delta * 400
|
||||
velocity = move_and_slide(velocity)
|
||||
|
||||
|
||||
func seek_player():
|
||||
if playerDetectionZone.can_see_player():
|
||||
state = CHASE
|
||||
|
@ -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://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://Enemies/PlayerDetectionZone.tscn" type="PackedScene" id=6]
|
||||
[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]
|
||||
atlas = ExtResource( 1 )
|
||||
@ -49,6 +50,9 @@ radius = 61.0328
|
||||
[sub_resource type="CircleShape2D" id=10]
|
||||
radius = 5.0
|
||||
|
||||
[sub_resource type="CircleShape2D" id=11]
|
||||
radius = 5.0
|
||||
|
||||
[node name="Bat" type="KinematicBody2D"]
|
||||
collision_layer = 16
|
||||
script = ExtResource( 4 )
|
||||
@ -56,7 +60,6 @@ script = ExtResource( 4 )
|
||||
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
|
||||
frames = SubResource( 6 )
|
||||
animation = "Fly"
|
||||
frame = 1
|
||||
playing = true
|
||||
offset = Vector2( 0, -12 )
|
||||
|
||||
@ -64,9 +67,11 @@ offset = Vector2( 0, -12 )
|
||||
texture = ExtResource( 2 )
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
visible = false
|
||||
shape = SubResource( 7 )
|
||||
|
||||
[node name="Hurtbox" parent="." instance=ExtResource( 3 )]
|
||||
visible = false
|
||||
collision_layer = 8
|
||||
|
||||
[node name="CollisionShape2D" parent="Hurtbox" index="0"]
|
||||
@ -77,21 +82,29 @@ shape = SubResource( 8 )
|
||||
max_health = 2
|
||||
|
||||
[node name="PlayerDetectionZone" parent="." instance=ExtResource( 6 )]
|
||||
visible = false
|
||||
|
||||
[node name="CollisionShape2D" parent="PlayerDetectionZone" index="0"]
|
||||
modulate = Color( 1, 1, 1, 0.258824 )
|
||||
shape = SubResource( 9 )
|
||||
|
||||
[node name="Hitbox" parent="." instance=ExtResource( 7 )]
|
||||
visible = false
|
||||
collision_mask = 4
|
||||
|
||||
[node name="CollisionShape2D" parent="Hitbox" index="0"]
|
||||
position = Vector2( 0, -15 )
|
||||
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="no_health" from="Stats" to="." method="_on_Stats_no_health"]
|
||||
|
||||
[editable path="Hurtbox"]
|
||||
[editable path="PlayerDetectionZone"]
|
||||
[editable path="Hitbox"]
|
||||
[editable path="SoftCollision"]
|
||||
|
14
ActionRPG-HeartBeast/Overlap/SoftCollision.gd
Normal file
14
ActionRPG-HeartBeast/Overlap/SoftCollision.gd
Normal 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
|
8
ActionRPG-HeartBeast/Overlap/SoftCollision.tscn
Normal file
8
ActionRPG-HeartBeast/Overlap/SoftCollision.tscn
Normal 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="."]
|
@ -527,7 +527,7 @@ points = PoolVector2Array( 0, 0, 32, 0, 32, 32, 0, 32 )
|
||||
position = Vector2( 160, 90 )
|
||||
texture = ExtResource( 3 )
|
||||
region_enabled = true
|
||||
region_rect = Rect2( 0, 0, 320, 180 )
|
||||
region_rect = Rect2( 0, 0, 880, 448 )
|
||||
|
||||
[node name="DirtPathTileMap" type="TileMap" parent="."]
|
||||
tile_set = SubResource( 1 )
|
||||
@ -542,6 +542,11 @@ collision_mask = 0
|
||||
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 )
|
||||
|
||||
[node name="Camera2D" type="Camera2D" parent="."]
|
||||
position = Vector2( 111, 71 )
|
||||
current = true
|
||||
smoothing_enabled = true
|
||||
|
||||
[node name="YSort" type="YSort" parent="."]
|
||||
|
||||
[node name="Player" parent="YSort" instance=ExtResource( 2 )]
|
||||
@ -550,6 +555,9 @@ __meta__ = {
|
||||
"_edit_group_": true
|
||||
}
|
||||
|
||||
[node name="RemoteTransform2D" type="RemoteTransform2D" parent="YSort/Player"]
|
||||
remote_path = NodePath("../../../Camera2D")
|
||||
|
||||
[node name="Bushes" type="YSort" parent="YSort"]
|
||||
|
||||
[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="HealthUI" parent="." instance=ExtResource( 9 )]
|
||||
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
||||
|
||||
[node name="HealthUI" parent="CanvasLayer" instance=ExtResource( 9 )]
|
||||
|
BIN
ActionRPG-HeartBeast/build/.DS_Store
vendored
BIN
ActionRPG-HeartBeast/build/.DS_Store
vendored
Binary file not shown.
BIN
ActionRPG-HeartBeast/build/web/.DS_Store
vendored
BIN
ActionRPG-HeartBeast/build/web/.DS_Store
vendored
Binary file not shown.
Binary file not shown.
@ -139,7 +139,7 @@
|
||||
<script type='text/javascript' src='index.js'></script>
|
||||
<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);
|
||||
|
||||
(function() {
|
||||
|
Binary file not shown.
@ -109,6 +109,7 @@ pointing/emulate_mouse_from_touch=false
|
||||
2d_physics/layer_3="PlayerHurtbox"
|
||||
2d_physics/layer_4="EnemyHurtbox"
|
||||
2d_physics/layer_5="Enemy"
|
||||
2d_physics/layer_6="SoftCollisions"
|
||||
|
||||
[physics]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user