TheoAllen

Iseng2 RGSSS3 (3)

Apr 19th, 2013
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.00 KB | None | 0 0
  1. #~ #==============================================================================
  2. #~ # ** Main
  3. #~ #------------------------------------------------------------------------------
  4. #~ #  This processing is executed after module and class definition is finished.
  5. #~ #==============================================================================
  6.  
  7. #~ rgss_main { SceneManager.run }
  8. DataManager.init
  9. # ========================
  10.  
  11. module THEO
  12.   SPEED = 3
  13. end
  14.  
  15. class Scene
  16.  
  17.   def initialize
  18.     clear_jump_info
  19.   end
  20.  
  21.   def clear_jump_info
  22.     @jump_x = 0
  23.     @jump_y = 0
  24.     @x_speed = 0.0
  25.     @y_speed = 0.0
  26.     @real_x = 0.0
  27.     @real_y = 0.0
  28.   end
  29.  
  30.   def updates
  31.     Graphics.update
  32.     Input.update
  33.     update_placement
  34.     input_jump
  35.     update_jump if jumping?
  36.   end
  37.  
  38.   def update_placement
  39.     if Input.press?(:RIGHT)
  40.       $window.x += THEO::SPEED
  41.     elsif Input.press?(:LEFT)
  42.       $window.x -= THEO::SPEED
  43.     elsif Input.press?(:UP)
  44.       $window.y -= THEO::SPEED
  45.     elsif Input.press?(:DOWN)
  46.       $window.y += THEO::SPEED
  47.     end
  48.   end
  49.  
  50.   def input_jump
  51.     if Input.trigger?(:ALT)
  52.       jump_to(100,100)
  53.     end
  54.   end
  55.  
  56.   def jump_to(x,y)
  57.     @jump_x = x
  58.     @jump_y = y
  59.     @real_x = $window.x.to_f
  60.     @real_y = $window.y.to_f
  61.     determine_speed
  62.   end
  63.  
  64.   def jumping?
  65.     return false if @jump_x == 0 && @jump_y == 0
  66.     return $window.x != @jump_x || $window.y != @jump_y
  67.   end
  68.  
  69.   def update_jump
  70.     @real_x += @x_speed
  71.     @real_y += @y_speed
  72.     $window.x = @real_x.round
  73.     $window.y = @real_y.round
  74.     puts @jump_x
  75.     puts @real_x
  76.     clear_jump_info if $window.x == @jump_x && $window.y == @jump_y
  77.   end
  78.  
  79.   def determine_speed
  80.     @x_speed = (@jump_x - $window.x) / 60.0
  81.     @y_speed = (@jump_y - $window.y) / 60.0
  82.   end
  83.  
  84. end
  85.  
  86. ww = 24
  87. wh = 24
  88. wx = Graphics.width - ww
  89. wy = 100
  90. $window = Window_Base.new(wx,wy,ww,wh)
  91. $window.x = 300
  92. $window.y = 300
  93.  
  94. main = Scene.new
  95.  
  96. main.updates while true
  97.  
  98. # ========================
Advertisement
Add Comment
Please, Sign In to add comment