Skip to content

Commit 71717ae

Browse files
committed
Update
1 parent 7f29ba4 commit 71717ae

5 files changed

Lines changed: 100 additions & 4 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
go.property("movement_speed", 400)
2+
go.property("zoom_speed", 2)
3+
4+
function init(self)
5+
msg.post(".", "acquire_input_focus")
6+
self.move = vmath.vector3()
7+
self.zoom_delta = 0
8+
self.move_up = hash("key_w")
9+
self.move_down = hash("key_s")
10+
self.move_left = hash("key_a")
11+
self.move_right = hash("key_d")
12+
self.zoom_out = hash("key_q")
13+
self.zoom_in = hash("key_e")
14+
end
15+
16+
17+
function update(self, dt)
18+
local p = go.get_position()
19+
p.x = p.x + self.move.x * self.movement_speed * dt
20+
p.y = p.y + self.move.y * self.movement_speed * dt
21+
go.set_position(p)
22+
23+
if self.zoom_delta ~= 0 then
24+
local zoom = go.get("#camera", "orthographic_zoom")
25+
zoom = zoom + self.zoom_delta * self.zoom_speed * dt
26+
zoom = math.max(0.1, zoom)
27+
go.set("#camera", "orthographic_zoom", zoom)
28+
end
29+
end
30+
31+
32+
function on_input(self, action_id, action)
33+
local v = action.pressed and 1 or (action.released and -1) or 0
34+
if v == 0 then return end
35+
if action_id == self.move_up then
36+
self.move.y = self.move.y + v
37+
elseif action_id == self.move_down then
38+
self.move.y = self.move.y - v
39+
elseif action_id == self.move_left then
40+
self.move.x = self.move.x - v
41+
elseif action_id == self.move_right then
42+
self.move.x = self.move.x + v
43+
elseif action_id == self.zoom_in then
44+
self.zoom_delta = self.zoom_delta + v
45+
elseif action_id == self.zoom_out then
46+
self.zoom_delta = self.zoom_delta - v
47+
end
48+
end

example/example_grid/example_grid.collection

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,21 @@ embedded_instances {
2121
}
2222
embedded_instances {
2323
id: "camera"
24-
data: "embedded_components {\n"
24+
data: "components {\n"
25+
" id: \"camera_wasd_control\"\n"
26+
" component: \"/example/assets/camera_wasd_control.script\"\n"
27+
" properties {\n"
28+
" id: \"movement_speed\"\n"
29+
" value: \"100.0\"\n"
30+
" type: PROPERTY_TYPE_NUMBER\n"
31+
" }\n"
32+
" properties {\n"
33+
" id: \"zoom_speed\"\n"
34+
" value: \"2.0\"\n"
35+
" type: PROPERTY_TYPE_NUMBER\n"
36+
" }\n"
37+
"}\n"
38+
"embedded_components {\n"
2539
" id: \"camera\"\n"
2640
" type: \"camera\"\n"
2741
" data: \"aspect_ratio: 1.0\\n"

example/example_grid/example_grid.script

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,12 @@ local function spawn_entity(entity)
1515
local position = vmath.vector3(position_x, position_y, position_z)
1616
local scale = vmath.vector3(scale_x, scale_y, 1)
1717
factory.create(factory_url, position, nil, nil, scale)
18-
19-
print("Spawn entity: ", factory_url, position_x, position_y, position_z)
2018
end
2119

2220

2321
local function spawn_map(map)
2422
local entities = map.child_instancies
2523
for _, entity in ipairs(entities) do
26-
print("Want to spawn entity: ", entity.prefab_id)
2724
spawn_entity(entity)
2825
end
2926
end

game.project

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,10 @@ dependencies#2 = https://github.com/Insality/defold-event/archive/refs/tags/13.z
2222
[library]
2323
include_dirs = detiled
2424

25+
[input]
26+
game_binding = /builtins/input/all.input_bindingc
27+
28+
[graphics]
29+
default_texture_min_filter = nearest
30+
default_texture_mag_filter = nearest
31+

input/game.input_binding

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
1+
key_trigger {
2+
input: KEY_W
3+
action: "move_up"
4+
}
5+
6+
key_trigger {
7+
input: KEY_S
8+
action: "move_down"
9+
}
10+
11+
key_trigger {
12+
input: KEY_A
13+
action: "move_left"
14+
}
15+
16+
key_trigger {
17+
input: KEY_D
18+
action: "move_right"
19+
}
20+
21+
key_trigger {
22+
input: KEY_E
23+
action: "zoom_in"
24+
}
25+
26+
key_trigger {
27+
input: KEY_Q
28+
action: "zoom_out"
29+
}
30+
131
mouse_trigger {
232
input: MOUSE_BUTTON_1
333
action: "touch"

0 commit comments

Comments
 (0)