ruby_game 0.0.4 → 0.0.5

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.
@@ -3,9 +3,8 @@ require File.expand_path('../lib/ruby_game', File.dirname(__FILE__))
3
3
 
4
4
  RubyGame::Monster.define :ghost1 do
5
5
  image_name "ghost1"
6
- velocity 3
7
- action :move_up, velocity: 2, repeat: 80
8
- action :move_down, velocity: 2, repeat: 80
6
+ action :move_up, velocity: 4, repeat: 40
7
+ action :move_down, repeat: 80
9
8
  end
10
9
 
11
10
  RubyGame::Monster.define :ghost2 do
@@ -25,10 +24,10 @@ end
25
24
 
26
25
  RubyGame::Monster.define :dark_knight do
27
26
  image_name "dark_knight"
28
- action :forward
27
+ action :forward, velocity: 1
29
28
  end
30
29
 
31
- game = RubyGame::Game.new(640, 480)
30
+ game = RubyGame::Game.new
32
31
  game.start! do
33
32
  player RubyGame::Player.new(590, 420)
34
33
  ruby RubyGame::Ruby.new(65, 115)
@@ -2,8 +2,8 @@ require_relative "ruby_game/static_object"
2
2
  require_relative "ruby_game/moving_object"
3
3
  require_relative "ruby_game/ruby"
4
4
  require_relative "ruby_game/player"
5
- require_relative "ruby_game/monster"
6
5
  require_relative "ruby_game/game"
6
+ require_relative "ruby_game/monster"
7
7
  require_relative "ruby_game/version"
8
8
 
9
9
  module RubyGame
@@ -2,10 +2,10 @@ require 'gosu'
2
2
 
3
3
  module RubyGame
4
4
  class Game < Gosu::Window
5
- def initialize(width, height)
6
- super(width, height, false)
5
+ def initialize
6
+ super(640, 480, false)
7
7
  self.caption = "Ruby Game"
8
- @background_image = Gosu::Image.new(self, File.join(RubyGame::IMAGES_PATH, 'background.png'), true)
8
+ @background_image = Gosu::Image.new(self, File.join(IMAGES_PATH, 'background.png'), true)
9
9
  @font = Gosu::Font.new(self, Gosu::default_font_name, 60)
10
10
  end
11
11
 
@@ -33,7 +33,7 @@ module RubyGame
33
33
  end
34
34
 
35
35
  def button_down(id)
36
- close if id == Gosu::Button::KbEscape
36
+ self.close if id == Gosu::Button::KbEscape
37
37
  self.restart! if id == Gosu::Button::KbR
38
38
  end
39
39
 
@@ -52,7 +52,7 @@ module RubyGame
52
52
  @init = block if block_given?
53
53
  self.instance_eval(&@init)
54
54
  ([@ruby, @player] + @monsters).each {|object| object.init_image(self)}
55
- ([@player] + @monsters).each {|moving_object| moving_object.init_limits(width, height, 15, 40)}
55
+ ([@player] + @monsters).each {|object| object.init_limits(width, height, 15, 40)}
56
56
  @state = :run
57
57
  self.show if block_given?
58
58
  end
@@ -4,11 +4,9 @@ module RubyGame
4
4
  @@monsters = {}
5
5
  Action = Struct.new(:direction, :velocity)
6
6
 
7
- def initialize(x = 0, y = 0, image_name = 'ghost')
7
+ def initialize(x = 0, y = 0, image_name = 'ghost1')
8
8
  super
9
- @velocity = 3
10
9
  @actions = []
11
- @action_index = 0
12
10
  end
13
11
 
14
12
  def self.build(name, number = 1)
@@ -16,14 +14,14 @@ module RubyGame
16
14
  end
17
15
 
18
16
  def init_limits(max_width, max_height, border_with, border_top_with)
19
- super
20
- @x = rand border_top_with..(max_width - 2*border_top_with)
21
- @y = rand border_top_with..(max_height - 2*border_top_with)
17
+ super
18
+ @x = rand border_top_with..(max_width - 2*border_top_with)
19
+ @y = rand border_top_with..(max_height - 2*border_top_with)
22
20
  end
23
21
 
24
- def forward(player)
25
- @x += player.x <=> @x
26
- @y += player.y <=> @y
22
+ def forward(player, velocity = @velocity)
23
+ @x += (player.x <=> @x) * velocity
24
+ @y += (player.y <=> @y) * velocity
27
25
  end
28
26
 
29
27
  def self.define(name, &block)
@@ -46,17 +44,13 @@ module RubyGame
46
44
  end
47
45
 
48
46
  def execute(player)
49
- next_index = @action_index % @actions.length
50
- action = @actions[next_index]
51
- default_velocity = @velocity
52
- @velocity = action.velocity
47
+ @actions_enum ||= @actions.cycle
48
+ action = @actions_enum.next
53
49
  if action.direction == :forward
54
- self.send(action.direction, player)
50
+ self.send(action.direction, player, action.velocity)
55
51
  else
56
- self.send(action.direction)
52
+ self.send(action.direction, action.velocity)
57
53
  end
58
- @velocity = default_velocity
59
- @action_index = next_index + 1
60
54
  end
61
55
  end
62
56
  end
@@ -14,20 +14,20 @@ module RubyGame
14
14
  Math.hypot(object.x - @x, object.y - @y) <= object.width/2
15
15
  end
16
16
 
17
- def move_left
18
- @x -= @velocity if @x > @border_with + (@image.width/2)
17
+ def move_left(velocity = @velocity)
18
+ @x -= velocity if @x > @border_with + (@image.width/2)
19
19
  end
20
20
 
21
- def move_right
22
- @x += @velocity if @x < @max_width - @border_with - (@image.width/2)
21
+ def move_right(velocity = @velocity)
22
+ @x += velocity if @x < @max_width - @border_with - (@image.width/2)
23
23
  end
24
24
 
25
- def move_up
26
- @y -= @velocity if @y > @border_with + @border_top_with + (@image.height/2)
25
+ def move_up(velocity = @velocity)
26
+ @y -= velocity if @y > @border_with + @border_top_with + (@image.height/2)
27
27
  end
28
28
 
29
- def move_down
30
- @y += @velocity if @y < @max_height - @border_with - (@image.height/2)
29
+ def move_down(velocity = @velocity)
30
+ @y += velocity if @y < @max_height - @border_with - (@image.height/2)
31
31
  end
32
32
  end
33
33
  end
@@ -11,7 +11,7 @@ module RubyGame
11
11
  end
12
12
 
13
13
  def init_image(window)
14
- @image = Gosu::Image.new(window, File.join(RubyGame::IMAGES_PATH, "#{@image_name}.png"), true)
14
+ @image = Gosu::Image.new(window, File.join(IMAGES_PATH, "#{@image_name}.png"), true)
15
15
  end
16
16
 
17
17
  def draw
@@ -1,3 +1,3 @@
1
1
  module RubyGame
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -4,8 +4,8 @@ require File.expand_path('../lib/ruby_game/version', __FILE__)
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["Matthieu Segret"]
6
6
  gem.email = ["matthieu@humancoders.com"]
7
- gem.description = %q{RubyGame est un jeu pour apprendre à développer avec Ruby}
8
- gem.summary = %q{RubyGame est un jeu pour apprendre à développer avec Ruby}
7
+ gem.description = %q{Ruby Game est un jeu pour apprendre à développer avec Ruby}
8
+ gem.summary = %q{Ruby Game est un jeu pour apprendre à développer avec Ruby}
9
9
  gem.homepage = "http://formations.humancoders.com/formations/ruby"
10
10
 
11
11
  gem.files = `git ls-files`.split($\)
@@ -14,4 +14,6 @@ Gem::Specification.new do |gem|
14
14
  gem.name = "ruby_game"
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = RubyGame::VERSION
17
+
18
+ gem.add_dependency "gosu"
17
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_game
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,9 +9,20 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-18 00:00:00.000000000 Z
13
- dependencies: []
14
- description: RubyGame est un jeu pour apprendre à développer avec Ruby
12
+ date: 2013-03-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: gosu
16
+ requirement: &70292594326840 !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: *70292594326840
25
+ description: Ruby Game est un jeu pour apprendre à développer avec Ruby
15
26
  email:
16
27
  - matthieu@humancoders.com
17
28
  executables:
@@ -67,6 +78,6 @@ rubyforge_project:
67
78
  rubygems_version: 1.8.11
68
79
  signing_key:
69
80
  specification_version: 3
70
- summary: RubyGame est un jeu pour apprendre à développer avec Ruby
81
+ summary: Ruby Game est un jeu pour apprendre à développer avec Ruby
71
82
  test_files: []
72
83
  has_rdoc: