From 7843bf2b8ddf2445aa380f9d2024115d73435289 Mon Sep 17 00:00:00 2001 From: Nathan Anderson Date: Thu, 4 Aug 2022 18:05:48 -0600 Subject: [PATCH] Added level mods and updated sprite imports --- icon.png | Bin 3305 -> 0 bytes icon.png.import | 35 ---------- project.godot | 1 - scenes/UI.tscn | 47 ++++++++++++++ scenes/{tree.tscn => decor.tscn} | 6 +- scenes/house.tscn | 32 +++++----- scenes/neighbor.tscn | 3 +- scenes/player.tscn | 12 +++- scenes/pop.tscn | 24 +++++++ scenes/stage.tscn | 30 ++++++--- scenes/trolley.tscn | 1 + scripts/UI.gd | 18 ++++++ scripts/decor.gd | 15 +++++ scripts/house.gd | 14 +++- scripts/neighbor.gd | 106 +++++++++++++++++++------------ scripts/player.gd | 15 +++-- scripts/pop.gd | 7 ++ scripts/stage.gd | 23 +++++++ scripts/trolley.gd | 13 +++- 19 files changed, 288 insertions(+), 114 deletions(-) delete mode 100644 icon.png delete mode 100644 icon.png.import create mode 100644 scenes/UI.tscn rename scenes/{tree.tscn => decor.tscn} (51%) create mode 100644 scenes/pop.tscn create mode 100644 scripts/UI.gd create mode 100644 scripts/decor.gd create mode 100644 scripts/pop.gd diff --git a/icon.png b/icon.png deleted file mode 100644 index c98fbb601c83c81ec8c22b1dba7d1d57c62b323c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3305 zcmVNc=P)Px>qe(&U$es`gSqKCHF-lq>v1vga#%UF>TTrLR zW%{UNJKZi|Pj@Rc9GyPBD1CamMMf6SL~V^ag9~Vzut^L^0!Tv0LK0FTdnJ`x->EF(MZIP5kY*1-@^egP~7mH>({qi7{6 zQF;bN-XMq~+RzA8lI9AtJuz@PY*+{SP-Gbd@mZ(r*eE&`XO5!C>w#-pcmS28K^qzY zfTGCjor*I@ltgKb03nh#Fh$KpDL=o}gj-g4v6{}ZR1*mvXv?|gEA&Yr#r;Zw*d zUabIx8iHf+WoIO_c11Ba&!34XihSMF&C#YFDjU0)mmbXz3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sHKM$+a{!w|Mt5QLwD>sA+;u-+k%z_ZL?el$#&|kX?ygLfm zxZ^Fo^bOhx)w*6In?vS{Q|uk08cKRK}t+0ukQSCOyP$^HEC+zzX51M#=e-?*xHWMDRcLdIV41daHy{HimwDo z6!_O=*(}MK!YeyJpmgu(cF1tpEv}m;0s8{4z4HlHyMxDncn8zs!g+OXEk`CeEj}9N zq#Ag1$#jyV_5AjYQg*!mS->;`S^;iU)ih9D+eks)H2z`1RHny;F<^CEwk+}d^k^Ph zl);*XQ|ayL;rZWh=fA(G2#AJz1&r&as9I8S@9m3Owftrb5n*)pTluK^9LHOFIo{G2 zG}l$9R*{<+L2hCsOJ~Lt6Q-rRub*8X{*4{)e}>%=_&DxOFeq1LRia4Yyj*Tyynw>F zxkKf(MiaG0*L|V-^Zhtvg-(-|F0&1rU8bqab*n5TT8~C860O$|6Rt%P1=1(EjIQZ% z;Y^PU2VC*~^2!sG?mbBPS0~0yd-+086)+rHjhfk6>CB$t`o%;=kdYF9NwiKkwbIpN z;_FlOuHQHHSZ&@fUuSI-S*t`DjsiIB z{=1M@JKVC$a8z{2;xCPfRb{~T>uo#5rL4L+z9n`rSUt3Tt nAZ`TZm+q1gPVN84&*%Ra7her>#-hHS00000NkvXXu0mjf|6N@O diff --git a/icon.png.import b/icon.png.import deleted file mode 100644 index a4c02e6..0000000 --- a/icon.png.import +++ /dev/null @@ -1,35 +0,0 @@ -[remap] - -importer="texture" -type="StreamTexture" -path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" -metadata={ -"vram_texture": false -} - -[deps] - -source_file="res://icon.png" -dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ] - -[params] - -compress/mode=0 -compress/lossy_quality=0.7 -compress/hdr_mode=0 -compress/bptc_ldr=0 -compress/normal_map=0 -flags/repeat=0 -flags/filter=true -flags/mipmaps=false -flags/anisotropic=false -flags/srgb=2 -process/fix_alpha_border=true -process/premult_alpha=false -process/HDR_as_SRGB=false -process/invert_color=false -process/normal_map_invert_y=false -stream=false -size_limit=0 -detect_3d=true -svg/scale=1.0 diff --git a/project.godot b/project.godot index 4ac6389..dd34a40 100644 --- a/project.godot +++ b/project.godot @@ -34,7 +34,6 @@ _global_script_class_icons={ config/name="roger" run/main_scene="res://scenes/stage.tscn" -config/icon="res://icon.png" [display] diff --git a/scenes/UI.tscn b/scenes/UI.tscn new file mode 100644 index 0000000..8f1da2e --- /dev/null +++ b/scenes/UI.tscn @@ -0,0 +1,47 @@ +[gd_scene load_steps=6 format=2] + +[ext_resource path="res://roger-roger/fonts/8-BIT WONDER.TTF" type="DynamicFontData" id=1] +[ext_resource path="res://scripts/UI.gd" type="Script" id=2] +[ext_resource path="res://roger-roger/ui/music-enabled.png" type="Texture" id=3] + +[sub_resource type="DynamicFont" id=1] +font_data = ExtResource( 1 ) + +[sub_resource type="Theme" id=2] +default_font = SubResource( 1 ) + +[node name="GUI" type="Node2D"] +script = ExtResource( 2 ) + +[node name="MarginContainer" type="MarginContainer" parent="."] +margin_left = 20.0 +margin_top = 20.0 +margin_right = 1279.0 +margin_bottom = 257.0 + +[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer"] +margin_right = 1259.0 +margin_bottom = 237.0 + +[node name="TimeLabel" type="RichTextLabel" parent="MarginContainer/HBoxContainer"] +margin_right = 1227.0 +margin_bottom = 237.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 +theme = SubResource( 2 ) +text = "Time 60" + +[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/HBoxContainer"] +margin_left = 1231.0 +margin_right = 1259.0 +margin_bottom = 237.0 + +[node name="ToolButton" type="ToolButton" parent="MarginContainer/HBoxContainer/VBoxContainer"] +margin_right = 28.0 +margin_bottom = 24.0 +toggle_mode = true +icon = ExtResource( 3 ) + +[node name="GameTimer" type="Timer" parent="."] + +[connection signal="toggled" from="MarginContainer/HBoxContainer/VBoxContainer/ToolButton" to="." method="_on_ToolButton_toggled"] diff --git a/scenes/tree.tscn b/scenes/decor.tscn similarity index 51% rename from scenes/tree.tscn rename to scenes/decor.tscn index 7d0f7f7..88bc635 100644 --- a/scenes/tree.tscn +++ b/scenes/decor.tscn @@ -1,8 +1,10 @@ -[gd_scene load_steps=2 format=2] +[gd_scene load_steps=3 format=2] [ext_resource path="res://roger-roger/tree.png" type="Texture" id=1] +[ext_resource path="res://scripts/decor.gd" type="Script" id=2] -[node name="Tree" type="Node2D"] +[node name="Decor" type="Node2D"] +script = ExtResource( 2 ) [node name="Sprite" type="Sprite" parent="."] scale = Vector2( 6, 6 ) diff --git a/scenes/house.tscn b/scenes/house.tscn index e0bd038..78648ef 100644 --- a/scenes/house.tscn +++ b/scenes/house.tscn @@ -4,20 +4,19 @@ [ext_resource path="res://roger-roger/chadHouse.png" type="Texture" id=2] [sub_resource type="CapsuleShape2D" id=3] -radius = 12.2857 -height = 2.57142 +radius = 12.4286 +height = 4.85714 -[sub_resource type="RectangleShape2D" id=4] -extents = Vector2( 86, 63.5 ) +[sub_resource type="ConvexPolygonShape2D" id=6] -[sub_resource type="RectangleShape2D" id=2] -extents = Vector2( 3.5, 2 ) +[sub_resource type="RectangleShape2D" id=5] +extents = Vector2( 142.5, 73.1641 ) [node name="House" type="Node2D"] script = ExtResource( 1 ) [node name="Sprite" type="Sprite" parent="."] -position = Vector2( 0, -125 ) +position = Vector2( 7, -125 ) scale = Vector2( 5, 5 ) texture = ExtResource( 2 ) @@ -26,19 +25,18 @@ collision_layer = 4 collision_mask = 7 [node name="CollisionShape2D" type="CollisionShape2D" parent="HouseBody"] -position = Vector2( -7, -90 ) +position = Vector2( -4.76837e-07, -90 ) scale = Vector2( 7, 7 ) shape = SubResource( 3 ) [node name="CollisionShape2D2" type="CollisionShape2D" parent="HouseBody"] -position = Vector2( -6, -49.5 ) -shape = SubResource( 4 ) +position = Vector2( 0, -49 ) +shape = SubResource( 6 ) -[node name="DoorBody" type="StaticBody2D" parent="."] -scale = Vector2( 7, 7 ) -collision_layer = 4 -collision_mask = 2 +[node name="DoorArea2D" type="Area2D" parent="."] -[node name="CollisionShape2D" type="CollisionShape2D" parent="DoorBody"] -position = Vector2( -0.857143, 1.57143 ) -shape = SubResource( 2 ) +[node name="CollisionShape2D" type="CollisionShape2D" parent="DoorArea2D"] +position = Vector2( 0, 36.836 ) +shape = SubResource( 5 ) + +[connection signal="body_entered" from="DoorArea2D" to="." method="_on_DoorArea2D_body_entered"] diff --git a/scenes/neighbor.tscn b/scenes/neighbor.tscn index 463a1a1..fd24719 100644 --- a/scenes/neighbor.tscn +++ b/scenes/neighbor.tscn @@ -48,8 +48,7 @@ shape = SubResource( 3 ) position = Vector2( 1, -29 ) scale = Vector2( 5, 5 ) frames = SubResource( 1 ) -animation = "walk" -frame = 2 +animation = "idle" playing = true [node name="CollisionShape2D" type="CollisionShape2D" parent="."] diff --git a/scenes/player.tscn b/scenes/player.tscn index 675a8e7..79c060d 100644 --- a/scenes/player.tscn +++ b/scenes/player.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=13 format=2] +[gd_scene load_steps=15 format=2] [ext_resource path="res://roger-roger/runningSprites/Rogers5.png" type="Texture" id=1] [ext_resource path="res://roger-roger/runningSprites/Rogers4.png" type="Texture" id=2] @@ -10,6 +10,8 @@ [ext_resource path="res://roger-roger/runningSprites/RogersStart.png" type="Texture" id=8] [ext_resource path="res://scripts/player.gd" type="Script" id=9] [ext_resource path="res://roger-roger/mrRogers.png" type="Texture" id=10] +[ext_resource path="res://roger-roger/chevron_pointer.png" type="Texture" id=11] +[ext_resource path="res://scenes/UI.tscn" type="PackedScene" id=12] [sub_resource type="CapsuleShape2D" id=2] radius = 13.0 @@ -48,3 +50,11 @@ playing = true [node name="Camera2D" type="Camera2D" parent="."] current = true + +[node name="ChevronSprite" type="Sprite" parent="."] +position = Vector2( 0, -111 ) +scale = Vector2( 3, 3 ) +texture = ExtResource( 11 ) + +[node name="GUI" parent="." instance=ExtResource( 12 )] +position = Vector2( -640, -481 ) diff --git a/scenes/pop.tscn b/scenes/pop.tscn new file mode 100644 index 0000000..40fae66 --- /dev/null +++ b/scenes/pop.tscn @@ -0,0 +1,24 @@ +[gd_scene load_steps=7 format=2] + +[ext_resource path="res://roger-roger/effects/pop-4.png" type="Texture" id=1] +[ext_resource path="res://roger-roger/effects/pop-3.png" type="Texture" id=2] +[ext_resource path="res://roger-roger/effects/pop-1.png" type="Texture" id=3] +[ext_resource path="res://roger-roger/effects/pop-2.png" type="Texture" id=4] +[ext_resource path="res://scripts/pop.gd" type="Script" id=5] + +[sub_resource type="SpriteFrames" id=1] +animations = [ { +"frames": [ ExtResource( 3 ), ExtResource( 4 ), ExtResource( 2 ), ExtResource( 1 ) ], +"loop": true, +"name": "pop", +"speed": 8.0 +} ] + +[node name="Pop" type="AnimatedSprite"] +position = Vector2( 0, -40 ) +scale = Vector2( 7, 7 ) +frames = SubResource( 1 ) +animation = "pop" +script = ExtResource( 5 ) + +[connection signal="animation_finished" from="." to="." method="_on_Pop_animation_finished"] diff --git a/scenes/stage.tscn b/scenes/stage.tscn index 19e0611..e3c2c69 100644 --- a/scenes/stage.tscn +++ b/scenes/stage.tscn @@ -12,7 +12,7 @@ [ext_resource path="res://roger-roger/tilemap/StreetVerticalRight.png" type="Texture" id=10] [ext_resource path="res://roger-roger/tilemap/grass1.png" type="Texture" id=11] [ext_resource path="res://roger-roger/tilemap/justRoad.png" type="Texture" id=12] -[ext_resource path="res://scenes/tree.tscn" type="PackedScene" id=13] +[ext_resource path="res://scenes/decor.tscn" type="PackedScene" id=13] [sub_resource type="ConvexPolygonShape2D" id=3] points = PoolVector2Array( 0, 0, 16, 0, 16, 16, 0, 16 ) @@ -139,6 +139,7 @@ tile_data = PoolIntArray( -13, 7, 0, -12, 7, 0, -11, 3, 0, -10, 1, 0, -9, 0, 0, [node name="Tree" parent="YSort" instance=ExtResource( 13 )] position = Vector2( 412.655, 542.278 ) +SPRITE_ASSET = "tree" [node name="Tree2" parent="YSort" instance=ExtResource( 13 )] position = Vector2( 862.175, 801.526 ) @@ -148,6 +149,7 @@ position = Vector2( 1506.73, 1272.45 ) [node name="Tree4" parent="YSort" instance=ExtResource( 13 )] position = Vector2( 1045.31, 479.251 ) +SPRITE_ASSET = "lamppos" [node name="Tree5" parent="YSort" instance=ExtResource( 13 )] position = Vector2( -64.6703, 908.108 ) @@ -159,22 +161,34 @@ position = Vector2( -68.0338, 1333.6 ) position = Vector2( 935.996, 1365.56 ) [node name="Trolley" parent="YSort" instance=ExtResource( 4 )] -position = Vector2( 111.946, -51.4683 ) +position = Vector2( 116.441, -118.892 ) [node name="Player" parent="YSort" instance=ExtResource( 1 )] position = Vector2( 521.375, 114 ) -[node name="House" parent="YSort" instance=ExtResource( 3 )] +[node name="House1" parent="YSort" instance=ExtResource( 3 )] position = Vector2( 1972.13, 1965.82 ) -[node name="Neighbor" parent="YSort" instance=ExtResource( 5 )] -position = Vector2( 760.201, 407.292 ) +[node name="House2" parent="YSort" instance=ExtResource( 3 )] +position = Vector2( 1079.23, 1518.43 ) + +[node name="House3" parent="YSort" instance=ExtResource( 3 )] +position = Vector2( -210.104, 1038.94 ) + +[node name="House4" parent="YSort" instance=ExtResource( 3 )] +position = Vector2( 1471.88, 482.054 ) + +[node name="Neighbor1" parent="YSort" instance=ExtResource( 5 )] +position = Vector2( 1561.16, 1687.12 ) [node name="Neighbor2" parent="YSort" instance=ExtResource( 5 )] -position = Vector2( 521.578, 319.171 ) +position = Vector2( 487.675, 1641.38 ) [node name="Neighbor3" parent="YSort" instance=ExtResource( 5 )] -position = Vector2( 477.85, 707.714 ) +position = Vector2( -23.5379, 746.218 ) [node name="Neighbor4" parent="YSort" instance=ExtResource( 5 )] -position = Vector2( -324.858, 684.091 ) +position = Vector2( 985.045, 718.4 ) + +[node name="Decor" parent="YSort" instance=ExtResource( 13 )] +position = Vector2( 1353.08, 1162.06 ) diff --git a/scenes/trolley.tscn b/scenes/trolley.tscn index beeb0ab..827fb66 100644 --- a/scenes/trolley.tscn +++ b/scenes/trolley.tscn @@ -34,3 +34,4 @@ position = Vector2( 0, -2.25 ) shape = SubResource( 3 ) [connection signal="body_entered" from="TrolleySeatArea" to="." method="_on_TrolleySeatArea_body_entered"] +[connection signal="body_exited" from="TrolleySeatArea" to="." method="_on_TrolleySeatArea_body_exited"] diff --git a/scripts/UI.gd b/scripts/UI.gd new file mode 100644 index 0000000..06a6a48 --- /dev/null +++ b/scripts/UI.gd @@ -0,0 +1,18 @@ +extends Node2D + +onready var time_label := $MarginContainer/HBoxContainer/TimeLabel +onready var game_timer := $GameTimer + +func start_timer(seconds: int) -> void: + game_timer.start(seconds) + +func _ready() -> void: + start_timer(60) + +func _process(delta: float) -> void: + var time = int(game_timer.get_time_left()) + time_label.text = "Time %s" % time + + +func _on_ToolButton_toggled(button_pressed: bool) -> void: + print(button_pressed) diff --git a/scripts/decor.gd b/scripts/decor.gd new file mode 100644 index 0000000..1af420f --- /dev/null +++ b/scripts/decor.gd @@ -0,0 +1,15 @@ +extends Node2D + +onready var sprite := $Sprite + + +const SpriteAsset = {bush1 = "bush1", bush2 = "bush2", tree = "tree", lamppost = "lamppost"} +export var SPRITE_ASSET := SpriteAsset.bush1 + +func _ready() -> void: + if SPRITE_ASSET in SpriteAsset: + sprite.texture = load("res://roger-roger/%s.png" % SPRITE_ASSET) + else: + print("ERROR - Provided Sprite asset is either not defined or misspelled: %s FIXME %s" % [SPRITE_ASSET, self.name]) + sprite.texture = load("res://roger-roger/%s.png" % SpriteAsset.bush1) + diff --git a/scripts/house.gd b/scripts/house.gd index 79a86d5..fa5b009 100644 --- a/scripts/house.gd +++ b/scripts/house.gd @@ -1,6 +1,18 @@ extends Node2D onready var sprite = $Sprite +onready var door_area = $DoorArea2D + +signal come_home + +var id : int func _ready() -> void: - sprite.set_modulate(Color(1.0, 0.0, 0.0)) + id = int(self.name[-1]) + + + +func _on_DoorArea2D_body_entered(body: Node) -> void: + if body is Neighbor: + if body.id == id: + emit_signal("come_home") diff --git a/scripts/neighbor.gd b/scripts/neighbor.gd index 234f8ea..3b677ef 100644 --- a/scripts/neighbor.gd +++ b/scripts/neighbor.gd @@ -2,11 +2,12 @@ extends KinematicBody2D class_name Neighbor -signal neighbor_following_roger +signal found_home(id) onready var roger_area := $RogerArea2D onready var sprite := $AnimatedSprite onready var wander_timer := $WanderTimer +onready var chevron_sprite := $ChevronSprite export var MAX_SPEED := 225 export var ACCELERATION := 1000 @@ -17,13 +18,20 @@ var neighbor_velocity := Vector2.ZERO var leader: KinematicBody2D var follower: KinematicBody2D var rng := RandomNumberGenerator.new() -var is_wandering := false var wander_direction := Vector2.ZERO +var matching_house_node : Node2D +var house_position := Vector2.ZERO +var house_direction := Vector2.ZERO +var id : int + +var pop_effect_scene = preload("res://scenes/pop.tscn") enum State { MOVE, WANDER, - IDLE + IDLE, + GO_HOME, + FOUND_HOME } func reset_leads() -> void: @@ -33,26 +41,31 @@ func reset_leads() -> void: follower = null func _ready() -> void: - sprite.set_modulate(Color(.5,0,0)) + id = int(self.name[-1]) + rng.set_seed(id) + matching_house_node = get_parent().get_node("House%s" % id) + matching_house_node.connect("come_home", self, "_on_house_come_home") func _physics_process(delta: float) -> void: + house_position = matching_house_node.global_position + house_direction = (house_position - global_position).normalized() match state: State.MOVE: - move_state(delta) + _move_state(delta) State.WANDER: - wander_state(delta) + _wander_state(delta) State.IDLE: - idle_state(delta) + _idle_state(delta) + State.GO_HOME: + _go_home_state(delta) -func move_state(delta: float) -> void: -# var player := get_parent().get_node("Player") as Player -# leader.follower = self +func _move_state(delta: float) -> void: if leader == null: state = State.IDLE return var result_vector := leader.global_position - global_position if result_vector.length() > 100: - move_neighbor(result_vector) + _move_neighbor(result_vector) else: state = State.IDLE if result_vector.length() > 250: @@ -63,32 +76,15 @@ func move_state(delta: float) -> void: follower = null state = State.IDLE -func wander_state(delta: float) -> void: +func _wander_state(delta: float) -> void: if leader != null: state = State.MOVE return - move_neighbor(wander_direction, true) - + _move_neighbor(wander_direction, true) -func move_neighbor(direction_vector: Vector2, is_wander: bool = false) -> void: - sprite.play("run") if not is_wander else sprite.play("walk") - var move_vector := Vector2(direction_vector).normalized() - if move_vector.x < 0 and not sprite.flip_h: - sprite.flip_h = true - elif move_vector.x > 0 and sprite.flip_h: - sprite.flip_h = false - if move_vector != Vector2.ZERO: - var velocity := move_vector * MAX_SPEED if not is_wander else move_vector * MAX_SPEED / 3 - neighbor_velocity = neighbor_velocity.move_toward(velocity, ACCELERATION * get_physics_process_delta_time()) - else: - neighbor_velocity = neighbor_velocity.move_toward(Vector2.ZERO, FRICTION * get_physics_process_delta_time()) - - neighbor_velocity = move_and_slide(neighbor_velocity) - - -func idle_state(delta: float) -> void: +func _idle_state(delta: float) -> void: if wander_timer.is_stopped(): - wander_timer.start(rng.randf_range(0, 1.5)) + wander_timer.start(rng.randf_range(1.8, 6.5)) sprite.play("idle") for body in roger_area.get_overlapping_bodies(): if body.is_class("KinematicBody2D") and not body is Trolley and leader == null and body.follower == null and body.leader != null: @@ -97,31 +93,63 @@ func idle_state(delta: float) -> void: if leader != null: state = State.MOVE +func _go_home_state(delta: float) -> void: + _move_neighbor(house_direction, true) +# print((house_position - global_position).length()) + if ((house_position - global_position).length() < 30): + emit_signal("found_home", id) + queue_free() + +func _move_neighbor(direction_vector: Vector2, is_walk: bool = false) -> void: + sprite.play("run") if not is_walk else sprite.play("walk") + var move_vector := Vector2(direction_vector).normalized() + if move_vector.x < 0 and not sprite.flip_h: + sprite.flip_h = true + elif move_vector.x > 0 and sprite.flip_h: + sprite.flip_h = false + if move_vector != Vector2.ZERO: + var velocity := move_vector * MAX_SPEED if not is_walk else move_vector * MAX_SPEED / 3 + neighbor_velocity = neighbor_velocity.move_toward(velocity, ACCELERATION * get_physics_process_delta_time()) + else: + neighbor_velocity = neighbor_velocity.move_toward(Vector2.ZERO, FRICTION * get_physics_process_delta_time()) + + neighbor_velocity = move_and_slide(neighbor_velocity) + func _on_RogerArea2D_body_entered(body: Node) -> void: if body != self and leader == null: if body is Player and body.follower == null: body.follower = self leader = body elif body.is_class("KinematicBody2D") and not body is Trolley and body.follower == null: - print('Got neighbor body') if body.leader != null: - print('Following the leader') leader = body leader.follower = self - func _on_WanderTimer_timeout() -> void: if state == State.IDLE: - print('wander timer done') var rand_x = rng.randf_range(-1.0, 1.0) var rand_y = rng.randf_range(-1.0, 1.0) - var wander_time = rng.randf_range(1.0, 1.5) + var wander_time = rng.randf_range(0.3, 1.2) state = State.WANDER wander_direction = Vector2(rand_x, rand_y) wander_timer.start(wander_time) elif state == State.WANDER: - print('Done wandering') - var wait_time = rng.randf_range(1.0, 5.5) + var wait_time = rng.randf_range(1.8, 6.5) state = State.IDLE wander_timer.start(wait_time) + elif state == State.FOUND_HOME: + state = State.GO_HOME + +func _on_house_come_home() -> void: + sprite.play("idle") + wander_timer.start(0.5) + var instance = pop_effect_scene.instance() + get_parent().add_child(instance) + instance.global_position = Vector2(global_position.x, global_position.y - 50) + if follower == null: + leader.follower = null + else: + leader.follower = follower + follower.leader = leader + state = State.FOUND_HOME diff --git a/scripts/player.gd b/scripts/player.gd index 75b3160..30affec 100644 --- a/scripts/player.gd +++ b/scripts/player.gd @@ -9,8 +9,10 @@ export var FRICTION := 2000 var player_velocity = Vector2.ZERO var state = State.IDLE var follower : KinematicBody2D +var leader := self onready var sprite := $AnimatedSprite +onready var chevron_sprite := $ChevronSprite enum State { MOVE, @@ -21,11 +23,14 @@ enum State { func _physics_process(delta: float) -> void: match state: State.MOVE: - move_state(delta) + _move_state(delta) State.IDLE: - idle_state(delta) - -func move_state(delta: float) -> void: + _idle_state(delta) + chevron_sprite.visible = follower != null + if follower != null: + chevron_sprite.rotation_degrees = rad2deg((follower.house_position - global_position).angle()) - 90 + +func _move_state(delta: float) -> void: var input_vector := Vector2.ZERO input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left") input_vector.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up") @@ -47,7 +52,7 @@ func move_state(delta: float) -> void: if player_velocity == Vector2.ZERO: state = State.IDLE -func idle_state(delta: float) -> void: +func _idle_state(delta: float) -> void: if Input.is_action_just_pressed("ui_up") or Input.is_action_just_pressed("ui_down") or Input.is_action_just_pressed("ui_left") or Input.is_action_just_pressed("ui_right"): sprite.set_animation("run") state = State.MOVE diff --git a/scripts/pop.gd b/scripts/pop.gd new file mode 100644 index 0000000..f22f385 --- /dev/null +++ b/scripts/pop.gd @@ -0,0 +1,7 @@ +extends AnimatedSprite + +func _ready() -> void: + play() + +func _on_Pop_animation_finished() -> void: + queue_free() diff --git a/scripts/stage.gd b/scripts/stage.gd index 3eb6c96..d1bc7c4 100644 --- a/scripts/stage.gd +++ b/scripts/stage.gd @@ -1,2 +1,25 @@ extends Node2D +var helped_neighbors := [] +var total_neighbors := 0 + +onready var trolley = $YSort/Trolley as Trolley + +func _ready() -> void: + trolley.connect("rogers_left_trolley", self, "_on_rogers_left_trolley") + for node in get_node("YSort").get_children(): + if 'Neighbor' in node.name: + var err = node.connect("found_home", self, "_on_neighbor_found_home") + total_neighbors += 1 + + +func _on_rogers_left_trolley() -> void: + pass + +func _on_neighbor_found_home(id: int) -> void: + print('You helped a neighbor') + helped_neighbors.append(id) + if len(helped_neighbors) == total_neighbors: + trolley.set_trolley_open(true) + + diff --git a/scripts/trolley.gd b/scripts/trolley.gd index ac7d185..5b21c8d 100644 --- a/scripts/trolley.gd +++ b/scripts/trolley.gd @@ -2,6 +2,8 @@ extends KinematicBody2D class_name Trolley +signal rogers_left_trolley() + export var TIME = 60 onready var trolley_closed_shape = $TrolleyClosedShape export var MAX_VELOCITY = .3 @@ -10,7 +12,7 @@ var velocity := Vector2.ZERO var has_roger := false func _ready() -> void: - trolley_closed_shape.set_deferred("disabled", true) + set_trolley_open(true) func _physics_process(delta: float) -> void: velocity.x = move_toward(velocity.x, MAX_VELOCITY, delta if not has_roger else delta * 10) @@ -22,8 +24,8 @@ func _physics_process(delta: float) -> void: MAX_VELOCITY = 10 collider.move_and_collide(velocity * 3) - - +func set_trolley_open(trolley_open: bool) -> void: + trolley_closed_shape.set_deferred("disabled", trolley_open) func _on_TrolleySeatArea_body_entered(body: Node) -> void: if body is Player: @@ -31,3 +33,8 @@ func _on_TrolleySeatArea_body_entered(body: Node) -> void: print('closing trolley') trolley_closed_shape.set_deferred("disabled", false) + + +func _on_TrolleySeatArea_body_exited(body: Node) -> void: + if body is Player: + emit_signal("rogers_left_trolley")