diff --git a/Camera2D.gd b/Camera2D.gd index 356a8d5..e6d1d35 100644 --- a/Camera2D.gd +++ b/Camera2D.gd @@ -6,12 +6,12 @@ onready var screen_size = Vector2(ProjectSettings.get("display/window/size/width onready var player = get_node("Player") export var tower_density = 200 -var last_built = 100 +var last_built = 300 func build_tower(): var tower = Tower.instance() tower.connect("exit", self, "_on_Tower_exit") - var pos = Vector2(last_built, randf() * screen_size.y - screen_size.y / 2) # The player's movement vector. + var pos = Vector2(last_built, randf() * (screen_size.y - 200) - screen_size.y / 2 + 100) # The player's movement vector. tower.position = pos add_child(tower) diff --git a/Main.tscn b/Main.tscn index 52c42c9..6851528 100644 --- a/Main.tscn +++ b/Main.tscn @@ -17,7 +17,7 @@ expand = true stretch_mode = 2 [node name="Player" parent="." instance=ExtResource( 3 )] -position = Vector2( 136.52, -24.4934 ) +position = Vector2( 155.182, -2.28882e-05 ) gravity = 0.0 collision_layer = 0 [connection signal="move" from="Player" to="." method="_on_Player_move"] diff --git a/Player.gd b/Player.gd index 43f51a8..03344f4 100644 --- a/Player.gd +++ b/Player.gd @@ -1,12 +1,14 @@ extends Area2D -export var speed = 1 # How fast the player will move (pixels/sec). -export var jump_speed = 10 +export var speed = 3 # How fast the player will move (pixels/sec). +export var jump_speed = 4 +export var speed_inc = 0.3 signal move signal hit var screen_size +var playing = false var speed_y = 0 @@ -19,19 +21,31 @@ func _ready(): func _process(delta): if Input.is_action_just_pressed("ui_accept"): + if not playing: + speed_y = 0 + playing = true + $CollisionShape2D.set_deferred("disabled", false) speed_y = min(speed_y, 0) - 1 * jump_speed - speed_y += 1 - position.x += 1 - position.y += speed_y * speed + if not playing: + return + + speed_y += speed_inc + + position += Vector2(speed, speed_y * speed) emit_signal("move") # TODO find the correct rotation, noob rotation = atan(speed_y / speed) + PI / 2 + + if position.y > screen_size.y / 2 - 100: + emit_signal("hit") + print(position) + playing = false func _on_Player_body_entered(body): - print("HIT") + playing = false #hide() # Player disappears after being hit. emit_signal("hit") $CollisionShape2D.set_deferred("disabled", true) \ No newline at end of file diff --git a/Tower.tscn b/Tower.tscn index 80d2908..8a860e3 100644 --- a/Tower.tscn +++ b/Tower.tscn @@ -4,7 +4,7 @@ [ext_resource path="res://icon.png" type="Texture" id=2] [sub_resource type="RectangleShape2D" id=1] -extents = Vector2( 29.9672, 132.942 ) +extents = Vector2( 29.9672, 264.93 ) [node name="Tower" type="Node2D"] script = ExtResource( 1 ) @@ -14,12 +14,12 @@ position = Vector2( -32, 100 ) [node name="TextureRect" type="TextureRect" parent="Lower"] margin_right = 64.0 -margin_bottom = 256.0 +margin_bottom = 500.0 texture = ExtResource( 2 ) expand = true [node name="CollisionShape2D" type="CollisionShape2D" parent="Lower"] -position = Vector2( 31.5038, 135.281 ) +position = Vector2( 31.5038, 267.238 ) shape = SubResource( 1 ) [node name="Upper" type="RigidBody2D" parent="."] @@ -28,12 +28,12 @@ rotation = 3.14159 [node name="TextureRect" type="TextureRect" parent="Upper"] margin_right = 64.0 -margin_bottom = 256.0 +margin_bottom = 500.0 texture = ExtResource( 2 ) expand = true [node name="CollisionShape2D" type="CollisionShape2D" parent="Upper"] -position = Vector2( 31.5038, 135.281 ) +position = Vector2( 32.6698, 265.913 ) shape = SubResource( 1 ) [node name="VisibilityNotifier2D" type="VisibilityNotifier2D" parent="."]