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.

Custom Movement System troubles...[Resolved]

I am in the midst of making my custom movement system. I have a few more issues to deal with, so bear with me. I'll just post the code, and then explain.

Code:
#==============================================================================
# ** Movement System
#------------------------------------------------------------------------------
#  
#==============================================================================
  
MOVEMENT_POINTS = 10
POINTS_PER_MOVE   = 1

class Game_Party
  alias mvment_initialize initialize
  def initialize
    $movement_points = MOVEMENT_POINTS
    mvment_initialize
  end
end

class Window_Movement < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0, 160, 96)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.opacity = 0
    refresh
  end  
  
  def draw_movepoints(x, y)
    points = RPG::Cache.picture("")
    src_rect = Rect.new(0, 0, width, height)
    self.contents.blt(x, y, points, src_rect)
  end
    
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    draw_movepoints(0, 0)
    self.contents.font.color = Color.new(255, 0, 0)
    self.contents.font.name = "Brush Script Std"
    self.contents.font.size = 42
    self.contents.draw_text(60, 6, 64, 32,$movement_points.to_s, 2)
  end
  def update
    refresh
  end
end
  
class Scene_Map
  alias mvment_main main
  alias mvment_update update
  alias mvment_call_battle call_battle
  def main
    @window_movement = Window_Movement.new
    @event_picture = Sprite.new
    @event_picture.bitmap = RPG::Cache.picture("ENCOUNTER")
    @event_picture.visible = false
    @event_picture.z = 5
    mvment_main
    @window_movement.dispose
    @event_picture.dispose
  end
  def update
    @window_movement.update
    @event_picture.x = $game_player.screen_x
    @event_picture.y = $game_player.screen_y - 56
    @event_picture.update
    mvment_update
  end
end 

class Scene_Battle
  alias mvment_start_phase5 start_phase5
  def start_phase5
      $movement_points += 1
    mvment_start_phase5
  end
end

class Game_Character
  alias mvment_move_down  move_down
  alias mvment_move_left  move_left
  alias mvment_move_right move_right
  alias mvment_move_up    move_up
  #--------------------------------------------------------------------------
  # * Move Down
  #     turn_enabled : a flag permits direction change on that spot
  #--------------------------------------------------------------------------
  def move_down(turn_enabled = true)
    $movement_points -= 1
    mvment_move_down
  end
  #--------------------------------------------------------------------------
  # * Move Left
  #     turn_enabled : a flag permits direction change on that spot
  #--------------------------------------------------------------------------
  def move_left(turn_enabled = true)
    $movement_points -= 1
    mvment_move_left
  end
  #--------------------------------------------------------------------------
  # * Move Right
  #     turn_enabled : a flag permits direction change on that spot
  #--------------------------------------------------------------------------
  def move_right(turn_enabled = true)
    $movement_points -= 1
    mvment_move_right
  end
  #--------------------------------------------------------------------------
  # * Move up
  #     turn_enabled : a flag permits direction change on that spot
  #--------------------------------------------------------------------------
  def move_up(turn_enabled = true)
    $movement_points -= 1
    mvment_move_up
  end
end

I'm having a hard time understanding this part:

Code:
  def update
    refresh
  end

I was looking around at how to display a variable in-game, and came across a topic that said to do that. I was wondering how I could make that go away/make more efficient.

Code:
class Game_Character
  alias mvment_move_down  move_down
  alias mvment_move_left  move_left
  alias mvment_move_right move_right
  alias mvment_move_up    move_up
  #--------------------------------------------------------------------------
  # * Move Down
  #     turn_enabled : a flag permits direction change on that spot
  #--------------------------------------------------------------------------
  def move_down(turn_enabled = true)
    $movement_points -= 1
    mvment_move_down
  end
  #--------------------------------------------------------------------------
  # * Move Left
  #     turn_enabled : a flag permits direction change on that spot
  #--------------------------------------------------------------------------
  def move_left(turn_enabled = true)
    $movement_points -= 1
    mvment_move_left
  end
  #--------------------------------------------------------------------------
  # * Move Right
  #     turn_enabled : a flag permits direction change on that spot
  #--------------------------------------------------------------------------
  def move_right(turn_enabled = true)
    $movement_points -= 1
    mvment_move_right
  end
  #--------------------------------------------------------------------------
  # * Move up
  #     turn_enabled : a flag permits direction change on that spot
  #--------------------------------------------------------------------------
  def move_up(turn_enabled = true)
    $movement_points -= 1
    mvment_move_up
  end
end

In here is my major dilemma. I'm trying to make it so that the system subtracts one point for every step taken. Right now, it takes away 1, then, 2, and then 3, and so on, even into the negatives.

If any could give me some pointers, thank you.
 
Code:
def update
  refresh
end

The update method is the most important method, next to a main/initialize method in most any scenes! Basically, all your update method is doing is 'refreshing' something, in this case your Window_Movement is being 're-drawn'. This method isn't needed, instead just call it in your scene like @window_movement.refresh instead of @window_movement.update.

Now, if you need to define the minimum and maximum number of $movement_points, just look at this line in Game_Party ; gain_gold(n) method.

Code:
@gold = [[@gold + n, 0].max, 9999999].min

You can turn that into your own, to determine the min/max number of steps taken.

Code:
$movement_points = [[$movement_points + 1, 0].max, 9999999].min


Other than that, I'm not sure what you're talking about much in this post, and I don't understand what $movement_points is supposed to represent, or what its special function is... so sorry if I can't help you anymore than that.

Good luck with it :thumb:
 
Basically, the $movement_points represents the amount of steps you may take. If you hit zero, you automatically get into a fight. Think of a board game type of thing. Instead of rolling, you get a set amount of points ($movement_points). Everytime you take a step, you waste a point.

Code:
 #--------------------------------------------------------------------------
  # * Move Right
  #     turn_enabled : a flag permits direction change on that spot
  #--------------------------------------------------------------------------
  def move_right(turn_enabled = true)
    $movement_points -= 1
    mvment_move_right
  end

That's what that is. But it's not subtracting one point. It's subtracting 1, then 2, then 3, like I said. I'll toy around with your advice though.

EDIT: Ok. Thanks for the refreshing thing. It's all good now. Now I need to figure out the other issue.

EDIT: I messed around with the gold thing. I can't seem to get it to work.
 

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