Skip to content

Commit

Permalink
feat: add interactive map to navigate to islands
Browse files Browse the repository at this point in the history
  • Loading branch information
audreygentili committed Feb 10, 2025
1 parent 6f8218e commit e2dde6b
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 1 deletion.
Binary file modified resources/localization/MenuTranslations.en.translation
Binary file not shown.
Binary file modified resources/localization/MenuTranslations.fr.translation
Binary file not shown.
60 changes: 60 additions & 0 deletions scenes/map/Map.tscn
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]]
36 changes: 36 additions & 0 deletions scenes/map/map.gd
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")
2 changes: 1 addition & 1 deletion scenes/menus/main/MainMenu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func _ready():


func _on_start_button_pressed():
SceneTransition.change_scene("res://scenes/levels/debug/DebugLevel.tscn")
SceneTransition.change_scene("res://scenes/map/Map.tscn")


func _on_credits_button_pressed():
Expand Down

0 comments on commit e2dde6b

Please sign in to comment.