diff --git a/Images/space-wallpaper-5.jpg b/Images/space-wallpaper-5.jpg new file mode 100644 index 0000000..d104042 Binary files /dev/null and b/Images/space-wallpaper-5.jpg differ diff --git a/Images/space-wallpaper-5.jpg.import b/Images/space-wallpaper-5.jpg.import new file mode 100644 index 0000000..5c750b4 --- /dev/null +++ b/Images/space-wallpaper-5.jpg.import @@ -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 diff --git a/Nodes/Game.tscn b/Nodes/Game.tscn index 68ef3c5..6d70009 100644 --- a/Nodes/Game.tscn +++ b/Nodes/Game.tscn @@ -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 ) diff --git a/Nodes/Player.tscn b/Nodes/Player.tscn new file mode 100644 index 0000000..7de23ce --- /dev/null +++ b/Nodes/Player.tscn @@ -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="."] diff --git a/Scripts/CameraFollow.gd b/Scripts/CameraFollow.gd new file mode 100644 index 0000000..5a08ccd --- /dev/null +++ b/Scripts/CameraFollow.gd @@ -0,0 +1,9 @@ +extends Camera2D + +var player + +func _ready(): + player = get_parent().get_node("Player") + +func _process(delta): + set_position(player.get_position()) \ No newline at end of file diff --git a/Scripts/Player.gd b/Scripts/Player.gd index 81c6d1a..573ba0b 100644 --- a/Scripts/Player.gd +++ b/Scripts/Player.gd @@ -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 @@ -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) @@ -55,4 +62,7 @@ func release_timeout(): func start_timer(time): timer_drag_release.set_wait_time(time) - timer_drag_release.start() \ No newline at end of file + timer_drag_release.start() + +func get_position_on_screen(pos): + return camera.get_camera_screen_center() - viewport_size/2 + pos \ No newline at end of file