pirate_game 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,8 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'autotest/restart'
4
+
5
+ Autotest.add_hook :initialize do |at|
6
+ at.testlib = 'minitest/autorun'
7
+ end
8
+
File without changes
@@ -0,0 +1,5 @@
1
+ === 1.0 / 2013-10-06
2
+
3
+ * Major enhancements
4
+ * Birthday!
5
+
@@ -0,0 +1,37 @@
1
+ .autotest
2
+ History.rdoc
3
+ Manifest.txt
4
+ README.md
5
+ Rakefile
6
+ bin/game_master
7
+ bin/pirate_game
8
+ config.json
9
+ imgs/jolly_roger.jpg
10
+ imgs/jolly_roger_sm.png
11
+ imgs/pirate_ship.png
12
+ imgs/pirate_ship_sm.png
13
+ lib/pirate_game.rb
14
+ lib/pirate_game/animation.rb
15
+ lib/pirate_game/background.rb
16
+ lib/pirate_game/boot.rb
17
+ lib/pirate_game/bridge.rb
18
+ lib/pirate_game/bridge_button.rb
19
+ lib/pirate_game/client.rb
20
+ lib/pirate_game/client_app.rb
21
+ lib/pirate_game/game_master.rb
22
+ lib/pirate_game/image.rb
23
+ lib/pirate_game/log_book.rb
24
+ lib/pirate_game/master_app.rb
25
+ lib/pirate_game/protocol.rb
26
+ lib/pirate_game/shoes4_patch.rb
27
+ lib/pirate_game/stage.rb
28
+ lib/pirate_game/timeout_renewer.rb
29
+ lib/pirate_game/wave.rb
30
+ lib/pirate_game/waving_item.rb
31
+ state_diagram.graffle
32
+ test/test_pirate_game_bridge.rb
33
+ test/test_pirate_game_client.rb
34
+ test/test_pirate_game_game_master.rb
35
+ test/test_pirate_game_log_book.rb
36
+ test/test_pirate_game_stage.rb
37
+ test/test_pirate_game_timeout_renewer.rb
@@ -0,0 +1,88 @@
1
+ # pirate_game
2
+
3
+ * https://github.com/davy/pirate_game
4
+
5
+ ## Description
6
+
7
+ You insouciant scalawags will share the experience of a lifetime as you play a game built atop DRb and Shoes based generally upon the phenomenon known as Spaceteam! Except with Pirates!!
8
+
9
+ Team up with your fellow pirates to plunder the high seas! Yarrrr….☠
10
+
11
+ ## INSTALL
12
+
13
+ * Install jruby (1.7.4, 1.7.5, 1.7.6 all should work), bundler
14
+ * Install shoes4
15
+
16
+ ```
17
+ $ git clone http://github.com/shoes/shoes4
18
+ $ git checkout 7d0a1eefea601917dd01419b14ded2812d0acb9f
19
+ $ gem build shoes.gemspec
20
+ $ gem install shoes-4.0.0.pre1
21
+ $ alias shoes4='/path/to/shoes4/bin/shoes'
22
+ ```
23
+
24
+ * Install pirate_game
25
+
26
+ ```
27
+ $ gem install pirate_game
28
+ ```
29
+
30
+ ## RUN GAME
31
+
32
+ * One person runs game_master
33
+
34
+ ```
35
+ $ ring_server
36
+ $ shoes4 bin/game_master
37
+ ```
38
+
39
+ * Players run pirate_game
40
+
41
+ ```
42
+ $ shoes4 bin/pirate_game
43
+ ```
44
+
45
+ ## Credits
46
+
47
+ Pirate Ship image used under [CC by-nc-sa
48
+ 3.0](http://creativecommons.org/licenses/by-nc-sa/3.0/) from
49
+ http://sweetclipart.com/pirate-ship-design
50
+
51
+ Jolly Roger Flag image used under [CC by-nc-sa
52
+ 3.0](http://creativecommons.org/licenses/by-nc-sa/3.0/)
53
+ from http://freestock.ca/flags_maps_g80-jolly_roger_pirate_grunge_flag_p1022.html
54
+
55
+ ## Developers
56
+
57
+ After checking out the source, run:
58
+
59
+ $ rake newb
60
+
61
+ This task will install any missing dependencies, run the tests/specs,
62
+ and generate the RDoc.
63
+
64
+ ## License
65
+
66
+ (The MIT License)
67
+
68
+ Copyright (c) Davy Stevenson, Eric Hodel
69
+
70
+ Permission is hereby granted, free of charge, to any person obtaining
71
+ a copy of this software and associated documentation files (the
72
+ 'Software'), to deal in the Software without restriction, including
73
+ without limitation the rights to use, copy, modify, merge, publish,
74
+ distribute, sublicense, and/or sell copies of the Software, and to
75
+ permit persons to whom the Software is furnished to do so, subject to
76
+ the following conditions:
77
+
78
+ The above copyright notice and this permission notice shall be
79
+ included in all copies or substantial portions of the Software.
80
+
81
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
82
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
83
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
84
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
85
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
86
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
87
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
88
+
@@ -0,0 +1,24 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+
6
+ Hoe.plugin :minitest
7
+ Hoe.plugin :git
8
+
9
+ Hoe.spec 'pirate_game' do
10
+ developer 'Davy Stevenson', 'davy.stevenson@gmail.com'
11
+ developer 'Eric Hodel', 'drbrain@segment7.net'
12
+
13
+ rdoc_locations << 'docs.seattlerb.org:/data/www/docs.seattlerb.org/pirate_game/'
14
+
15
+ extra_deps << ['json', '~> 1.8.0']
16
+ extra_deps << ['pirate_command', '~> 0.0', '>= 0.0.2']
17
+ extra_deps << ['shuttlecraft', '~> 0.0']
18
+
19
+ license 'MIT'
20
+
21
+ self.readme_file = 'README.md'
22
+ end
23
+
24
+ # vim: syntax=ruby
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pirate_game'
4
+
5
+ PirateGame::MasterApp.run
6
+
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pirate_game'
4
+
5
+ PirateGame::ClientApp.run
@@ -0,0 +1,4 @@
1
+ {
2
+ "stage_duration": 30,
3
+ "action_duration": 8
4
+ }
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,21 @@
1
+ module PirateGame
2
+ VERSION = '0.0.1'
3
+ end
4
+
5
+ require 'pirate_game/animation'
6
+ require 'pirate_game/background'
7
+ require 'pirate_game/boot'
8
+ require 'pirate_game/waving_item'
9
+ require 'pirate_game/bridge'
10
+ require 'pirate_game/bridge_button'
11
+ require 'pirate_game/client'
12
+ require 'pirate_game/client_app'
13
+ require 'pirate_game/game_master'
14
+ require 'pirate_game/image'
15
+ require 'pirate_game/log_book'
16
+ require 'pirate_game/master_app'
17
+ require 'pirate_game/protocol'
18
+ require 'pirate_game/stage'
19
+ require 'pirate_game/timeout_renewer'
20
+ require 'pirate_game/wave'
21
+
@@ -0,0 +1,35 @@
1
+ require 'shoes'
2
+
3
+ ##
4
+ # An animation that resets the client application if a DRb::DRbConnError is
5
+ # raised during animation.
6
+
7
+ class PirateGame::Animation < Shoes::Animation
8
+
9
+ ##
10
+ # See Shoes::Animation for details
11
+
12
+ def initialize app, opts, blk
13
+ blk = wrap_block blk
14
+
15
+ super app, opts, blk
16
+ end
17
+
18
+ ##
19
+ # Wraps +block+ in an exception handler that switches to the
20
+ # select_game_screen.
21
+
22
+ def wrap_block block # :nodoc:
23
+ proc do |*args|
24
+ begin
25
+ block.call(*args)
26
+ rescue DRb::DRbConnError
27
+ @app.state = :select_game
28
+
29
+ @app.select_game_screen
30
+ end
31
+ end
32
+ end
33
+
34
+ end
35
+
@@ -0,0 +1,95 @@
1
+ class PirateGame::Background
2
+
3
+ STATES = [:clear, :foggy, :windy]
4
+
5
+ def initialize shoes, state=nil
6
+ @shoes = shoes
7
+ set_state state
8
+
9
+ @items = []
10
+
11
+ @items << PirateGame::Wave.new(@shoes, 0)
12
+ @items << PirateGame::Wave.new(@shoes, 20)
13
+
14
+ image = File.expand_path '../../../imgs/pirate_ship_sm.png', __FILE__
15
+
16
+ @items << PirateGame::Image.new(@shoes, image, 66, 55)
17
+
18
+ [40, 60, 80, 100].each do |top|
19
+ @items << PirateGame::Wave.new(@shoes, top)
20
+ end
21
+ end
22
+
23
+ def set_state state
24
+ @state = state if STATES.include?(state)
25
+ @state ||= :clear
26
+ end
27
+
28
+ def randomize_state
29
+ case rand
30
+ when 0.0..0.1
31
+ @state = :foggy
32
+ when 0.2..0.3
33
+ @state = :windy
34
+ else
35
+ @state = :clear
36
+ end
37
+ end
38
+
39
+ def send_speed_to_items
40
+ case @state
41
+ when :windy
42
+ all_items.each {|item| item.speed = :fast}
43
+ end
44
+ end
45
+
46
+ def all_items
47
+ @items + @extra_items
48
+ end
49
+
50
+ def color
51
+ case @state
52
+ when :foggy
53
+ @shoes.rgb(105, 138, 150, 180)
54
+ else # :clear, :windy
55
+ PirateGame::Boot::SKY_COLOR
56
+ end
57
+ end
58
+
59
+ def draw
60
+ randomize_state
61
+
62
+ @shoes.background color unless foreground?
63
+
64
+ @items.each do |item|
65
+ item.draw
66
+ end
67
+
68
+ @extra_items = []
69
+
70
+ yield if block_given?
71
+
72
+ @extra_items.each do |item|
73
+ item.draw
74
+ end
75
+
76
+ # doesn't draw over input items (buttons, text boxes, etc) >:(
77
+ @shoes.background color if foreground?
78
+
79
+ send_speed_to_items
80
+ end
81
+
82
+ def add_extra_item item
83
+ @extra_items << item
84
+ end
85
+
86
+ def animate frame
87
+ all_items.each do |item|
88
+ item.animate frame
89
+ end
90
+ end
91
+
92
+ def foreground?
93
+ @state == :foggy
94
+ end
95
+ end
@@ -0,0 +1,68 @@
1
+ require 'shoes/color'
2
+ require 'json'
3
+
4
+ module PirateGame
5
+ module Boot
6
+
7
+ DARK_COLOR = '#696969' #dimgray
8
+ LIGHT_COLOR = '#dcdcdc' #gainsboro
9
+ SKY_COLOR = '#00ffff' #aqua
10
+ PUB_COLOR = '#52352b' #brown
11
+
12
+ COLORS = {dark: DARK_COLOR, light: LIGHT_COLOR, sky: SKY_COLOR, pub: PUB_COLOR}
13
+
14
+ BLUE_COLORS = [
15
+ Shoes::COLORS[:cornflowerblue],
16
+ Shoes::COLORS[:darkcyan],
17
+ Shoes::COLORS[:deepskyblue],
18
+ Shoes::COLORS[:mediumturquoise],
19
+ Shoes::COLORS[:steelblue],
20
+ Shoes::COLORS[:teal],
21
+ Shoes::COLORS[:turquoise]
22
+ ]
23
+
24
+ GREEN_COLORS = [Shoes::COLORS[:lightseagreen],
25
+ Shoes::COLORS[:mediumaquamarine],
26
+ Shoes::COLORS[:mediumseagreen],
27
+ Shoes::COLORS[:seagreen],
28
+ Shoes::COLORS[:teal]
29
+ ]
30
+
31
+ def self.config_file
32
+ File.expand_path '../../../config.json', __FILE__
33
+ end
34
+
35
+ def self.config_hash
36
+ begin
37
+ JSON.parse(open(self.config_file).read)
38
+ rescue
39
+ {"stage_duration" => 30, "action_duration" => 8}
40
+ end
41
+ end
42
+
43
+ def self.config
44
+ @config ||= self.config_hash
45
+ @config
46
+ end
47
+
48
+ def self.waving_offset(frame, seed, delta_x, delta_y, speed = :normal)
49
+ t1 = frame + seed
50
+ t2 = frame + seed * 2
51
+ vel = 10.0
52
+
53
+ case speed
54
+ when :slow
55
+ vel = 20.0
56
+ when :fast
57
+ vel = 2.0
58
+ delta_x *= 2
59
+ delta_y *= 2
60
+ end
61
+
62
+ offset_x = Math.sin(t1/vel) * delta_x
63
+ offset_y = Math.cos(t2/vel) * delta_y
64
+
65
+ return offset_x, offset_y
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,21 @@
1
+ class PirateGame::Bridge
2
+
3
+ attr_accessor :items, :stage_items
4
+
5
+ def initialize(items, stage_items)
6
+ @items = items
7
+ @stage_items = stage_items
8
+ end
9
+
10
+ def sample_item
11
+ item = @stage_items.sample
12
+
13
+ # if we selected an item in the current bridge
14
+ # reselect a new item 80% of the time
15
+ if items.include?(item) && items.size < stage_items.size
16
+ item = sample_item if rand > 0.2
17
+ end
18
+
19
+ return item
20
+ end
21
+ end