Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # =============================================================================
- # THEOALLEN - WINDOW AND SPRITE CORE MOVEMENT
- # VERSION : 1.17
- # CONTACT : www.rpgmakerid.com
- # (This script documentation is written in informal indonesian language)
- # =============================================================================
- $imported = {} if $imported.nil?
- $imported[:Theo_Movement] = true
- # =============================================================================
- # CHANGE LOGS:
- # -----------------------------------------------------------------------------
- # - 2013.04.29 - Nambahin preset movement
- # - 2013.04.28 - Fixed bug di update movement
- # - 2013.04.27 - Script selesai
- # =============================================================================
- =begin
- PENGENALAN :
- Script ini ngebikin sebuah object dengan class Window atau Sprite bisa
- digerakkan dengan memanggil method goto dan slide. Script ini digunain
- buat devtoolnya para scripter. Jadi butuh implementasi. Bukan cuman sekedar
- cucuk dan main (plug n play) :v
- CARA PENGGUNAAN:
- Tulis dalam script seperti ini :
- (note1: object harus sebuah sprite atau window)
- (note2: duration dalam hitungan frame (60 = 1 detik))
- - object.goto(x,y) >> mindah object ke koordinat x,y dengan waktu satu detik
- - object.goto(x,y,dur) >> mindah object dengan waktu yg ditentuin
- - object.goto(x,y,dur,jump) >> mindah object cuman ditambahin loncat
- - object.slide(x,y) >> geser object sebanyak x,y
- - object.slide(x,y,dur) >> geser object dengan waktu yg dah ditentuin
- - object.slide(x,y,dur,jump) >> geser object dengan loncat
- -object.moving? >> ngecek lagi bergerak apa kaga
- PRESET MOVEMENT:
- - object.up(range[,dur,jump]) >> geser ke atas
- - object.down(range[,dur,jump]) >> geser ke bawah
- - object.right(range[,dur,jump]) >> geser ke kanan
- - object.left(range[,dur,jump]) >> geser ke kiri
- - object.upright(range[,dur,jump]) >> geser ke kanan atas
- - object.upleft(range[,dur,jump]) >> geser ke kiri atas
- - object.downright(range[,dur,jump]) >> geser ke kanan bawah
- - object.downleft(range[,dur,jump]) >> geser ke kiri bawah
- TERMS OF USE :
- Karena ini emang cuman buat tool para scripter, silahkan2 aja kalo mo dipake.
- Mau komersil juga boleh. Btw, kalo ada ide trus mo ngembangil ni modul
- monggo terserah. Gw mah dmen banget kalo ada yg mo ngembangin script gw yg
- satu ini. Tapi tetep kredit ya? \=w=/
- =end
- # =============================================================================
- # Module THEO::Movement (diimplement ke window dan sprite)
- # =============================================================================
- module THEO
- module Movement
- # =========================================================================
- # Class Move_Object ~
- # -------------------------------------------------------------------------
- # Class untuk ngehandle perpindahan object
- # Tiap satu object sprite ato window punya satu object dengan class ini
- # =========================================================================
- class Move_Object
- attr_reader :obj # <-- Sprite atau Window
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # inisialisasi object
- # -----------------------------------------------------------------------
- # parameter obj adalah pointer menuju object aslinya, yaitu :
- # Sprite atau Window yang udah diinstant
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- def initialize(obj)
- @obj = obj
- clear_move_info
- end
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # Bersihin info pergerakan
- # -----------------------------------------------------------------------
- # @to_x =>> koordinat tujuan x
- # @to_y =>> koordinat tujuan y
- # @real_x =>> posisi (asli) x object dalam bentuk float number
- # @real_y =>> posisi (asli) y object dalam bentuk float number
- # @x_speed =>> perpindahan posisi x per-frame
- # @y_speed =>> perpindahan posisi y per-frame
- # @jump =>> kekuatan loncat keatas
- # @jump_interval =>> nilai untuk pengurangan kecepatan @jump per-frame
- # @offset =>> nilai pelencengan y object dari garis vektor
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- def clear_move_info
- @to_x = -1
- @to_y = -1
- @real_x = 0.0
- @real_y = 0.0
- @x_speed = 0.0
- @y_speed = 0.0
- @jump = 0.0
- @jump_interval = 0.0
- @offset = 0
- end
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # Ngeset pergerakan menuju x, y, kekuatan loncat dan durasi (frame)
- # -----------------------------------------------------------------------
- # x = koordinat tujuan x
- # y = koordinat tujuan x
- # jump = kekuatan loncat
- # duration = lama perjalanan (60 = satu detik)
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- def move_to(x,y,jump,duration)
- @to_x = x
- @to_y = y
- @real_x = @obj.x.to_f
- @real_y = @obj.y.to_f
- determine_speed(duration,jump)
- end
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # Penentuan perubahan nilai per-frame / kecepatan gerak
- # -----------------------------------------------------------------------
- # speed = jarak / waktu (u dont say)
- # jump_interval = kekuatan loncat / setengah dari perjalanan
- # (asumsi setelah setengah perjalanan akan turun)
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- def determine_speed(duration,jump)
- @x_speed = (@to_x - @obj.x) / duration.to_f
- @y_speed = (@to_y - @obj.y) / duration.to_f
- @jump = jump.to_f
- @jump_interval = @jump/(duration/2.0)
- end
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # Cek lagi bergerak apa kaga?
- # -----------------------------------------------------------------------
- # false >> tujuan x ama y = -1 (anggap aja g ada tujuannya)
- # true >> kalo tujuannya g sama ama posisi object
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- def moving?
- return false if @to_x == -1 && @to_y == -1
- result = @obj.x != @to_x || @obj.y != @to_y
- return result
- end
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # Untuk ngeupdate perpindahan posisi. (dipanggil perframe)
- # -----------------------------------------------------------------------
- # @real_x += kecepatan x (floating number)
- # @real_y += kecepatan y (floating number)
- # posisi x object = hasil pembulatan dari real_x
- # posisi y object = hasil pembulatan dari real_y + offset (kalo loncat)
- # @jump -= intervalnya (setengah perjalanan, jump = 0)
- # @offset += kekuatan loncat (stengah perjalanan - akhir, berkurang)
- # -----------------------------------------------------------------------
- # bersihin info pergerakan kalo dah nyampe tujuan
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- def update_move
- @real_x += @x_speed
- @real_y += @y_speed
- @obj.x = @real_x.round
- @obj.y = @real_y.round + @offset.round
- @jump -= @jump_interval
- @offset -= @jump
- clear_move_info unless moving?
- end
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # Akhir dari Class Move_Object ~
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- end
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # Buat pengecekan aja (error handling)
- # -------------------------------------------------------------------------
- # false >> kalo bukan window || sprite
- # true >> kalo window || sprite
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- def can_move?(obj)
- return obj.is_a?(Window) || obj.is_a?(Sprite)
- end
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # pengesetan object dengan class Move_Object
- # kecuali objectnya ga bisa digerakin :v
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- def set_obj(obj)
- @move_obj = Move_Object.new(obj)
- end
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # Perjalanan langsung ke koordinat (x,y)
- # -------------------------------------------------------------------------
- # jump = kekuatan loncat (default : 0 / ga loncat)
- # duration = lama perjalanan (default : 60 frame)
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- def goto(x,y,duration = Graphics.frame_rate,jump = 0.0)
- @move_obj.move_to(x,y,jump,duration)
- end
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # Geser posisi sebanyak (x,y)
- # -------------------------------------------------------------------------
- # jump = kekuatan loncat (default : 0 / ga loncat)
- # duration = lama perjalanan (default : 60 frame)
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- def slide(x,y,duration = Graphics.frame_rate,jump = 0.0)
- slide_x = @move_obj.obj.x + x
- slide_y = @move_obj.obj.y + y
- goto(slide_x,slide_y,duration,jump) unless moving?
- end
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # Ngeupdate pergerakan objectnya. Dipanggil sekali tiap frame
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- def update_move
- @move_obj.update_move if moving?
- end
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # Ngecek, lagi gerak apa kaga
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- def moving?
- @move_obj.moving?
- end
- # =========================================================================
- # PRESET MOVEMENT :
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # Geser atas
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- def up(range,duration = Graphics.frame_rate,jump = 0.0)
- slide(0,-range,duration,jump)
- end
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # Geser bawah
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- def down(range,duration = Graphics.frame_rate,jump = 0.0)
- slide(0,range,duration,jump)
- end
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # Geser kanan
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- def right(range,duration = Graphics.frame_rate,jump = 0.0)
- slide(range,0,duration,jump)
- end
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # Geser kiri
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- def left(range,duration = Graphics.frame_rate,jump = 0.0)
- slide(-range,0,duration,jump)
- end
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # Geser kanan atas
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- def upright(range,duration = Graphics.frame_rate,jump = 0.0)
- slide(range,-range,duration,jump)
- end
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # Geser kiri atas
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- def upleft(range,duration = Graphics.frame_rate,jump = 0.0)
- slide(-range,-range,duration,jump)
- end
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # Geser kanan bawah
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- def downright(range,duration = Graphics.frame_rate,jump = 0.0)
- slide(range,-range,duration,jump)
- end
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- # Geser kiri bawah
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- def downleft(range,duration = Graphics.frame_rate,jump = 0.0)
- slide(-range,range,duration,jump)
- end
- # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- end
- end
- # =============================================================================
- # Akhir dari Module THEO::Movement
- # -----------------------------------------------------------------------------
- # class Sprite (yg ngehandle gambar2 gitu)
- # =============================================================================
- class Sprite
- # ---------------------------------------------------------------------------
- include THEO::Movement # <-- implementasinya ke class Sprite
- # ---------------------------------------------------------------------------
- alias theolized_sprite_init initialize
- def initialize(viewport = nil)
- theolized_sprite_init(viewport)
- set_obj(self) # <-- ngeset diri sendiri untuk digerakin
- end
- # ---------------------------------------------------------------------------
- # Masukin update
- # ---------------------------------------------------------------------------
- alias theolized_move_update update
- def update
- theolized_move_update
- update_move
- end
- # ---------------------------------------------------------------------------
- end
- # =============================================================================
- # Class Window (yg ngehandle window) <-- u dont say
- # =============================================================================
- class Window
- # ---------------------------------------------------------------------------
- include THEO::Movement # <-- implementasinya ke class Window
- # ---------------------------------------------------------------------------
- alias theolized_move_window_init initialize
- def initialize(x, y, width, height)
- theolized_move_window_init(x, y, width, height)
- set_obj(self) # <-- ngeset diri sendiri untuk digerakin
- end
- # ---------------------------------------------------------------------------
- # Masukin update
- # ---------------------------------------------------------------------------
- alias theolized_move_update update
- def update
- theolized_move_update
- update_move
- end
- # ---------------------------------------------------------------------------
- end
- # =============================================================================
- #
- # END OF SCRIPT
- #
- # =============================================================================
Advertisement
Add Comment
Please, Sign In to add comment