escape_to_rubyconf 1.0

Sign up to get free protection for your applications and to get access to all the features.
File without changes
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2012-09-19
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
@@ -0,0 +1,24 @@
1
+ CHANGELOG.rdoc
2
+ Manifest.txt
3
+ README.rdoc
4
+ Rakefile
5
+ bin/escape_to_rubyconf
6
+ escape_to_rubyconf.gemspec
7
+ lib/escape_to_rubyconf.rb
8
+ lib/escape_to_rubyconf/assets/begin.wav
9
+ lib/escape_to_rubyconf/assets/fail.png
10
+ lib/escape_to_rubyconf/assets/fail.wav
11
+ lib/escape_to_rubyconf/assets/ninja-walk.wav
12
+ lib/escape_to_rubyconf/assets/ninja.png
13
+ lib/escape_to_rubyconf/assets/rubyconf-background.png
14
+ lib/escape_to_rubyconf/assets/snake-hiss.wav
15
+ lib/escape_to_rubyconf/assets/snake.png
16
+ lib/escape_to_rubyconf/assets/win.png
17
+ lib/escape_to_rubyconf/assets/win.wav
18
+ lib/escape_to_rubyconf/fail_level.rb
19
+ lib/escape_to_rubyconf/ninja.rb
20
+ lib/escape_to_rubyconf/play_level.rb
21
+ lib/escape_to_rubyconf/round.rb
22
+ lib/escape_to_rubyconf/snake.rb
23
+ lib/escape_to_rubyconf/win_level.rb
24
+ test/test_escape_to_rubyconf.rb
@@ -0,0 +1,47 @@
1
+ = Escape to RubyConf!
2
+
3
+ You want to get to RubyConf, but there are snakes in the way!
4
+ You need to train by playing this exciting game!
5
+
6
+ == Install
7
+
8
+ gem install escape_to_rubyconf
9
+
10
+ == Start the game
11
+
12
+ $ escape_to_rubyconf
13
+
14
+ == Wait, what?
15
+
16
+ This game was born from a talk I gave at RubyConf 2010 on Writing Games with Ruby:
17
+
18
+ http://www.confreaks.com/videos/490-rubyconf2010-writing-games-with-ruby
19
+
20
+ You can find the code I used here:
21
+
22
+ https://github.com/blowmage/ZOMG_GAMES
23
+
24
+ == LICENSE:
25
+
26
+ (The MIT License)
27
+
28
+ Copyright (c) 2010 Mike Moore
29
+
30
+ Permission is hereby granted, free of charge, to any person obtaining
31
+ a copy of this software and associated documentation files (the
32
+ 'Software'), to deal in the Software without restriction, including
33
+ without limitation the rights to use, copy, modify, merge, publish,
34
+ distribute, sublicense, and/or sell copies of the Software, and to
35
+ permit persons to whom the Software is furnished to do so, subject to
36
+ the following conditions:
37
+
38
+ The above copyright notice and this permission notice shall be
39
+ included in all copies or substantial portions of the Software.
40
+
41
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
42
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
43
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
44
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
45
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
46
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
47
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,20 @@
1
+ require 'rubygems'
2
+ require 'hoe'
3
+
4
+ Hoe.plugin :git
5
+ Hoe.plugin :gemspec
6
+ Hoe.plugin :minitest
7
+ Hoe.plugins.delete :rubyforge
8
+
9
+ Hoe.spec 'escape_to_rubyconf' do
10
+ developer 'Mike Moore', 'mike@blowmage.com'
11
+
12
+ self.summary = 'Escape to RubyConf!'
13
+ self.description = 'Game built for Writing Games with Ruby presentation at RubyConf 2010.'
14
+ self.urls = ['https://github.com/blowmage/escape_to_rubyconf']
15
+
16
+ self.history_file = "CHANGELOG.rdoc"
17
+ self.readme_file = "README.rdoc"
18
+
19
+ dependency 'gosu', '~> 0.7.45'
20
+ end
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "escape_to_rubyconf"
4
+
5
+ EscapeToRubyConf.new.show
@@ -0,0 +1,43 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "escape_to_rubyconf"
5
+ s.version = "1.0.20120919175018"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Mike Moore"]
9
+ s.date = "2012-09-19"
10
+ s.description = "Game built for Writing Games with Ruby presentation at RubyConf 2010."
11
+ s.email = ["mike@blowmage.com"]
12
+ s.executables = ["escape_to_rubyconf"]
13
+ s.extra_rdoc_files = ["CHANGELOG.rdoc", "Manifest.txt", "README.rdoc"]
14
+ s.files = ["CHANGELOG.rdoc", "Manifest.txt", "README.rdoc", "Rakefile", "bin/escape_to_rubyconf", "escape_to_rubyconf.gemspec", "lib/escape_to_rubyconf.rb", "lib/escape_to_rubyconf/assets/begin.wav", "lib/escape_to_rubyconf/assets/fail.png", "lib/escape_to_rubyconf/assets/fail.wav", "lib/escape_to_rubyconf/assets/ninja-walk.wav", "lib/escape_to_rubyconf/assets/ninja.png", "lib/escape_to_rubyconf/assets/rubyconf-background.png", "lib/escape_to_rubyconf/assets/snake-hiss.wav", "lib/escape_to_rubyconf/assets/snake.png", "lib/escape_to_rubyconf/assets/win.png", "lib/escape_to_rubyconf/assets/win.wav", "lib/escape_to_rubyconf/fail_level.rb", "lib/escape_to_rubyconf/ninja.rb", "lib/escape_to_rubyconf/play_level.rb", "lib/escape_to_rubyconf/round.rb", "lib/escape_to_rubyconf/snake.rb", "lib/escape_to_rubyconf/win_level.rb", "test/test_escape_to_rubyconf.rb", ".gemtest"]
15
+ s.homepage = "https://github.com/blowmage/escape_to_rubyconf"
16
+ s.rdoc_options = ["--main", "README.rdoc"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = "escape_to_rubyconf"
19
+ s.rubygems_version = "1.8.24"
20
+ s.summary = "Escape to RubyConf!"
21
+ s.test_files = ["test/test_escape_to_rubyconf.rb"]
22
+
23
+ if s.respond_to? :specification_version then
24
+ s.specification_version = 3
25
+
26
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
27
+ s.add_runtime_dependency(%q<gosu>, ["~> 0.7.45"])
28
+ s.add_development_dependency(%q<minitest>, ["~> 3.4"])
29
+ s.add_development_dependency(%q<rdoc>, ["~> 3.10"])
30
+ s.add_development_dependency(%q<hoe>, ["~> 3.0"])
31
+ else
32
+ s.add_dependency(%q<gosu>, ["~> 0.7.45"])
33
+ s.add_dependency(%q<minitest>, ["~> 3.4"])
34
+ s.add_dependency(%q<rdoc>, ["~> 3.10"])
35
+ s.add_dependency(%q<hoe>, ["~> 3.0"])
36
+ end
37
+ else
38
+ s.add_dependency(%q<gosu>, ["~> 0.7.45"])
39
+ s.add_dependency(%q<minitest>, ["~> 3.4"])
40
+ s.add_dependency(%q<rdoc>, ["~> 3.10"])
41
+ s.add_dependency(%q<hoe>, ["~> 3.0"])
42
+ end
43
+ end
@@ -0,0 +1,73 @@
1
+ require 'rubygems'
2
+ require 'gosu'
3
+
4
+ require 'escape_to_rubyconf/play_level'
5
+ require 'escape_to_rubyconf/win_level'
6
+ require 'escape_to_rubyconf/fail_level'
7
+
8
+ class EscapeToRubyConf < Gosu::Window
9
+ VERSION = "1.0"
10
+ attr_reader :time, :sounds
11
+ def initialize width=800, height=600, fullscreen=false
12
+ super
13
+
14
+ self.caption = 'ESCAPE TO RUBYCONF!!!'
15
+
16
+ # So multiple sprites don't create duplicate objects
17
+ @sounds = {}
18
+
19
+ # Levels
20
+ @play = PlayLevel.new self
21
+ @win = WinLevel.new self
22
+ @fail = FailLevel.new self
23
+
24
+ # @play.on_start { do_something_here! }
25
+ @play.on_win { win! }
26
+ @play.on_fail { fail! }
27
+ @play.on_quit { close }
28
+
29
+ @fail.on_continue { play! }
30
+ @fail.on_quit { close }
31
+
32
+ @win.on_continue { @play.add_snake!; play!}
33
+ @win.on_quit { close }
34
+
35
+ play!
36
+ end
37
+
38
+ def play!
39
+ @level = @play
40
+ @play.start!
41
+ end
42
+
43
+ def fail!
44
+ @level = @fail
45
+ @fail.start!
46
+ end
47
+
48
+ def win!
49
+ @level = @win
50
+ @win.start!
51
+ end
52
+
53
+ def button_down id
54
+ @level.button_down id if @level.respond_to? :button_down
55
+ end
56
+
57
+ def button_up id
58
+ @level.button_up id if @level.respond_to? :button_up
59
+ end
60
+
61
+ def snakes_count
62
+ @play.snakes_count
63
+ end
64
+
65
+ def update
66
+ @time = Time.now.to_f
67
+ @level.update
68
+ end
69
+
70
+ def draw
71
+ @level.draw
72
+ end
73
+ end
@@ -0,0 +1,60 @@
1
+ require 'gosu'
2
+
3
+ class FailLevel
4
+ attr_accessor :window
5
+ def initialize window
6
+ @window = window
7
+ @fail = Gosu::Image.new @window, File.dirname(__FILE__) + '/assets/fail.png'
8
+ @msg = Gosu::Image.from_text @window,
9
+ "You were defeated!\n" +
10
+ "Press ESCAPE to quit. Quitter\n" +
11
+ "Or SPACE to try again. Doubt it.",
12
+ Gosu::default_font_name, 24
13
+ @msg_x = @window.width/2 - @msg.width/2
14
+ @msg_y = @window.height * 2 / 3
15
+ @sound = Gosu::Sample.new @window, File.dirname(__FILE__) + '/assets/fail.wav'
16
+
17
+ # Add callback holders
18
+ @continue_callbacks = []
19
+ @quit_callbacks = []
20
+ end
21
+
22
+ def on_continue &block
23
+ @continue_callbacks << block
24
+ end
25
+
26
+ def on_quit &block
27
+ @quit_callbacks << block
28
+ end
29
+
30
+ def continue!
31
+ @continue_callbacks.each { |c| c.call }
32
+ end
33
+
34
+ def quit!
35
+ @quit_callbacks.each { |c| c.call }
36
+ end
37
+
38
+ def start!
39
+ @sound.play
40
+ end
41
+
42
+ def update
43
+ quit! if @window.button_down? Gosu::KbEscape
44
+ continue! if ( @window.button_down?(Gosu::KbSpace) ||
45
+ @window.button_down?(Gosu::KbReturn) ||
46
+ @window.button_down?(Gosu::KbEnter) )
47
+ end
48
+
49
+ def draw
50
+ c = Math.cos(@window.time*4)
51
+ @fail.draw_rot(((@window.width)/2), ((@window.height)/2 - 80), 1, 0,
52
+ 0.5, 0.5, 1.0+c*0.25, 1.0+c*0.25)
53
+ s = Math.sin @window.time
54
+ @msg.draw_rot( ((@window.width)/2 + (100*(s)).to_i),
55
+ ((@window.height)/2 + 160 + s*s*s.abs*50),
56
+ 1, s*5, 0.5, 0.5,
57
+ 1.0+(0.1*s*s*s.abs), 1.0+(0.1*s*s*s.abs),
58
+ Gosu::Color::RED )
59
+ end
60
+ end
@@ -0,0 +1,120 @@
1
+ require 'gosu'
2
+ require 'escape_to_rubyconf/round'
3
+
4
+ class Ninja
5
+ attr_accessor :x, :y, :width, :height, :boundary
6
+ def initialize level, width=128, height=128, boundary=80
7
+ @level = level
8
+ @width, @height = width, height
9
+ # x and y are the center of the bounds
10
+ @x, @y = 0, 0
11
+ @boundary = boundary
12
+ @tiles = Gosu::Image.load_tiles @level.window,
13
+ File.dirname(__FILE__) + '/assets/ninja.png',
14
+ @width, @height, false
15
+ @direction = :right
16
+ @state = :idle
17
+ @states = { :walk => { :frames => [1,2,3,4], :speed => 0.5,
18
+ :movement => 5, :time => 0.0 },
19
+ :idle => { :frames => [0], :speed => 1.0,
20
+ :movement => 0, :time => 0.0 } }
21
+ @bounds = [ [ @boundary/2 - 0.49, @boundary/2 - 0.49 ],
22
+ [ @level.window.width - @boundary/2 + 0.49,
23
+ @level.window.height - @boundary/2 + 0.49] ]
24
+
25
+ @sneak = Gosu::Sample.new @level.window, File.dirname(__FILE__) + '/assets/ninja-walk.wav'
26
+ @sneak_impl = nil
27
+ end
28
+
29
+ def state
30
+ @states[idle? ? :idle : :walk]
31
+ end
32
+
33
+ def idle?
34
+ @state == :idle
35
+ end
36
+
37
+ def walk?
38
+ !idle?
39
+ end
40
+
41
+ def frame
42
+ (((@level.window.time - state[:time]) / state[:speed] % 1) * state[:frames].size).to_i + state[:frames].first
43
+ end
44
+
45
+ def play_sneak
46
+ if @sneak_impl.nil?
47
+ @sneak_impl = @sneak.play 1, 1, true
48
+ end
49
+ end
50
+
51
+ def stop_sneak
52
+ @sneak_impl.stop if @sneak_impl
53
+ @sneak_impl = nil
54
+ end
55
+
56
+ def update
57
+ a = current_angle
58
+ if a
59
+ @state = :walk
60
+ @direction = direction_from_angle a
61
+ @x += Gosu::offset_x a, state[:movement]
62
+ @y += Gosu::offset_y a, state[:movement]
63
+ play_sneak
64
+ else
65
+ @state = :idle
66
+ stop_sneak
67
+ end
68
+ @x = @bounds[0][0] if @x < @bounds[0][0]
69
+ @x = @bounds[1][0] if @x > @bounds[1][0]
70
+ @y = @bounds[0][1] if @y < @bounds[0][1]
71
+ @y = @bounds[1][1] if @y > @bounds[1][1]
72
+ end
73
+
74
+ def current_angle
75
+ angle = nil
76
+ if @level.window.button_down? Gosu::KbRight
77
+ if @level.window.button_down? Gosu::KbUp
78
+ 45
79
+ elsif @level.window.button_down? Gosu::KbDown
80
+ angle = 135
81
+ else
82
+ angle = 90
83
+ end
84
+ elsif @level.window.button_down? Gosu::KbLeft
85
+ if @level.window.button_down? Gosu::KbUp
86
+ angle = 315
87
+ elsif @level.window.button_down? Gosu::KbDown
88
+ angle = 225
89
+ else
90
+ angle = 270
91
+ end
92
+ elsif @level.window.button_down? Gosu::KbUp
93
+ angle = 0
94
+ elsif @level.window.button_down? Gosu::KbDown
95
+ angle = 180
96
+ end
97
+ angle
98
+ end
99
+
100
+ def direction_from_angle a
101
+ (a >= 0 && a <= 180) ? :right : :left
102
+ end
103
+
104
+ def draw
105
+ @tiles[frame].draw *draw_coordinates
106
+ end
107
+
108
+ def draw_coordinates
109
+ x = Math::round(@x - @width/2)
110
+ y = Math::round((@y - @boundary/2)/2+200 - @height + @boundary/2)
111
+ z = 1 + (@y/@level.window.height)
112
+ fx = 1.0
113
+ fy = 1.0
114
+ if @direction == :left
115
+ fx = -1.0
116
+ x += @width
117
+ end
118
+ [x, y, z, fx, fy]
119
+ end
120
+ end
@@ -0,0 +1,125 @@
1
+ require 'gosu'
2
+
3
+ require 'escape_to_rubyconf/ninja'
4
+ require 'escape_to_rubyconf/snake'
5
+
6
+ class PlayLevel # inherit from Level? why?!?
7
+ attr_accessor :window, :state, :sounds
8
+ def initialize window
9
+ @window = window
10
+
11
+ @begin = Gosu::Sample.new @window, File.dirname(__FILE__) + '/assets/begin.wav'
12
+
13
+ # Create level elements
14
+ @background = Gosu::Image.new @window, File.dirname(__FILE__) + '/assets/rubyconf-background.png'
15
+ @ninja = Ninja.new self
16
+ @snakes = []
17
+ 3.times { add_snake! }
18
+
19
+ # Set ninja start and win positions
20
+ offset = @ninja.boundary/2
21
+ @start_position = [offset, offset]
22
+ @win_position = [@window.width - offset, @window.height - offset]
23
+
24
+ # Add callback holders
25
+ # @start_callbacks = []
26
+ @win_callbacks = []
27
+ @fail_callbacks = []
28
+ @quit_callbacks = []
29
+ end
30
+
31
+ # def on_start &block
32
+ # @start_callbacks << block
33
+ # end
34
+
35
+ def on_win &block
36
+ @win_callbacks << block
37
+ end
38
+
39
+ def on_fail &block
40
+ @fail_callbacks << block
41
+ end
42
+
43
+ def on_quit &block
44
+ @quit_callbacks << block
45
+ end
46
+
47
+ def start!
48
+ # @start_callbacks.each { |c| c.call }
49
+ @ninja.x = @start_position[0]
50
+ @ninja.y = @start_position[1]
51
+ @snakes.each do |snake|
52
+ snake.start *rand_position
53
+ snake.end *rand_position
54
+ end
55
+ play_begin_sound
56
+ end
57
+
58
+ def play_begin_sound
59
+ @begin.play
60
+ end
61
+
62
+ def rand_position
63
+ x, y = 0, 0
64
+ begin
65
+ x, y = rand(@window.width), rand(@window.height)
66
+ end while ((x < 120 && y < 120) ||
67
+ (x > @window.width-120 && y > @window.height-120))
68
+ [x, y]
69
+ end
70
+
71
+ def ninja_escaped?
72
+ ( (Math::round(@ninja.x) == @win_position.first) &&
73
+ (Math::round(@ninja.y) == @win_position.last) )
74
+ end
75
+
76
+ def snakes_count
77
+ @snakes.size
78
+ end
79
+
80
+ def add_snake!
81
+ @snakes << Snake.new(self)
82
+ end
83
+
84
+ def win!
85
+ stop
86
+ @win_callbacks.each { |c| c.call }
87
+ end
88
+
89
+ def fail!
90
+ stop
91
+ @fail_callbacks.each { |c| c.call }
92
+ end
93
+
94
+ def quit!
95
+ stop
96
+ @quit_callbacks.each { |c| c.call }
97
+ end
98
+
99
+ def stop
100
+ @ninja.stop_sneak
101
+ end
102
+
103
+ def update
104
+ quit! if @window.button_down? Gosu::KbEscape
105
+ @ninja.update
106
+ @snakes.each { |snake| snake.update }
107
+ # Did the player make it?
108
+ if ninja_escaped?
109
+ win!
110
+ return
111
+ end
112
+ # Check for collision and attacks
113
+ @snakes.each do |snake|
114
+ range = Gosu.distance @ninja.x, @ninja.y, snake.x, snake.y
115
+ fail! if range < snake.range
116
+ snake.attack! if range < snake.range*2.5
117
+ end
118
+ end
119
+
120
+ def draw
121
+ @background.draw 0, 0, 0
122
+ @ninja.draw
123
+ @snakes.each { |snake| snake.draw }
124
+ end
125
+ end
@@ -0,0 +1,5 @@
1
+ module Math
2
+ def self.round int
3
+ (int + 0.5).to_i
4
+ end
5
+ end
@@ -0,0 +1,113 @@
1
+ require 'gosu'
2
+ require 'escape_to_rubyconf/round'
3
+
4
+ class Snake
5
+ attr_accessor :x, :y, :height, :width, :boundary, :range
6
+ def initialize level, width=128, height=128, boundary=80
7
+ @level = level
8
+ @width, @height = width, height
9
+ # x and y are the center of the bounds
10
+ @range = @boundary = boundary
11
+ @tiles = Gosu::Image.load_tiles @level.window,
12
+ File.dirname(__FILE__) + '/assets/snake.png',
13
+ @width, @height, false
14
+ @direction = :right
15
+ @state = :walk
16
+ @states = { :walk => { :frames => [0,1], :speed => 0.25,
17
+ :movement => 6, :time => 0.0 },
18
+ :attack => { :frames => [2,3,4], :speed => 0.35,
19
+ :movement => 6, :time => 0.0 } }
20
+ self.start @level.window.width-@boundary, @boundary
21
+ self.end @boundary, @level.window.height-@boundary
22
+ @target = :start # :start
23
+
24
+ # Register the sound so multiple snakes will use same hiss
25
+ register_hiss
26
+ end
27
+
28
+ def state
29
+ @states[attack? ? :attack : :walk]
30
+ end
31
+
32
+ def attack!
33
+ unless attack?
34
+ @states[:attack][:time] = @level.window.time
35
+ hiss!
36
+ end
37
+ end
38
+
39
+ def attack?
40
+ @states[:attack][:time] + @states[:attack][:speed] > @level.window.time
41
+ end
42
+
43
+ def walk?
44
+ !attack
45
+ end
46
+
47
+ def frame
48
+ (((@level.window.time - state[:time]) / state[:speed] % 1) * state[:frames].size).to_i + state[:frames].first
49
+ end
50
+
51
+ def target
52
+ (@target == :start) ? @start : @end # patrol state
53
+ end
54
+
55
+ def reverse!
56
+ @target = (@target == :start) ? :end : :start
57
+ end
58
+
59
+ def at_target?
60
+ ( (@x <= target.first + 0.5 && @x >= target.first - 0.5) &&
61
+ (@y <= target.last + 0.5 && @y >= target.last - 0.5) )
62
+ end
63
+
64
+ def start x, y
65
+ @x, @y = x, y
66
+ @start = [x, y]
67
+ end
68
+
69
+ def end x, y
70
+ @end = [x, y]
71
+ end
72
+
73
+ def register_hiss
74
+ if @level.window.sounds[:hiss].nil?
75
+ hiss = Gosu::Sample.new @level.window, File.dirname(__FILE__) + '/assets/snake-hiss.wav'
76
+ @level.window.sounds[:hiss] = hiss
77
+ end
78
+ end
79
+
80
+ def hiss!
81
+ hiss = @level.window.sounds[:hiss]
82
+ hiss.play if hiss
83
+ end
84
+
85
+ def update
86
+ a = Gosu::angle @x, @y, target.first, target.last
87
+ xmd = Gosu::offset_x a, state[:movement]
88
+ xsd = target.first - @x
89
+ ymd = Gosu::offset_y a, state[:movement]
90
+ ysd = target.last - @y
91
+ @direction = (xmd < 0) ? :left : :right
92
+ @x += (xmd.abs < xsd.abs) ? xmd : xsd
93
+ @y += (ymd.abs < ysd.abs) ? ymd : ysd
94
+ reverse! if at_target?
95
+ end
96
+
97
+ def draw
98
+ @tiles[frame].draw *draw_coordinates
99
+ end
100
+
101
+ def draw_coordinates
102
+ x = Math::round(@x - @width/2)
103
+ y = Math::round((@y - @boundary/2)/2+200 - @height + @boundary/2)
104
+ z = 1 + (@y/@level.window.height)
105
+ fx = 1.0
106
+ fy = 1.0
107
+ if @direction == :left
108
+ fx = -1.0
109
+ x += @width
110
+ end
111
+ [x, y, z, fx, fy]
112
+ end
113
+ end
@@ -0,0 +1,62 @@
1
+ require 'gosu'
2
+
3
+ class WinLevel
4
+ attr_accessor :window, :difficulty
5
+ def initialize window
6
+ @window = window
7
+ @win = Gosu::Image.new @window, File.dirname(__FILE__) + '/assets/win.png'
8
+ @sound = Gosu::Sample.new @window, File.dirname(__FILE__) + '/assets/win.wav'
9
+
10
+ # Add callback holders
11
+ @continue_callbacks = []
12
+ @quit_callbacks = []
13
+ end
14
+
15
+ def on_continue &block
16
+ @continue_callbacks << block
17
+ end
18
+
19
+ def on_quit &block
20
+ @quit_callbacks << block
21
+ end
22
+
23
+ def start!
24
+ @sound.play
25
+ create_msg!
26
+ end
27
+
28
+ def continue!
29
+ @continue_callbacks.each { |c| c.call }
30
+ end
31
+
32
+ def quit!
33
+ @quit_callbacks.each { |c| c.call }
34
+ end
35
+
36
+ def create_msg!
37
+ @msg = Gosu::Image.from_text @window,
38
+ "You are a RUBY NINJA ROCKSTAR!!1!\n" +
39
+ "You avoided #{@window.snakes_count} snakes!!!\n" +
40
+ "Press SPACE if you dare to continue...\n" +
41
+ "Or ESCAPE if it is just too much for you.",
42
+ Gosu::default_font_name, 24
43
+ @msg_x = @window.width/2 - @msg.width/2
44
+ @msg_y = @window.height * 2 / 3
45
+ end
46
+
47
+ def update
48
+ quit! if @window.button_down? Gosu::KbEscape
49
+ continue! if ( @window.button_down?(Gosu::KbSpace) ||
50
+ @window.button_down?(Gosu::KbReturn) ||
51
+ @window.button_down?(Gosu::KbEnter) )
52
+ end
53
+
54
+ def draw
55
+ c = Math.cos(@window.time*4)
56
+ a = Math.cos(@window.time)
57
+ @win.draw_rot(((@window.width)/2), ((@window.height)/2 - 80), 1, a,
58
+ 0.5, 0.5, 1.0+c*0.25, 1.0+c*0.25)
59
+
60
+ @msg.draw @msg_x, @msg_y, 1, 1.0, 1.0, Gosu::Color::RED if @msg
61
+ end
62
+ end
@@ -0,0 +1,8 @@
1
+ require "test/unit"
2
+ require "escape_to_rubyconf"
3
+
4
+ class TestEscapeToRubyconf < Test::Unit::TestCase
5
+ def test_sanity
6
+ flunk "HAH HAH HAH!!! As if!"
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: escape_to_rubyconf
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mike Moore
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: gosu
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.7.45
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.7.45
30
+ - !ruby/object:Gem::Dependency
31
+ name: minitest
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '3.4'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '3.4'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rdoc
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '3.10'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '3.10'
62
+ - !ruby/object:Gem::Dependency
63
+ name: hoe
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '3.0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '3.0'
78
+ description: Game built for Writing Games with Ruby presentation at RubyConf 2010.
79
+ email:
80
+ - mike@blowmage.com
81
+ executables:
82
+ - escape_to_rubyconf
83
+ extensions: []
84
+ extra_rdoc_files:
85
+ - CHANGELOG.rdoc
86
+ - Manifest.txt
87
+ - README.rdoc
88
+ files:
89
+ - CHANGELOG.rdoc
90
+ - Manifest.txt
91
+ - README.rdoc
92
+ - Rakefile
93
+ - bin/escape_to_rubyconf
94
+ - escape_to_rubyconf.gemspec
95
+ - lib/escape_to_rubyconf.rb
96
+ - lib/escape_to_rubyconf/assets/begin.wav
97
+ - lib/escape_to_rubyconf/assets/fail.png
98
+ - lib/escape_to_rubyconf/assets/fail.wav
99
+ - lib/escape_to_rubyconf/assets/ninja-walk.wav
100
+ - lib/escape_to_rubyconf/assets/ninja.png
101
+ - lib/escape_to_rubyconf/assets/rubyconf-background.png
102
+ - lib/escape_to_rubyconf/assets/snake-hiss.wav
103
+ - lib/escape_to_rubyconf/assets/snake.png
104
+ - lib/escape_to_rubyconf/assets/win.png
105
+ - lib/escape_to_rubyconf/assets/win.wav
106
+ - lib/escape_to_rubyconf/fail_level.rb
107
+ - lib/escape_to_rubyconf/ninja.rb
108
+ - lib/escape_to_rubyconf/play_level.rb
109
+ - lib/escape_to_rubyconf/round.rb
110
+ - lib/escape_to_rubyconf/snake.rb
111
+ - lib/escape_to_rubyconf/win_level.rb
112
+ - test/test_escape_to_rubyconf.rb
113
+ - .gemtest
114
+ homepage: https://github.com/blowmage/escape_to_rubyconf
115
+ licenses: []
116
+ post_install_message:
117
+ rdoc_options:
118
+ - --main
119
+ - README.rdoc
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project: escape_to_rubyconf
136
+ rubygems_version: 1.8.24
137
+ signing_key:
138
+ specification_version: 3
139
+ summary: Escape to RubyConf!
140
+ test_files:
141
+ - test/test_escape_to_rubyconf.rb