Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # =============================================================================
- # THEOALLEN - OBJECT COLLISION CHECK
- # VERSION : 1.0
- # CONTACT : www.rpgmakerid.com
- # (This script documentation is written in informal indonesian language)
- # =============================================================================
- $imported = {} if $imported.nil?
- $imported[:Theo_Collision] = true
- # =============================================================================
- # CHANGE LOGS :
- # -----------------------------------------------------------------------------
- # 2013.04.30 - Started and finished script
- # =============================================================================
- =begin
- PENGENALAN:
- Script ini untuk ngecek apakah suatu object bertabrakan dengan object lain
- atau tidak. Object yang bisa dibandingin adalah Window dan Sprite.
- CARA PENGGUNAAN:
- - object.collision?(another) >> True kalo object berkolisi ama another
- 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::Collision (Diimplement ke Window ama Sprite)
- # =============================================================================
- module THEO
- module Collision
- def object_toCheck(obj)
- @check = obj if can_collision?(obj)
- end
- def border_x
- @check.x + @check.width
- end
- def border_y
- @check.y + @check.height
- end
- def can_collision?(other)
- other.is_a?(Sprite) || other.is_a?(Window)
- end
- def collision?(other)
- return false unless can_collision?(other) && @check
- return (collision_right(other) || collision_left(other)) &&
- (collision_below(other) || collision_above(other))
- end
- def collision_right(other)
- (other.x <= border_x) && (other.x > @check.x)
- end
- def collision_left(other)
- (other.border_x >= @check.x) && (other.border_x < border_x)
- end
- def collision_below(other)
- (other.y <= border_y) && (other.y > @check.y)
- end
- def collision_above(other)
- (other.border_y >= @check.y) && (other.border_y < border_y)
- end
- end
- end
- class Sprite
- include THEO::Collision
- alias theo_collision_init initialize
- def initialize(viewport = nil)
- theo_collision_init(viewport)
- object_toCheck(self)
- end
- end
- class Window
- include THEO::Collision
- alias theo_collision_init initialize
- def initialize(x,y,width,height)
- theo_collision_init(x,y,width,height)
- object_toCheck(self)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment