-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPalos.gd
More file actions
68 lines (53 loc) · 2.44 KB
/
Copy pathPalos.gd
File metadata and controls
68 lines (53 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
extends Node2D
const WITH = 24
const HEIGHT = 14
var Sticker
var Position : Vector2
var LocalMap : Dictionary
func _ready():
if not Data.Map["Planets"][Data.LandingInfo["Planet"]][Data.LandingInfo["Position"]].has("Surface"):
$Player.position = Vector2(0,0)
else:
LoadSurface()
$Player.position = Data.Map["Planets"][Data.LandingInfo["Planet"]][Data.LandingInfo["Position"]]["Surface"]["Position"]
LocalMap = {"Ground": {"Gras_Block":[],"Ice_Block":[],"Sand_Block":[]},"Sticker":{"Gras_Block":[],"Ice_Block":[],"Sand_Block":[]}}
Sticker = OpenSimplexNoise.new()
Sticker.period = 10
Sticker.persistence = 1
Sticker.seed = int(randf_range(1,999))
GenerateWorld()
func GenerateWorld():
for x in WITH:
for y in HEIGHT:
if $Ground.get_cellv(Ground(x,y)) == -1:
$Ground.set_cellv(Ground(x,y), Data.Translator["GetID"]["Ground"]["Sand_Block"])
if Sticker.get_noise_2dv(Ground(x,y)) > 0.25:
$Sticker.set_cellv(Ground(x,y), Data.Translator["GetID"]["Sticker"]["Sand_Block"])
$Sticker.update_bitmask_area(Ground(x,y))
func Ground(x,y):
Position = $Ground.local_to_map($Player.position)
Position.x = int(Position.x-(x - WITH / 2))
Position.y = int(Position.y-(y - HEIGHT / 2))
return Position
func _on_Ticks_timeout():
GenerateWorld()
func _on_LeavePlanet_LeavePlanet():
SaveLocalMap()
get_tree().change_scene_to_file("res://Space.tscn")
func SaveLocalMap():
for pos in $Ground.get_used_cells():
LocalMap["Ground"][Data.Translator["GetName"]["Ground"][str($Ground.get_cellv(pos))]].append(pos)
for pos in $Sticker.get_used_cells():
LocalMap["Sticker"][Data.Translator["GetName"]["Sticker"][str($Sticker.get_cellv(pos))]].append(pos)
LocalMap["Position"] = $Player.position
Data.Map["Planets"][Data.LandingInfo["Planet"]][Data.LandingInfo["Position"]]["Surface"] = LocalMap
func LoadSurface():
for node in Data.Map["Planets"][Data.LandingInfo["Planet"]][Data.LandingInfo["Position"]]["Surface"]:
if node == "Ground" or node == "Sticker":
for tile in Data.Map["Planets"][Data.LandingInfo["Planet"]][Data.LandingInfo["Position"]]["Surface"][node]:
if Data.Map["Planets"][Data.LandingInfo["Planet"]][Data.LandingInfo["Position"]]["Surface"][node][tile] != []:
for pos in Data.Map["Planets"][Data.LandingInfo["Planet"]][Data.LandingInfo["Position"]]["Surface"][node][tile]:
get_node(node).set_cellv(pos, Data.Translator["GetID"][node][tile])
$Sticker.update_bitmask_area(pos)
func _on_Title_pressed():
SaveLocalMap()