ippa-movie_maker 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/History.txt +27 -0
  2. data/README.rdoc +154 -0
  3. data/Rakefile +19 -0
  4. data/examples/axe.rb +24 -0
  5. data/examples/balls.rb +20 -0
  6. data/examples/echoes.rb +30 -0
  7. data/examples/gosu_base.rb +40 -0
  8. data/examples/gosu_rain.rb +34 -0
  9. data/examples/gosu_river_of_stars.rb +35 -0
  10. data/examples/gosu_triangles.rb +34 -0
  11. data/examples/gosu_wish_upon_a_star.rb +48 -0
  12. data/examples/ippagaming_intro.rb +23 -0
  13. data/examples/media/23700__hazure__chop.wav +0 -0
  14. data/examples/media/Establo.ttf +0 -0
  15. data/examples/media/FeaturedItem.ttf +0 -0
  16. data/examples/media/FreeSans.ttf +0 -0
  17. data/examples/media/Hursheys.ttf +0 -0
  18. data/examples/media/axe.png +0 -0
  19. data/examples/media/axe.svg +136 -0
  20. data/examples/media/ball.png +0 -0
  21. data/examples/media/ball.svg +182 -0
  22. data/examples/media/black.bmp +0 -0
  23. data/examples/media/blue_triangle.png +0 -0
  24. data/examples/media/blue_triangle.svg +81 -0
  25. data/examples/media/chop.wav +0 -0
  26. data/examples/media/cloth_background.png +0 -0
  27. data/examples/media/drawing.svg +86 -0
  28. data/examples/media/drip.wav +0 -0
  29. data/examples/media/green_triangle.png +0 -0
  30. data/examples/media/green_triangle.svg +104 -0
  31. data/examples/media/hit.wav +0 -0
  32. data/examples/media/ippa_gaming.png +0 -0
  33. data/examples/media/ippa_gaming.svg +463 -0
  34. data/examples/media/oil_drip.wav +0 -0
  35. data/examples/media/outdoor_scene.bmp +0 -0
  36. data/examples/media/outdoor_scene.png +0 -0
  37. data/examples/media/outdoor_scene.svg +316 -0
  38. data/examples/media/rain-bak1.wav +0 -0
  39. data/examples/media/rain.wav +0 -0
  40. data/examples/media/rain2.wav +0 -0
  41. data/examples/media/raindrop.png +0 -0
  42. data/examples/media/raindrop.svg +87 -0
  43. data/examples/media/raindrop_small.bmp +0 -0
  44. data/examples/media/raindrop_small.png +0 -0
  45. data/examples/media/red_triangle.png +0 -0
  46. data/examples/media/red_triangle.svg +81 -0
  47. data/examples/media/spaceship_noalpha.png +0 -0
  48. data/examples/media/star_5.png +0 -0
  49. data/examples/media/star_5.svg +83 -0
  50. data/examples/media/star_6.png +0 -0
  51. data/examples/media/star_6.svg +86 -0
  52. data/examples/rain.rb +26 -0
  53. data/examples/rain_advanced.rb +26 -0
  54. data/examples/rubygame_river_of_stars.rb +28 -0
  55. data/examples/zoom.rb +27 -0
  56. data/lib/movie_maker.rb +411 -0
  57. data/lib/movie_maker/action.rb +389 -0
  58. data/lib/movie_maker/core_extensions.rb +17 -0
  59. data/lib/movie_maker/gosu_autoload.rb +38 -0
  60. data/lib/movie_maker/gosu_clock.rb +139 -0
  61. data/lib/movie_maker/named_resource.rb +254 -0
  62. data/lib/movie_maker/sprite.rb +157 -0
  63. metadata +126 -0
data/History.txt ADDED
@@ -0,0 +1,27 @@
1
+ === 0.3.0 2009-08-17
2
+ - new name, new gemified filestructure, gemspec
3
+
4
+ === 0.x 2008-08-13
5
+ - Too much to list. New shiny API, better c0dezetc.
6
+ - this CHANGELOG deprecated until further.
7
+ - See http://github.com/ippa/rubygame_movie_maker/commits/master for changes.
8
+
9
+ === 0.x 2008-08-06:
10
+ - Too much to list, but new actions.. zoom, rotate, play_sound etc
11
+ - Better chaining with "after" method
12
+ - Alot more samples
13
+
14
+ === 0.x 2008-08-05:
15
+ - various renaming, :target_surface => :screen, :surface => sprite
16
+ - All action-work is now done with sprites instead of surfaces, a sprite must meet some common rubygameish criterias: have attributes x,y and image.
17
+ - make it more rubygame'ish
18
+
19
+ === 0.x 2008-07-31:
20
+ - New better namespace/class names
21
+ - able to pass a Color to :background params
22
+ - new examples
23
+ - better organizing of files
24
+ - screen.update Outside of eventloop makes stuff faster :)
25
+
26
+ === 0.x 2008-07-30:
27
+ - first version with basic example
data/README.rdoc ADDED
@@ -0,0 +1,154 @@
1
+ = MovieMaker README
2
+ http://github.com/ippa/movie_maker/tree/master
3
+
4
+ == DESCRIPTION
5
+ Automate image movements/effects and sounds over a period of time, useful for games.
6
+
7
+ == What is it?
8
+ A rubylibrary to automate sprite movement/effects and sound over a timeline.
9
+ Either Rubygame (SDL) or Gosu (OpenGL) does the heavy lifting for us when it comes to drawing on the screen.
10
+ MovieMaker transparently supports both gamelibraries.
11
+
12
+ Use it for intros, ingame animations and simple "demos". Namingconventions tries to follow Rubygame.
13
+ It's also easy extendable with own actions. Documentation about that comming as soon as someone wants it =).
14
+
15
+ == Features:
16
+
17
+ Basic:
18
+ * @movie = MovieMaker.new
19
+ * @movie.resource(@sprite) - choose a resource (for now, a sprite) that following commands will apply on
20
+
21
+ Timeline methods
22
+
23
+ * @movie.between(start_at, stop_at) - following actions are performered between start_at/stop_at (seconds in floats)
24
+ * @movie.at(start_at) - following actions are performered once at start_at seconds into the movie
25
+ * @movie.delay(delay) - pause timeline for delay seconds
26
+ * @movie.during(time) - perform actions during time in seconds, starting right after the last action
27
+ * @movie.then - perform next action after the last one finishes
28
+
29
+ Action modifying a resource + are influenced by the timeline methods
30
+
31
+ * @movie.move([x,y]) - move sprite to x,y coordinates
32
+ * @movie.move_facing_direction([x,y]) - move sprite to x,y coordinates, but also turn the sprite in that direction using angle
33
+ * @movie.zoom(factor) - zoom height/width by factor (factor of 2 doubles the size, 0.5 makes it half the size)
34
+ * @movie.rotate(angle) - rotates clockwise for angle degrees. Give negative angles to rotate counterclockwise.
35
+ * @movie.fade_out - Fades to total transperency, only GOSU so far.
36
+
37
+ Actions modifying a resource
38
+
39
+ * @movie.acceleration([x,y]) - accelerates resource with the specified [x,y] offset. For example [-1,0] would make object accelerate left.
40
+ * @movie.velocity([x,y]) - sets static velocity specified [x,y] offset. For example [-1,0] would make object move left in a constant rate.
41
+
42
+ Actions doing a single thing
43
+
44
+ * @movie.play_sound(sound) - Play sound-object
45
+
46
+
47
+ All commands are chainable for a clear and verbose way of building scenes. For example:
48
+ @movie.resource(@cat).move([0,100]).between(0,5).move([500,100]).rotate(360).then.during(4).move([500,600]).then.play_sound(@sound)
49
+
50
+ see samples/ dir for more examples.
51
+
52
+ == Use it for:
53
+ === Intros
54
+ Build up your game with a intro
55
+
56
+ === ingame animations
57
+ You can make the movie play by calling update on it in your gameloop -- just like you do with your rubygame sprites/spritegroups. Note - this remains to be tested in an example.
58
+
59
+ === Simple demos for your local demoparty
60
+
61
+
62
+ == Simple example
63
+ create your sprite (should include rubygames Sprites::Sprite):
64
+ @sprite = Sprite.new("sprite.png")
65
+
66
+ Sets up the movie, give it your initiated @screen-object and @background. MovieMaker supports autocreation of simple colored background as you can see bellow
67
+ movie = MovieMaker::Movie.new(:screen => @screen, :background => Color[:black])
68
+
69
+ 1 sec (1000ms) into the movie, start moving the sprite from x/y: 0,0 (top left of the screen)
70
+ during 9 seconds (until 10000ms into the movie), set the speed so it will reach position x/y 800,600.
71
+ @movie.resource(@sprite).move([0,0]).between(1,10).move([800,600])
72
+
73
+ Play the movie you're created, blocks until it's done
74
+ @movie.play
75
+
76
+
77
+ == Chaining Simple example
78
+ movie_maker supports various chaining of actions, we could for example modify our last example like this:
79
+ Between seconds 1-9, move the sprite across the screen,rotate it 360 degrees at the same time, and when it's done, play a sound woff. Without the ".after."-chaining the sound would have been played after 1 seconds, not 10.
80
+ @movie.resource(@sprite).move([0,0]).between(1,10).move([800,600]).rotate(360).then.play_sound(Sound["woff.wav"])
81
+
82
+
83
+ == Gosu Example
84
+ Since Gosu has a different approach then rubygame a longer example is needed:
85
+
86
+ class MovieMakerWindow < Gosu::Window
87
+ def initialize
88
+ $screen = super(800, 600, false)
89
+
90
+ # Make Surface & Sound behave like shortcuts to GOSUs Image & Sample
91
+ require 'gosu_autoload'
92
+
93
+ # Set our autoloading dirs for quick and easy access to images and samples
94
+ Surface.autoload_dirs = [ File.join("samples", "media"), "media" ]
95
+ Sound.autoload_dirs = [ File.join("samples", "media"), "media" ]
96
+
97
+ @clock = ::Gosu::Clock.new
98
+ @clock.target_framerate = 200
99
+
100
+ setup_movie
101
+ end
102
+
103
+ #
104
+ # It's there the movie gets created
105
+ #
106
+ def setup_movie
107
+ @movie = Movie.new(:framework => :gosu, :screen => $screen)
108
+ 0.upto(200) do |start|
109
+ # x,y = 0,0 is default
110
+ @star = Sprite.new("star_5.png")
111
+ # all following actions are applied to this resource
112
+ @movie.resource(@star)
113
+ @movie.color( Color.new(100 + rand(155),rand(255),rand(255),rand(255)) )
114
+ @movie.zoom(0.2)
115
+ @movie.between(start/10.0, start/10.0 + 2)
116
+ @movie.velocity([10,0])
117
+ @movie.acceleration([0, 0.05 + rand(0.1)])
118
+ @movie.rotate(angle = 90 * rand(10))
119
+ @movie.zoom(1.0 + rand(2.0))
120
+ @movie.fade_out.then.color(0x00FFFFFF)
121
+ end
122
+ end
123
+
124
+ #
125
+ # Gosu calls update() automaticly
126
+ #
127
+ def update
128
+ @tick = @clock.tick()
129
+
130
+ if @movie.playing?(@clock.lifetime)
131
+ @movie.gosu_update(@clock.lifetime)
132
+ self.caption = "[framerate: #{@clock.framerate.to_i}] [Spriteupdates: #{@movie.updated_count}] [#{@clock.lifetime} : #{@movie.stop_at}]"
133
+ else
134
+ close
135
+ end
136
+ end
137
+
138
+ #
139
+ # Gosu calls draw() automaticly
140
+ #
141
+ def draw
142
+ @movie.gosu_draw(@clock.lifetime)
143
+ end
144
+ end
145
+
146
+ MovieMakerWindow.new.show # Initialize and show main gosu window (starts calling update/draw)
147
+
148
+ == Requirements
149
+ Rubygame 2.3+ or Gosu 0.7.9+
150
+
151
+
152
+ == License
153
+
154
+ Same as rubygame.
data/Rakefile ADDED
@@ -0,0 +1,19 @@
1
+ require 'rubygems'
2
+ require 'hoe'
3
+ require File.dirname(__FILE__) + '/lib/movie_maker.rb'
4
+
5
+ include MovieMaker
6
+
7
+ Hoe.plugin :git
8
+ Hoe.spec "movie_maker" do
9
+ developer "ippa", "ippa@rubylicio.us"
10
+ self.readme_file = 'README.rdoc'
11
+ self.rubyforge_name = "movie_maker"
12
+ self.version = MovieMaker::VERSION
13
+ end
14
+
15
+ desc "Build a working gemspec"
16
+ task :gemspec do
17
+ system "rake git:manifest"
18
+ system "rake debug_gem | grep -v \"(in \" | grep -v \"erik\" > movie_maker.gemspec"
19
+ end
data/examples/axe.rb ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/ruby
2
+ require File.join("..", "lib", "movie_maker")
3
+
4
+ include Rubygame
5
+ include MovieMaker
6
+ include MovieMaker::Rubygame
7
+
8
+ Rubygame.init()
9
+ Surface.autoload_dirs = [ "media" ]
10
+ Sound.autoload_dirs = [ "media" ]
11
+
12
+ @screen = Screen.set_mode([800, 600], 0, [HWSURFACE, DOUBLEBUF])
13
+ @background = Surface.autoload("outdoor_scene.bmp")
14
+ @axe = Sprite.new("axe.png")
15
+ @chop = Sound["chop.wav"]
16
+
17
+ movie = Movie.new(:screen => @screen, :background => @background)
18
+ #
19
+ # Monsterline that demonstrates moviemakes chaining
20
+ #
21
+ # OLD: movie.between(0, 2).move(@axe, :from => [0,200], :to => [700,350]).rotate(@axe, :angle => 370*2, :direction => :clockwise).after.play_sound(@chop)
22
+
23
+ movie.resource(@axe).move([0,200]).between(0, 2).move([700,350]).rotate(370*2).then.play_sound(@chop)
24
+ movie.play(:stop_at => 4)
data/examples/balls.rb ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/ruby
2
+ require File.join("..", "lib", "movie_maker")
3
+
4
+ include Rubygame
5
+ include MovieMaker
6
+ include MovieMaker::Rubygame
7
+
8
+ Rubygame.init()
9
+ Surface.autoload_dirs = [ "media" ]
10
+
11
+ @screen = Screen.set_mode([800, 600], 0)
12
+ @background = Surface.autoload("cloth_background.png")
13
+
14
+ movie = Movie.new(:screen => @screen, :background => @background)
15
+ movie.resource(Sprite.new("ball.png")).move([100,100]).between(0,6).move([600,100])
16
+ movie.resource(Sprite.new("ball.png")).move([100,200]).between(1,6).move([600,200])
17
+ movie.resource(Sprite.new("ball.png")).move([100,300]).between(2,6).move([600,300])
18
+ movie.resource(Sprite.new("ball.png")).move([100,400]).between(3,6).move([600,400])
19
+ movie.resource(Sprite.new("ball.png")).move([100,500]).between(4,6).move([600,500])
20
+ movie.play
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/ruby
2
+ require File.join("..", "lib", "movie_maker")
3
+
4
+ include Rubygame
5
+ include MovieMaker
6
+ include MovieMaker::Rubygame
7
+
8
+ TTF.setup()
9
+ Rubygame.init()
10
+ Surface.autoload_dirs = [ "media" ]
11
+ Sound.autoload_dirs = [ "media" ]
12
+
13
+ @raindrop = Sprite.new("raindrop.png")
14
+ @drip = Sound["drip.wav"]
15
+ @screen = Screen.set_mode([800, 600], 0, [HWSURFACE])
16
+ @movie = Movie.new(:screen => @screen, :background => Color[:black], :target_framerate => 200)
17
+
18
+ @echo_delay = 0.4
19
+ #
20
+ # create 10 raindrops after eachother with echo soundeffects
21
+ #
22
+ (0..5).each do |nr|
23
+ x = 100+rand(600)
24
+ fall_time = 2
25
+ start_at = nr * fall_time
26
+ stop_at = nr * fall_time + fall_time
27
+ @movie.resource(@raindrop).move([x,-1000]).between(start_at,stop_at).move([x, 650])
28
+ @movie.at(stop_at).play_sound(@drip.dup).delay(@echo_delay).play_sound(@drip.dup, :volume=>0.6).delay(@echo_delay).play_sound(@drip.dup,:volume => 0.3).delay(@echo_delay).play_sound(@drip.dup,:volume => 0.2)
29
+ end
30
+ @movie.play(:stop_at => 13)
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby
2
+ require File.join("..", "lib", "movie_maker")
3
+
4
+ #
5
+ # Usefull stuff for the Gosu examples
6
+ #
7
+ module Gosu
8
+ class MovieMakerWindow < Gosu::Window
9
+ def initialize
10
+ $screen = super(800, 600, false)
11
+
12
+ # Make Surface & Sound behave like shortcuts to GOSUs Image & Sample
13
+ require 'gosu_autoload'
14
+
15
+ # Set our autoloading dirs for quick and easy access to images and samples
16
+ Surface.autoload_dirs = [ File.join("samples", "media"), "media" ]
17
+ Sound.autoload_dirs = [ File.join("samples", "media"), "media" ]
18
+
19
+ @clock = ::Gosu::Clock.new
20
+ @clock.target_framerate = 200
21
+
22
+ self
23
+ end
24
+
25
+ def update
26
+ @tick = @clock.tick()
27
+
28
+ #if @movie.playing?(@clock.lifetime)
29
+ @movie.gosu_update(@clock.lifetime)
30
+ self.caption = "[framerate: #{@clock.framerate.to_i}] [Spriteupdates: #{@movie.updated_count}] [#{@clock.lifetime} : #{@movie.stop_at}]"
31
+ #else
32
+ # close
33
+ #end
34
+ end
35
+
36
+ def draw
37
+ @movie.gosu_draw(@clock.lifetime)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+ require File.join("..", "lib", "movie_maker")
3
+ require 'gosu_base.rb'
4
+
5
+ class GameWindow < Gosu::MovieMakerWindow
6
+ def initialize
7
+ super
8
+ setup_movie
9
+ end
10
+
11
+ def setup_movie
12
+ @movie = Movie.new(:framework => :gosu, :screen => $screen)
13
+
14
+ start_at = stop_at = 0
15
+ (1..500).each do |nr|
16
+ x = rand(800)
17
+ start_at = nr / 50.0
18
+ stop_at = nr / 50.0 + 1.0
19
+
20
+ @raindrop = Sprite.new("raindrop_small.png")
21
+ @movie.resource(@raindrop).move([x,0]).between(start_at, stop_at).move_facing_direction([x+100+(nr/5)+rand(50),650])
22
+ end
23
+
24
+ @movie.at(0).play_sound(Sample["rain2.wav"])
25
+ end
26
+ end
27
+
28
+ if $0 == __FILE__
29
+ include MovieMaker
30
+ include MovieMaker::Gosu # Among others add sprites image to global $screen
31
+ GameWindow.new.show
32
+ end
33
+
34
+
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+ require File.join("..", "lib", "movie_maker")
3
+ require 'gosu_base.rb'
4
+
5
+ class GameWindow < Gosu::MovieMakerWindow
6
+ def initialize
7
+ super
8
+ setup_movie
9
+ end
10
+
11
+ def setup_movie
12
+ @movie = Movie.new(:framework => :gosu, :screen => $screen)
13
+ 0.upto(200) do |start|
14
+ @star = Sprite.new("star_5.png") # x,y = 0,0 is default
15
+ @movie.resource(@star) # all following actions are applied to this resource
16
+ @movie.color( Color.new(100 + rand(155),rand(255),rand(255),rand(255)) )
17
+ @movie.zoom(0.2)
18
+ @movie.between(start/10.0, start/10.0 + 2)
19
+ @movie.velocity([10,0])
20
+ @movie.acceleration([0, 0.05 + rand(0.1)])
21
+ @movie.rotate(angle = 90 * rand(10))
22
+ @movie.zoom(1.0 + rand(2.0))
23
+ @movie.fade_out.then.color(0x00FFFFFF)
24
+ end
25
+ end
26
+
27
+ end
28
+
29
+ if $0 == __FILE__
30
+ include MovieMaker
31
+ include MovieMaker::Gosu
32
+ GameWindow.new.show
33
+ end
34
+
35
+
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+ require File.join("..", "lib", "movie_maker")
3
+ require 'gosu_base.rb'
4
+
5
+ class GameWindow < Gosu::MovieMakerWindow
6
+ def initialize
7
+ super
8
+ setup_movie
9
+ end
10
+
11
+ def setup_movie
12
+ @movie = Movie.new(:framework => :gosu, :screen => $screen)
13
+ 0.upto(5) do |start|
14
+
15
+ @red = Sprite.new("red_triangle.png")
16
+ @green = Sprite.new("green_triangle.png")
17
+ @blue = Sprite.new("blue_triangle.png")
18
+ stop = start + 4
19
+
20
+ @movie.resource(@red).move([0,0]).zoom(0.1).between(start, stop).move([800,650]).rotate(1000).zoom(3).fade_out
21
+ @movie.resource(@green).move([800,0]).zoom(0.1).between(start, stop).move([0,650]).rotate(1000).zoom(3).fade_out
22
+ @movie.resource(@blue).move([800,600]).zoom(0.1).between(start, stop).move([0,0]).rotate(1000).zoom(3).fade_out
23
+ end
24
+ end
25
+
26
+ end
27
+
28
+ if $0 == __FILE__
29
+ include MovieMaker
30
+ include MovieMaker::Gosu
31
+ GameWindow.new.show
32
+ end
33
+
34
+
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env ruby
2
+ require File.join("..", "lib", "movie_maker")
3
+ require 'gosu_base.rb'
4
+
5
+ class GameWindow < Gosu::MovieMakerWindow
6
+ def initialize
7
+ super
8
+ setup_movie
9
+ end
10
+
11
+ def setup_movie
12
+ @movie = Movie.new(:framework => :gosu, :screen => $screen, :draw_mode => :additive, :loop => true)
13
+ 0.upto(40) do |nr|
14
+ @star = Sprite.new("star_6.png", :x => rand(800), :y => -10)
15
+ color = Color.new(0x66484D18)
16
+ flash = Color.new(0xFFFFFFFF)
17
+
18
+ @start = nr/4.0
19
+ zoom = 0.1+rand(0)/5
20
+
21
+ # this resource will follow through all steps bellow
22
+ @movie.resource(@star)
23
+
24
+ # setup (before a between)
25
+ @movie.zoom(zoom).color(color)
26
+
27
+ # the "movie" (resource is still choosen)
28
+ @movie.between(@start, @start+10).velocity([0,1.2+rand(0)/5]).rotate(200-rand(400))
29
+
30
+ # A falling star
31
+ if rand(10) == 0
32
+ @movie.at(@start+2+rand(4)).zoom(zoom+0.3).color(flash).during(1).rotate(720).zoom(0.01).fade_out
33
+ end
34
+ end
35
+
36
+ @movie.restart_at(@start)
37
+
38
+ end
39
+
40
+ end
41
+
42
+ if $0 == __FILE__
43
+ include MovieMaker
44
+ include MovieMaker::Gosu
45
+ GameWindow.new.show
46
+ end
47
+
48
+