-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tscn
118 lines (89 loc) · 4.04 KB
/
main.tscn
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
[gd_scene load_steps=5 format=2]
[ext_resource path="res://tileset.tres" type="TileSet" id=1]
[sub_resource type="GDScript" id=1]
script/source = "extends Node2D
var FPS := [] # Array for FPS measurements
onready var Map := $TileMap # Grab the map node once
onready var Camera := $Camera # Get camera node once
func _ready():
# Spawn random tiles for 100x100 cells.
var x = 0
var y = 0
while x < 100:
while y < 100:
Map.set_cell(x,y,randi()%13)
y += 1
y = 0
x += 1
Map.set_cell(2,3,-1)
Map.load_map() # Load map manually again, because we just generated it.
func _process(delta):
if Input.is_key_pressed(KEY_ESCAPE):
var avg = 0
for fps in FPS:
avg += fps
avg = avg / FPS.size()
print(\"Average FPS: \",avg)
get_tree().quit()
FPS.append(Performance.get_monitor(Performance.TIME_FPS)) # Log FPS each frame
"
[sub_resource type="GDScript" id=2]
script/source = "extends Camera2D
var addsub = Vector2(0.05,0.05) #Interval for zooming
func _unhandled_input(event): #Take care of camera zooming
if event is InputEventMouseButton and event.pressed:
if event.button_index == BUTTON_WHEEL_DOWN:
if zoom < Vector2(1.45,1.45): #Max zoom: 1.5
zoom += addsub
position = get_camera_screen_center()
elif event.button_index == BUTTON_WHEEL_UP:
if zoom > Vector2(0.5,0.5): #Max zoom: 0.5
zoom -= addsub
position = get_camera_screen_center()
get_tree().set_input_as_handled()
func _process(delta): #Take care of camera movement
var pixelspeed = 200 #Speed of the camera in pixel/frame
if Input.is_key_pressed(KEY_W) or Input.is_key_pressed(KEY_UP):
if get_position().y >= get_camera_position().y:
position.y -= pixelspeed * delta
get_tree().set_input_as_handled()
if Input.is_key_pressed(KEY_S) or Input.is_key_pressed(KEY_DOWN):
if get_position().y <= get_camera_position().y:
position.y += pixelspeed * delta
get_tree().set_input_as_handled()
if Input.is_key_pressed(KEY_D) or Input.is_key_pressed(KEY_RIGHT):
if get_position().x <= get_camera_position().x:
position.x += pixelspeed * delta
get_tree().set_input_as_handled()
if Input.is_key_pressed(KEY_A) or Input.is_key_pressed(KEY_LEFT):
if get_position().x >= get_camera_position().x:
position.x -= pixelspeed * delta
get_tree().set_input_as_handled()
"
[sub_resource type="GDScript" id=3]
script/source = "## Important:
## You need to extend from FovTileMap:
extends FovTileMap
# Declare member variables here. Examples:
# var a = 2
# var b = \"text\"
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
"
[node name="Main" type="Node2D"]
script = SubResource( 1 )
[node name="Camera" type="Camera2D" parent="."]
current = true
limit_smoothed = true
script = SubResource( 2 )
[node name="TileMap" type="TileMap" parent="."]
tile_set = ExtResource( 1 )
cell_size = Vector2( 20, 20 )
format = 1
tile_data = PoolIntArray( 327686, 11, 0, 327687, 11, 0, 327688, 11, 0, 327689, 11, 0, 327690, 11, 0, 327691, 11, 0, 327692, 11, 0, 327694, 11, 0, 327695, 11, 0, 327696, 11, 0, 327697, 11, 0, 327698, 11, 0, 327700, 11, 0, 327701, 11, 0, 327702, 11, 0, 327703, 11, 0, 327704, 11, 0, 327706, 11, 0, 327707, 11, 0, 327708, 11, 0, 327709, 11, 0, 327710, 11, 0, 327711, 11, 0, 327712, 11, 0, 393225, 11, 0, 393230, 11, 0, 393236, 11, 0, 393245, 11, 0, 458761, 11, 0, 458766, 11, 0, 458772, 11, 0, 458781, 11, 0, 524297, 11, 0, 524302, 11, 0, 524303, 11, 0, 524304, 11, 0, 524305, 11, 0, 524308, 11, 0, 524309, 11, 0, 524310, 11, 0, 524311, 11, 0, 524312, 11, 0, 524317, 11, 0, 589833, 11, 0, 589838, 11, 0, 589848, 11, 0, 589853, 11, 0, 655369, 11, 0, 655374, 11, 0, 655384, 11, 0, 655389, 11, 0, 720905, 11, 0, 720910, 11, 0, 720920, 11, 0, 720925, 11, 0, 786441, 11, 0, 786446, 11, 0, 786447, 11, 0, 786448, 11, 0, 786449, 11, 0, 786450, 11, 0, 786452, 11, 0, 786453, 11, 0, 786454, 11, 0, 786455, 11, 0, 786456, 11, 0, 786461, 11, 0 )
script = SubResource( 3 )
CameraNode = NodePath("../Camera")