add tower instance

This commit is contained in:
ajuvercr 2020-01-15 14:43:08 +01:00
parent f73c86d4a1
commit 59e69df83d
6 changed files with 71 additions and 11 deletions

View file

@ -14,6 +14,4 @@ func _ready():
update_view() update_view()
func _on_Player_move(): func _on_Player_move():
print("moving")
update_view() update_view()
pass # Replace with function body.

View file

@ -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://Camera2D.gd" type="Script" id=1]
[ext_resource path="res://icon.png" type="Texture" id=2] [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"] [node name="View" type="Node"]
script = ExtResource( 1 ) script = ExtResource( 1 )
[node name="Background" type="TextureRect" parent="."] [node name="Background" type="TextureRect" parent="."]
margin_top = -320.0 margin_left = -1.16638
margin_right = 420.0 margin_top = -321.166
margin_bottom = 320.0 margin_right = 1244.83
margin_bottom = 318.834
texture = ExtResource( 2 ) texture = ExtResource( 2 )
expand = true expand = true
stretch_mode = 2
[node name="Player" parent="." instance=ExtResource( 3 )] [node name="Tower" parent="." instance=ExtResource( 3 )]
jump_speed = 10 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"] [connection signal="move" from="Player" to="." method="_on_Player_move"]

View file

@ -4,6 +4,7 @@ export var speed = 1 # How fast the player will move (pixels/sec).
export var jump_speed = 10 export var jump_speed = 10
signal move signal move
signal hit
var screen_size var screen_size
@ -18,7 +19,6 @@ func _ready():
func _process(delta): func _process(delta):
if Input.is_action_just_pressed("ui_accept"): if Input.is_action_just_pressed("ui_accept"):
print("HERE")
speed_y = min(speed_y, 0) - 1 * jump_speed speed_y = min(speed_y, 0) - 1 * jump_speed
speed_y += 1 speed_y += 1
@ -29,3 +29,9 @@ func _process(delta):
# TODO find the correct rotation, noob # TODO find the correct rotation, noob
rotation = atan(speed_y / speed) + PI / 2 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)

View file

@ -16,8 +16,11 @@ radius = 12.8837
height = 4.07484 height = 4.07484
[node name="Player" type="Area2D"] [node name="Player" type="Area2D"]
position = Vector2( 210, 0 ) position = Vector2( 0.581787, 0 )
script = ExtResource( 1 ) script = ExtResource( 1 )
__meta__ = {
"_edit_group_": true
}
[node name="AnimatedSprite" type="AnimatedSprite" parent="."] [node name="AnimatedSprite" type="AnimatedSprite" parent="."]
scale = Vector2( 0.498334, 0.531778 ) scale = Vector2( 0.498334, 0.531778 )
@ -26,3 +29,4 @@ frames = SubResource( 1 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] [node name="CollisionShape2D" type="CollisionShape2D" parent="."]
rotation = 1.5708 rotation = 1.5708
shape = SubResource( 2 ) shape = SubResource( 2 )
[connection signal="body_entered" from="." to="." method="_on_Player_body_entered"]

17
Tower.gd Normal file
View file

@ -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.

23
Tower.tscn Normal file
View file

@ -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 )