Skip to content

Commit e4f9b5b

Browse files
committed
drag the screen around with the middle mouse button
1 parent 3b6ae5f commit e4f9b5b

File tree

1 file changed

+37
-20
lines changed

1 file changed

+37
-20
lines changed

scripts/Camera/Camera.gml

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,52 @@ function Camera() constructor {
1616
mouse_cast = undefined;
1717
floor_intersect = undefined;
1818

19+
mouse_last = { x: undefined, y: undefined };
20+
1921
Update = function() {
2022
var mspd = 200;
2123
var dt = DT;
24+
var mx = 0;
25+
var my = 0
2226

2327
if (GAME.gameplay_mode != GameModes.TITLE) {
24-
if (/*keyboard_check(vk_left) || */keyboard_check(ord("A"))) {
25-
if (to.x >= 0) {
26-
from.x -= mspd * dt;
27-
to.x -= mspd * dt;
28-
}
28+
if (keyboard_check(ord("A"))) {
29+
mx -= mspd * dt;
30+
mx -= mspd * dt;
31+
}
32+
if (keyboard_check(ord("D"))) {
33+
mx += mspd * dt;
34+
mx += mspd * dt;
2935
}
30-
if (/*keyboard_check(vk_right) || */keyboard_check(ord("D"))) {
31-
if (to.x <= room_width) {
32-
from.x += mspd * dt;
33-
to.x += mspd * dt;
34-
}
36+
if (keyboard_check(ord("W"))) {
37+
my -= mspd * dt;
38+
my -= mspd * dt;
3539
}
36-
if (/*keyboard_check(vk_up) || */keyboard_check(ord("W"))) {
37-
if (to.y >= -room_height / 2) {
38-
from.y -= mspd * dt;
39-
to.y -= mspd * dt;
40-
}
40+
if (keyboard_check(ord("S"))) {
41+
my += mspd * dt;
42+
my += mspd * dt;
4143
}
42-
if (/*keyboard_check(vk_down) || */keyboard_check(ord("S"))) {
43-
if (to.y <= room_height / 2) {
44-
from.y += mspd * dt;
45-
to.y += mspd * dt;
46-
}
44+
}
45+
46+
if (GAME.gameplay_mode == GameModes.GAMEPLAY) {
47+
if (self.mouse_last.x != undefined && mouse_check_button(mb_middle)) {
48+
var mouse_drag_speed = 0.4;
49+
mx += (window_mouse_get_x() - self.mouse_last.x) * mouse_drag_speed;
50+
my += (window_mouse_get_y() - self.mouse_last.y) * mouse_drag_speed;
4751
}
52+
53+
self.mouse_last.x = window_mouse_get_x();
54+
self.mouse_last.y = window_mouse_get_y();
55+
}
56+
57+
if (to.x + mx >= 0 && to.x + mx <= room_width) {
58+
from.x += mx;
59+
to.x += mx;
60+
}
61+
62+
if (to.y + my >= 0 && to.y + my <= room_height / 2) {
63+
from.y += my;
64+
to.y += my;
4865
}
4966

5067
view_mat = matrix_build_lookat(from.x, from.y, from.z, to.x, to.y, to.z, up.x, up.y, up.z);

0 commit comments

Comments
 (0)