ruby-fighter 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/Gemfile +3 -0
  4. data/Gemfile.lock +17 -0
  5. data/LICENSE.txt +21 -0
  6. data/README.md +19 -0
  7. data/assets/background-1.jpg +0 -0
  8. data/assets/chun-li.gif +0 -0
  9. data/assets/chun-li/blocking-1.gif +0 -0
  10. data/assets/chun-li/hit-1.gif +0 -0
  11. data/assets/chun-li/idle-1.gif +0 -0
  12. data/assets/chun-li/idle-2.gif +0 -0
  13. data/assets/chun-li/idle-3.gif +0 -0
  14. data/assets/chun-li/idle-4.gif +0 -0
  15. data/assets/chun-li/kick-1.gif +0 -0
  16. data/assets/chun-li/kick-2.gif +0 -0
  17. data/assets/chun-li/kick-3.gif +0 -0
  18. data/assets/chun-li/kick-4.gif +0 -0
  19. data/assets/chun-li/kick-5.gif +0 -0
  20. data/assets/chun-li/punch-1.gif +0 -0
  21. data/assets/chun-li/punch-2.gif +0 -0
  22. data/assets/chun-li/punch-3.gif +0 -0
  23. data/assets/chun-li/walking-1.gif +0 -0
  24. data/assets/chun-li/walking-2.gif +0 -0
  25. data/assets/chun-li/walking-3.gif +0 -0
  26. data/assets/chun-li/walking-4.gif +0 -0
  27. data/assets/chun-li/walking-5.gif +0 -0
  28. data/assets/chun-li/walking-6.gif +0 -0
  29. data/assets/chun-li/walking-7.gif +0 -0
  30. data/assets/chun-li/walking-8.gif +0 -0
  31. data/assets/ryu.gif +0 -0
  32. data/assets/ryu/blocking-1.gif +0 -0
  33. data/assets/ryu/hit-1.gif +0 -0
  34. data/assets/ryu/hit-2.gif +0 -0
  35. data/assets/ryu/hit-3.gif +0 -0
  36. data/assets/ryu/idle-1.gif +0 -0
  37. data/assets/ryu/idle-2.gif +0 -0
  38. data/assets/ryu/idle-3.gif +0 -0
  39. data/assets/ryu/idle-4.gif +0 -0
  40. data/assets/ryu/kick-1.gif +0 -0
  41. data/assets/ryu/kick-2.gif +0 -0
  42. data/assets/ryu/kick-3.gif +0 -0
  43. data/assets/ryu/kick-4.gif +0 -0
  44. data/assets/ryu/kick-5.gif +0 -0
  45. data/assets/ryu/punch-1.gif +0 -0
  46. data/assets/ryu/punch-2.gif +0 -0
  47. data/assets/ryu/punch-3.gif +0 -0
  48. data/assets/ryu/punch-4.gif +0 -0
  49. data/assets/ryu/punch-5.gif +0 -0
  50. data/assets/ryu/walking-1.gif +0 -0
  51. data/assets/ryu/walking-2.gif +0 -0
  52. data/assets/ryu/walking-3.gif +0 -0
  53. data/assets/ryu/walking-4.gif +0 -0
  54. data/assets/ryu/walking-5.gif +0 -0
  55. data/bin/ruby-fighter +7 -0
  56. data/lib/ruby-fighter.rb +1 -0
  57. data/lib/ruby_fighter.rb +11 -0
  58. data/lib/ruby_fighter/animation.rb +53 -0
  59. data/lib/ruby_fighter/backdrop.rb +18 -0
  60. data/lib/ruby_fighter/controls.rb +58 -0
  61. data/lib/ruby_fighter/game.rb +44 -0
  62. data/lib/ruby_fighter/player.rb +124 -0
  63. data/lib/ruby_fighter/version.rb +3 -0
  64. data/lib/start.rb +11 -0
  65. data/ruby-fighter.gemspec +24 -0
  66. metadata +137 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f0b7885d79fac58a86436474337de18ed918c4c0
4
+ data.tar.gz: 4343add694bc99019bfd8a79b452aac8c7797c3e
5
+ SHA512:
6
+ metadata.gz: bbde6f2f6ed7310156a59c91b8c7f1c17d786e68632636b4880ed8d032bddc303b2afcc79a29316bf84f6c461de766d445ca726fe259decfc5c7bf26aeaa318f
7
+ data.tar.gz: 29fb19b981461149a2d1a39f71ed95600b1a856f90979f33fcd7901f269830d4355fc01ab3e2e13eeadbcb64c9dfd39a50cb53572a6eba5588b6fa70afae4bfa
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,17 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ruby-fighter (0.0.0)
5
+ gosu (~> 0.8)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ gosu (0.8.7.2)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ bundler (~> 1.9)
17
+ ruby-fighter!
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Nikolay Nemshilov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,19 @@
1
+ # Ruby Fighter
2
+
3
+ Street fighter in ruby + gosu.
4
+
5
+ ```
6
+ git clone git@github.com/MadRabbit/ruby-fighter.git
7
+ cd ruby-fighter
8
+ bundle
9
+ ./bin/ruby-fighter
10
+ ```
11
+
12
+ # Copyright & License
13
+
14
+ All assets in this repository are properties of Capcom and copyrighted
15
+ to Capcom : Street Fighter® ©CAPCOM U.S.A., INC. ALL RIGHTS RESERVED.
16
+
17
+ All code in this repository is released under the terms of the MIT license.
18
+
19
+ Copyright (C) 2015 Nikolay Nemshilov.
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
4
+
5
+ require 'bundler/setup'
6
+
7
+ require_relative "../lib/start.rb"
@@ -0,0 +1 @@
1
+ require_relative "./ruby_fighter"
@@ -0,0 +1,11 @@
1
+ module RubyFighter
2
+ end
3
+
4
+
5
+ require "gosu"
6
+ require "ruby_fighter/version"
7
+ require "ruby_fighter/game"
8
+ require "ruby_fighter/backdrop"
9
+ require "ruby_fighter/player"
10
+ require "ruby_fighter/controls"
11
+ require "ruby_fighter/animation"
@@ -0,0 +1,53 @@
1
+ module RubyFighter
2
+
3
+ class Animation
4
+
5
+ def initialize(window, pattern)
6
+ @images = find_images_matching(pattern, window)
7
+ end
8
+
9
+ def width
10
+ @images[0].width
11
+ end
12
+
13
+ def draw(*args)
14
+ current_image.draw *args
15
+ end
16
+
17
+ def play_once(&callback)
18
+ @index = nil
19
+ @last_time = nil
20
+ @finish_callback = callback
21
+ end
22
+
23
+ private
24
+
25
+ def current_image
26
+ @last_time ||= Gosu.milliseconds
27
+ @index ||= 0
28
+
29
+ next_image if Gosu.milliseconds - @last_time > 150
30
+
31
+ @images[@index]
32
+ end
33
+
34
+ def next_image
35
+ @last_time = Gosu.milliseconds
36
+ @index += 1
37
+ @index = 0 if @index > @images.size - 1
38
+
39
+ if @index == 0 && @finish_callback
40
+ @finish_callback.call
41
+ @finish_callback = nil
42
+ end
43
+ end
44
+
45
+ def find_images_matching(pattern, window)
46
+ Dir["assets/#{pattern}*"].map do |path|
47
+ Gosu::Image.new(window, path, false)
48
+ end
49
+ end
50
+
51
+ end
52
+
53
+ end
@@ -0,0 +1,18 @@
1
+ module RubyFighter
2
+
3
+ class Backdrop < Gosu::Image
4
+
5
+ def initialize(window, filename)
6
+ super(window, "assets/#{filename}", false)
7
+
8
+ @scale = window.height / height
9
+ @bg_x = -(width * @scale - window.width) / 2
10
+ end
11
+
12
+ def draw
13
+ super @bg_x, 0, 0, @scale, @scale
14
+ end
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,58 @@
1
+ module RubyFighter
2
+
3
+ class Controls
4
+ PLAYER1 = {
5
+ 'a' => :left,
6
+ 'd' => :right,
7
+ 'q' => :block,
8
+ 'e' => :punch,
9
+ 'r' => :kick
10
+ }
11
+
12
+ PLAYER2 = {
13
+ 'k' => :left,
14
+ ';' => :right,
15
+ 'i' => :block,
16
+ 'p' => :punch,
17
+ '[' => :kick
18
+ }
19
+
20
+ def initialize(window, player, num)
21
+ @window = window
22
+ @player = player
23
+ @keys = [PLAYER1, PLAYER2][num-1]
24
+ end
25
+
26
+ def update(left, right)
27
+ case matching_action
28
+ when :left then @player.move_left if @player.left > left
29
+ when :right then @player.move_right if @player.right < right
30
+ end
31
+ end
32
+
33
+ def button_down(key)
34
+ case @keys[key]
35
+ when :left, :right then @player.walking!
36
+ when :block then @player.blocking!
37
+ when :punch then @player.punch!
38
+ when :kick then @player.kick!
39
+ end
40
+ end
41
+
42
+ def button_up(key)
43
+ @player.idle!
44
+ end
45
+
46
+ private
47
+
48
+ def matching_action
49
+ @keys.each do |key, action|
50
+ if @window.button_down? key
51
+ return action
52
+ end
53
+ end
54
+ end
55
+
56
+ end
57
+
58
+ end
@@ -0,0 +1,44 @@
1
+ module RubyFighter
2
+
3
+ class Game < Gosu::Window
4
+ def initialize
5
+ super(768, 480, false)
6
+ self.caption = "Ruby Fighter"
7
+
8
+ @backdrop = Backdrop.new(self, "background-1.jpg")
9
+
10
+ @player1 = Player.new(self, "ryu", false)
11
+ @player2 = Player.new(self, "chun-li", true)
12
+
13
+ @controls1 = Controls.new(self, @player1, 1)
14
+ @controls2 = Controls.new(self, @player2, 2)
15
+ end
16
+
17
+ def draw
18
+ @backdrop.draw
19
+
20
+ @player1.draw
21
+ @player2.draw
22
+ end
23
+
24
+ def update
25
+ @controls1.update 0, @player2.left
26
+ @controls2.update @player1.right, width
27
+ end
28
+
29
+ def button_down(id)
30
+ @controls1.button_down button_id_to_char(id)
31
+ @controls2.button_down button_id_to_char(id)
32
+ end
33
+
34
+ def button_up(id)
35
+ @controls1.button_up button_id_to_char(id)
36
+ @controls2.button_up button_id_to_char(id)
37
+ end
38
+
39
+ def button_down?(char)
40
+ super char_to_button_id(char)
41
+ end
42
+ end
43
+
44
+ end
@@ -0,0 +1,124 @@
1
+ module RubyFighter
2
+
3
+ class Player
4
+ SCALE = 3 # same for all players
5
+ POS_Y = 180
6
+ SPEED = 3
7
+
8
+ def initialize(window, name, flip=false)
9
+ @tiles = Tileset.new(window, name)
10
+ @pos_x = 0
11
+ @flip = flip
12
+ @max_x = window.width
13
+
14
+ move_to flip ? @max_x - 100 - width : 100
15
+ idle!
16
+ end
17
+
18
+ def idle!
19
+ return if @busy
20
+ @tiles.idle!
21
+ end
22
+
23
+ def walking!
24
+ @tiles.walking!
25
+ end
26
+
27
+ def blocking!
28
+ @tiles.blocking!
29
+ end
30
+
31
+ def punch!
32
+ @busy = true
33
+ @tiles.punch! do
34
+ @busy = false
35
+ idle!
36
+ end
37
+ end
38
+
39
+ def kick!
40
+ @busy = true
41
+ @tiles.kick! do
42
+ @busy = false
43
+ idle!
44
+ end
45
+ end
46
+
47
+ def move_to(x)
48
+ @pos_x = x
49
+ end
50
+
51
+ def move_left
52
+ @pos_x -= SPEED
53
+ end
54
+
55
+ def move_right
56
+ @pos_x += SPEED
57
+ end
58
+
59
+ def left
60
+ @pos_x
61
+ end
62
+
63
+ def right
64
+ @pos_x + width
65
+ end
66
+
67
+ def width
68
+ @tiles.width * SCALE
69
+ end
70
+
71
+ def draw
72
+ pos_x = @pos_x + (@flip ? width : 0)
73
+ scale_x = SCALE * (@flip ? -1 : 1)
74
+
75
+ @tiles.draw(pos_x, POS_Y, 1, scale_x, SCALE)
76
+ end
77
+
78
+ private
79
+
80
+ class Tileset < Hash
81
+
82
+ def initialize(window, name)
83
+ self[:idle] = RubyFighter::Animation.new(window, "#{name}/idle")
84
+ self[:walking] = RubyFighter::Animation.new(window, "#{name}/walking")
85
+ self[:blocking] = RubyFighter::Animation.new(window, "#{name}/blocking")
86
+ self[:punch] = RubyFighter::Animation.new(window, "#{name}/punch")
87
+ self[:kick] = RubyFighter::Animation.new(window, "#{name}/kick")
88
+
89
+ idle!
90
+ end
91
+
92
+ def idle!
93
+ @current_animation = self[:idle]
94
+ end
95
+
96
+ def walking!
97
+ @current_animation = self[:walking]
98
+ end
99
+
100
+ def blocking!
101
+ @current_animation = self[:blocking]
102
+ end
103
+
104
+ def punch!(&callback)
105
+ @current_animation = self[:punch]
106
+ @current_animation.play_once &callback
107
+ end
108
+
109
+ def kick!(&callback)
110
+ @current_animation = self[:kick]
111
+ @current_animation.play_once &callback
112
+ end
113
+
114
+ def width
115
+ @current_animation.width
116
+ end
117
+
118
+ def draw(*args)
119
+ @current_animation.draw *args
120
+ end
121
+
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,3 @@
1
+ module RubyFighter
2
+ VERSION = "0.0.0"
3
+ end
@@ -0,0 +1,11 @@
1
+ #
2
+ # The start file
3
+ #
4
+
5
+ require_relative "./ruby-fighter"
6
+
7
+ begin
8
+ RubyFighter::Game.new.show
9
+ rescue Interrupt => e
10
+ puts "\rScratch by bellah!"
11
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ruby_fighter/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ruby-fighter"
8
+ spec.version = RubyFighter::VERSION
9
+ spec.authors = ["Nikolay Nemshilov"]
10
+ spec.email = ["nemshilov@gmail.com"]
11
+
12
+ spec.summary = %q{Street Fighter II in Ruby}
13
+ spec.description = %q{An example of the usage of the Gosu library with Ruby}
14
+ spec.homepage = "https://github.com/MadRabbit/ruby-fighter"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "bin"
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "gosu", "~> 0.8"
23
+ spec.add_development_dependency "bundler", "~> 1.9"
24
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-fighter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Nikolay Nemshilov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gosu
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.9'
41
+ description: An example of the usage of the Gosu library with Ruby
42
+ email:
43
+ - nemshilov@gmail.com
44
+ executables:
45
+ - ruby-fighter
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - Gemfile.lock
52
+ - LICENSE.txt
53
+ - README.md
54
+ - assets/background-1.jpg
55
+ - assets/chun-li.gif
56
+ - assets/chun-li/blocking-1.gif
57
+ - assets/chun-li/hit-1.gif
58
+ - assets/chun-li/idle-1.gif
59
+ - assets/chun-li/idle-2.gif
60
+ - assets/chun-li/idle-3.gif
61
+ - assets/chun-li/idle-4.gif
62
+ - assets/chun-li/kick-1.gif
63
+ - assets/chun-li/kick-2.gif
64
+ - assets/chun-li/kick-3.gif
65
+ - assets/chun-li/kick-4.gif
66
+ - assets/chun-li/kick-5.gif
67
+ - assets/chun-li/punch-1.gif
68
+ - assets/chun-li/punch-2.gif
69
+ - assets/chun-li/punch-3.gif
70
+ - assets/chun-li/walking-1.gif
71
+ - assets/chun-li/walking-2.gif
72
+ - assets/chun-li/walking-3.gif
73
+ - assets/chun-li/walking-4.gif
74
+ - assets/chun-li/walking-5.gif
75
+ - assets/chun-li/walking-6.gif
76
+ - assets/chun-li/walking-7.gif
77
+ - assets/chun-li/walking-8.gif
78
+ - assets/ryu.gif
79
+ - assets/ryu/blocking-1.gif
80
+ - assets/ryu/hit-1.gif
81
+ - assets/ryu/hit-2.gif
82
+ - assets/ryu/hit-3.gif
83
+ - assets/ryu/idle-1.gif
84
+ - assets/ryu/idle-2.gif
85
+ - assets/ryu/idle-3.gif
86
+ - assets/ryu/idle-4.gif
87
+ - assets/ryu/kick-1.gif
88
+ - assets/ryu/kick-2.gif
89
+ - assets/ryu/kick-3.gif
90
+ - assets/ryu/kick-4.gif
91
+ - assets/ryu/kick-5.gif
92
+ - assets/ryu/punch-1.gif
93
+ - assets/ryu/punch-2.gif
94
+ - assets/ryu/punch-3.gif
95
+ - assets/ryu/punch-4.gif
96
+ - assets/ryu/punch-5.gif
97
+ - assets/ryu/walking-1.gif
98
+ - assets/ryu/walking-2.gif
99
+ - assets/ryu/walking-3.gif
100
+ - assets/ryu/walking-4.gif
101
+ - assets/ryu/walking-5.gif
102
+ - bin/ruby-fighter
103
+ - lib/ruby-fighter.rb
104
+ - lib/ruby_fighter.rb
105
+ - lib/ruby_fighter/animation.rb
106
+ - lib/ruby_fighter/backdrop.rb
107
+ - lib/ruby_fighter/controls.rb
108
+ - lib/ruby_fighter/game.rb
109
+ - lib/ruby_fighter/player.rb
110
+ - lib/ruby_fighter/version.rb
111
+ - lib/start.rb
112
+ - ruby-fighter.gemspec
113
+ homepage: https://github.com/MadRabbit/ruby-fighter
114
+ licenses:
115
+ - MIT
116
+ metadata: {}
117
+ post_install_message:
118
+ rdoc_options: []
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ requirements: []
132
+ rubyforge_project:
133
+ rubygems_version: 2.4.5
134
+ signing_key:
135
+ specification_version: 4
136
+ summary: Street Fighter II in Ruby
137
+ test_files: []