Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Click Movement System

The idea came to me from playing too much Diablo :)

The click movement system is of course, you point your mouse somewhere on the screen of the game...and the character moves to that point without any restrictions, except collisions. (i.e. doesn't move to a specified coordinate you have placed within the game itself...ect..ect..).

Now I have spoken to Near about this and my lack of understanding scripts have me puzzled on the best way to achieve this type of system. He said:

From MSN":278tr1r7 said:
[ NEAR ] [ http://www.venatiostudios.com ] says: use the keyboard input module to get a left mouse click
then get the mouse x.y using the mouse input module
then feed the mouse x.y into the pathfinding script

Then he said something about having to use an if statement in the keyboard module. AN IF STATEMENT! ZOMG! Wtf...

So...needless to say I am looking for a way for someone to explain this a little better so that even the most Ruby challenged could understand it or attempt to make a simplified version of the Click Movement System that wouldn't confuse...me.

~ Wings
 

arev

Sponsor

this has already been done in cybersam's mouse menu I belive. here's the link to a demo, for I know there's a little chance of finding it right now.
http://www.calamity.cba.pl/files/mm.rar

also I'm hoping that now, when f0tz!'s pixelmovement with pathfinding is almost done, we'll be able to make it work exactly like it did in Diablo (probably even better, since the movement in Diablo was "tiled").
 
Ok. This Requires: Near's Keyboard & Mouse Module, as well as the Pathfinding Script.

Code:
class Scene_Map
  alias seph_pointandclick_scnmap_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
    seph_pointandclick_scnmap_update
  end
end

That's it.
 
Appreciate it Seph :) However I do seem to have a little problem that I should of mentioned before you went ahead and did this.

The game that I am developing uses 8-direction (iso) movement. The way that this one moves, is 4-way (very blocky). So as arevulopapo said, I may need to go ahead and wait for a decent pixel movement script to be integrated with SDK and the mouse/keyboard modules to perform correctly.

Also I wish to disable the arrow keys on the keyboard...because mouse and keyboard movement can get quite annoying at times. :)

~ Wings
 

Vash

Member

This sounds interesting and would like to try this out as well. Where would one find Near's Keyboard & Mouse Module?
 
Make a new Script above Main and paste this into it:
module Input
VK_LBUTTON = 1
VK_RBUTTON = 2
VK_MBUTTON = 4
SM_SWAPBUTTON = 23
$mousez = Win32API.new 'user32', 'ShowCursor', 'l',''

gsm = Win32API.new 'user32', 'GetSystemMetrics', 'i', 'i'

@@swapped = gsm.call(SM_SWAPBUTTON) != 0
@@key_state = Win32API.new 'user32', 'GetAsyncKeyState',
'i', 'i'
@@cursor_pos = Win32API.new 'user32', 'GetCursorPos',
'p', 'i'

module_function

def mouse_global_pos
pos = [0, 0].pack('ll')
if @@cursor_pos.call(pos) != 0
return pos.unpack('ll')
else
return nil
end
end

def mouse_pos(catch_anywhere = false)
x, y = screen_to_client(*mouse_global_pos)
width, height = client_size
if catch_anywhere or (x >= 0 and y >= 0 and x < width and y < height)
if($game_map.display_x == 0 or $game_map.display_x == ($game_map.width-20)*128)
$game_variables[8] = x / 32 +$game_map.display_x / 128
else
$game_variables[8] = (x+16) / 32 +$game_map.display_x / 128
end
$game_variables[9] = y / 32 + $game_map.display_y / 128
x = x-16
y = y-16
end
return x, y
else
return nil
end
end

def mouse_lbutton(ignore_swap = false)
if @@swapped and !ignore_swap
button = @@key_state.call(VK_RBUTTON)
else
button = @@key_state.call(VK_LBUTTON)
end
return(button == -32767 or button == 32768)
end
def mouse_rbutton(ignore_swap = false)
if @@swapped and !ignore_swap
button = @@key_state.call(VK_LBUTTON)
else
button = @@key_state.call(VK_RBUTTON)
end
return(button == -32767 or button == 32768)
end
def mouse_mbuton
button = @@key_state.call(VK_MBUTTON)
return(button == -32767 or button == 32768)
end


$scr2cli = Win32API.new 'user32', 'ScreenToClient', %w(l p), 'i'
$client_rect = Win32API.new 'user32', 'GetClientRect', %w(l p), 'i'
$readini = Win32API.new 'kernel32', 'GetPrivateProfileStringA',
%w(p p p p l p), 'l'
$findwindow = Win32API.new 'user32', 'FindWindowA', %w(p p), 'l'


def screen_to_client(x, y)
return nil unless x and y
pos = [x, y].pack('ll')
if $scr2cli.call(hwnd, pos) != 0
return pos.unpack('ll')
else
return nil
end
end

def hwnd
game_name = "\0" * 256
$readini.call('Game','Title','',game_name,255,".\\Game.ini")
game_name.delete!("\0")
return $findwindow.call('RGSS Player',game_name)
end
def client_size
rect = [0, 0, 0, 0].pack('l4')
$client_rect.call(hwnd, rect)
right, bottom = rect.unpack('l4')[2..3]
return right, bottom
end


now make a new Script BELOW the one above:
class Maus_Anzeigen
def initialize
$mausz = 0
x, y = Input.mouse_pos
if x and y
$temp = Maus_Auswahl.new(x,y)
end
end
def update
x, y = Input.mouse_pos
if x and y
if $temp
$temp.dispose
$temp = Maus_Auswahl.new(x,y)
else
$temp = Maus_Auswahl.new(x,y)
end
end
end
end

class Maus_Auswahl < Sprite
def initialize(px, py)
super()
@x = px
@y = py
$mausz += 1
if $mausz < 10
if $key.getkey >= 2
#RECHTSKLICK
self.bitmap = RPG::Cache.picture("ZielKreuz2.png")
$game_switches[7] = false
$game_switches[8] = true
$mausz = 1
else
if $key.getkey >= 1
#LINKSKLICK
self.bitmap = RPG::Cache.picture("ZielKreuz2.png")
$game_switches[7] = true
$game_switches[8] = false
$mausz = 1
else
#KEIN KLICK
self.bitmap = RPG::Cache.picture("ZielKreuz.png")
$game_switches[7] = false
$game_switches[8] = false
$mausz = 1
end
end
end
self.x = @x
self.y = @y
self.z = 65535
self.opacity = 255
self.visible = true
end
def dispose
if self.bitmap != nil
self.bitmap.dispose
end
super
end
end



now the last part... Go in Game_Player and search for this part:
case Input.dir4
when 2
move_down
when 4
move_left
when 6
move_right
when 8
move_up
end
end

and replace it complete with this:
if $game_switches[7] == true
if $game_variables[8] > $game_variables[18]
if $game_variables[9] > $game_variables[19]
move_down
move_right
else
if $game_variables[9] == $game_variables[19]
move_right
else
move_up
move_right
end
end
else
if $game_variables[8] < $game_variables[18]
if $game_variables[9] > $game_variables[19]
move_down
move_left
else
if $game_variables[9] == $game_variables[19]
move_left
else
move_up
move_left
end
end
else
if $game_variables[8] == $game_variables[18]
if $game_variables[9] > $game_variables[19]
move_down
else
if $game_variables[9] < $game_variables[19]
move_up
else
#nix
end
end
else
#nix
end
end
end
else
#nix
end
end





How it´ll works?:
You´ll need the
Variable 8 = Mouse_X
Variable 9 = Mouse_Y

a Common_Event wich sets the
Variable 18 to Hero´s Tile_X
Variable 19 to Hero´s Tile_Y

And the Switch 7 for Left_klick and 8 for Right_Klick


and you´ll need the two pictures in the Attach ( import them in your picture folder ).



The Rest works by itself ^^ ...hold left mouse_button to walk.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top