IceDragon200

ISS - OnScreen?

Jun 16th, 2011
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 14.33 KB | None | 0 0
  1. # // 06/04/2011
  2. $imported = {} if $imported == nil
  3. $imported["ISS-Core"] = true
  4. #==============================================================================#
  5. # Object
  6. #==============================================================================#
  7. class Object
  8.  
  9.   #--------------------------------------------------------------------------#
  10.   # * new-method :acquire
  11.   #--------------------------------------------------------------------------#  
  12.   def self.acquire( filename )
  13.     File.open( filename, "r" ) { |f| eval( f.read ) }
  14.   end
  15.  
  16. end
  17. #==============================================================================#
  18. # ISS
  19. #==============================================================================#
  20. module ISS
  21.  
  22. #==============================================================================#
  23. # Circle
  24. #==============================================================================#  
  25.   class Circle
  26.    
  27.     def initialize( x, y, radius ) ; @x, @y, @radius = x, y, radius end
  28.    
  29.     def get_angle_xy ( angle )
  30.       rx = @x + @radius * cos( angle )
  31.       ry = @y + @radius * sin( angle )
  32.     end  
  33.    
  34.     def set_xy( x, y ) ; @x, @y = x, y end
  35.      
  36.   end
  37.  
  38. #==============================================================================#
  39. # Pos
  40. #==============================================================================#  
  41.   class Pos
  42.    
  43.     attr_accessor :x # // X
  44.     attr_accessor :y # // Y
  45.     attr_accessor :z # // Z
  46.    
  47.     def initialize( x, y, z=0 ) ; @x = x ; @y = y ; @z = z end
  48.     def ==( otherpos )
  49.       return ( @x == otherpos.x && @y == otherpos.y && @z == otherpos.z )
  50.     end
  51.    
  52.   end
  53.  
  54. #==============================================================================#
  55. # Pop_Handler
  56. #==============================================================================#  
  57.   class Pop_Handler
  58.    
  59.     attr_accessor :x
  60.     attr_accessor :y
  61.     attr_accessor :ox
  62.     attr_accessor :oy
  63.    
  64.     attr_accessor :x_velocity
  65.     attr_accessor :y_velocity
  66.     attr_accessor :x_boost
  67.     attr_accessor :y_boost
  68.     attr_accessor :x_add
  69.     attr_accessor :y_add
  70.    
  71.     attr_accessor :cap_duration
  72.     attr_accessor :finished
  73.     attr_accessor :pause_update
  74.     attr_accessor :gravity
  75.     attr_accessor :floor_val
  76.    
  77.     GRAVITY = 0.58
  78.     TRANCEPARENT_START = 40
  79.     TRANCEPARENT_X_SLIDE = 0    
  80.    
  81.     def initialize( x, y )
  82.       @start_settings = [x, y, 0, 0]
  83.       @cap_duration = 80
  84.       @x_velocity = 0.4
  85.       @y_velocity = 1.5
  86.       @x_boost    = 8
  87.       @y_boost    = 4
  88.       @x_add      = 0
  89.       @y_add      = 4
  90.       @gravity    = GRAVITY
  91.       @floor_val  = 0
  92.       reset
  93.     end
  94.    
  95.     def reset
  96.       @x, @y, @ox, @oy = *@start_settings
  97.       @finished = false
  98.       @pause_update = false
  99.       prep_pop
  100.     end
  101.    
  102.     def damage_x_init_velocity()
  103.       return @x_velocity * ( rand(@x_boost) + @x_add )
  104.     end
  105.    
  106.     def damage_y_init_velocity()
  107.       return @y_velocity * ( rand(@y_boost) + @y_add )  
  108.     end
  109.    
  110.     def prep_pop
  111.       @now_x_speed = damage_x_init_velocity
  112.       @now_y_speed = damage_y_init_velocity
  113.       @potential_x_energy = 0.0
  114.       @potential_y_energy = 0.0
  115.       @speed_off_x = rand(2)
  116.       @pop_duration = @cap_duration
  117.     end
  118.    
  119.     def update
  120.       return if @finished or @pause_update
  121.       if @pop_duration <= TRANCEPARENT_START
  122.         @x += TRANCEPARENT_X_SLIDE if @speed_off_x == 0
  123.         @x -= TRANCEPARENT_X_SLIDE if @speed_off_x == 1
  124.       end
  125.       n = @oy + @now_y_speed
  126.       if n <= @floor_val #0
  127.         @now_y_speed *= -1
  128.         @now_y_speed /=  2
  129.         @now_x_speed /=  2
  130.       end      
  131.       @oy = [n, @floor_val].min #max
  132.       @potential_y_energy += @gravity
  133.       speed                = @potential_y_energy.floor
  134.       @now_y_speed        -= speed
  135.       @potential_y_energy -= speed
  136.       @potential_x_energy += @now_x_speed
  137.       speed                = @potential_x_energy.floor
  138.       @ox                 += speed if @speed_off_x == 0
  139.       @ox                 -= speed if @speed_off_x == 1
  140.       @potential_x_energy -= speed
  141.       @pop_duration       -= 1
  142.       if @pop_duration == 0
  143.         @finished = true
  144.       end
  145.     end
  146.    
  147.   end
  148.  
  149. end  
  150.  
  151. #==============================================================================#
  152. # Game_Character
  153. #==============================================================================#
  154. class Game_Character
  155.  
  156.   #--------------------------------------------------------------------------#
  157.   # * new-method :get_xy_infront
  158.   #--------------------------------------------------------------------------#  
  159.   def get_xy_infront( dist, sway )
  160.     case direction
  161.     when 2 # // Down
  162.       return [x+sway, y+dist]
  163.     when 4 # // Left
  164.       return [x-dist, y+sway]
  165.     when 6 # // Right
  166.       return [x+dist, y-sway]
  167.     when 8 # // Up
  168.       return [x-sway, y-dist]
  169.     end
  170.   end    
  171.  
  172.   #--------------------------------------------------------------------------
  173.   # * Calculate X Distance From Target X
  174.   #--------------------------------------------------------------------------
  175.   def distance_x_from_tx(tx)
  176.     sx = @x - tx
  177.     if $game_map.loop_horizontal?         # When looping horizontally
  178.       if sx.abs > $game_map.width / 2     # Larger than half the map width?
  179.         sx -= $game_map.width             # Subtract map width
  180.       end
  181.     end
  182.     return sx
  183.   end
  184.  
  185.   #--------------------------------------------------------------------------
  186.   # * Calculate Y Distance From Target Y
  187.   #--------------------------------------------------------------------------
  188.   def distance_y_from_ty(ty)
  189.     sy = @y - ty
  190.     if $game_map.loop_vertical?           # When looping vertically
  191.       if sy.abs > $game_map.height / 2    # Larger than half the map height?
  192.         sy -= $game_map.height            # Subtract map height
  193.       end
  194.     end
  195.     return sy
  196.   end
  197.  
  198.   #--------------------------------------------------------------------------
  199.   # * Move toward Character
  200.   #--------------------------------------------------------------------------
  201.   def move_toward_char( char )
  202.     move_toward_xy( char.x, char.y )
  203.   end
  204.  
  205.   #--------------------------------------------------------------------------
  206.   # * Move away from Character
  207.   #--------------------------------------------------------------------------
  208.   def move_away_from_char( char )
  209.     move_away_from_xy( char.x, char.y )
  210.   end
  211.  
  212.   #--------------------------------------------------------------------------
  213.   # * Move toward XY
  214.   #--------------------------------------------------------------------------
  215.   def move_toward_xy( x, y )
  216.     sx = distance_x_from_tx(x)
  217.     sy = distance_y_from_ty(y)
  218.     if sx != 0 or sy != 0
  219.       if sx.abs > sy.abs                  # Horizontal distance is longer
  220.         sx > 0 ? move_left : move_right   # Prioritize left-right
  221.         if @move_failed and sy != 0
  222.           sy > 0 ? move_up : move_down
  223.         end
  224.       else                                # Vertical distance is longer
  225.         sy > 0 ? move_up : move_down      # Prioritize up-down
  226.         if @move_failed and sx != 0
  227.           sx > 0 ? move_left : move_right
  228.         end
  229.       end
  230.     end
  231.   end
  232.   #--------------------------------------------------------------------------
  233.   # * Move away from XY
  234.   #--------------------------------------------------------------------------
  235.   def move_away_from_xy( x, y )
  236.     sx = distance_x_from_tx(x)
  237.     sy = distance_y_from_ty(y)
  238.     if sx != 0 or sy != 0
  239.       if sx.abs > sy.abs                  # Horizontal distance is longer
  240.         sx > 0 ? move_right : move_left   # Prioritize left-right
  241.         if @move_failed and sy != 0
  242.           sy > 0 ? move_down : move_up
  243.         end
  244.       else                                # Vertical distance is longer
  245.         sy > 0 ? move_down : move_up      # Prioritize up-down
  246.         if @move_failed and sx != 0
  247.           sx > 0 ? move_right : move_left
  248.         end
  249.       end
  250.     end
  251.   end
  252.  
  253. end  
  254.  
  255. #==============================================================================#
  256. # Spriteset_Map
  257. #==============================================================================#
  258. class Spriteset_Map
  259.  
  260.   #--------------------------------------------------------------------------#
  261.   # * alias-method :initialize
  262.   #--------------------------------------------------------------------------#  
  263.   alias :iss000_spm_initialize :initialize unless $@
  264.   def initialize()
  265.     @tilemap_maxtime = 2
  266.     @tilemap_uptime  = 0
  267.     iss000_spm_initialize()
  268.   end
  269.  
  270.   #--------------------------------------------------------------------------#
  271.   # * overwrite-method :initialize
  272.   #--------------------------------------------------------------------------#
  273.   def update_tilemap()
  274.     @tilemap_uptime -= 1 unless @tilemap_uptime == 0
  275.     @tilemap.ox = $game_map.display_x / 8
  276.     @tilemap.oy = $game_map.display_y / 8
  277.     if @tilemap_uptime == 0
  278.       3.times { @tilemap.update() }
  279.       @tilemap_uptime = @tilemap_maxtime
  280.     end  
  281.   end
  282.  
  283. end  
  284.  
  285. #==============================================================================#
  286. # Window_Base
  287. #==============================================================================#
  288. class Window_Base < Window
  289.  
  290.   #--------------------------------------------------------------------------
  291.   # * Draw HP
  292.   #     actor : actor
  293.   #     x     : draw spot x-coordinate
  294.   #     y     : draw spot y-coordinate
  295.   #     width : Width
  296.   #--------------------------------------------------------------------------
  297.   def draw_actor_hp(actor, x, y, width = 120)
  298.     draw_actor_hp_gauge(actor, x, y, width)
  299.     self.contents.font.color = system_color
  300.     self.contents.draw_text(x, y, 30, WLH, Vocab::hp_a)
  301.     self.contents.font.color = hp_color(actor)
  302.     last_font_size = self.contents.font.size
  303.     xr = x + width
  304.     self.contents.font.size = 18
  305.     if width < 120
  306.       self.contents.draw_text(xr - 44, y, 44, WLH, actor.hp, 2)
  307.     else
  308.       self.contents.draw_text(xr - 99, y, 44, WLH, actor.hp, 2)
  309.       self.contents.font.color = normal_color
  310.       self.contents.draw_text(xr - 55, y, 11, WLH, "/", 2)
  311.       self.contents.draw_text(xr - 44, y, 44, WLH, actor.maxhp, 2)
  312.     end
  313.    
  314.     #if width < 120
  315.     #  self.contents.draw_text(xr - 44, y, 44, WLH, sprintf("%04d", actor.hp), 2)
  316.     #else
  317.     #  self.contents.draw_text(xr - 99, y, 44, WLH, sprintf("%04d", actor.hp), 2)
  318.     #  self.contents.font.color = normal_color
  319.     #  self.contents.draw_text(xr - 55, y, 11, WLH, "/", 2)
  320.     #  self.contents.draw_text(xr - 44, y, 44, WLH, sprintf("%04d", actor.maxhp), 2)
  321.     #end
  322.     self.contents.font.size = last_font_size
  323.   end
  324.  
  325.   #--------------------------------------------------------------------------
  326.   # * Draw MP
  327.   #     actor : actor
  328.   #     x     : draw spot x-coordinate
  329.   #     y     : draw spot y-coordinate
  330.   #     width : Width
  331.   #--------------------------------------------------------------------------
  332.   def draw_actor_mp(actor, x, y, width = 120)
  333.     draw_actor_mp_gauge(actor, x, y, width)
  334.     self.contents.font.color = system_color
  335.     self.contents.draw_text(x, y, 30, WLH, Vocab::mp_a)
  336.     self.contents.font.color = mp_color(actor)
  337.     last_font_size = self.contents.font.size
  338.     xr = x + width
  339.     self.contents.font.size = 18
  340.     if width < 120
  341.       self.contents.draw_text(xr - 44, y, 44, WLH, actor.mp, 2)
  342.     else
  343.       self.contents.draw_text(xr - 99, y, 44, WLH, actor.mp, 2)
  344.       self.contents.font.color = normal_color
  345.       self.contents.draw_text(xr - 55, y, 11, WLH, "/", 2)
  346.       self.contents.draw_text(xr - 44, y, 44, WLH, actor.maxmp, 2)
  347.     end
  348.     self.contents.font.size = last_font_size
  349.   end
  350.  
  351.   #--------------------------------------------------------------------------
  352.   # * Draw HP gauge
  353.   #     actor : actor
  354.   #     x     : draw spot x-coordinate
  355.   #     y     : draw spot y-coordinate
  356.   #     width : Width
  357.   #--------------------------------------------------------------------------
  358.   def draw_actor_hp_gauge(actor, x, y, width = 120)
  359.     #gw = width * actor.hp / actor.maxhp
  360.     gc1 = hp_gauge_color1
  361.     gc2 = hp_gauge_color2
  362.     #self.contents.fill_rect(x, y + WLH - 8, width, 6, gauge_back_color)
  363.     #self.contents.gradient_fill_rect(x, y + WLH - 8, gw, 6, gc1, gc2)
  364.     val, max = actor.hp, actor.maxhp
  365.     rect = Rect.new( x, y+WLH-6, width, 4 )
  366.     draw_round_grad_bar( rect, val, max, gc1, gc2, gauge_back_color )
  367.   end
  368.  
  369.   #--------------------------------------------------------------------------
  370.   # * Draw MP Gauge
  371.   #     actor : actor
  372.   #     x     : draw spot x-coordinate
  373.   #     y     : draw spot y-coordinate
  374.   #     width : Width
  375.   #--------------------------------------------------------------------------
  376.   def draw_actor_mp_gauge(actor, x, y, width = 120)
  377.     #gw = width * actor.mp / [actor.maxmp, 1].max
  378.     gc1 = mp_gauge_color1
  379.     gc2 = mp_gauge_color2
  380.     #self.contents.fill_rect(x, y + WLH - 8, width, 6, gauge_back_color)
  381.     #self.contents.gradient_fill_rect(x, y + WLH - 8, gw, 6, gc1, gc2)
  382.     val, max = actor.mp, actor.maxmp
  383.     rect = Rect.new( x, y+WLH-6, width, 4 )
  384.     draw_round_grad_bar( rect, val, max, gc1, gc2, gauge_back_color )
  385.   end
  386.  
  387. end
  388.  
  389. #==============================================================================#
  390. # Game_Character
  391. #==============================================================================#
  392. class Game_Character
  393.  
  394.   attr_accessor :lastpos
  395.  
  396.   #--------------------------------------------------------------------------#
  397.   # * alias method :initialize
  398.   #--------------------------------------------------------------------------#
  399.   alias iss003_gc_initialize initialize unless $@
  400.   def initialize
  401.     iss003_gc_initialize()
  402.     @lastpos = ::ISS::Pos.new(self.x, self.y, 0)
  403.     @screenrect = Rect.new(0, 0, 544, 416)
  404.   end
  405.  
  406.   #--------------------------------------------------------------------------#
  407.   # * new method :onScreen?
  408.   #--------------------------------------------------------------------------#  
  409.   def onScreen?
  410.     r = @screenrect
  411.     return ( screen_x >= r.x && screen_x < r.width &&
  412.             screen_y >= r.y && screen_y < r.height )
  413.   end
  414.          
  415. end
  416.  
  417. #=*==========================================================================*=#
  418. # ** END OF FILE
  419. #=*==========================================================================*=#
Advertisement
Add Comment
Please, Sign In to add comment