MVP still sprites and hud etc

This commit is contained in:
ajuvercr 2020-01-15 18:48:07 +01:00
parent e3e785c044
commit c2421926ac
4 changed files with 28 additions and 14 deletions

View file

@ -6,12 +6,12 @@ onready var screen_size = Vector2(ProjectSettings.get("display/window/size/width
onready var player = get_node("Player") onready var player = get_node("Player")
export var tower_density = 200 export var tower_density = 200
var last_built = 100 var last_built = 300
func build_tower(): func build_tower():
var tower = Tower.instance() var tower = Tower.instance()
tower.connect("exit", self, "_on_Tower_exit") 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 tower.position = pos
add_child(tower) add_child(tower)

View file

@ -17,7 +17,7 @@ expand = true
stretch_mode = 2 stretch_mode = 2
[node name="Player" parent="." instance=ExtResource( 3 )] [node name="Player" parent="." instance=ExtResource( 3 )]
position = Vector2( 136.52, -24.4934 ) position = Vector2( 155.182, -2.28882e-05 )
gravity = 0.0 gravity = 0.0
collision_layer = 0 collision_layer = 0
[connection signal="move" from="Player" to="." method="_on_Player_move"] [connection signal="move" from="Player" to="." method="_on_Player_move"]

View file

@ -1,12 +1,14 @@
extends Area2D extends Area2D
export var speed = 1 # How fast the player will move (pixels/sec). export var speed = 3 # How fast the player will move (pixels/sec).
export var jump_speed = 10 export var jump_speed = 4
export var speed_inc = 0.3
signal move signal move
signal hit signal hit
var screen_size var screen_size
var playing = false
var speed_y = 0 var speed_y = 0
@ -19,19 +21,31 @@ func _ready():
func _process(delta): func _process(delta):
if Input.is_action_just_pressed("ui_accept"): 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 = min(speed_y, 0) - 1 * jump_speed
speed_y += 1 if not playing:
position.x += 1 return
position.y += speed_y * speed
speed_y += speed_inc
position += Vector2(speed, speed_y * speed)
emit_signal("move") emit_signal("move")
# 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
if position.y > screen_size.y / 2 - 100:
emit_signal("hit")
print(position)
playing = false
func _on_Player_body_entered(body): func _on_Player_body_entered(body):
print("HIT") playing = false
#hide() # Player disappears after being hit. #hide() # Player disappears after being hit.
emit_signal("hit") emit_signal("hit")
$CollisionShape2D.set_deferred("disabled", true) $CollisionShape2D.set_deferred("disabled", true)

View file

@ -4,7 +4,7 @@
[ext_resource path="res://icon.png" type="Texture" id=2] [ext_resource path="res://icon.png" type="Texture" id=2]
[sub_resource type="RectangleShape2D" id=1] [sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 29.9672, 132.942 ) extents = Vector2( 29.9672, 264.93 )
[node name="Tower" type="Node2D"] [node name="Tower" type="Node2D"]
script = ExtResource( 1 ) script = ExtResource( 1 )
@ -14,12 +14,12 @@ position = Vector2( -32, 100 )
[node name="TextureRect" type="TextureRect" parent="Lower"] [node name="TextureRect" type="TextureRect" parent="Lower"]
margin_right = 64.0 margin_right = 64.0
margin_bottom = 256.0 margin_bottom = 500.0
texture = ExtResource( 2 ) texture = ExtResource( 2 )
expand = true expand = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="Lower"] [node name="CollisionShape2D" type="CollisionShape2D" parent="Lower"]
position = Vector2( 31.5038, 135.281 ) position = Vector2( 31.5038, 267.238 )
shape = SubResource( 1 ) shape = SubResource( 1 )
[node name="Upper" type="RigidBody2D" parent="."] [node name="Upper" type="RigidBody2D" parent="."]
@ -28,12 +28,12 @@ rotation = 3.14159
[node name="TextureRect" type="TextureRect" parent="Upper"] [node name="TextureRect" type="TextureRect" parent="Upper"]
margin_right = 64.0 margin_right = 64.0
margin_bottom = 256.0 margin_bottom = 500.0
texture = ExtResource( 2 ) texture = ExtResource( 2 )
expand = true expand = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="Upper"] [node name="CollisionShape2D" type="CollisionShape2D" parent="Upper"]
position = Vector2( 31.5038, 135.281 ) position = Vector2( 32.6698, 265.913 )
shape = SubResource( 1 ) shape = SubResource( 1 )
[node name="VisibilityNotifier2D" type="VisibilityNotifier2D" parent="."] [node name="VisibilityNotifier2D" type="VisibilityNotifier2D" parent="."]