TheoAllen

Iseng2 RGSSS3 (4)

Apr 26th, 2013
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.24 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.   JUMP = 10
  14. end
  15.  
  16. class Scene
  17.  
  18.   def initialize
  19.     clear_jump_info
  20.   end
  21.  
  22.   def clear_jump_info
  23.     @jump_x = 0
  24.     @jump_y = 0
  25.     @x_speed = 0.0
  26.     @y_speed = 0.0
  27.     @real_x = 0.0
  28.     @real_y = 0.0
  29.     @jump_height = 0.0
  30.     @offset = 0.0
  31.   end
  32.  
  33.   def jump_interval
  34.     THEO::JUMP / 30.0
  35.   end
  36.  
  37.   def updates
  38.     Graphics.update
  39.     Input.update
  40.     update_placement
  41.     input_jump
  42.     update_jump if jumping?
  43.   end
  44.  
  45.   def update_placement
  46.     if Input.press?(:RIGHT)
  47.       $window.x += THEO::SPEED
  48.     elsif Input.press?(:LEFT)
  49.       $window.x -= THEO::SPEED
  50.     elsif Input.press?(:UP)
  51.       $window.y -= THEO::SPEED
  52.     elsif Input.press?(:DOWN)
  53.       $window.y += THEO::SPEED
  54.     end
  55.   end
  56.  
  57.   def input_jump
  58.     if Input.trigger?(:ALT)
  59.       jump_to(100,100)
  60.     end
  61.   end
  62.  
  63.   def jump_to(x,y)
  64.     @jump_x = x
  65.     @jump_y = y
  66.     @real_x = $window.x.to_f
  67.     @real_y = $window.y.to_f
  68.     @jump_height = THEO::JUMP
  69.     determine_speed
  70.   end
  71.  
  72.   def jumping?
  73.     return false if @jump_x == 0 && @jump_y == 0
  74.     return $window.x != @jump_x || $window.y != @jump_y
  75.   end
  76.  
  77.   def update_jump
  78.     @real_x += @x_speed
  79.     @real_y += @y_speed
  80.     $window.x = @real_x.round
  81.     $window.y = @real_y.round + @offset.round
  82.     @jump_height -= jump_interval
  83.     @offset -= @jump_height
  84.     puts $window.y.to_s + " <--> " + $window.x.to_s
  85.     clear_jump_info if $window.x == @jump_x && $window.y == @jump_y
  86.   end
  87.  
  88.   def determine_speed
  89.     @x_speed = (@jump_x - $window.x) / 60.0
  90.     @y_speed = (@jump_y - $window.y) / 60.0
  91.   end
  92.  
  93. end
  94.  
  95. ww = 24
  96. wh = 24
  97. wx = Graphics.width - ww
  98. wy = 100
  99. $window = Window_Base.new(wx,wy,ww,wh)
  100. $window.x = 300
  101. $window.y = 100
  102.  
  103. main = Scene.new
  104.  
  105. main.updates while true
  106.  
  107. # ========================
Advertisement
Add Comment
Please, Sign In to add comment