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.

battle scripting question

adma

Member

Hi everyone, quick question

Making a battle system to have the characters physically move up to the enemy and swing at it, then return, I can handle the animation but here's the problem I'm having.

Code from Scene Battle 4
Code:
#--------------------------------------------------------------------------
  # * Frame Update (main phase step 3 : animation for action performer)
  #--------------------------------------------------------------------------
  def update_phase4_step3
    # Animation for action performer (if ID is 0, then white flash)
    if @animation1_id == 0
      @active_battler.white_flash = true
    else
      @active_battler.animation_id = @animation1_id
      @active_battler.animation_hit = true
    end
    #@active_battler.attack
    @wait_count = 8
    # Shift to step 4
    @phase4_step = 4
  end

That @active_battler seems to be a Game_Actor, whereas I need it to get access to the Sprite_Battler that corresponds to it. Also, I need to get the Sprite_Battler for the corresponding target so that I can get x,y values and move/animate the sprites accordingly.

Any suggestions?
 

Anonymous

Guest

Instead of doing it from Scene_Battle, set a value in the Game_Actor object, and handle the animation in Sprite_Battler. The same way the white flash works.
 

adma

Member

Well, I need to pass the target, or at least it's x,y values to the Sprite_Battler, will I have to pass them through Scene_Battle?

Edit: Basically I need to know how to get Scene_Battle to talk to specific Sprite_Battlers
 
@active_battler is enemy or actor.

You don't need to talk to Sprite_Battler from Scene_Battle, instead try doing it vice versa.

Lets say this;

@active_battler.print = "Hi"

and then you can go to Sprite_Battler and go to it's update method an do this;

print @battler.print

that would print "HI" none stop, if done correctly :P. It will cause an error most likely :P

Just an example tho.
 
Shark_Tooth, that WOULD work, if you added an attr_accessor :print to Game_Actor. Just a thought.

You should do what Ccoa says, she made a great (and expansive) CBS after all. Talk to Sprite_Battler through Game_Actor. In Game_Actor, you'll find a set of defs called screen_x, screen_y, and screen_z. X and Y control position, X is the horizontal, so if you want to work with that you should alter that def to accept input from a value called @x. Then place an attr_accessor :x at the top of Game_Actor.

Then, whenever you need to move the X position of the battler, you can use the command:

Code:
@active_battler.x = #Insert value here
]

That will immediately reflect in the character's position as soon as the Sprite_Battler updates itself (in Scene_Battle#update), so you should make an attempt to make the movement smooth with variables and testing and the like in the update def, if you are familiar with coding animations it shouldn't be too difficult, but if not I could provide further explanation on smoothing it out.
 
mewsterus said:
Shark_Tooth, that WOULD work, if you added an attr_accessor :print to Game_Actor. Just a thought.

No, it would caues an error if its the enemies turn. It would work if its in the Game_Battler and if its given a value.
You should do what Ccoa says, she made a great (and expansive) CBS after all. Talk to Sprite_Battler through Game_Actor. In Game_Actor, you'll find a set of defs called screen_x, screen_y, and screen_z. X and Y control position, X is the horizontal, so if you want to work with that you should alter that def to accept input from a value called @x. Then place an attr_accessor :x at the top of Game_Actor.

Then, whenever you need to move the X position of the battler, you can use the command:

Code:
@active_battler.x = #Insert value here
]

That will immediately reflect in the character's position as soon as the Sprite_Battler updates itself (in Scene_Battle#update), so you should make an attempt to make the movement smooth with variables and testing and the like in the update def, if you are familiar with coding animations it shouldn't be too difficult, but if not I could provide further explanation on smoothing it out.

You are gonna have to change screen_x, and y and z a little. I had a hard time figuring it out :P.

She/he is also going to need a moving algortim and I'm having a hard time coming up with it myself..

Make sure to set the folloing variables in Game_Actor and Game_Enemy;

@original_x
@current_x
@target_x
@original_y
@current_y
@target_y

In game enemy you can put it in def initialize like so;

@original_x = $data_troops[@troop_id].members[@member_index].x
same with the rest. change .x to .y when you are goign to store it to the y variables.

and in Game_Actor do this;

Code:
  def battler_setup
    # Gets the x positions of actor
    @original_x = screen_x
    @current_x = @original_x
    @target_x = @original_x
    # Gets the y positions of actor
    @original_y = screen_y
    @current_y = @original_y
    @target_y = @original_y
  end

call battler_setup from SpriteSet_Battle. Now you have x and y of the battler's current, starting and end. You can call it from Scene_Battler too, if you want.
 

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