getting pretty close actually :)

This commit is contained in:
ajuvercr 2020-01-15 15:44:46 +01:00
parent 59e69df83d
commit e3e785c044
6 changed files with 68 additions and 26 deletions

View file

@ -1,17 +1,39 @@
extends Node
export (PackedScene) var Tower = preload("res://Tower.tscn");
onready var screen_size = Vector2(ProjectSettings.get("display/window/size/width"), ProjectSettings.get("display/window/size/height"))
onready var player = get_node("Player")
export var tower_density = 200
var last_built = 100
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.
tower.position = pos
add_child(tower)
last_built += tower_density
func update_view():
var canvas_transform = get_viewport().get_canvas_transform()
var pos = player.position
pos.y = 0
canvas_transform[2] = -player.position + screen_size / 2
canvas_transform[2] = -pos + screen_size / 2
get_viewport().set_canvas_transform(canvas_transform)
func _ready():
randomize()
update_view()
print(screen_size)
while last_built < screen_size.x * 2:
build_tower()
func _on_Player_move():
update_view()
func _on_Tower_exit():
build_tower()

View file

@ -1,10 +1,8 @@
[gd_scene load_steps=6 format=2]
[gd_scene load_steps=4 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://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]
[ext_resource path="res://Player.tscn" type="PackedScene" id=3]
[node name="View" type="Node"]
script = ExtResource( 1 )
@ -18,14 +16,8 @@ texture = ExtResource( 2 )
expand = true
stretch_mode = 2
[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 )
[node name="Player" parent="." instance=ExtResource( 3 )]
position = Vector2( 136.52, -24.4934 )
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"]

View file

@ -32,6 +32,6 @@ func _process(delta):
func _on_Player_body_entered(body):
print("HIT")
hide() # Player disappears after being hit.
#hide() # Player disappears after being hit.
emit_signal("hit")
$CollisionShape2D.set_deferred("disabled", true)

View file

@ -1,5 +1,6 @@
extends RigidBody2D
extends Node2D
signal exit
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
@ -15,3 +16,8 @@ func _ready():
func _on_Tower_body_entered(body):
print("HIT HERE")
pass # Replace with function body.
func _on_Visibility_screen_exited():
print("Leaving")
queue_free()
emit_signal("exit")

View file

@ -1,23 +1,40 @@
[gd_scene load_steps=3 format=2]
[gd_scene load_steps=4 format=2]
[ext_resource path="res://icon.png" type="Texture" id=1]
[ext_resource path="res://Tower.gd" type="Script" id=1]
[ext_resource path="res://icon.png" type="Texture" id=2]
[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="Tower" type="Node2D"]
script = ExtResource( 1 )
[node name="TextureRect" type="TextureRect" parent="."]
[node name="Lower" type="RigidBody2D" parent="."]
position = Vector2( -32, 100 )
[node name="TextureRect" type="TextureRect" parent="Lower"]
margin_right = 64.0
margin_bottom = 256.0
texture = ExtResource( 1 )
texture = ExtResource( 2 )
expand = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="Lower"]
position = Vector2( 31.5038, 135.281 )
shape = SubResource( 1 )
[node name="Upper" type="RigidBody2D" parent="."]
position = Vector2( 32, -100 )
rotation = 3.14159
[node name="TextureRect" type="TextureRect" parent="Upper"]
margin_right = 64.0
margin_bottom = 256.0
texture = ExtResource( 2 )
expand = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="Upper"]
position = Vector2( 31.5038, 135.281 )
shape = SubResource( 1 )
[node name="VisibilityNotifier2D" type="VisibilityNotifier2D" parent="."]
[connection signal="screen_exited" from="VisibilityNotifier2D" to="." method="_on_Visibility_screen_exited"]

View file

@ -24,6 +24,11 @@ config/icon="res://icon.png"
window/size/width=420
window/size/height=640
[physics]
2d/default_gravity=0
2d/default_gravity_vector=Vector2( 0, 0 )
[rendering]
quality/driver/driver_name="GLES2"