Ogłoszenie 

Uwaga! To forum jest w trybie offline.
Wszelką pomoc uzyskasz pod adresem
forum.ultimateam.pl


Administracja Forum


Poprzedni temat «» Następny temat
Skrypt na grawitacje
Autor Wiadomość
Nex 




Preferowany:
RPG Maker XP

Pomógł: 15 razy
Dołączył: 27 Paź 2012
Posty: 145
Wysłany: Czw 28 Lut, 2013 15:56
Skrypt na grawitacje
~ Gravity ~


Krótki opis:
Skrypt dodaje do gry efekt grawitacji

Autor:
LiTTleDRAgo Zeus81

Kompatybilność:
RPG Maker XP

Skrypt:
Spoiler:

part 1
Spoiler:


Kod:

class Game_Player
 
  Jump_Input = Input::Y
 
  alias update_sebelum_gravity_spx update
  def update
    gravity_jump
    update_sebelum_gravity_spx
  end
 
  def gravity_jump
    unless moving? or $game_system.map_interpreter.running? or
           @move_route_forcing or $game_temp.message_window_showing
      unless new_jumping?
        new_jump if Input.trigger?(Jump_Input)
      end
    end
  end
end


part 2
Spoiler:


Kod:

#============================================================================
# ** RPG::MapInfo
#============================================================================

$data_maps = load_data("Data/MapInfos.rxdata")
class RPG::MapInfo
  def name
    v = @name.gsub(/\\[Nn]\[(\d+)\]/) {$game_actors[$1.to_i] != nil ?
      $game_actors[$1.to_i].name : ""}
    return v.gsub(/\[.*\]/) {""}
  end
 
  def full_name
    return @name
  end
end



class Game_Character
 
  attr_reader   :x2, :y2, :z, :z2, :real_zoom, :real_move_speed
  attr_accessor :character_hue,:gravity,
      :through,
      :move_speed, :move_frequency, :move_type,
      :move_animation_speed, :real_z, :floor,
      :jump_power, :zoom, :follow_event_id
 
  alias amsu_game_character_initialize initialize
  def initialize
    amsu_game_character_initialize
    initialize_for_gravity
  end
   
  def initialize_for_gravity
    @move_animation_speed, @real_move_speed, @real_direction = 0, 4, 2
    @zoom = @real_zoom = 1
    @jump_power = 1.5
    @gravity = 10
  end
 
  def new_jumping?() @real_z != 0 or @z2 != 0 end
 
  def passable?(x, y, d)
    new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
    new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
   
    passable_xas?(new_x, new_y,d) if $xrxs_xas
   
    return false unless $game_map.valid?(new_x, new_y)
    return true if @through
    y_plus = change_floor(@x, @y, new_x, new_y, @real_z/128.0, d) rescue 0
    if y_plus == 0
      return false unless $game_map.passable?(x, y, d, self)
      return false unless $game_map.passable?(new_x, new_y, 10 - d)
    else
      new_y += y_plus
      return false unless $game_map.passable?(new_x, new_y, 0)
    end
    return event_passable?(new_x, new_y)
  end
 
 
  def event_passable?(new_x, new_y)
    $game_map.events.each_value {|event|
      if event.x == new_x and event.y == new_y and !event.character_name.empty?
        if $xrxs_xas && !event.through && event.event_name =~ /<Actor>/       
          event.x = x
          event.y = y
          event.direction = d
          return true
        end 
        if @id < 2000 and event.id > 2000
          event.move_away_from_event(@id) unless event.moving?
        else return false unless event.through
        end
      end}
    if $game_player.x == new_x and $game_player.y == new_y
      return false if !$game_player.through and !@character_name.empty?
    end
    return true
  end

  def change_floor(last_x, last_y, new_x, new_y, z, d)
    return 0 unless $game_map.amsu_height
    last_floor = $game_map.floor(last_x, last_y, self)
    new_floor = $game_map.floor(new_x, new_y, self)
    if d != 0 and new_floor != last_floor
      if new_floor < 0
        if d == 2 or d == 8
          sens = d == 2 ? 1 : -1
        else
          sens = (new_floor == -4 or new_floor == -d/2) ? -1 : 1
        end
      else
        if d == 2 or d == 8
          return 0
        else
          sens = new_floor < last_floor ? 1 : -1
        end
      end
      y_plus = 0
      loop do
        y_plus += sens
        new_floor = $game_map.floor(new_x, new_y+y_plus, self)
        break if new_floor >= 0 and (sens == 1 ?
           (last_floor <= new_floor+y_plus) : (last_floor >= new_floor+y_plus))
      end
      return y_plus if $game_map.valid?(new_x, new_y+y_plus) and
         new_floor != last_floor and new_floor < last_floor+z
    end
    return 0
  end
 
  def need_new_jump?(d = @real_direction)
    return false if !$game_map.amsu_height or d % 2 == 1
    new_x = @x + (d == 6 ? 1 : d == 4 ? -1 : 0)
    new_y = @y + (d == 2 ? 1 : d == 8 ? -1 : 0)
    new_z = @z2 + @jump_power * (2-$game_map.gravity) * @zoom
    y_plus = change_floor(@x, @y, new_x, new_y, new_z, d)
    return (y_plus < 0 ? passable?(new_x, new_y + y_plus, 0) : false)
  end
 
 
end

class Game_Character
  # ALIASES
  alias update_before_gravity update
  alias move_to_gravity moveto
  alias screen_y_gravity screen_y
 
  def update
    update_new_jump if new_jumping?
    update_before_gravity
  end
 
  def moveto(x, y)
    @last_real_y = nil
    move_to_gravity(x, y)
    @x2,@y2 = @real_x,@real_y
  end
 
  def screen_y
    if new_jumping? #&& !$xrxs_xas
      scry = ((@real_y - $game_map.display_y + 3) / 4 + 32)
      return scry - (@real_z / 4.0) rescue screen_y_gravity
    end
    return screen_y_gravity
  end
end

class Game_Character
 
  alias move_grafity_down move_down
  alias move_grafity_left move_left
  alias move_grafity_right move_right
  alias move_grafity_up move_up
 
 
  def move_down(turn_enabled = true)
    last_x, last_y = @x, @y
    move_grafity_down(turn_enabled)
    if $game_map.amsu_height
      y_plus = change_floor(last_x, last_y, @x, @y, @z2, 2)
      @y += y_plus
      @y2 += y_plus * 128
      @real_y += y_plus * 128
      return  if @z2.nil?
      @z2 += y_plus
      @real_z += y_plus * 128
    end
  end
   
  def move_left(turn_enabled = true)
    last_x, last_y = @x, @y
    move_grafity_left(turn_enabled)
    if $game_map.amsu_height
      y_plus = change_floor(last_x, last_y, @x, @y, @z2, 4)
      @y += y_plus
      @y2 += y_plus * 128
      @real_y += y_plus * 128
      return  if @z2.nil?
      @z2 += y_plus
      @real_z += y_plus * 128
    end
  end
   
  def move_right(turn_enabled = true)
    last_x, last_y = @x, @y
    move_grafity_right(turn_enabled)
    if $game_map.amsu_height
      y_plus = change_floor(last_x, last_y, @x, @y, @z2, 6)
      @y += y_plus
      @y2 += y_plus * 128
      @real_y += y_plus * 128
      return  if @z2.nil?
      @z2 += y_plus
      @real_z += y_plus * 128
    end
  end
   
  def move_up(turn_enabled = true)
    last_x, last_y = @x, @y
    move_grafity_up(turn_enabled)
    if $game_map.amsu_height
      y_plus = change_floor(last_x, last_y, @x, @y, @z2, 8)
      @y += y_plus
      @y2 += y_plus * 128
      @real_y += y_plus * 128
      return  if @z2.nil?
      @z2 += y_plus
      @real_z += y_plus * 128
    end
  end
end

 
class Game_Character
 
  def move_type_toward_event
    event = (@follow_event_id == 0) ? $game_player : $game_map.events[@follow_event_id]
    return unless event
    sx, sy= (@x2 - event.x2).abs, (@y2 - event.y2).abs
    distance = Math.hypot(sx, sy)
    if distance > 15 * 128
      @dash = false
      @id > 1000 ? moveto($game_player.x, $game_player.y) : move_type_random
      return
    end
    @dash = (distance > @follow_distance * 256)
    speed = @move_frequency == 6 ? @real_move_speed : 7
    if distance > @follow_distance * 128
      move_toward_event(@follow_event_id, speed)
    elsif distance < @follow_distance * 128 - 2**speed * 2
      move_away_from_event(@follow_event_id)
    elsif !moving?
      turn_toward_event(@follow_event_id)
    end
  end
   
  def new_jump
    @z2 += @jump_power * (2-$game_map.gravity) * @real_zoom
  #  if @walk_steps > 0
   #   make_step(0, true)
  #    make_step(1, true)
  #  end
    @stop_count = 0
  end
 
  def update_new_jump
  #  initialize_for_gravity if @z2.nil?
    $game_map.setup_gravity_system($game_map.map_id) if $game_map.gravity.nil?
    if !@z2.nil? && @z2 * 128 > @real_z
      distance = 48 * [1-@real_z/@z2/128.0, 0.1].max * $game_map.gravity * @real_zoom
      @real_z = [@real_z + distance, @z2 * 128].min
    else
      @fall_count = 0 if @fall_count.nil?
      @fall_count += 2 * $game_map.gravity
      distance = @fall_count * $game_map.gravity * @real_zoom
      @real_z = [(@real_z.nil? ? 0 : @real_z) - distance, 0].max
      @z2 = @real_z/128.0
    end
    @phase = (@z2 * 128 > @real_z ? 4 : 5)
  #  @anime_count += 1.5 if (@phase == 5 ? @fall_anime : @jump_anime)
    if @real_z == 0
      if @down_anime and @fall_count * $game_map.gravity > 48
        @phase, @pattern, @anim_count = 6, 0, 0
      end
    end
    update_move
  end
 
  def updating_new_jump?
    if new_jumping?
      last_direction, @direction = @direction, @real_direction
      move_forward(3)
      @direction = last_direction
    elsif need_new_jump?; new_jump
    else return false
    end; return true
  end
 
 
  def move_toward_event(event_id = 0, speed = 7)
    event = (event_id == 0) ? $game_player : $game_map.events[event_id]
    return unless event
    sx, sy = @x2 - event.x2, @y2 - event.y2
    return if sx == 0 and sy == 0
    abs_sx, abs_sy = sx.abs, sy.abs
    if (abs_sx - abs_sy).abs <= 128
      if sy > 0; sx > 0 ? move_upper_left(true, speed) : move_upper_right(true, speed)
      else       sx > 0 ? move_lower_left(true, speed) : move_lower_right(true, speed)
      end
    end
    if !moving? and !need_new_jump?
      if abs_sx > abs_sy
        sx > 0 ? move_left : move_right
        if !moving? and !need_new_jump? and sy != 0
          sy > 0 ? move_up : move_down
        end
      else
        sy > 0 ? move_up : move_down
        if !moving? and !need_new_jump? and sx != 0
          sx > 0 ? move_left : move_right
        end
      end
      move_random if !moving? and !need_new_jump?
    end
  end
 
  def move_away_from_event(event_id = 0, speed = 7)
    event = (event_id == 0) ? $game_player : $game_map.events[event_id]
    return unless event
    sx, sy = @x2 - event.x2, @y2 - event.y2
    return move_random if sx == 0 and sy == 0
    abs_sx, abs_sy = sx.abs, sy.abs
    if (abs_sx - abs_sy).abs <= 128
      if sy > 0; sx > 0 ? move_lower_right : move_lower_left
      else       sx > 0 ? move_upper_right : move_upper_left
      end
    end
    if !moving? and !need_new_jump?
      if abs_sx > abs_sy
        sx > 0 ? move_right : move_left
        if !moving? and !need_new_jump? and sy != 0
          sy > 0 ? move_down : move_up
        end
      else
        sy > 0 ? move_down : move_up
        if !moving? and !need_new_jump? and sx != 0
          sx > 0 ? move_right : move_left
        end
      end
      move_random if !moving? and !need_new_jump?
    end
  end
end

class Game_Character
 
 
  $sect = true if !method_defined?(:turn_upper_left)
  #--------------------------------------------------------------------------
  # * Turn Toward Event
  #--------------------------------------------------------------------------
  def turn_toward_event(event_id = 0)
    event = (event_id == 0) ? $game_player : $game_map.events[event_id]
    return unless event
    sx, sy = @x - event.x, @y - event.y
    return if sx == 0 and sy == 0
    if sx.abs == sy.abs
      return if $sect
      sy > 0 ? (sx > 0 ? turn_upper_left : turn_upper_right) :
        (sx > 0 ? turn_lower_left : turn_lower_right)
    else
      sx.abs > sy.abs ? (sx > 0 ? turn_left : turn_right) :
                      (sy > 0 ?   turn_up : turn_down)
    end
  end
  #--------------------------------------------------------------------------
  # * Turn Away From Event
  #--------------------------------------------------------------------------
  def turn_away_from_event(event_id = 0)
    event = (event_id == 0) ? $game_player : $game_map.events[event_id]
    return unless event
    sx, sy = @x - event.x, @y - event.y
    return if sx == 0 and sy == 0
    if sx.abs == sy.abs
      return if $sect
       sy > 0 ? (sx > 0 ? turn_lower_right : turn_lower_left) :
        (sx > 0 ? turn_upper_right : turn_upper_left)
    else
      sx.abs > sy.abs ? (sx > 0 ? turn_right : turn_left) :
                       (sy > 0 ?  turn_down : turn_up)
    end
  end
end


part 3
Spoiler:


Kod:


class Game_Map
 
  Default_Gravity = 10
  Default_Depth   = [100, 100, 0, 0, 0]
 
  attr_reader :tile_events, :amsu_height, :amsu_depth,
        :walk_audio, :walk_graphics,
        :gravity, :zoom_max, :zoom_min, :zoom_factor,
        :zoom_origin, :zoom_default
 
  alias amsu_game_map_setup setup
  def setup(map_id)
    setup_gravity_system(map_id)
    amsu_game_map_setup(map_id)
  end
 
  def setup_gravity_system(map_id = @map_id)
    @tile_events = []
   
    map_data = $data_maps[$game_map.map_id]
    return if map_data.nil?
    if map_data.full_name =~ /<GMap(\d+)>/i
      load_data = $1.to_i
    end
    if load_data
      @map = load_data(sprintf("Data/Map%03d.rxdata", map_id))
      data = load_data(sprintf("Data/Map%03d.rxdata", load_data))
      @temp,events = Table.new(data.width, data.height), {}
      if [data.width, data.height] !=  [@map.width, @map.height]
        raise "The map dimension is different"
      end
      for i in data.events.keys
        events[i] = Game_Event.new(load_data, data.events[i])
        s = [events[i].direction,events[i].pattern]
        @temp[events[i].x, events[i].y] = case events[i].character_name
        when 'gravi1'
          case s[0]
          when 2
            case events[i].pattern
            when 0 then -1
            when 1 then -2
            when 2 then -3
            when 3 then -4
            end
          end
        when 'gravi2'
          case s[0]
          when 2,4,6,8
            case events[i].pattern
            when 0 then s[0] == 2 ? 0 : s[0] == 4 ? 4 : s[0] == 6 ? 8  : 12
            when 1 then s[0] == 2 ? 1 : s[0] == 4 ? 5 : s[0] == 6 ? 9  : 13
            when 2 then s[0] == 2 ? 2 : s[0] == 4 ? 6 : s[0] == 6 ? 10 : 14
            when 3 then s[0] == 2 ? 3 : s[0] == 4 ? 7 : s[0] == 6 ? 11 : 15
            end
          end
        end
      end
      @gravity, @floors = $game_player.gravity, @temp
      @gravity, @amsu_height = @gravity * 0.1, true
    else @gravity, @amsu_height = Default_Gravity * 0.1, false
    end
  end
   
  def passable?(x, y, d, self_event = nil)
    return false unless valid?(x, y)
    bit = d / 2 - 1
    for event in @tile_events
      if !event.through and event != self_event and event.x == x and event.y == y
        if @passages[event.tile_id][bit] == 1 or @passages[event.tile_id] & 0x0f == 0x0f
          return false
        elsif @priorities[event.tile_id] == 0
          return true
        end
      end
    end
    for i in 0..2
      tile_id = data[x, y, 2-i]
      if !tile_id or @passages[tile_id][bit] == 1 or @passages[tile_id] & 0x0f == 0x0f
        return false
      elsif @priorities[tile_id] == 0
        return true
      end
    end
    return true
  end
 
  def bush?(x, y)
    if @map_id != 0
      for event in @tile_events
        if event.x == x and event.y == y
          return true if @passages[event.tile_id][6] == 1
        end
      end
      for i in 0..2
        tile_id = data[x, y, 2-i]
        if !tile_id
          return false
        elsif @passages[tile_id][6] == 1
          return true
        end
      end
    end
    return false
  end
 
  def counter?(x, y)
    if @map_id != 0
      for event in @tile_events
        if event.x == x and event.y == y
          return true if @passages[event.tile_id][7] == 1
        end
      end
      for i in 0..2
        tile_id = data[x, y, 2-i]
        if !tile_id
          return false
        elsif @passages[tile_id][7] == 1
          return true
        end
      end
    end
    return false
  end
 
  def terrain_tag(x, y)
    if @map_id != 0
      for event in @tile_events
        if event.x == x and event.y == y
          return @terrain_tags[event.tile_id] if @terrain_tags[event.tile_id] > 0
        end
      end
      for i in 0..2
        tile_id = data[x, y, 2-i]
        if !tile_id
          return 0
        elsif @terrain_tags[tile_id] > 0
          return @terrain_tags[tile_id]
        end
      end
    end
    return 0
  end
 
  def floor(x, y, self_event = nil)
    if @amsu_height
      for event in @tile_events
        if !event.through and event != self_event and event.x == x and event.y == y
          return event.floor if event.floor != 0
        end
      end
      return @floors[x, y] if @floors[x, y]
    end
    return 0
  end
end


Demo:
 
 
Kerdian 



Preferowany:
RPG Maker XP

Dołączył: 23 Lis 2012
Posty: 20
Wysłany: Sob 09 Mar, 2013 20:40
A mogę wiedzieć na czym ten skrypt polega? :P Tzn. na co mi ta grawitacja? :P
________________________
Nothing is true, everything is permitted.
 
 
Nex 




Preferowany:
RPG Maker XP

Pomógł: 15 razy
Dołączył: 27 Paź 2012
Posty: 145
Wysłany: Sob 09 Mar, 2013 21:02
żeby było ciekawiej
to jest dodatek a nie jakiś ABS :roll:
 
 
Kerdian 



Preferowany:
RPG Maker XP

Dołączył: 23 Lis 2012
Posty: 20
Wysłany: Sob 09 Mar, 2013 21:03
No tak, ale na jakiej zasadzie to działa? Spadamy w przepaście czy coś takiego?
________________________
Nothing is true, everything is permitted.
 
 
Falkret 



Dołączył: 20 Lis 2012
Posty: 80
Wysłany: Nie 10 Mar, 2013 14:15
Skrypt nawet spoko, tylko ekranem troche trzęsie :D
A i jeszcze jedno, da się zrobić coś takiego że przy upadku ze zbyt dużej wysokości odejmuje postaci nieco punktów życia?
________________________
SKOŃCZYŁEM ZABAWĘ Z MAKEREM
Przede wszystkim, za mało czasu i chęci, a także cierpliwości. Prace nad wszelkimi projektami przekazuje thiefferowi119.
================================
 
 
Nex 




Preferowany:
RPG Maker XP

Pomógł: 15 razy
Dołączył: 27 Paź 2012
Posty: 145
Wysłany: Wto 12 Mar, 2013 16:24
Jakoś na pewno da się tak zrobić, też tego szukam ale jakoś nie mogę znaleźć :-(
 
 
Wyświetl posty z ostatnich:   
Odpowiedz do tematu
Nie możesz pisać nowych tematów
Nie możesz odpowiadać w tematach
Nie możesz zmieniać swoich postów
Nie możesz usuwać swoich postów
Nie możesz głosować w ankietach
Nie możesz załączać plików na tym forum
Możesz ściągać załączniki na tym forum
Dodaj temat do Ulubionych
Wersja do druku

Skocz do:  

Powered by phpBB modified by Przemo © 2003 phpBB Group | Template Klam by Ayene