My bird flying
This commit is contained in:
parent
3b0fcda34b
commit
aa768c6635
2 changed files with 28 additions and 12 deletions
19
Camera2D.gd
19
Camera2D.gd
|
@ -8,7 +8,9 @@ export var tower_density = 250
|
|||
|
||||
signal spawn
|
||||
|
||||
var last_built = 500
|
||||
var last_built = 300
|
||||
|
||||
var towers = []
|
||||
|
||||
func build_tower():
|
||||
var tower = Tower.instance()
|
||||
|
@ -17,23 +19,30 @@ func build_tower():
|
|||
var pos = Vector2(last_built, (randf() * (screen_size.y * 0.7)) + screen_size.y * 0.15) # The player's movement vector.
|
||||
|
||||
tower.position = pos
|
||||
towers.append(tower)
|
||||
|
||||
emit_signal("spawn", tower.get_global_transform().get_origin().x)
|
||||
|
||||
add_child(tower)
|
||||
last_built += tower_density
|
||||
|
||||
func build_all_towers():
|
||||
while towers.size() > 0:
|
||||
towers.pop_back().queue_free()
|
||||
|
||||
last_built = 300
|
||||
while last_built < screen_size.x * 3:
|
||||
build_tower()
|
||||
|
||||
func _ready():
|
||||
var ui = get_node("UI")
|
||||
var player = get_node("Player")
|
||||
player.connect("start", self, "build_all_towers")
|
||||
player.connect("start", ui, "_on_Player_start")
|
||||
player.connect("hit", ui, "_on_Player_hit")
|
||||
player.connect("passed", ui, "_on_Player_passed")
|
||||
connect("spawn", player, "_on_Tower_spawn")
|
||||
randomize()
|
||||
|
||||
while last_built < screen_size.x * 3:
|
||||
build_tower()
|
||||
|
||||
func _on_Tower_exit():
|
||||
towers.pop_front()
|
||||
build_tower()
|
||||
|
|
21
Player.gd
21
Player.gd
|
@ -15,19 +15,22 @@ var playing = false
|
|||
|
||||
var speed_y = 0
|
||||
|
||||
var x_offset
|
||||
|
||||
func start():
|
||||
position = screen_size / 2
|
||||
tower_locations = []
|
||||
screen_size = get_viewport_rect().size
|
||||
position = Vector2(0, screen_size.y / 2)
|
||||
speed_y = 0
|
||||
update_rotation()
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
screen_size = get_viewport_rect().size
|
||||
x_offset = get_global_transform().get_origin().x
|
||||
# x_offset = get_global_transform().get_origin().x
|
||||
|
||||
func _process(delta):
|
||||
if Input.is_action_just_pressed("ui_accept"):
|
||||
if not playing:
|
||||
start()
|
||||
emit_signal("start")
|
||||
speed_y = 0
|
||||
playing = true
|
||||
|
@ -42,20 +45,24 @@ func _process(delta):
|
|||
position += Vector2(speed, speed_y * speed)
|
||||
|
||||
var global = get_global_transform().get_origin()
|
||||
while global.x - x_offset > tower_locations[0]:
|
||||
while global.x > tower_locations[0]:
|
||||
emit_signal("passed")
|
||||
tower_locations.pop_front()
|
||||
|
||||
rotation = atan(speed_y / speed)
|
||||
update_rotation()
|
||||
|
||||
if position.y > screen_size.y:
|
||||
emit_signal("hit")
|
||||
print(position)
|
||||
playing = false
|
||||
|
||||
func update_rotation():
|
||||
rotation = atan(speed_y / speed)
|
||||
|
||||
func _on_Player_body_entered(body):
|
||||
playing = false
|
||||
#hide() # Player disappears after being hit.
|
||||
start()
|
||||
|
||||
emit_signal("hit")
|
||||
$CollisionShape2D.set_deferred("disabled", true)
|
||||
|
||||
|
|
Loading…
Reference in a new issue