-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMap.gd
94 lines (73 loc) · 3 KB
/
Map.gd
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
extends Node2D
const WITH = 24
const HEIGHT = 14
var Position : Vector2
var Space
var Planets = ["Orbis", "Armenia", "Palos"]
var Planet
var Digit
signal InventoryChanged(item)
func _ready():
LoadSpace()
Space = OpenSimplexNoise.new()
Space.period = 10
Space.persistence = 1
Space.seed = int(randf_range(1,999))
GenerateWorld()
func GenerateWorld():
for x in WITH:
for y in HEIGHT:
if $Asteroids.get_cellv(Asteroid(x,y)) == -1 and $Planets.get_cellv(Planet(x,y)) == -1:
GenerateSpace(x,y)
func Asteroid(x,y):
Position = $Asteroids.local_to_map(get_parent().get_node("Player").position)
Position.x = int(Position.x-(x - WITH / 2))
Position.y = int(Position.y-(y - HEIGHT / 2))
return Position
func Planet(x,y):
Position = $Planets.local_to_map(get_parent().get_node("Player").position)
Position.x = int(Position.x-(x - WITH / 2))
Position.y = int(Position.y-(y - HEIGHT / 2))
return Position
func GenerateSpace(x,y):
Digit = str(int(randf_range(0,3)))
if randi()%1000+1 > 995:
Planet = str(Planets[int(randf_range(0,3))])
$Planets.set_cellv(Planet(x,y), Data.Translator["GetID"]["Planets"][Planet + Digit])
Data.Map["Planets"][Planet+Digit][Planet(x,y)] = {"Health": Data.Permissions[Planet]["Health"]}
elif randi()%1000+1 > 980:
$Asteroids.set_cellv(Asteroid(x,y), Data.Translator["GetID"]["Asteroids"]["Metroid" + Digit])
Data.Map["Asteroids"]["Metroid"+Digit][Asteroid(x,y)] = {"Health": Data.Permissions["Metroid"]["Health"]}
else:
$Asteroids.set_cellv(Asteroid(x,y), Data.Translator["GetID"]["Asteroids"]["Empty"])
Data.Map["Asteroids"]["Empty"][Asteroid(x,y)] = {}
func _on_Reload_timeout():
GenerateWorld()
func _on_Gun_DeleteTile(tile, node, pos):
get_node(node.get_name()).set_cellv(pos, -1)
LoadContext($Planets.local_to_map(get_global_mouse_position()))
for loot in Data.Permissions[Data.Properties[tile]["Type"]]["Loot"]:
Data.Inventory[loot] += int(randf_range(Data.Permissions[Data.Properties[tile]["Type"]]["Loot"][loot]["min"], Data.Permissions[Data.Properties[tile]["Type"]]["Loot"][loot]["max"]))
if Data.Inventory[loot] > 999:
Data.Inventory[loot] = 999
emit_signal("InventoryChanged",loot)
func _on_Space_CurrentPlanetChanged(CurrentPlanet):
LoadContext(CurrentPlanet)
func LoadContext(CurrentPlanet):
if $Planets.get_cellv(CurrentPlanet) != -1:
Data.NextScene = Data.Properties[Data.Translator["GetName"]["Planets"][str($Planets.get_cellv(CurrentPlanet))]]["Type"]
$Land.position.x = $Planets.map_to_local(CurrentPlanet).x + 16
$Land.position.y = $Planets.map_to_local(CurrentPlanet).y + 16
Data.LandingInfo = {"Position":CurrentPlanet,"Planet":Data.Translator["GetName"]["Planets"][str($Planets.get_cellv(CurrentPlanet))]}
$Land.show()
return
else:
$Land.hide()
Data.NextScene = null
func LoadSpace():
for node in Data.Map:
if node == "Asteroids" or node == "Planets":
for tile in Data.Map[node]:
if Data.Map[node][tile] != {}:
for pos in Data.Map[node][tile]:
get_node(node).set_cellv(pos, Data.Translator["GetID"][node][tile])