Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Stars
#1
Stars
A french script by an french scripter...me
corbaque
Oct 30 2006

This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.


Hello every body ^^
I'am an french maker...
So my english is really horrible xD

I would like to give you an script what I've just do ^^

Insert an script under the script "main" name it "stars" :

Code:
#===================================
# Stars
#---------------------------------------------------------------
# By Corbaque
#---------------------------------------------------------------
# I am a French maker,
# so excuse my horrible english ^^
# I created this script with english comment to
# propose it to you
# and know your opinion on my manner of
# creation
#---------------------------------------------------------------
# Contact : corbaque@hotmail.fr
# I speak french only :-(
#---------------------------------------------------------------
# 29 / 10 / 2006
#===================================
def stars(n=200, opacity=130)
  # $stars is an array
  $stars = []
  # Do to n times
  n.times do |i|
    # Defined the Sprite
    $stars[i] = Sprite.new
    # Defined the Bitmap (5 x 5)
    $stars[i].bitmap = Bitmap.new(5, 5)
    # Fill the bitmap in 3 times, to obtain an
    # Square inclined at 45 degrees
    $stars[i].bitmap.fill_rect(1, 1, 3, 3, Color.new(255, 255, 255))
    $stars[i].bitmap.fill_rect(0, 2, 5, 1, Color.new(255, 255, 255))
    $stars[i].bitmap.fill_rect(2, 0, 1, 5, Color.new(255, 255, 255))
    # Defined opacity
    $stars[i].opacity = opacity
    # The sprite is under all the other pictures
    $stars[i].z = 20000
    # Zoom at 0 (the sprite isn't visible)
    $stars[i].zoom_x = $stars[i].zoom_y = 0
    # End of loop
  end
  # End of method
end
#---------------------------------------------------------------
# Destroy the stars
#---------------------------------------------------------------
def destroy_stars
  # Do to size of the array $stars
  $stars.size.times do |i|
    # x position out of screen (debug)
    $stars[i].x = -100
    # Destroy star
    $stars[i] = nil
    # End of loop
  end
  # Destroy $stars
  $stars = nil
  # End of method
end
#---------------------------------------------------------------
# Update stars
#---------------------------------------------------------------
def update_stars(n=200, zoom=1.0)
  # if $stars isn't destroy
  if not $stars == nil
    # Do to n times
    n.times do |i|
      # Update star
      $stars[i].update
      # Move the star according to its angle
      $stars[i].x -= Math.cos(-$stars[i].angle * Math::PI / 180) * 3
      $stars[i].y -= Math.sin(-$stars[i].angle * Math::PI / 180) * 3
      # Increase the size of star
      $stars[i].zoom_x += 0.005 * zoom
      $stars[i].zoom_y += 0.005 * zoom
      # if the star is out of screen
      if $stars[i].x < 0 || $stars[i].x > 640 || $stars[i].y < 0 || $stars[i].y > 480
        # Defined angle into random angle    
        # Between 0 and 360.0, first decimal included
        $stars[i].angle = rand(3600) / 10.0
        # Defined position x and y starting from
        # A convertion polar-cartesian starting
        # From the angle of star converted into
        # Radian, and on a random ray of value
        # Between 1 and 101.
        $stars[i].x, $stars[i].y = p_c(rand(100) + 1, $stars[i].angle * Math::PI / 180.0)
        # center star
        $stars[i].x += 320
        $stars[i].y += 240
        # mirror of the x position (debug)
        $stars[i].x -= 640
        $stars[i].x *= -1
        # defined zoom to 0.2 (20%)
        $stars[i].zoom_x = $stars[i].zoom_y = 0.2
        # End of condition
      end
      # End of loop
    end
    # End of condition
  end
  # End of method
end
#---------------------------------------------------------------
# convertion polar-cartesian
#---------------------------------------------------------------
def p_c(ray, teta)
  # x = ray multiplied by the cosine of teta
  x = ray * Math.cos(teta)
  y = ray * Math.sin(teta)
  # Retourn x and y position
  return x, y
  # End of method
end





To use it, creat an event in parallel process, with an flag on condition, insert into it a script :
Code:
update_stars(n, zoom)

n = number of stars(200)
zoom = factor of speed of zoom (1.0)

For initialize this effect, into an event, use this :
<>insert a script :
Code:
stars(n, opacity)

n = number of stars (200)
opacity = opacity of stars (130)
<> flag active # update active

To destroy the stars use it :
<> flag desactive # update not active
insert script :
Code:
destroy_stars


200 stars, 130 of opacity, 1 on factor of zoom :
(missing pic)


And all the stars move ^^
Random position ect...
Try to use it =)

so, what do you think to this ?

PS :
If an moderator pass by there, thanks him to correct my (enormous) faults ^^"

Corbaque.
}




Users browsing this thread: