[RESOLVED] I'm trying to mod the movement system

Started by Elrim, February 23, 2008, 09:34:41 pm

Previous topic - Next topic

Elrim

February 23, 2008, 09:34:41 pm Last Edit: July 25, 2008, 06:19:24 pm by Blizzard
I would like to change the movement system to being able to move diagonally (not simply square by square).  My major goal is to make a game that works either like "secret of mana" or "earthbound" in how encounters are initialized.  I have a bit of knowledge of how to script myself and I know someone who can do most of the harder things that I can't handle.

My major questions are:

1)  Is this possible?  (I've seen some youtube videos and unless I'm mistaken it can be done)

2)  Where do I begin?  (I know where the script editor is and how to mess with it, but I have no idea where movement is stored)

I'd like to at least attempt to script on my own without copying and pasting, but even just looking at some code or a point in the right direction would be greatly appreciated.

Chaze007

ahhaaahh something im actually good at, gimme a few minutes. + if you want i got it where the view is actually diaginol and looks 3d :)
Always I Wanna Be With You! Make Believe With You!

Chaze007

This script allows your character to move in 8 directions. It also allows you to modify the character sprite's facing and animation to make the movement more realistic.

Instructions


Firstly, you can still have 8 directional movement even if you do not have or cannot create graphics for your characters to correspond to the additional modes of movement. Find the 'case input.dir4' statement in the update method of Game_Player class (I think it starts at line 211) and replace it (and all its 'when's, until the first 'end' you find) with script 8a.

Now, you need to prepare special graphics for your characters if you want your characters to have 8 directional facing and animation. The template is basically the same as the standard RPG Maker XP characters, but you need to include the diagonal movements in this order, from top to bottom: Lower-Left (1), Down (2), Lower-Right (3), Left (4), Right (6), Upper-Left (7), Up (8), Upper-Right (9) (don't worry about the numbers, they are just the numbers used for the direction variable in Game_Character class. If you want to memorize their order, look at your numpad!).

Take the following steps:

1. Overwrite everything in Game_Character 3 section of the script editor with script 8b (note that you do not need to overwrite everything, it is mainly the move_xxxx methods with the extra directions, as well as adding new turn methods for these direction).

2. Overwrite Sprite_Character update method (starts at line 26 for me) with script 8c (or just find the changes in ch and sy and fix them yourself).

3. Done, don't forget you need to apply script 8a or you won't notice any difference. Also all characters and NPCs will need to be based on the character graphic template, even if you don't need 8 directional movement for them (if you don't, don't add the extra directions but do add empty areas instead). Note that I haven't modified the movement route commands (such as move random or move forward) to work with this script because I believe public scripts should be as basic as possible to allow people to modify them as they see fit (you can still use commands such as move up-down etc. though).
8A
Spoiler: ShowHide
case Input.dir8
     when 1
       move_lower_left
     when 2
       move_down
     when 3
       move_lower_right
     when 4
       move_left
     when 6
       move_right
     when 7
       move_upper_left
     when 8
       move_up
     when 9
       move_upper_right
     end


8B
Spoiler: ShowHide
class Game_Character

  def move_down(turn_enabled = true)
    if turn_enabled
      turn_down
    end
    if passable?(@x, @y, 2)
      turn_down
      @y += 1
      increase_steps
    else
      check_event_trigger_touch(@x, @y+1)
    end
  end
#---------------------------------------------------------
  def move_left(turn_enabled = true)
    if turn_enabled
      turn_left
    end
    if passable?(@x, @y, 4)
      turn_left
      @x -= 1
      increase_steps
    else
      check_event_trigger_touch(@x-1, @y)
    end
  end
#---------------------------------------------------------
  def move_right(turn_enabled = true)
    if turn_enabled
      turn_right
    end
    if passable?(@x, @y, 6)
      turn_right
      @x += 1
      increase_steps
    else
      check_event_trigger_touch(@x+1, @y)
    end
  end
#---------------------------------------------------------
  def move_up(turn_enabled = true)
    if turn_enabled
      turn_up
    end
    if passable?(@x, @y, 8)
      turn_up
      @y -= 1
      increase_steps
    else
      check_event_trigger_touch(@x, @y-1)
    end
  end
#---------------------------------------------------------
  def move_lower_left
    unless @direction_fix
      @direction = 1
    end
    if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4)) or
       (passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))
      turn_downleft
      @x -= 1
      @y += 1
      increase_steps
    end
  end
#---------------------------------------------------------
  def move_lower_right
    unless @direction_fix
      @direction = 3
    end
    if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 6)) or
       (passable?(@x, @y, 6) and passable?(@x + 1, @y, 2))
      turn_downright
      @x += 1
      @y += 1
      increase_steps
    end
  end
#---------------------------------------------------------
  def move_upper_left
    unless @direction_fix
      @direction = 7
    end
    if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 4)) or
       (passable?(@x, @y, 4) and passable?(@x - 1, @y, 8))
      turn_upleft
      @x -= 1
      @y -= 1
      increase_steps
    end
  end
#---------------------------------------------------------
  def move_upper_right
    unless @direction_fix
      @direction = 9
    end
    if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 6)) or
       (passable?(@x, @y, 6) and passable?(@x + 1, @y, 8))
      turn_upright
      @x += 1
      @y -= 1
      increase_steps
    end
  end
#---------------------------------------------------------
  def move_random
    case rand(4)
    when 0 
      move_down(false)
    when 1 
      move_left(false)
    when 2 
      move_right(false)
    when 3 
      move_up(false)
    end
  end
#---------------------------------------------------------
  def move_toward_player
    sx = @x - $game_player.x - 1
    sy = @y - $game_player.y
    if sx == 0 and sy == 0
      return
    end
    abs_sx = sx.abs
    abs_sy = sy.abs
    if abs_sx == abs_sy
      rand(2) == 0 ? abs_sx += 1 : abs_sy += 1
    end
    if abs_sx > abs_sy
      sx > 0 ? move_left : move_right
      if not moving? and sy != 0
        sy > 0 ? move_up : move_down
      end
    else
      sy > 0 ? move_up : move_down
      if not moving? and sx != 0
        sx > 0 ? move_left : move_right
      end
    end
  end
#---------------------------------------------------------
  def move_away_from_player
    sx = @x - $game_player.x
    sy = @y - $game_player.y
    if sx == 0 and sy == 0
      return
    end
    abs_sx = sx.abs
    abs_sy = sy.abs
    if abs_sx == abs_sy
      rand(2) == 0 ? abs_sx += 1 : abs_sy += 1
    end
    if abs_sx > abs_sy
      sx > 0 ? move_right : move_left
      if not moving? and sy != 0
        sy > 0 ? move_down : move_up
      end
    else
      sy > 0 ? move_down : move_up
      if not moving? and sx != 0
        sx > 0 ? move_right : move_left
      end
    end
  end
#---------------------------------------------------------
  def move_forward
    case @direction
    when 2
      move_down(false)
    when 4
      move_left(false)
    when 6
      move_right(false)
    when 8
      move_up(false)
    end
  end
#---------------------------------------------------------
  def move_backward
    last_direction_fix = @direction_fix
    @direction_fix = true
    case @direction
    when 2 
      move_up(false)
    when 4 
      move_right(false)
    when 6 
      move_left(false)
    when 8 
      move_down(false)
    end
    @direction_fix = last_direction_fix
  end
#---------------------------------------------------------
  def jump(x_plus, y_plus)
    if x_plus != 0 or y_plus != 0
      if x_plus.abs > y_plus.abs
        x_plus < 0 ? turn_left : turn_right
      else
        y_plus < 0 ? turn_up : turn_down
      end
    end
    new_x = @x + x_plus
    new_y = @y + y_plus
    if (x_plus == 0 and y_plus == 0) or passable?(new_x, new_y, 0)
      straighten
      @x = new_x
      @y = new_y
      distance = Math.sqrt(x_plus * x_plus + y_plus * y_plus).round
      @jump_peak = 10 + distance - @move_speed
      @jump_count = @jump_peak * 2
      @stop_count = 0
    end
  end
#---------------------------------------------------------
  def turn_down
    unless @direction_fix
      @direction = 2
      @stop_count = 0
    end
  end

  def turn_left
    unless @direction_fix
      @direction = 4
      @stop_count = 0
    end
  end
#---------------------------------------------------------
  def turn_right
    unless @direction_fix
      @direction = 6
      @stop_count = 0
    end
  end
#---------------------------------------------------------
  def turn_up
    unless @direction_fix
      @direction = 8
      @stop_count = 0
    end
  end
#--------------------------------------------------------- 
  def turn_upleft
    unless @direction_fix
      @direction = 7
      @stop_count = 0
    end
  end
#--------------------------------------------------------- 
  def turn_upright
    unless @direction_fix
      @direction = 9
      @stop_count = 0
    end
  end
#--------------------------------------------------------- 
  def turn_downleft
    unless @direction_fix
      @direction = 1
      @stop_count = 0
    end
  end
#--------------------------------------------------------- 
  def turn_downright
    unless @direction_fix
      @direction = 3
      @stop_count = 0
    end
  end
#---------------------------------------------------------
  def turn_right_90
    case @direction
    when 2
      turn_left
    when 4
      turn_up
    when 6
      turn_down
    when 8
      turn_right
    end
  end
#---------------------------------------------------------
  def turn_left_90
    case @direction
    when 2
      turn_right
    when 4
      turn_down
    when 6
      turn_up
    when 8
      turn_left
    end
  end
#---------------------------------------------------------
  def turn_180
    case @direction
    when 2
      turn_up
    when 4
      turn_right
    when 6
      turn_left
    when 8
      turn_down
    end
  end
#---------------------------------------------------------
  def turn_right_or_left_90
    if rand(2) == 0
      turn_right_90
    else
      turn_left_90
    end
  end
#---------------------------------------------------------
  def turn_random
    case rand(4)
    when 0
      turn_up
    when 1
      turn_right
    when 2
      turn_left
    when 3
      turn_down
    end
  end
#---------------------------------------------------------
  def turn_toward_player
    sx = @x - $game_player.x
    sy = @y - $game_player.y
    if sx == 0 and sy == 0
      return
    end
    if sx.abs > sy.abs
      sx > 0 ? turn_left : turn_right
    else
      sy > 0 ? turn_up : turn_down
    end
  end

  def turn_away_from_player
    sx = @x - $game_player.x
    sy = @y - $game_player.y
    if sx == 0 and sy == 0
      return
    end
    if sx.abs > sy.abs
      sx > 0 ? turn_right : turn_left
    else
      sy > 0 ? turn_down : turn_up
    end
  end
end


8C
Spoiler: ShowHide
def update
    super
    if @tile_id != @character.tile_id or
       @character_name != @character.character_name or
       @character_hue != @character.character_hue
      @tile_id = @character.tile_id
      @character_name = @character.character_name
      @character_hue = @character.character_hue
      if @tile_id >= 384
        self.bitmap = RPG::Cache.tile($game_map.tileset_name,
          @tile_id, @character.character_hue)
        self.src_rect.set(0, 0, 32, 32)
        self.ox = 16
        self.oy = 32
      else
        self.bitmap = RPG::Cache.character(@character.character_name,
          @character.character_hue)
        @cw = bitmap.width / 4
        @ch = bitmap.height / 8
        self.ox = @cw / 2
        self.oy = @ch
      end
    end
    self.visible = (not @character.transparent)
    if @tile_id == 0
      sx = @character.pattern * @cw
      dir = @character.direction
      dec = (dir == 7 or dir== 9) ? 3 : 1
      sy = (dir - dec) * @ch
      self.src_rect.set(sx, sy, @cw, @ch)
    end
    self.x = @character.screen_x
    self.y = @character.screen_y
    self.z = @character.screen_z(@ch)
    self.opacity = @character.opacity
    self.blend_type = @character.blend_type
    self.bush_depth = @character.bush_depth
    if @character.animation_id != 0
      animation = $data_animations[@character.animation_id]
      animation(animation, true)
      @character.animation_id = 0
    end
  end
end
Always I Wanna Be With You! Make Believe With You!

Elrim


Chaze007

your welcome if you need sumthin else just ask *cough powers you back up to 0* who did that? lol.
Always I Wanna Be With You! Make Believe With You!

Elrim

i think for simplicity sake i'm going to just define up and down as facing directions for the diagonals... at least until i take the initiative to work on diagonal facing sprites.  With that said everything works great and this can help me really get a jumpstart on how i want my rpg to function.

Nortos

Blizz has the pixel movement system in his ABS as well there are lots of different ones and different ones have different compability issues

Blizzard

Somebody (Susys?) posted a common event system for that ages ago, lol! Dunno if the topic was moved already.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.