From 59e69df83d4700c6435686bba2c5b85dda1b1fe9 Mon Sep 17 00:00:00 2001 From: ajuvercr Date: Wed, 15 Jan 2020 14:43:08 +0100 Subject: [PATCH] add tower instance --- Camera2D.gd | 2 -- Main.tscn | 26 +++++++++++++++++++------- Player.gd | 8 +++++++- Player.tscn | 6 +++++- Tower.gd | 17 +++++++++++++++++ Tower.tscn | 23 +++++++++++++++++++++++ 6 files changed, 71 insertions(+), 11 deletions(-) create mode 100644 Tower.gd create mode 100644 Tower.tscn diff --git a/Camera2D.gd b/Camera2D.gd index 0f53f48..33c7ae1 100644 --- a/Camera2D.gd +++ b/Camera2D.gd @@ -14,6 +14,4 @@ func _ready(): update_view() func _on_Player_move(): - print("moving") update_view() - pass # Replace with function body. diff --git a/Main.tscn b/Main.tscn index ad129d3..726c531 100644 --- a/Main.tscn +++ b/Main.tscn @@ -1,19 +1,31 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=6 format=2] [ext_resource path="res://Camera2D.gd" type="Script" id=1] [ext_resource path="res://icon.png" type="Texture" id=2] -[ext_resource path="res://Player.tscn" type="PackedScene" id=3] +[ext_resource path="res://Tower.tscn" type="PackedScene" id=3] +[ext_resource path="res://Tower.gd" type="Script" id=4] +[ext_resource path="res://Player.tscn" type="PackedScene" id=5] [node name="View" type="Node"] script = ExtResource( 1 ) [node name="Background" type="TextureRect" parent="."] -margin_top = -320.0 -margin_right = 420.0 -margin_bottom = 320.0 +margin_left = -1.16638 +margin_top = -321.166 +margin_right = 1244.83 +margin_bottom = 318.834 texture = ExtResource( 2 ) expand = true +stretch_mode = 2 -[node name="Player" parent="." instance=ExtResource( 3 )] -jump_speed = 10 +[node name="Tower" parent="." instance=ExtResource( 3 )] +position = Vector2( 734.801, 66.482 ) +gravity_scale = 0.0 +script = ExtResource( 4 ) + +[node name="Player" parent="." instance=ExtResource( 5 )] +position = Vector2( 571.569, 183.117 ) +gravity = 0.0 +collision_layer = 0 +[connection signal="body_entered" from="Tower" to="Tower" method="_on_Tower_body_entered"] [connection signal="move" from="Player" to="." method="_on_Player_move"] diff --git a/Player.gd b/Player.gd index ba07ad3..4232cf0 100644 --- a/Player.gd +++ b/Player.gd @@ -4,6 +4,7 @@ export var speed = 1 # How fast the player will move (pixels/sec). export var jump_speed = 10 signal move +signal hit var screen_size @@ -18,7 +19,6 @@ func _ready(): func _process(delta): if Input.is_action_just_pressed("ui_accept"): - print("HERE") speed_y = min(speed_y, 0) - 1 * jump_speed speed_y += 1 @@ -29,3 +29,9 @@ func _process(delta): # TODO find the correct rotation, noob rotation = atan(speed_y / speed) + PI / 2 + +func _on_Player_body_entered(body): + print("HIT") + hide() # Player disappears after being hit. + emit_signal("hit") + $CollisionShape2D.set_deferred("disabled", true) \ No newline at end of file diff --git a/Player.tscn b/Player.tscn index 5dc7967..a58910c 100644 --- a/Player.tscn +++ b/Player.tscn @@ -16,8 +16,11 @@ radius = 12.8837 height = 4.07484 [node name="Player" type="Area2D"] -position = Vector2( 210, 0 ) +position = Vector2( 0.581787, 0 ) script = ExtResource( 1 ) +__meta__ = { +"_edit_group_": true +} [node name="AnimatedSprite" type="AnimatedSprite" parent="."] scale = Vector2( 0.498334, 0.531778 ) @@ -26,3 +29,4 @@ frames = SubResource( 1 ) [node name="CollisionShape2D" type="CollisionShape2D" parent="."] rotation = 1.5708 shape = SubResource( 2 ) +[connection signal="body_entered" from="." to="." method="_on_Player_body_entered"] diff --git a/Tower.gd b/Tower.gd new file mode 100644 index 0000000..895e499 --- /dev/null +++ b/Tower.gd @@ -0,0 +1,17 @@ +extends RigidBody2D + +# Declare member variables here. Examples: +# var a = 2 +# var b = "text" + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + +# Called every frame. 'delta' is the elapsed time since the previous frame. +#func _process(delta): +# pass + +func _on_Tower_body_entered(body): + print("HIT HERE") + pass # Replace with function body. diff --git a/Tower.tscn b/Tower.tscn new file mode 100644 index 0000000..fbefec5 --- /dev/null +++ b/Tower.tscn @@ -0,0 +1,23 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://icon.png" type="Texture" id=1] + +[sub_resource type="RectangleShape2D" id=1] +extents = Vector2( 29.9672, 132.942 ) + +[node name="Tower" type="RigidBody2D"] +position = Vector2( -32, 50 ) +collision_mask = 0 +__meta__ = { +"_edit_group_": true +} + +[node name="TextureRect" type="TextureRect" parent="."] +margin_right = 64.0 +margin_bottom = 256.0 +texture = ExtResource( 1 ) +expand = true + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +position = Vector2( 31.5038, 135.281 ) +shape = SubResource( 1 )