| Pour ceux qui souhaite simplement pouvoir se déplacer à la souris, et sans lag, vous pouvez utiliser script Déplacement à la sourirs V1.0 de Berka, aussi.
Il s'agit la aussi d'un simple copier coller du script qui a été classer dans RPG Maker XP, je ne sais pas pourquoi ...
Article original : http://www.rpg-maker.fr/scripts-149-mouvement-par-la-souris.html
Ce script permet de diriger le hero a l'aide de la souris
sur les bases de SephirothSpawn
# clic gauche: definir le point d'arrivée
# clic droit: suivre/ne pas suivre le héros
# touche directionnelles: deplacer la map
a placer au dessus de main, dans l'ordre:
Module Keyboard/Mouse
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
|
#===========================================
# Module Keyboard/Mouse
# par SephirothSpawn
#===========================================
module Keyboard
@keys = []
@pressed = []
Mouse_Left = 1
Mouse_Right = 2
State = Win32API.new("user32","GetKeyState",['i'],'i')
Key = Win32API.new("user32","GetAsyncKeyState",['i'],'i')
def Keyboard.getstate(key)
return true unless State.call(key).between?(0, 1)
return false
end
def Keyboard.testkey(key)
Key.call(key) & 0x01 == 1
end
def Keyboard.update
@keys = []
@keys.push(Keyboard::Mouse_Left) if Keyboard.testkey(Keyboard::Mouse_Left)
@keys.push(Keyboard::Mouse_Right) if Keyboard.testkey(Keyboard::Mouse_Right)
@pressed = []
@pressed.push(Keyboard::Mouse_Left) if Keyboard.getstate(Keyboard::Mouse_Left)
@pressed.push(Keyboard::Mouse_Right) if Keyboard.getstate(Keyboard::Mouse_Right)
end
def Keyboard.trigger?(key)
return true if @keys.include?(key)
return false
end
def Keyboard.pressed?(key)
return true if @pressed.include?(key)
return false
end
end
module Mouse
@mouse_menu = 0
def Mouse.click?(button)
return true if @keys.include?(button)
return false
end
def Mouse.press?(button)
return true if @press.include?(button)
return false
end
def Mouse.area?(x, y, width=32, height=32)
return false if @pos == nil
return true if @pos[0] >= x and @pos[0] <= (x+width) and @pos[1] >= y and @pos[1] <= (y+height)
return false
end
def Mouse.pixels
return @pos == nil ? [0, 0] : @pos
end
def Mouse.tiles
return nil if @pos == nil
x = @pos[0] / 32
y = @pos[1] / 32
return [x, y]
end
def Mouse.set_pos(x_pos=0, y_pos=0)
width, height = Mouse.client_size
if (x_pos.between?(0, width) && y_pos.between?(0, height))
x = Mouse.client_pos[0] + x_pos; y = Mouse.client_pos[1] + y_pos
Win32API.new('user32', 'SetCursorPos', 'NN', 'N').call(x, y)
end
end
def Mouse.update
@pos = Mouse.pos
@keys, @press = [], []
@keys.push(1) if Win32API.new("user32","GetAsyncKeyState",['i'],'i').call(1) & 0X01 == 1
@keys.push(2) if Win32API.new("user32","GetAsyncKeyState",['i'],'i').call(2) & 0X01 == 1
@keys.push(3) if Win32API.new("user32","GetAsyncKeyState",['i'],'i').call(4) & 0X01 == 1
@press.push(1) if Win32API.new("user32","GetKeyState",['i'],'i').call(1) & 0X01 == 1
@press.push(2) if Win32API.new("user32","GetKeyState",['i'],'i').call(2) & 0X01 == 1
@press.push(3) if Win32API.new("user32","GetKeyState",['i'],'i').call(4) & 0X01 == 1
end
def Mouse.global_pos
pos = [0, 0].pack('ll')
if Win32API.new('user32', 'GetCursorPos', 'p', 'i').call(pos) != 0
return pos.unpack('ll')
else
return nil
end
end
def Mouse.pos
x, y = Mouse.screen_to_client(*Mouse.global_pos)
width, height = Mouse.client_size
begin
if (x >= 0 and y >= 0 and x < width and y < height)
return x, y
else
return nil
end
rescue
return nil
end
end
def Mouse.screen_to_client(x, y)
return nil unless x and y
pos = [x, y].pack('ll')
if Win32API.new('user32', 'ScreenToClient', %w(l p), 'i').call(Mouse.hwnd, pos) != 0
return pos.unpack('ll')
else
return nil
end
end
def Mouse.hwnd
game_name = "\0" * 256
Win32API.new('kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l').call('Game','Title','',game_name,255,".\\Game.ini")
game_name.delete!("\0")
return Win32API.new('user32', 'FindWindowA', %w(p p), 'l').call('RGSS Player',game_name)
end
def Mouse.client_size
rect = [0, 0, 0, 0].pack('l4')
Win32API.new('user32', 'GetClientRect', %w(l p), 'i').call(Mouse.hwnd, rect)
right, bottom = rect.unpack('l4')[2..3]
return right, bottom
end
def Mouse.client_pos
rect = [0, 0, 0, 0].pack('l4')
Win32API.new('user32', 'GetWindowRect', %w(l p), 'i').call(Mouse.hwnd, rect)
left, upper = rect.unpack('l4')[0..1]
return left+4, upper+30
end
def Mouse.grid
return nil if @pos == nil
offsetx = $game_map.display_x / 8
offsety = $game_map.display_y / 8
x = (@pos[0] + offsetx) / 32
y = (@pos[1] + offsety) / 32
return [x, y]
end
end
|
Pathfinding
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
#===========================================
# Pathfinding
# par SephirothSpawn
#===========================================
class Game_Character
alias nf_pf_game_character_initialize initialize
alias nf_pf_game_character_update update
attr_accessor :map
attr_accessor :runpath
def initialize
nf_pf_game_character_initialize
@map = nil
@runpath = false
end
def update
run_path if @runpath == true
nf_pf_game_character_update
end
def run_path
return if moving?
step = @map[@x,@y]
if step == 1
@map = nil
@runpath = false
return
end
dir = rand(2)
case dir
when 0
move_right if @map[@x+1,@y] == step - 1 and step != 0
move_down if @map[@x,@y+1] == step - 1 and step != 0
move_left if @map[@x-1,@y] == step -1 and step != 0
move_up if @map[@x,@y-1] == step - 1 and step != 0
when 1
move_up if @map[@x,@y-1] == step - 1 and step != 0
move_left if @map[@x-1,@y] == step -1 and step != 0
move_down if @map[@x,@y+1] == step - 1 and step != 0
move_right if @map[@x+1,@y] == step - 1 and step != 0
end
end
def find_path(x,y)
sx, sy = @x, @y
result = setup_map(sx,sy,x,y)
@runpath = result[0]
@map = result[1]
@map[sx,sy] = result[2] if result[2] != nil
end
def clear_path
@map = nil
@runpath = false
end
def setup_map(sx,sy,ex,ey)
map = Table.new($game_map.width, $game_map.height)
map[ex,ey] = 1
old_positions = []
new_positions = []
old_positions.push([ex, ey])
depth = 2
depth.upto(100){|step|
loop do
break if old_positions[0] == nil
x,y = old_positions.shift
return [true, map, step] if x == sx and y+1 == sy
if $game_player.passable?(x, y) and map[x,y + 1] == 0
map[x,y + 1] = step
new_positions.push([x,y + 1])
end
return [true, map, step] if x-1 == sx and y == sy
if $game_player.passable?(x, y) and map[x - 1,y] == 0
map[x - 1,y] = step
new_positions.push([x - 1,y])
end
return [true, map, step] if x+1 == sx and y == sy
if $game_player.passable?(x, y) and map[x + 1,y] == 0
map[x + 1,y] = step
new_positions.push([x + 1,y])
end
return [true, map, step] if x == sx and y-1 == sy
if $game_player.passable?(x, y) and map[x,y - 1] == 0
map[x,y - 1] = step
new_positions.push([x,y - 1])
end
end
old_positions = new_positions
new_positions = []
}
return [false, nil, nil]
end
end
class Game_Map
alias pf_game_map_setup setup
def setup(map_id)
pf_game_map_setup(map_id)
$game_player.clear_path
end
end
|
Mouvement par souris
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
119
120
121
|
#===========================================
# Mouvement par souris
# par berka
#===========================================
#
# clic gauche: definir le point d'arrivée
# clic droit: suivre/ne pas suivre le héros
# touche directionnelles: deplacer la map
#===========================================
Vitesse = 8 #vitesse du scroll de la map
class Scene_Map
alias scroll_update update
def update
Keyboard.update
Mouse.update
if Keyboard.trigger?(Keyboard::Mouse_Left)
$game_player.find_path(Mouse.grid[0], Mouse.grid[1])
end
scroll_update
end
end
class Game_Player < Game_Character
alias scroll_init initialize
def initialize
scroll_init
@scroll = false
end
def update
last_real_x = @real_x
last_real_y = @real_y
last_moving = moving?
move_by_input
super
if Keyboard.trigger?(Keyboard::Mouse_Right)
if @scroll == false
$game_player.center($game_player.x, $game_player.y)
@scroll = true
else
@scroll = false
end
end
@scroll = false if Input.dir4 != 0
$game_player.update_scroll(last_real_x, last_real_y) if @scroll == true
update_vehicle
update_nonmoving(last_moving)
end
def move_by_input
return unless movable?
return if $game_map.interpreter.running?
case Input.dir4
when 2; $game_map.start_scroll(2, 1, Vitesse)
when 4; $game_map.start_scroll(4, 1, Vitesse)
when 6; $game_map.start_scroll(6, 1, Vitesse)
when 8; $game_map.start_scroll(8, 1, Vitesse)
end
end
end
|
Et sinon, pour un maximums d'options, voici le script "Mouse Système", qui permet d'avoir une gestion totale de la souris, avec moins de lag que le script "Déplacement à la souris V2.0" :
http://www.rpg-maker.fr/scripts-417-mouse-systeme.html
.
|