ruby_game 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ ruby_game.tmproj
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruby_game.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Matthieu Segret
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # RubyGame
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'ruby_game'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install ruby_game
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
Binary file
Binary file
Binary file
Binary file
data/bin/ruby_game ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path('../lib/ruby_game', File.dirname(__FILE__))
4
+ =begin
5
+ RubyGame::MonsterFactory.define :ghost do
6
+ image 'Ghost'
7
+ velocity 4
8
+ actions do
9
+ 15.times {move_up}
10
+ 15.times {move_down}
11
+ end
12
+ end
13
+ =end
14
+ game = RubyGame::Game.new(640, 480)
15
+ game.start! do |g|
16
+ g.player RubyGame::Player.new(590, 420)
17
+ g.ruby RubyGame::Ruby.new(65, 115)
18
+ g.monster RubyGame::Monster.new(520, 300)# RubyGame::MonsterFactory.build(:ghost, 3)
19
+ end
data/lib/ruby_game.rb ADDED
@@ -0,0 +1,13 @@
1
+ require_relative 'ruby_game/static_object'
2
+ require_relative 'ruby_game/moving_object'
3
+ require_relative 'ruby_game/player'
4
+ require_relative 'ruby_game/ruby'
5
+ require_relative 'ruby_game/monster'
6
+ #require_relative 'ruby_game/monster_factory'
7
+ require_relative 'ruby_game/game'
8
+ require_relative 'ruby_game/version'
9
+
10
+ module RubyGame
11
+ ROOT_PATH = File.expand_path('../', File.dirname(__FILE__))
12
+ IMAGES_PATH = File.join(ROOT_PATH, '/app/assets/images')
13
+ end
@@ -0,0 +1,69 @@
1
+ require 'gosu'
2
+
3
+ module RubyGame
4
+ class Game < Gosu::Window
5
+ def initialize(width, height)
6
+ super(width, height, false)
7
+ self.caption = "Ruby Game"
8
+ @background_image = Gosu::Image.new(self, File.join(RubyGame::IMAGES_PATH, 'background.png'), true)
9
+ @font = Gosu::Font.new(self, Gosu::default_font_name, 60)
10
+ end
11
+
12
+ def update
13
+ if self.run?
14
+ @player.move_left if button_down? Gosu::Button::KbLeft
15
+ @player.move_right if button_down? Gosu::Button::KbRight
16
+ @player.move_up if button_down? Gosu::Button::KbUp
17
+ @player.move_down if button_down? Gosu::Button::KbDown
18
+
19
+ self.win! if @player.touch?(@ruby)
20
+ #self.gameover! if @monster.touch?(@player)
21
+ end
22
+ end
23
+
24
+ def draw
25
+ @background_image.draw(0, 0, 0)
26
+ @font.draw("Victoire !", 210, 240, 2, 1.0, 1.0, 0xffffff00) if self.won?
27
+ @font.draw("Game Over", 175, 240, 2, 1.0, 1.0, 0xffffff00) if self.gameover?
28
+ @objects.each {|object| object.draw}
29
+ end
30
+
31
+ def button_down(id)
32
+ close if id == Gosu::Button::KbEscape
33
+ self.restart! if id == Gosu::Button::KbR
34
+ end
35
+
36
+
37
+ %w(player ruby monster).each do |object|
38
+ define_method object do |value|
39
+ instance_variable_set("@#{object}", value)
40
+ @objects << value
41
+ end
42
+ end
43
+
44
+ def start!(&block)
45
+ @objects = []
46
+ @init = block if block
47
+ @init.call(self)
48
+ @objects.each {|object| object.init_image(self)}
49
+ [@player, @monster].compact.each {|moving_object| moving_object.init_limits(width, height, 15, 40)}
50
+ @state = :run
51
+ self.show if block
52
+ end
53
+ alias_method :restart!, :start!
54
+
55
+ def win!
56
+ @state = :won
57
+ end
58
+
59
+ def gameover!
60
+ @state = :gameover
61
+ end
62
+
63
+ %w(won run gameover).each do |state|
64
+ define_method "#{state}?" do
65
+ @state == state.to_sym
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,8 @@
1
+ module RubyGame
2
+ class Monster < MovingObject
3
+ def initialize(x, y, image_name = 'ghost')
4
+ super
5
+ @velocity = 3
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,33 @@
1
+ module RubyGame
2
+ class MovingObject < StaticObject
3
+ def initialize(x, y, image_name = 'player')
4
+ super
5
+ @velocity = 2
6
+ end
7
+
8
+ def touch?(object)
9
+ Math.hypot(object.x - @x, object.y - @y) <= object.width/2
10
+ end
11
+
12
+ def init_limits(max_width, max_height, border_with, border_top_with)
13
+ @max_width, @max_height, @border_with = max_width, max_height
14
+ @border_with, @border_top_with = border_with, border_top_with
15
+ end
16
+
17
+ def move_left
18
+ @x -= @velocity if @x > @border_with + (@image.width/2)
19
+ end
20
+
21
+ def move_right
22
+ @x += @velocity if @x < @max_width - @border_with - (@image.width/2)
23
+ end
24
+
25
+ def move_up
26
+ @y -= @velocity if @y > @border_with + @border_top_with + (@image.height/2)
27
+ end
28
+
29
+ def move_down
30
+ @y += @velocity if @y < @max_height - @border_with - (@image.height/2)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,7 @@
1
+ module RubyGame
2
+ class Player < MovingObject
3
+ def initialize(x, y, image_name = 'player')
4
+ super
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module RubyGame
2
+ class Ruby < StaticObject
3
+ def initialize(x, y, image_name = 'ruby')
4
+ super
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,22 @@
1
+ require 'forwardable'
2
+
3
+ module RubyGame
4
+ class StaticObject
5
+ extend Forwardable
6
+ def_delegator :@image, :width
7
+ attr_accessor :x, :y
8
+
9
+ def initialize(x, y, image_name)
10
+ @x, @y = x, y
11
+ @image_name = image_name
12
+ end
13
+
14
+ def init_image(window)
15
+ @image = Gosu::Image.new(window, File.join(RubyGame::IMAGES_PATH, "#{@image_name}.png"), true)
16
+ end
17
+
18
+ def draw
19
+ @image.draw_rot(@x, @y, 1, 0)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module RubyGame
2
+ VERSION = "0.0.1"
3
+ end
data/ruby_game.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/ruby_game/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Matthieu Segret"]
6
+ gem.email = ["matthieu.segret@gmail.com"]
7
+ gem.description = %q{RubyGame est jeux pour apprendre à développer avec Ruby}
8
+ gem.summary = %q{RubyGame est jeux pour apprendre à développer avec Ruby}
9
+ gem.homepage = "http://formations.humancoders.com/formations/ruby"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "ruby_game"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = RubyGame::VERSION
17
+ gem.platform = Gem::Platform::RUBY
18
+
19
+ gem.add_dependency "gosu"
20
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby_game
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Matthieu Segret
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: gosu
16
+ requirement: &70117118687300 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70117118687300
25
+ description: RubyGame est jeux pour apprendre à développer avec Ruby
26
+ email:
27
+ - matthieu.segret@gmail.com
28
+ executables:
29
+ - ruby_game
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - .gitignore
34
+ - Gemfile
35
+ - LICENSE
36
+ - README.md
37
+ - Rakefile
38
+ - app/assets/images/background.png
39
+ - app/assets/images/ghost.png
40
+ - app/assets/images/player.png
41
+ - app/assets/images/ruby.png
42
+ - bin/ruby_game
43
+ - lib/ruby_game.rb
44
+ - lib/ruby_game/game.rb
45
+ - lib/ruby_game/monster.rb
46
+ - lib/ruby_game/moving_object.rb
47
+ - lib/ruby_game/player.rb
48
+ - lib/ruby_game/ruby.rb
49
+ - lib/ruby_game/static_object.rb
50
+ - lib/ruby_game/version.rb
51
+ - ruby_game.gemspec
52
+ homepage: http://formations.humancoders.com/formations/ruby
53
+ licenses: []
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubyforge_project:
72
+ rubygems_version: 1.8.11
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: RubyGame est jeux pour apprendre à développer avec Ruby
76
+ test_files: []
77
+ has_rdoc: