From 8f985b37d87b208fc19c817dece6d352b23e5dd4 Mon Sep 17 00:00:00 2001 From: Luiz Date: Tue, 4 Sep 2018 09:21:00 -0400 Subject: [PATCH] =?UTF-8?q?anima=C3=A7=C3=A3o,=20inicio,=20fim=20de=20jogo?= =?UTF-8?q?,=20pontua=C3=A7=C3=A3o=20e=20record?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...n.png-487276ed1e3a0c39cad0279d744ee560.md5 | 0 ....png-487276ed1e3a0c39cad0279d744ee560.stex | Bin ...s.png-6400cb1186e3521f833030ecfd34f068.md5 | 0 ....png-6400cb1186e3521f833030ecfd34f068.stex | Bin Area2D.gd | 18 ++- CactoG1.tscn | 0 CactoG2.tscn | 0 CactoG3.tscn | 0 CactoP2.tscn | 0 CactoP3.tscn | 0 Dinossauro.gd | 27 +++- Dinossauro.tscn | 116 ++++++++++++++++++ Main.gd | 15 +++ Main.tscn | 83 ++++++++----- ParallaxBackground.gd | 3 + icon.png | Bin icon.png.import | 0 project.godot | 2 +- sprites/sprites.png | Bin sprites/sprites.png.import | 0 20 files changed, 228 insertions(+), 36 deletions(-) mode change 100644 => 100755 .import/icon.png-487276ed1e3a0c39cad0279d744ee560.md5 mode change 100644 => 100755 .import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex mode change 100644 => 100755 .import/sprites.png-6400cb1186e3521f833030ecfd34f068.md5 mode change 100644 => 100755 .import/sprites.png-6400cb1186e3521f833030ecfd34f068.stex mode change 100644 => 100755 CactoG1.tscn mode change 100644 => 100755 CactoG2.tscn mode change 100644 => 100755 CactoG3.tscn mode change 100644 => 100755 CactoP2.tscn mode change 100644 => 100755 CactoP3.tscn create mode 100644 Dinossauro.tscn mode change 100644 => 100755 ParallaxBackground.gd mode change 100644 => 100755 icon.png mode change 100644 => 100755 icon.png.import mode change 100644 => 100755 project.godot mode change 100644 => 100755 sprites/sprites.png mode change 100644 => 100755 sprites/sprites.png.import diff --git a/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.md5 b/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.md5 old mode 100644 new mode 100755 diff --git a/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex b/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex old mode 100644 new mode 100755 diff --git a/.import/sprites.png-6400cb1186e3521f833030ecfd34f068.md5 b/.import/sprites.png-6400cb1186e3521f833030ecfd34f068.md5 old mode 100644 new mode 100755 diff --git a/.import/sprites.png-6400cb1186e3521f833030ecfd34f068.stex b/.import/sprites.png-6400cb1186e3521f833030ecfd34f068.stex old mode 100644 new mode 100755 diff --git a/Area2D.gd b/Area2D.gd index d9b7f0f..c1c2eb3 100644 --- a/Area2D.gd +++ b/Area2D.gd @@ -4,17 +4,33 @@ onready var dinossauro = get_parent().get_node("Dinossauro") var chao = Vector2(1400, 708) var velocidade = Vector2(-500, 0) var tempo_vida = 5 +var pulou = false +onready var main = get_parent() #get_node("/root/Main") func _ready(): set_position(chao) connect("area_entered", dinossauro, "colidiu") + dinossauro.connect("recomecou", self, "recomecou") pass func _physics_process(delta): + if not main.comecou: + return + set_position(position + get_node("/root/Main").velocidade * delta) tempo_vida = tempo_vida - delta if tempo_vida <= 0: - queue_free() \ No newline at end of file + queue_free() + + # Verifica se jogador já pulou esse cacto e adiciona pontos + if not pulou: + if get_position().x < main.get_node("Dinossauro").get_position().x: + pulou = true + main.pontos = main.pontos + main.pontuacao_cacto + main.get_node("Pontos").text = "Pontos: " + str(main.pontos) + +func recomecou(): + queue_free() \ No newline at end of file diff --git a/CactoG1.tscn b/CactoG1.tscn old mode 100644 new mode 100755 diff --git a/CactoG2.tscn b/CactoG2.tscn old mode 100644 new mode 100755 diff --git a/CactoG3.tscn b/CactoG3.tscn old mode 100644 new mode 100755 diff --git a/CactoP2.tscn b/CactoP2.tscn old mode 100644 new mode 100755 diff --git a/CactoP3.tscn b/CactoP3.tscn old mode 100644 new mode 100755 diff --git a/Dinossauro.gd b/Dinossauro.gd index 7dbfcd3..b3edc2b 100644 --- a/Dinossauro.gd +++ b/Dinossauro.gd @@ -1,5 +1,7 @@ extends Area2D +signal recomecou + var chao = Vector2(110, 659) var gravidade = 4000 var velocidade = Vector2() @@ -21,9 +23,13 @@ var cactos = [preload("res://CactoP1.tscn"), func _ready(): set_position(chao) randomize() + $AnimationPlayer.play("parado") pass func _physics_process(delta): + if not get_parent().comecou: + return + tempo += delta if tempo >= intervalo: @@ -36,8 +42,6 @@ func _physics_process(delta): # Decide novo intervalo intervalo = rand_range(intervalo_min, intervalo_max) - print(intervalo) - if Input.is_action_pressed("pular"): @@ -56,4 +60,21 @@ func _physics_process(delta): velocidade = Vector2() func colidiu(area): - queue_free() \ No newline at end of file + $AnimationPlayer.play("morto") + get_parent().comecou = false + get_parent().acabou = true + if get_parent().pontos > get_parent().record: + get_parent().record = get_parent().pontos + pass + +func _input(event): + if event is InputEventKey or event is InputEventMouseButton: + if get_parent().acabou and not event.is_echo(): + emit_signal("recomecou") +# get_tree().reload_current_scene() + get_parent().acabou = false + get_parent().get_node("Record").text = "Record: " + str(get_parent().record) + pass + + get_parent().comecou = true + $AnimationPlayer.play("andando") \ No newline at end of file diff --git a/Dinossauro.tscn b/Dinossauro.tscn new file mode 100644 index 0000000..cbbbab7 --- /dev/null +++ b/Dinossauro.tscn @@ -0,0 +1,116 @@ +[gd_scene load_steps=7 format=2] + +[ext_resource path="res://Dinossauro.gd" type="Script" id=1] +[ext_resource path="res://sprites/sprites.png" type="Texture" id=2] + +[sub_resource type="RectangleShape2D" id=1] + +custom_solver_bias = 0.0 +extents = Vector2( 23.4716, 36.259 ) + +[sub_resource type="Animation" id=2] + +resource_name = "andando" +length = 0.5 +loop = true +step = 0.25 +tracks/0/type = "value" +tracks/0/path = NodePath("sprites:region_rect") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/keys = { +"times": PoolRealArray( 0, 0.25 ), +"transitions": PoolRealArray( 1, 1 ), +"update": 1, +"values": [ Rect2( 1602, 2, 88, 94 ), Rect2( 1514, 2, 88, 94 ) ] +} + +[sub_resource type="Animation" id=3] + +resource_name = "morto" +length = 2.0 +loop = false +step = 0.1 +tracks/0/type = "value" +tracks/0/path = NodePath("sprites:region_rect") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/keys = { +"times": PoolRealArray( 0, 0.6 ), +"transitions": PoolRealArray( 1, 1 ), +"update": 1, +"values": [ Rect2( 1690, 2, 88, 94 ), Rect2( 1782, 6, 81, 86 ) ] +} +tracks/1/type = "value" +tracks/1/path = NodePath(".:position") +tracks/1/interp = 2 +tracks/1/loop_wrap = true +tracks/1/imported = false +tracks/1/enabled = false +tracks/1/keys = { +"times": PoolRealArray( 0, 0.6, 1.7 ), +"transitions": PoolRealArray( 0.25, 0.307901, 1 ), +"update": 0, +"values": [ Vector2( 0, 0 ), Vector2( 0, -106 ), Vector2( 0, 151 ) ] +} + +[sub_resource type="Animation" id=4] + +length = 1.0 +loop = false +step = 0.1 +tracks/0/type = "value" +tracks/0/path = NodePath("sprites:region_rect") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/keys = { +"times": PoolRealArray( 0 ), +"transitions": PoolRealArray( 1 ), +"update": 0, +"values": [ Rect2( 1338, 2, 88, 94 ) ] +} + +[node name="Dinossauro" type="Area2D"] + +input_pickable = true +gravity_vec = Vector2( 0, 1 ) +gravity = 98.0 +linear_damp = 0.1 +angular_damp = 1.0 +audio_bus_override = false +audio_bus_name = "Master" +script = ExtResource( 1 ) +_sections_unfolded = [ "Transform" ] + +[node name="sprites" type="Sprite" parent="." index="0"] + +z_index = 2 +texture = ExtResource( 2 ) +region_enabled = true +region_rect = Rect2( 1602, 2, 88, 94 ) +_sections_unfolded = [ "Offset", "Region", "Transform", "Z Index" ] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="." index="1"] + +shape = SubResource( 1 ) +_sections_unfolded = [ "Transform" ] + +[node name="AnimationPlayer" type="AnimationPlayer" parent="." index="2"] + +root_node = NodePath("..") +autoplay = "" +playback_process_mode = 1 +playback_default_blend_time = 0.0 +playback_speed = 1.0 +anims/andando = SubResource( 2 ) +anims/morto = SubResource( 3 ) +anims/parado = SubResource( 4 ) +blend_times = [ ] + + diff --git a/Main.gd b/Main.gd index 71292c0..f4bf73d 100644 --- a/Main.gd +++ b/Main.gd @@ -1,9 +1,24 @@ extends Node var velocidade = Vector2(-500, 0) +var velocidade_inicial = velocidade +var offset_inicial = Vector2() +var comecou = false +var acabou = false +var pontuacao_cacto = 10 +var pontos = 0 +var record = 0 func _ready(): + get_node("Dinossauro").connect("recomecou", self, "quando_recomecou") pass func _process(delta): + if not comecou: + return + velocidade.x -= delta/5 + +func quando_recomecou(): + velocidade = velocidade_inicial + $ParallaxBackground.set_scroll_offset(offset_inicial) \ No newline at end of file diff --git a/Main.tscn b/Main.tscn index 680f71f..4be6627 100644 --- a/Main.tscn +++ b/Main.tscn @@ -1,14 +1,9 @@ -[gd_scene load_steps=6 format=2] +[gd_scene load_steps=5 format=2] [ext_resource path="res://Main.gd" type="Script" id=1] [ext_resource path="res://ParallaxBackground.gd" type="Script" id=2] [ext_resource path="res://sprites/sprites.png" type="Texture" id=3] -[ext_resource path="res://Dinossauro.gd" type="Script" id=4] - -[sub_resource type="RectangleShape2D" id=1] - -custom_solver_bias = 0.0 -extents = Vector2( 23.4716, 36.259 ) +[ext_resource path="res://Dinossauro.tscn" type="PackedScene" id=4] [node name="Main" type="Node" index="0"] @@ -35,7 +30,7 @@ _sections_unfolded = [ "Scroll" ] motion_scale = Vector2( 1, 1 ) motion_offset = Vector2( 0, 0 ) motion_mirroring = Vector2( 2400, 0 ) -_sections_unfolded = [ "Motion" ] +_sections_unfolded = [ "Motion", "Transform" ] [node name="Chão" type="Sprite" parent="ParallaxBackground/ParallaxLayer" index="0"] @@ -45,28 +40,54 @@ region_enabled = true region_rect = Rect2( 2, 103, 2400, 25 ) _sections_unfolded = [ "Region", "Transform" ] -[node name="Dinossauro" type="Area2D" parent="." index="1"] - -position = Vector2( 46, 654 ) -input_pickable = true -gravity_vec = Vector2( 0, 1 ) -gravity = 98.0 -linear_damp = 0.1 -angular_damp = 1.0 -audio_bus_override = false -audio_bus_name = "Master" -script = ExtResource( 4 ) -_sections_unfolded = [ "Transform" ] - -[node name="sprites" type="Sprite" parent="Dinossauro" index="0"] - -texture = ExtResource( 3 ) -region_enabled = true -region_rect = Rect2( 1338, 2, 88, 94 ) -_sections_unfolded = [ "Offset", "Region", "Transform" ] - -[node name="CollisionShape2D" type="CollisionShape2D" parent="Dinossauro" index="1"] - -shape = SubResource( 1 ) +[node name="Dinossauro" parent="." index="1" instance=ExtResource( 4 )] + +position = Vector2( 60, 660 ) + +[node name="Pontos" type="Label" parent="." index="2"] + +anchor_left = 0.0 +anchor_top = 0.0 +anchor_right = 0.0 +anchor_bottom = 0.0 +margin_left = 16.0 +margin_top = 17.0 +margin_right = 56.0 +margin_bottom = 31.0 +rect_pivot_offset = Vector2( 0, 0 ) +rect_clip_content = false +mouse_filter = 2 +mouse_default_cursor_shape = 0 +size_flags_horizontal = 1 +size_flags_vertical = 4 +custom_colors/font_color = Color( 1, 1, 1, 1 ) +text = "Pontos: 0" +percent_visible = 1.0 +lines_skipped = 0 +max_lines_visible = -1 +_sections_unfolded = [ "custom_colors", "custom_fonts", "custom_styles" ] + +[node name="Record" type="Label" parent="." index="3"] + +anchor_left = 0.0 +anchor_top = 0.0 +anchor_right = 0.0 +anchor_bottom = 0.0 +margin_left = 560.0 +margin_top = 17.0 +margin_right = 620.0 +margin_bottom = 31.0 +rect_pivot_offset = Vector2( 0, 0 ) +rect_clip_content = false +mouse_filter = 2 +mouse_default_cursor_shape = 0 +size_flags_horizontal = 1 +size_flags_vertical = 4 +custom_colors/font_color = Color( 1, 1, 1, 1 ) +text = "Record: 0" +percent_visible = 1.0 +lines_skipped = 0 +max_lines_visible = -1 +_sections_unfolded = [ "custom_colors", "custom_fonts", "custom_styles" ] diff --git a/ParallaxBackground.gd b/ParallaxBackground.gd old mode 100644 new mode 100755 index d403da6..651b3af --- a/ParallaxBackground.gd +++ b/ParallaxBackground.gd @@ -7,6 +7,9 @@ func _ready(): pass func _process(delta): + if not get_parent().comecou: + return + parallax_offset -= get_node("/root/Main").velocidade * -delta set_scroll_offset(parallax_offset) diff --git a/icon.png b/icon.png old mode 100644 new mode 100755 diff --git a/icon.png.import b/icon.png.import old mode 100644 new mode 100755 diff --git a/project.godot b/project.godot old mode 100644 new mode 100755 index 8bba3a9..f57d000 --- a/project.godot +++ b/project.godot @@ -30,5 +30,5 @@ pular=[ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"", [rendering] quality/2d/use_pixel_snap=true -environment/default_clear_color=Color( 0.886719, 0.886719, 0.886719, 1 ) +environment/default_clear_color=Color( 0.679688, 0.679688, 0.679688, 1 ) environment/default_environment="res://default_env.tres" diff --git a/sprites/sprites.png b/sprites/sprites.png old mode 100644 new mode 100755 diff --git a/sprites/sprites.png.import b/sprites/sprites.png.import old mode 100644 new mode 100755