Camera transition and upper and lower bounds added.
This commit is contained in:
parent
4bf2a3f788
commit
36828498c4
37
Main.tscn
37
Main.tscn
|
|
@ -17,16 +17,19 @@ b = Vector2( -1, 349 )
|
||||||
[node name="Main" type="Node2D"]
|
[node name="Main" type="Node2D"]
|
||||||
|
|
||||||
[node name="Level" parent="." instance=ExtResource( 1 )]
|
[node name="Level" parent="." instance=ExtResource( 1 )]
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_lock_": true
|
||||||
|
}
|
||||||
|
|
||||||
[node name="Player" parent="." instance=ExtResource( 14 )]
|
[node name="Player" parent="." instance=ExtResource( 14 )]
|
||||||
position = Vector2( 93, 54 )
|
position = Vector2( 506, 35 )
|
||||||
|
|
||||||
[node name="CameraControl" type="Position2D" parent="."]
|
[node name="CameraControl" type="Position2D" parent="."]
|
||||||
|
pause_mode = 2
|
||||||
process_priority = 1
|
process_priority = 1
|
||||||
script = ExtResource( 5 )
|
script = ExtResource( 5 )
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
"_edit_group_": true,
|
"_edit_group_": true
|
||||||
"_edit_lock_": true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[node name="Line2D" type="Line2D" parent="CameraControl"]
|
[node name="Line2D" type="Line2D" parent="CameraControl"]
|
||||||
|
|
@ -41,7 +44,29 @@ __meta__ = {
|
||||||
process_priority = 1
|
process_priority = 1
|
||||||
anchor_mode = 0
|
anchor_mode = 0
|
||||||
current = true
|
current = true
|
||||||
smoothing_speed = 30.0
|
smoothing_speed = 3.0
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_lock_": true
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="Up" type="RayCast2D" parent="CameraControl"]
|
||||||
|
position = Vector2( 160, 90 )
|
||||||
|
enabled = true
|
||||||
|
cast_to = Vector2( 0, -90 )
|
||||||
|
collision_mask = 256
|
||||||
|
collide_with_areas = true
|
||||||
|
collide_with_bodies = false
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_lock_": true
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="Down" type="RayCast2D" parent="CameraControl"]
|
||||||
|
position = Vector2( 160, 90 )
|
||||||
|
enabled = true
|
||||||
|
cast_to = Vector2( 0, 90 )
|
||||||
|
collision_mask = 256
|
||||||
|
collide_with_areas = true
|
||||||
|
collide_with_bodies = false
|
||||||
__meta__ = {
|
__meta__ = {
|
||||||
"_edit_lock_": true
|
"_edit_lock_": true
|
||||||
}
|
}
|
||||||
|
|
@ -68,6 +93,9 @@ __meta__ = {
|
||||||
"_edit_lock_": true
|
"_edit_lock_": true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[node name="Timer" type="Timer" parent="CameraControl"]
|
||||||
|
wait_time = 1.5
|
||||||
|
|
||||||
[node name="CameraBoundaries" type="Area2D" parent="."]
|
[node name="CameraBoundaries" type="Area2D" parent="."]
|
||||||
collision_layer = 256
|
collision_layer = 256
|
||||||
collision_mask = 0
|
collision_mask = 0
|
||||||
|
|
@ -92,6 +120,7 @@ __meta__ = {
|
||||||
[node name="UI_Layer" type="CanvasLayer" parent="."]
|
[node name="UI_Layer" type="CanvasLayer" parent="."]
|
||||||
pause_mode = 2
|
pause_mode = 2
|
||||||
layer = 2
|
layer = 2
|
||||||
|
visible = false
|
||||||
script = ExtResource( 9 )
|
script = ExtResource( 9 )
|
||||||
|
|
||||||
[node name="PanelContainer" type="PanelContainer" parent="UI_Layer"]
|
[node name="PanelContainer" type="PanelContainer" parent="UI_Layer"]
|
||||||
|
|
|
||||||
|
|
@ -4,17 +4,21 @@ export(String) var LINE_COLOR_HEX = '#FFEB3B'
|
||||||
|
|
||||||
var grid_position = Vector2()
|
var grid_position = Vector2()
|
||||||
var grid_size = Vector2()
|
var grid_size = Vector2()
|
||||||
var t = 0.0
|
|
||||||
|
|
||||||
onready var parent = PlayerInfo
|
onready var parent = PlayerInfo
|
||||||
|
onready var timer: Timer = $Timer
|
||||||
#onready var parent = $Player
|
#onready var parent = $Player
|
||||||
|
|
||||||
|
##TODO: Quick and dirty because we need to pause these
|
||||||
|
#onready var player_node = $"../Player"
|
||||||
|
#onready var level_node = $"../Level"
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
# If you drag the camera from the OffsetPivot node,
|
# If you drag the camera from the OffsetPivot node,
|
||||||
# its position will not be (0, 0)
|
# its position will not be (0, 0)
|
||||||
#$Camera2D.global_position = Vector2(160,90) # when doing grid snapping
|
#$Camera2D.global_position = Vector2(160,90) # when doing grid snapping
|
||||||
#$Left.position = Vector2(160,90)
|
#$Left.position = Vector2(160,90)
|
||||||
$Camera2D.position = Vector2(0,-4)
|
#$Camera2D.position = Vector2(0,-4)
|
||||||
#grid_size = OS.get_screen_size()
|
#grid_size = OS.get_screen_size()
|
||||||
grid_size = get_node("/root").size
|
grid_size = get_node("/root").size
|
||||||
#grid_size = get_node("/root").get_visible_rect().size
|
#grid_size = get_node("/root").get_visible_rect().size
|
||||||
|
|
@ -27,7 +31,6 @@ func _ready():
|
||||||
|
|
||||||
|
|
||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
t += delta * 0.4
|
|
||||||
#print(parent.position.x)
|
#print(parent.position.x)
|
||||||
update_grid_position()
|
update_grid_position()
|
||||||
#draw_line( Vector2(0, -half_line_length), Vector2(0, half_line_length), color, 3.0)
|
#draw_line( Vector2(0, -half_line_length), Vector2(0, half_line_length), color, 3.0)
|
||||||
|
|
@ -44,13 +47,40 @@ func update_grid_position():
|
||||||
# print("Oh God! No!")
|
# print("Oh God! No!")
|
||||||
# if grid_position == new_grid_position:
|
# if grid_position == new_grid_position:
|
||||||
# return
|
# return
|
||||||
grid_position = new_grid_position
|
# if the y value has changed we can flip transition the camera
|
||||||
jump_to_grid_position()
|
##TODO: this logic is working but I don't like it.
|
||||||
|
if grid_position.y != new_grid_position.y:
|
||||||
|
if !$Up.is_colliding() and grid_position.y > new_grid_position.y:
|
||||||
|
get_tree().paused = true
|
||||||
|
grid_position = new_grid_position
|
||||||
|
timer.start()
|
||||||
|
$Camera2D.smoothing_enabled = true
|
||||||
|
jump_to_grid_position()
|
||||||
|
#wait for stability.
|
||||||
|
yield(timer, "timeout")
|
||||||
|
$Camera2D.smoothing_enabled = false
|
||||||
|
get_tree().paused = false
|
||||||
|
elif !$Down.is_colliding() and grid_position.y < new_grid_position.y:
|
||||||
|
get_tree().paused = true
|
||||||
|
grid_position = new_grid_position
|
||||||
|
timer.start()
|
||||||
|
$Camera2D.smoothing_enabled = true
|
||||||
|
jump_to_grid_position()
|
||||||
|
#wait for stability.
|
||||||
|
yield(timer, "timeout")
|
||||||
|
$Camera2D.smoothing_enabled = false
|
||||||
|
get_tree().paused = false
|
||||||
|
else:
|
||||||
|
# Only allow horizontal camera moving
|
||||||
|
grid_position.x = new_grid_position.x
|
||||||
|
jump_to_grid_position()
|
||||||
|
else:
|
||||||
|
jump_to_grid_position()
|
||||||
#$Left.position = Vector2(grid_position * grid_size)
|
#$Left.position = Vector2(grid_position * grid_size)
|
||||||
#print("Ray Left: ", $Left.global_position, $Left.cast_to)
|
#print("Ray Left: ", $Left.global_position, $Left.cast_to)
|
||||||
|
|
||||||
|
|
||||||
func calculate_grid_position():
|
func calculate_grid_position() -> Vector2:
|
||||||
# this needs to heavily round off the parents position
|
# this needs to heavily round off the parents position
|
||||||
var x_offset = floor(parent.player_position.x / grid_size.x)
|
var x_offset = floor(parent.player_position.x / grid_size.x)
|
||||||
var y_offset = floor(parent.player_position.y / grid_size.y)
|
var y_offset = floor(parent.player_position.y / grid_size.y)
|
||||||
|
|
@ -84,6 +114,16 @@ func jump_to_grid_position():
|
||||||
$Camera2D.limit_right = $Right.get_collision_point().x
|
$Camera2D.limit_right = $Right.get_collision_point().x
|
||||||
else:
|
else:
|
||||||
$Camera2D.limit_right = 10000000
|
$Camera2D.limit_right = 10000000
|
||||||
|
|
||||||
|
if $Up.is_colliding():
|
||||||
|
$Camera2D.limit_top = $Up.get_collision_point().y
|
||||||
|
else:
|
||||||
|
$Camera2D.limit_top = -10000000
|
||||||
|
if $Down.is_colliding():
|
||||||
|
$Camera2D.limit_bottom = $Down.get_collision_point().y
|
||||||
|
else:
|
||||||
|
$Camera2D.limit_bottom = 10000000
|
||||||
|
|
||||||
position = Vector2( x_pos ,grid_position.y * grid_size.y)
|
position = Vector2( x_pos ,grid_position.y * grid_size.y)
|
||||||
#$Camera2D.force_update_scroll()
|
#$Camera2D.force_update_scroll()
|
||||||
#position = Vector2( grid_position * grid_size)
|
#position = Vector2( grid_position * grid_size)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
[gd_scene load_steps=9 format=2]
|
[gd_scene load_steps=10 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://src/templates/Actor/ActorTemplate.tscn" type="PackedScene" id=1]
|
[ext_resource path="res://src/templates/Actor/ActorTemplate.tscn" type="PackedScene" id=1]
|
||||||
[ext_resource path="res://assets/Tiles/Assets/Demo TileSet.tres" type="TileSet" id=2]
|
[ext_resource path="res://assets/Tiles/Assets/Demo TileSet.tres" type="TileSet" id=2]
|
||||||
|
|
@ -9,6 +9,9 @@
|
||||||
[ext_resource path="res://src/enemyC/EnemyC.tscn" type="PackedScene" id=7]
|
[ext_resource path="res://src/enemyC/EnemyC.tscn" type="PackedScene" id=7]
|
||||||
[ext_resource path="res://src/Interactables/Door.tscn" type="PackedScene" id=8]
|
[ext_resource path="res://src/Interactables/Door.tscn" type="PackedScene" id=8]
|
||||||
|
|
||||||
|
[sub_resource type="SegmentShape2D" id=1]
|
||||||
|
b = Vector2( 1500, 0 )
|
||||||
|
|
||||||
[node name="Level" type="Node2D"]
|
[node name="Level" type="Node2D"]
|
||||||
|
|
||||||
[node name="ParallaxBackground" type="ParallaxBackground" parent="."]
|
[node name="ParallaxBackground" type="ParallaxBackground" parent="."]
|
||||||
|
|
@ -63,10 +66,7 @@ __meta__ = {
|
||||||
}
|
}
|
||||||
|
|
||||||
[node name="EnemyC2" parent="." instance=ExtResource( 7 )]
|
[node name="EnemyC2" parent="." instance=ExtResource( 7 )]
|
||||||
position = Vector2( 492, 27 )
|
position = Vector2( 787, 132 )
|
||||||
__meta__ = {
|
|
||||||
"_edit_lock_": true
|
|
||||||
}
|
|
||||||
|
|
||||||
[node name="ActorTemplate" parent="." instance=ExtResource( 1 )]
|
[node name="ActorTemplate" parent="." instance=ExtResource( 1 )]
|
||||||
position = Vector2( 262, 44 )
|
position = Vector2( 262, 44 )
|
||||||
|
|
@ -86,3 +86,13 @@ position = Vector2( 187, 144 )
|
||||||
|
|
||||||
[node name="Door" parent="." instance=ExtResource( 8 )]
|
[node name="Door" parent="." instance=ExtResource( 8 )]
|
||||||
position = Vector2( 866, 120 )
|
position = Vector2( 866, 120 )
|
||||||
|
|
||||||
|
[node name="CameraBoundaries" type="Area2D" parent="."]
|
||||||
|
collision_layer = 256
|
||||||
|
collision_mask = 0
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_lock_": true
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="CollisionShape2D3" type="CollisionShape2D" parent="CameraBoundaries"]
|
||||||
|
shape = SubResource( 1 )
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user