generated from GnuCodingStudio/Godot-4.3-2D-Template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add interactive map to navigate to islands
- Loading branch information
1 parent
6f8218e
commit e2dde6b
Showing
5 changed files
with
97 additions
and
1 deletion.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
[gd_scene load_steps=5 format=3 uid="uid://dscw6cfkblva7"] | ||
|
||
[ext_resource type="PackedScene" uid="uid://disjjplik7m85" path="res://components/clickable/Clickable.tscn" id="1_3mm8m"] | ||
[ext_resource type="Script" path="res://scenes/map/map.gd" id="1_bve3w"] | ||
|
||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_6tl2x"] | ||
|
||
[sub_resource type="CircleShape2D" id="CircleShape2D_i4h8t"] | ||
|
||
[node name="Map" type="Node2D"] | ||
script = ExtResource("1_bve3w") | ||
|
||
[node name="ShipSprite" type="Sprite2D" parent="."] | ||
unique_name_in_owner = true | ||
position = Vector2(320, 300) | ||
|
||
[node name="Area2D" type="Area2D" parent="ShipSprite"] | ||
|
||
[node name="CollisionShape2D" type="CollisionShape2D" parent="ShipSprite/Area2D"] | ||
shape = SubResource("RectangleShape2D_6tl2x") | ||
debug_color = Color(1, 0, 0, 0.419608) | ||
|
||
[node name="Island0Sprite" type="Sprite2D" parent="."] | ||
unique_name_in_owner = true | ||
position = Vector2(320, 220) | ||
|
||
[node name="Clickable" parent="Island0Sprite" instance=ExtResource("1_3mm8m")] | ||
|
||
[node name="Area2D" type="Area2D" parent="Island0Sprite/Clickable"] | ||
|
||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Island0Sprite/Clickable/Area2D"] | ||
shape = SubResource("CircleShape2D_i4h8t") | ||
|
||
[node name="Island1Sprite" type="Sprite2D" parent="."] | ||
unique_name_in_owner = true | ||
position = Vector2(320, 140) | ||
|
||
[node name="Clickable" parent="Island1Sprite" instance=ExtResource("1_3mm8m")] | ||
|
||
[node name="Area2D" type="Area2D" parent="Island1Sprite/Clickable"] | ||
|
||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Island1Sprite/Clickable/Area2D"] | ||
shape = SubResource("CircleShape2D_i4h8t") | ||
|
||
[node name="Island2Sprite" type="Sprite2D" parent="."] | ||
unique_name_in_owner = true | ||
position = Vector2(320, 60) | ||
scale = Vector2(2, 2) | ||
|
||
[node name="Clickable" parent="Island2Sprite" instance=ExtResource("1_3mm8m")] | ||
|
||
[node name="Area2D" type="Area2D" parent="Island2Sprite/Clickable"] | ||
|
||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Island2Sprite/Clickable/Area2D"] | ||
shape = SubResource("CircleShape2D_i4h8t") | ||
|
||
[connection signal="area_entered" from="ShipSprite/Area2D" to="." method="_on_island_entered"] | ||
[connection signal="click" from="Island0Sprite/Clickable" to="." method="_on_island_clicked" binds= [0]] | ||
[connection signal="click" from="Island1Sprite/Clickable" to="." method="_on_island_clicked" binds= [1]] | ||
[connection signal="click" from="Island2Sprite/Clickable" to="." method="_on_island_clicked" binds= [2]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
extends Node2D | ||
|
||
@onready var ship = %ShipSprite | ||
@onready var island_0: Sprite2D = %Island0Sprite | ||
@onready var island_1: Sprite2D = %Island1Sprite | ||
@onready var island_2: Sprite2D = %Island2Sprite | ||
|
||
var goal_island = null | ||
|
||
# Called when the node enters the scene tree for the first time. | ||
func _ready(): | ||
pass | ||
|
||
|
||
# Called every frame. 'delta' is the elapsed time since the previous frame. | ||
func _process(delta): | ||
if (goal_island != null): | ||
var island = _get_island(goal_island) | ||
ship.position = ship.position.lerp(island.position, delta) | ||
|
||
|
||
func _on_island_clicked(island_id: int): | ||
print('Island '+str(island_id)+' clicked') | ||
goal_island = island_id | ||
|
||
|
||
func _get_island(island_id: int) -> Sprite2D: | ||
if (island_id == 0): | ||
return island_0 | ||
elif (island_id == 1): | ||
return island_1 | ||
else: return island_2 | ||
|
||
|
||
func _on_island_entered(area: Area2D): | ||
SceneTransition.change_scene("res://scenes/levels/debug/DebugLevel.tscn") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters