Skip to content

Commit

Permalink
Camera follow
Browse files Browse the repository at this point in the history
the camera literally has a smooth follow checkbox wtf
- added smooth camera
- removed walls
- added space background for reference
- added support for moving camera and touch position on input manager
  • Loading branch information
MaxwellDexter committed Mar 19, 2020
1 parent 33d3743 commit f0d77ad
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 59 deletions.
Binary file added Images/space-wallpaper-5.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions Images/space-wallpaper-5.jpg.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="StreamTexture"
path="res://.import/space-wallpaper-5.jpg-e298f425bede8d53820df581acad687d.stex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://Images/space-wallpaper-5.jpg"
dest_files=[ "res://.import/space-wallpaper-5.jpg-e298f425bede8d53820df581acad687d.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=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0
70 changes: 13 additions & 57 deletions Nodes/Game.tscn
Original file line number Diff line number Diff line change
@@ -1,63 +1,19 @@
[gd_scene load_steps=6 format=2]
[gd_scene load_steps=4 format=2]

[ext_resource path="res://Scripts/Player.gd" type="Script" id=1]
[ext_resource path="res://icon.png" type="Texture" id=2]

[sub_resource type="CircleShape2D" id=1]
radius = 15.6796

[sub_resource type="RectangleShape2D" id=2]
extents = Vector2( 4.14182, 352.581 )

[sub_resource type="RectangleShape2D" id=3]
extents = Vector2( 614.659, 5.0593 )
[ext_resource path="res://Images/space-wallpaper-5.jpg" type="Texture" id=1]
[ext_resource path="res://Nodes/Player.tscn" type="PackedScene" id=2]
[ext_resource path="res://Scripts/CameraFollow.gd" type="Script" id=3]

[node name="Game" type="Node2D"]

[node name="Player" type="RigidBody2D" parent="."]
position = Vector2( 150, 150 )
mass = 0.170408
gravity_scale = 0.0
linear_damp = 1.7
script = ExtResource( 1 )
drag_speed = 100
hold_speed = 2
maximum_drag_force = 8000
drag_force_minimum = 50.0
drag_release_time = 10.0

[node name="CollisionShape2D" type="CollisionShape2D" parent="Player"]
shape = SubResource( 1 )

[node name="Sprite" type="Sprite" parent="Player"]
scale = Vector2( 0.2, 0.2 )
texture = ExtResource( 2 )

[node name="Timer" type="Timer" parent="Player"]

[node name="Walls" type="Node" parent="."]
editor/display_folded = true

[node name="Left" type="StaticBody2D" parent="Walls"]
position = Vector2( 0, 300 )

[node name="CollisionShape2D" type="CollisionShape2D" parent="Walls/Left"]
shape = SubResource( 2 )

[node name="Right" type="StaticBody2D" parent="Walls"]
position = Vector2( 1023.88, 300 )

[node name="CollisionShape2D" type="CollisionShape2D" parent="Walls/Right"]
shape = SubResource( 2 )

[node name="Top" type="StaticBody2D" parent="Walls"]
position = Vector2( 500, 0 )

[node name="CollisionShape2D" type="CollisionShape2D" parent="Walls/Top"]
shape = SubResource( 3 )
[node name="space-wallpaper-5" type="Sprite" parent="."]
scale = Vector2( 2, 2 )
texture = ExtResource( 1 )

[node name="Bottom" type="StaticBody2D" parent="Walls"]
position = Vector2( 500, 599.46 )
[node name="Player" parent="." instance=ExtResource( 2 )]

[node name="CollisionShape2D" type="CollisionShape2D" parent="Walls/Bottom"]
shape = SubResource( 3 )
[node name="MainCamera" type="Camera2D" parent="."]
current = true
smoothing_enabled = true
smoothing_speed = 7.4
script = ExtResource( 3 )
27 changes: 27 additions & 0 deletions Nodes/Player.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[gd_scene load_steps=4 format=2]

[ext_resource path="res://Scripts/Player.gd" type="Script" id=1]
[ext_resource path="res://icon.png" type="Texture" id=2]

[sub_resource type="CircleShape2D" id=1]
radius = 15.6796

[node name="Player" type="RigidBody2D"]
mass = 0.170408
gravity_scale = 0.0
linear_damp = 1.7
script = ExtResource( 1 )
drag_speed = 100
hold_speed = 2
maximum_drag_force = 8000
drag_force_minimum = 50.0
drag_release_time = 10.0

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource( 1 )

[node name="Sprite" type="Sprite" parent="."]
scale = Vector2( 0.2, 0.2 )
texture = ExtResource( 2 )

[node name="Timer" type="Timer" parent="."]
9 changes: 9 additions & 0 deletions Scripts/CameraFollow.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
extends Camera2D

var player

func _ready():
player = get_parent().get_node("Player")

func _process(delta):
set_position(player.get_position())
14 changes: 12 additions & 2 deletions Scripts/Player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@ var dragging
var holding_pos
onready var timer_drag_release = get_node("Timer")

# camera stuff
var camera
var viewport_size

func _ready():
InputManager.connect("single_touch", self, "touch")
InputManager.connect("single_drag", self, "drag")
timer_drag_release.set_one_shot(true)
timer_drag_release.connect("timeout", self, "release_timeout")

camera = get_parent().get_node("MainCamera")
viewport_size = get_viewport().get_visible_rect().size

func _physics_process(delta):
# rotation
Expand All @@ -30,7 +37,7 @@ func _physics_process(delta):
# signal method
func touch(event):
if (event.pressed):
hold_this(event.position)
hold_this(get_position_on_screen(event.position))
else:
hold_this(null)

Expand All @@ -55,4 +62,7 @@ func release_timeout():

func start_timer(time):
timer_drag_release.set_wait_time(time)
timer_drag_release.start()
timer_drag_release.start()

func get_position_on_screen(pos):
return camera.get_camera_screen_center() - viewport_size/2 + pos

0 comments on commit f0d77ad

Please sign in to comment.