Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- =begin
- CREER UNE PARTICULE :
- COLOR = [240,30,30] #<= Best color
- $game_map.particule.push(Game_Particule.new(X,Y,ANGLE,FORCE,COLOR,$game_map.nbr_particule))
- $game_map.nbr_particule += 1
- =end
- module Math
- CONV = 3.141592654/180.0
- def self.angle_between(x1,y1,x2,y2)
- x = (x1-x2).to_f
- y = (y1-y2).to_f
- if x < 0.0 && y < 0.0
- angle = atan(x/y)*180.0/PI
- elsif x < 0.0 && y > 0.0
- angle = 180.0+atan(x/y)*180.0/PI
- elsif x >= 0.0 && y < 0.0
- angle = 360.0-atan(-x/y)*180.0/PI
- else
- angle = 180.0+atan(x/y)*180.0/PI
- end
- angle -= 180.0
- angle = 90.0 if angle.nan?
- return angle%360
- end
- def self.get_charact(st,en,txt)
- return false unless txt
- id = txt.index(st)
- return false unless id
- id += st.length
- res = ""
- for i in id...txt.length
- break if txt[i...i+en.length] == en
- res += txt[i]
- end
- return res
- end
- def self.intersect(x,y,angle,rect)
- result = []
- x2 = rect[0]
- y2 = rect[1]
- w = rect[2]
- h = rect[3]
- a = 1/tan(angle*CONV)
- b = y-a*x
- c1 = a*x2+b
- c2 = a*(x2+w)+b
- c3 = a != 0 ? (y2-b)/a : -10
- c4 = a != 0 ? (y2+h-b)/a : -10
- d = 0; e = 0;
- d = 1 if angle > 0
- e = 1 if angle.abs < 90
- if (d == 0 && x2 <= x)||
- (d == 1 && x2 >= x)
- result.push([x2,c1]) if c1 > y2 && c1 < y2+h
- end
- if(d == 0 && x2+w <= x)||
- (d == 1 && x2+w >= x)
- result.push([x2+w,c2]) if c2 > y2 && c2 < y2+h
- end
- if(e == 0 && y2 <= y)||
- (e == 1 && y2 >= y)
- result.push([c3,y2]) if c3 > x2 && c3 < x2+w
- end
- if(e == 0 && y2+h <= y)||
- (e == 1 && y2+h >= y)
- result.push([c4,y2+h]) if c4 > x2 && c4 < x2+w
- end
- return result
- end
- def self.pos_line(x,y,angle,dist)
- x2 = x + cos(angle*CONV)*dist
- y2 = y + sin(angle*CONV)*dist
- return [x2,y2]
- end
- end
- class Game_Map
- attr_accessor :particule
- attr_accessor :nbr_particule
- alias initialize_arpg_system_particule initialize
- def initialize
- @particule = []
- @nbr_particule = 0
- initialize_arpg_system_particule
- end
- alias setup_arpg_system_particule setup
- def setup(map_id)
- setup_arpg_system_particule(map_id)
- refresh_particule
- end
- def refresh_particule
- @particule = []
- @nbr_particule = 0
- end
- alias update_arpg_system_particule update
- def update(main = false)
- update_arpg_system_particule(main)
- update_particule
- end
- def update_particule
- i = 0
- while i != @particule.length
- if @particule[i].deleted?
- @particule.delete_at(i) rescue true
- else
- i += 1
- end
- end
- end
- end
- class Spriteset_Map
- alias initialize_arpg_system_particule initialize
- def initialize
- initialize_particule
- create_particule
- @map_id = $game_map.map_id
- end
- def create_particule
- @particules_sprites = {}
- end
- alias dispose_arpg_system_particule dispose
- def dispose
- dispose_arpg_system_particule
- dispose_particule
- end
- def dispose_particule
- @particules_sprites.each {|id,sprite| sprite.dispose }
- create_particule
- end
- alias update_arpg_system_particule update
- def update
- update_particule
- update_arpg_system_particule
- @map_id = $game_map.map_id
- end
- def update_particule
- if @map_id != $game_map.map_id
- @particules_sprites.each do |key,value|
- value.dispose
- end
- @particules_sprites = {}
- else
- id = []
- $game_map.particule.each do |part|
- @particules_sprites[part.id] ||= Sprite_Particule.new(part,@parallax)
- @particules_sprites[part.id].update
- if @particules_sprites[part.id].disposed?
- part.delete = true
- id.push(part.id)
- end
- end
- @particules_sprites.each do |key,value|
- if id.include?(key)
- @particules_sprites.delete(key)
- end
- end
- end
- end
- end
- class Game_Particule
- attr_accessor :x
- attr_accessor :y
- attr_accessor :angle
- attr_accessor :force
- attr_accessor :id
- attr_accessor :delete
- attr_accessor :color
- attr_accessor :param
- def initialize(x,y,angle,force,color,id,param_plus = {})
- @x = x
- @y = y
- @angle = angle
- @force = force
- @color = color
- @id = id
- @param = param_plus
- @delete = false
- end
- def deleted?
- return @delete
- end
- end
- class Spriteset_Map
- alias update_parallax_arpg update_parallax
- def update_parallax
- update_parallax_arpg
- @parallax.ox = $game_map.display_x * 32
- @parallax.oy = $game_map.display_y * 32
- end
- end
- class Sprite_Particule < Sprite
- CONV = 3.141592654/180.0
- COULEUR = [20,20,20]
- COULEUR_1 = 0
- def initialize(particule,sprite_parra)
- super($viewport)
- @x = particule.x
- @y = particule.y
- @angle = particule.angle
- @force = particule.force
- @color_base = particule.color
- @vit_base = particule.param[:vitesse] ? particule.param[:vitesse] : 3
- @timer = rand(2)
- @particule = []
- @parrallax = sprite_parra
- create_particule
- create_bitmap
- end
- def dispose
- bitmap.dispose if bitmap
- super
- end
- def create_particule
- @distance = @force*20
- for i in 0...@force*4
- x = 0.0
- y = 0.0
- a = (5.0-rand(10))/10.0
- var = [@color_base[0]*2/3,@color_base[1]*2/3,@color_base[2]*2/3]
- b = [@color_base[0]/3+rand(var[0]),@color_base[1]/3+rand(var[1]),@color_base[2]/3+rand(var[2])]
- @particule.push([x,y,a,b])
- end
- end
- def create_bitmap
- self.bitmap = Bitmap.new(@distance*2,@distance*4)
- self.ox = self.width/2
- self.x = @x + $game_map.display_x * 32
- self.y = @y + $game_map.display_y * 32
- self.z = 1
- self.angle = 180.0+@angle
- update_bitmap
- end
- def update
- unless disposed?
- super
- return unless @parrallax.bitmap
- update_position
- update_bitmap if @timer % 2 == 0
- @timer += 1
- end
- end
- def update_position
- begin
- self.x = (@x - $game_map.display_x*32)
- self.y = (@y - $game_map.display_y*32)
- bit = Bitmap.new(2,2)
- a = (@angle%360)*CONV
- for i in 0...@particule.length
- x = @particule[i][0]+[@vit_base.to_f*2.5/@timer.to_f,@vit_base.to_f].min+2-rand(4)
- y = @particule[i][1]+@particule[i][2]*[@vit_base.to_f*2.0/@timer.to_f,@vit_base.to_f].min
- @particule[i][0] = x
- @particule[i][1] = y
- x2 = -x*2/3*Math.sin(a).to_f + y*(1+rand(2))*Math.cos(a).to_f
- y2 = -x*2/3*Math.cos(a).to_f - y*(1+rand(2))*Math.sin(a).to_f
- unless $game_map.contact.check_pixel(@x+x2, @y+y2)
- b = rand(5)
- else
- b = 10+rand(20)
- end
- if @parrallax.bitmap.get_pixel(@x+x2, @y+y2).red < 170
- co = Color.new([@particule[i][3][0]-@timer,0].max,[@particule[i][3][1]-@timer,0].max,[@particule[i][3][2]-@timer,0].max,b)
- bit.fill_rect(0,0,2,2,co)
- end
- @parrallax.bitmap.blt(@x+x2, @y+y2,bit,bit.rect)
- end
- rescue
- return
- end
- end
- def update_bitmap
- begin
- self.bitmap.clear
- #~ self.bitmap.fill_rect(0,0,width,height, Color.new(255,255,255,50))
- result = []
- for i in 0...@particule.length
- a = 255-Math.exp(@particule[i][0]/10)
- result.push(a)
- co = Color.new(@particule[i][3][0],@particule[i][3][1],@particule[i][3][2],a)
- self.bitmap.fill_rect(@particule[i][1]+@distance, @particule[i][0],2,2, co)
- end
- dispose if result.max < 0
- rescue
- return
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement