MVP still sprites and hud etc
This commit is contained in:
parent
e3e785c044
commit
c2421926ac
4 changed files with 28 additions and 14 deletions
|
@ -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)
|
||||
|
|
|
@ -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"]
|
||||
|
|
26
Player.gd
26
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)
|
10
Tower.tscn
10
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="."]
|
||||
|
|
Loading…
Reference in a new issue