Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

> New Particle Engine, RGSS Script / By arevulopapo
SeeYouAlways
post Nov 29 2007, 08:59 PM
Post #1


Demented Moogle
Group Icon

Group: Banned
Posts: 1,130
Type: None
RM Skill: Undisclosed




New Particle Engine

Script: http://www.rpgrevolution.com/script/49
Author: arevulopapo
Language: Ruby Game Scripting System (RGSS)

Post anything related to the script in this topic.
- You may ask for support, but do not always expect an answer from the author of the script (however, other skilled scripters may provide assistance where possible).
- Please report any bugs if you find any, so the script may be fixed to work properly.
- Feel free to suggest new additions or improvements to the script.
- Feel free to post other comments regarding this script.


Script
CODE
#===============================================================================
# New Particle Engine
#   by arevulopapo
#   Nov 15th 2007
#
# This script lets you create particle effects in your game.
# Particles are integrated into "Spriteset_Map,
# so the can be displayed over/under an event.
# Effects are called from "Script" command like this:
# $scene.effect(EVENT_ID, EFFECT, LOCK, X, Y)
# EVENT_ID  - ID of an event the particles will flow from.
#             (-1) for player, (1) and above for events.
# EFFECT    - name of the effect to call. Names are defined in the Spriteset_Map.
# LOCK      - alignment of the particles. 'event' to align particles
#             with event's map position, 'screen' to align with event's screen position.
#             For static events, like fireplaces, teleports, etc. 'event' alignment is recommended.
#             For moving events use 'screen' mode.
# X, Y      - number of pixels that will be added to the event's position
#             to determine the starting point of particles.
#             That's your most powerful weapon;) See the demo for examples.
#===============================================================================
class Scene_Map
  
  def effect(event=1, effect='', lock='event', x=0, y=0)
    @spriteset.add_effect(event, effect, lock, x, y)
  end
  
end
#===============================================================================
#
#===============================================================================
class Spriteset_Map
  
  attr_reader :particles
  
  alias particle_ssm_init initialize
  alias particle_ssm_update update
  alias particle_ssm_dispose dispose
  #-----------------------------------------------------------------------------
  def initialize
    @particles = []
    particle_ssm_init
  end
  #-----------------------------------------------------------------------------
  def dispose
    @particles.each{ |d| d.dispose }
    particle_ssm_dispose
  end
  #-----------------------------------------------------------------------------
  def update
    @particles.each_with_index{ |p,i|
      @particles[i].update
      if p.opacity == 0
        p.dispose
        @particles.delete_at(i)
      end
      }
    particle_ssm_update
  end
  #-----------------------------------------------------------------------------
  def add_effect(event=1, effect='', lock='event', x=0, y=0)
    
    case event
    when -1
      object = $game_player
    else
      object = $game_map.events[event]
    end
    
    case effect
    # (sprite, acceleration[x,y], gravity[x,y], opacity[base,loss], blending)
    when 'blue'
      sprite='star_blue'
      add_particles(object, x, y, sprite, [1.00*(-15+rand(30))/10, 1.00*(-15+rand(30))/10], [0,0], [160,5+rand(15)], lock, 1)
    when 'red'
      sprite='star_red'
      add_particles(object, x, y, sprite, [1.00*(-15+rand(30))/10, 1.00*(-15+rand(30))/10], [0,0], [160,5+rand(15)], lock, 1)
    when 'green'
      sprite='star_green'
      add_particles(object, x, y, sprite, [1.00*(-15+rand(30))/10, 1.00*(-15+rand(30))/10], [0,0], [160,5+rand(15)], lock, 1)
    when 'yellow'
      sprite='star_yellow'
      add_particles(object, x, y, sprite, [1.00*(-15+rand(30))/10, 1.00*(-15+rand(30))/10], [0,0], [160,5+rand(15)], lock, 1)
    when 'smash'
      sprite='smash'
      add_particles(object, x, y, sprite, [1.00*(-15+rand(30))/10, 1.00*(-15+rand(30))/10], [0,0], [160,5+rand(15)], lock, 1)
    when 'fire'
      sprite='particle_yellow'
      add_particles(object, x, y, sprite, [(rand(7)-3)*0.2, 0], [0,0.15], [255,8+rand(5)], lock, 1)
    when 'fire2'
      sprite='particle_orange'
      add_particles(object, x, y, sprite, [(rand(7)-3)*0.2, 0], [0,0.15], [255,8+rand(5)], lock, 1)
    when 'sparks'
      sprite='particle_red'
      add_particles(object, x, y, sprite, [0.5*(-25+rand(50))/10, -4], [0,-0.5], [255,20], lock, 1)
    when 'smoke'
      sprite='smoke'
      add_particles(object, x, y, sprite, [0.1*(-25+rand(50))/10, 0], [0,0.13], [128,3], lock, 1)
    when 'cells'
      sprite='particle_red'
      dx = 1.00*(-100 + rand(200))/100
      dy = 1.00*(-100 + rand(200))/100
      add_particles(object, x, y, sprite, [5*dx, 5*dy], [0.3*dx,0.3*dy], [255,10], lock, 1)
      #sines
    when 'black'
      sprite='star_sine'
      add_particles(object, x, y, sprite, [(rand(7)-3)*0.2, 0], [0,0.15], [255,8+rand(5)], lock, 1)
      #sines end
      end
    end
  #-----------------------------------------------------------------------------
  def add_particles(object=$game_player, x=0, y=0, sprite='', acc=[0,0], grav=[0,0], opacity=[255,0], lock='event', blend=0)
    if lock=='event'
      @particles << Particle_Event.new(@viewport1, object, x, y, sprite, acc, grav, opacity, blend)
    elsif lock=='screen'
      @particles << Particle_Screen.new(@viewport1, object, x, y, sprite, acc, grav, opacity, blend)
    end
  end
  
end
#===============================================================================
#
#===============================================================================
class Particle_Screen < Sprite
  
  def initialize(viewport=Viewport.new(0,0,800,600), object=$game_player, x=0, y=0, sprite='', acc=[0,0], grav=[0,0], opacity=[255,3], blend=0)
    super(viewport)
    self.bitmap = RPG::Cache.picture('Particles/' + sprite)
    self.x = object.screen_x + x
    self.y = object.screen_y - 16 + y
    self.ox = self.oy = self.bitmap.width/2
    self.blend_type = blend
    self.opacity = opacity[0]
    @object = object
    @origin = [self.x, self.y]
    @acceleration = acc
    @gravity = grav
    @coords = [0.00, 0.00]
    @opacity = opacity[1]
    update
  end
  
  def update
    @acceleration[0] -= @gravity[0] if @gravity[0] != 0
    @acceleration[1] -= @gravity[1] if @gravity[1] != 0
    @coords[0] += @acceleration[0]
    @coords[1] += @acceleration[1]
    self.opacity -= @opacity
    self.x = @origin[0] + @coords[0]
    self.y = @origin[1] + @coords[1]
    if self.y > (@object.screen_y - 16)
      self.z = @object.screen_z + 32
    else
      self.z = @object.screen_z - 32
    end
  end
  
end

class Particle_Event < Sprite
  
  def initialize(viewport=Viewport.new(0,0,800,600), object=$game_player, x=0, y=0, sprite='', acc=[0,0], grav=[0,0], opacity=[255,3], blend=0)
    super(viewport)
    self.bitmap = RPG::Cache.picture('Particles/' + sprite)
    self.x = object.x*32 + 16 - $game_map.display_x / 4 + x
    self.y = object.y*32 + 32 - $game_map.display_y / 4 + y
    self.ox = self.oy = self.bitmap.width/2
    self.blend_type = blend
    self.opacity = opacity[0]
    @object = object
    @origin = [object.x*32 + x + 16, object.y*32 + y + 32]
    @acceleration = acc
    @gravity = grav
    @coords = [0.00, 0.00]
    @opacity = opacity[1]
    update
  end
  
  def update
    @acceleration[0] -= @gravity[0] if @gravity[0] != 0
    @acceleration[1] -= @gravity[1] if @gravity[1] != 0
    @coords[0] += @acceleration[0]
    @coords[1] += @acceleration[1]
    self.opacity -= @opacity
    self.x = @origin[0] + @coords[0] - $game_map.display_x / 4
    self.y = @origin[1] + @coords[1] - $game_map.display_y / 4 - 16
    if self.y > (@object.screen_y - 16)
      self.z = @object.screen_z + 32
    else
      self.z = @object.screen_z - 32
    end
  end
  
end


Instructions
This script uses the pictures found in the Graphics/Pictures/Particles folder (see demo). The script assumes that the picture input is square, and will offset the image to half the width, in both the x & y coordinates, and will randomly accelerate the particle away from the object is it attached to.
Refer to the comments at the start of the code for more details.


__________________________
Go to the top of the page
 
+Quote Post
   
 
Start new topic
Replies (1 - 5)
elfyelf
post Dec 2 2007, 09:05 PM
Post #2


(~*A D A N*~)
Group Icon

Group: Revolutionary
Posts: 436
Type: Developer
RM Skill: Advanced




I cant play it because it says this:

RGSS102E.dll is missing


__________________________
Go to the top of the page
 
+Quote Post
   
SeeYouAlways
post Dec 2 2007, 11:45 PM
Post #3


Demented Moogle
Group Icon

Group: Banned
Posts: 1,130
Type: None
RM Skill: Undisclosed




That probably means you haven't installed the RPG Maker XP English RTP. Download it and install it from here:

http://www.rpgrevolution.com/rmxp/download


__________________________
Go to the top of the page
 
+Quote Post
   
hegerp
post Apr 13 2008, 01:04 AM
Post #4


Level 2
Group Icon

Group: Member
Posts: 25
Type: Developer
RM Skill: Advanced




It crashes for me when I want to save on a map where there are particles.

It doesn't crash when I save but when I want to load it...
Go to the top of the page
 
+Quote Post
   
KelJar87
post May 31 2008, 02:10 AM
Post #5



Group Icon

Group: Member
Posts: 2
Type: Developer
RM Skill: Skilled




Does anyone know how to display the particles over the events?
Go to the top of the page
 
+Quote Post
   
4tutoralcom
post Jun 20 2008, 09:50 AM
Post #6



Group Icon

Group: Member
Posts: 1
Type: None
RM Skill: Undisclosed




QUOTE (KelJar87 @ May 31 2008, 04:24 AM) *
Does anyone know how to display the particles over the events?

if you are using the same New Particle Engine by "arevulopapo" then you need to first check your event's always on top option is suppose to be on.
The script the particles will be over the event.
if this isn't the same script use this
CODE
#===============================================================================
# New Particle Engine
#   by arevulopapo
#   Nov 15th 2007
#
# This script lets you create particle effects in your game.
# Particles are integrated into "Spriteset_Map,
# so the can be displayed over/under an event.
# Effects are called from "Script" command like this:
# $scene.effect(EVENT_ID, EFFECT, LOCK, X, Y)
# EVENT_ID  - ID of an event the particles will flow from.
#             (-1) for player, (1) and above for events.
# EFFECT    - name of the effect to call. Names are defined in the Spriteset_Map.
# LOCK      - alignment of the particles. 'event' to align particles
#             with event's map position, 'screen' to align with event's screen position.
#             For static events, like fireplaces, teleports, etc. 'event' alignment is recommended.
#             For moving events use 'screen' mode.
# X, Y      - number of pixels that will be added to the event's position
#             to determine the starting point of particles.
#             That's your most powerful weapon;) See the demo for examples.
#===============================================================================
class Scene_Map
  
  def effect(event=1, effect='', lock='event', x=0, y=0)
    @spriteset.add_effect(event, effect, lock, x, y)
  end
  
end
#===============================================================================
#
#===============================================================================
class Spriteset_Map
  
  attr_reader :particles
  
  alias particle_ssm_init initialize
  alias particle_ssm_update update
  alias particle_ssm_dispose dispose
  #-----------------------------------------------------------------------------
  def initialize
    @particles = []
    particle_ssm_init
  end
  #-----------------------------------------------------------------------------
  def dispose
    @particles.each{ |d| d.dispose }
    particle_ssm_dispose
  end
  #-----------------------------------------------------------------------------
  def update
    @particles.each_with_index{ |p,i|
      @particles[i].update
      if p.opacity == 0
        p.dispose
        @particles.delete_at(i)
      end
      }
    particle_ssm_update
  end
  #-----------------------------------------------------------------------------
  def add_effect(event=1, effect='', lock='event', x=0, y=0)
    
    case event
    when -1
      object = $game_player
    else
      object = $game_map.events[event]
    end
    
    case effect
    # (sprite, acceleration[x,y], gravity[x,y], opacity[base,loss], blending)
    when 'blue'
      sprite='star_blue'
      add_particles(object, x, y, sprite, [1.00*(-15+rand(30))/10, 1.00*(-15+rand(30))/10], [0,0], [160,5+rand(15)], lock, 1)
    when 'red'
      sprite='star_red'
      add_particles(object, x, y, sprite, [1.00*(-15+rand(30))/10, 1.00*(-15+rand(30))/10], [0,0], [160,5+rand(15)], lock, 1)
    when 'green'
      sprite='star_green'
      add_particles(object, x, y, sprite, [1.00*(-15+rand(30))/10, 1.00*(-15+rand(30))/10], [0,0], [160,5+rand(15)], lock, 1)
    when 'yellow'
      sprite='star_yellow'
      add_particles(object, x, y, sprite, [1.00*(-15+rand(30))/10, 1.00*(-15+rand(30))/10], [0,0], [160,5+rand(15)], lock, 1)
    when 'smash'
      sprite='smash'
      add_particles(object, x, y, sprite, [1.00*(-15+rand(30))/10, 1.00*(-15+rand(30))/10], [0,0], [160,5+rand(15)], lock, 1)
    when 'fire'
      sprite='particle_yellow'
      add_particles(object, x, y, sprite, [(rand(7)-3)*0.2, 0], [0,0.15], [255,8+rand(5)], lock, 1)
    when 'fire2'
      sprite='particle_orange'
      add_particles(object, x, y, sprite, [(rand(7)-3)*0.2, 0], [0,0.15], [255,8+rand(5)], lock, 1)
    when 'sparks'
      sprite='particle_red'
      add_particles(object, x, y, sprite, [0.5*(-25+rand(50))/10, -4], [0,-0.5], [255,20], lock, 1)
    when 'smoke'
      sprite='smoke'
      add_particles(object, x, y, sprite, [0.1*(-25+rand(50))/10, 0], [0,0.13], [128,3], lock, 1)
    when 'cells'
      sprite='particle_red'
      dx = 1.00*(-100 + rand(200))/100
      dy = 1.00*(-100 + rand(200))/100
      add_particles(object, x, y, sprite, [5*dx, 5*dy], [0.3*dx,0.3*dy], [255,10], lock, 1)
      #sines
    when 'black'
      sprite='star_sine'
      add_particles(object, x, y, sprite, [(rand(7)-3)*0.2, 0], [0,0.15], [255,8+rand(5)], lock, 1)
      #sines end
      end
    end
  #-----------------------------------------------------------------------------
  def add_particles(object=$game_player, x=0, y=0, sprite='', acc=[0,0], grav=[0,0], opacity=[255,0], lock='event', blend=0)
    if lock=='event'
      @particles << Particle_Event.new(@viewport1, object, x, y, sprite, acc, grav, opacity, blend)
    elsif lock=='screen'
      @particles << Particle_Screen.new(@viewport1, object, x, y, sprite, acc, grav, opacity, blend)
    end
  end
  
end
#===============================================================================
#
#===============================================================================
class Particle_Screen < Sprite
  
  def initialize(viewport=Viewport.new(0,0,800,600), object=$game_player, x=0, y=0, sprite='', acc=[0,0], grav=[0,0], opacity=[255,3], blend=0)
    super(viewport)
    self.bitmap = RPG::Cache.picture('Particles/' + sprite)
    self.x = object.screen_x + x
    self.y = object.screen_y - 16 + y
    self.ox = self.oy = self.bitmap.width/2
    self.blend_type = blend
    self.opacity = opacity[0]
    @object = object
    @origin = [self.x, self.y]
    @acceleration = acc
    @gravity = grav
    @coords = [0.00, 0.00]
    @opacity = opacity[1]
    update
  end
  
  def update
    @acceleration[0] -= @gravity[0] if @gravity[0] != 0
    @acceleration[1] -= @gravity[1] if @gravity[1] != 0
    @coords[0] += @acceleration[0]
    @coords[1] += @acceleration[1]
    self.opacity -= @opacity
    self.x = @origin[0] + @coords[0]
    self.y = @origin[1] + @coords[1]
    if self.y > (@object.screen_y - 16)
      self.z = @object.screen_z + 32
    else
      self.z = @object.screen_z - 32
    end
  end
  
end

class Particle_Event < Sprite
  
  def initialize(viewport=Viewport.new(0,0,800,600), object=$game_player, x=0, y=0, sprite='', acc=[0,0], grav=[0,0], opacity=[255,3], blend=0)
    super(viewport)
    self.bitmap = RPG::Cache.picture('Particles/' + sprite)
    self.x = object.x*32 + 16 - $game_map.display_x / 4 + x
    self.y = object.y*32 + 32 - $game_map.display_y / 4 + y
    self.ox = self.oy = self.bitmap.width/2
    self.blend_type = blend
    self.opacity = opacity[0]
    @object = object
    @origin = [object.x*32 + x + 16, object.y*32 + y + 32]
    @acceleration = acc
    @gravity = grav
    @coords = [0.00, 0.00]
    @opacity = opacity[1]
    update
  end
  
  def update
    @acceleration[0] -= @gravity[0] if @gravity[0] != 0
    @acceleration[1] -= @gravity[1] if @gravity[1] != 0
    @coords[0] += @acceleration[0]
    @coords[1] += @acceleration[1]
    self.opacity -= @opacity
    self.x = @origin[0] + @coords[0] - $game_map.display_x / 4
    self.y = @origin[1] + @coords[1] - $game_map.display_y / 4 - 16
    if self.y > (@object.screen_y - 16)
      self.z = @object.screen_z + 32
    else
      self.z = @object.screen_z - 32
    end
  end
  
end


This post has been edited by puppeto4: Jun 21 2008, 10:51 AM
Go to the top of the page
 
+Quote Post
   

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 19th June 2013 - 08:32 AM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker