chingu 0.5.8.1 → 0.5.8.2

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
data/Manifest.txt CHANGED
@@ -16,6 +16,7 @@ examples/example1.rb
16
16
  examples/example10.rb
17
17
  examples/example11.rb
18
18
  examples/example12.rb
19
+ examples/example13.rb
19
20
  examples/example2.rb
20
21
  examples/example3.rb
21
22
  examples/example4.rb
@@ -25,6 +26,7 @@ examples/example7.rb
25
26
  examples/example8.rb
26
27
  examples/example9.rb
27
28
  examples/game1.rb
29
+ examples/high_score_list.yml
28
30
  examples/media/Parallax-scroll-example-layer-0.png
29
31
  examples/media/Parallax-scroll-example-layer-1.png
30
32
  examples/media/Parallax-scroll-example-layer-2.png
@@ -71,7 +73,7 @@ lib/chingu/helpers/gfx.rb
71
73
  lib/chingu/helpers/input_client.rb
72
74
  lib/chingu/helpers/input_dispatcher.rb
73
75
  lib/chingu/helpers/rotation_center.rb
74
- lib/chingu/high_score.rb
76
+ lib/chingu/high_score_list.rb
75
77
  lib/chingu/inflector.rb
76
78
  lib/chingu/input.rb
77
79
  lib/chingu/named_resource.rb
data/README.rdoc CHANGED
@@ -528,10 +528,14 @@ You also have:
528
528
  Sound["shot.png"]
529
529
  Song["intromusic.ogg"]
530
530
 
531
- By default Image, Sound and Sound searches the current directory and directory "media".
531
+ The default settings are like this:
532
+ Image["image.png"] -- searches directories ".", "images", "gfx" and "media"
533
+ Sample["sample.wav"] -- searches directories ".", "sounds", "sfx" and "media"
534
+ Song["song.ogg"] -- searches directories ".", "songs", "sounds", "sfx" and "media"
535
+
532
536
  Add your own searchpaths like this:
533
- Gosu::Image.autoload_dirs << File.join($window.root, "gfx")
534
- Gosu::Sound.autoload_dirs << File.join($window.root, "samples")
537
+ Gosu::Image.autoload_dirs << File.join(ROOT, "gfx")
538
+ Gosu::Sound.autoload_dirs << File.join(ROOT, "samples")
535
539
 
536
540
  This will add \path\to\your\game\gfx and \path\to\your\game\samples to Image and Sound.
537
541
 
data/chingu.gemspec CHANGED
@@ -2,17 +2,17 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{chingu}
5
- s.version = "0.5.8.1"
5
+ s.version = "0.5.8.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["ippa"]
9
- s.date = %q{2009-10-19}
9
+ s.date = %q{2009-10-22}
10
10
  s.description = %q{OpenGL accelerated 2D game framework for Ruby.
11
11
  Builds on the awesome Gosu (Ruby/C++) which provides all the core functionality.
12
12
  It adds simple yet powerful game states, prettier input handling, deployment safe asset-handling, a basic re-usable game object and automation of common task.}
13
13
  s.email = ["ippa@rubylicio.us"]
14
14
  s.extra_rdoc_files = ["History.txt", "Manifest.txt", "benchmarks/README.txt"]
15
- s.files = ["History.txt", "LICENSE", "Manifest.txt", "README.rdoc", "Rakefile", "benchmarks/README.txt", "benchmarks/benchmark.rb", "benchmarks/benchmark3.rb", "benchmarks/benchmark4.rb", "benchmarks/benchmark5.rb", "benchmarks/benchmark6.rb", "benchmarks/meta_benchmark.rb", "benchmarks/meta_benchmark2.rb", "chingu.gemspec", "examples/example1.rb", "examples/example10.rb", "examples/example11.rb", "examples/example12.rb", "examples/example2.rb", "examples/example3.rb", "examples/example4.rb", "examples/example5.rb", "examples/example6.rb", "examples/example7.rb", "examples/example8.rb", "examples/example9.rb", "examples/game1.rb", "examples/media/Parallax-scroll-example-layer-0.png", "examples/media/Parallax-scroll-example-layer-1.png", "examples/media/Parallax-scroll-example-layer-2.png", "examples/media/Parallax-scroll-example-layer-3.png", "examples/media/background1.png", "examples/media/bullet.png", "examples/media/bullet_hit.wav", "examples/media/city1.csv", "examples/media/city1.png", "examples/media/city2.png", "examples/media/droid.bmp", "examples/media/enemy_bullet.png", "examples/media/explosion.wav", "examples/media/fire_bullet.png", "examples/media/fireball.png", "examples/media/laser.wav", "examples/media/particle.png", "examples/media/plane.csv", "examples/media/plane.png", "examples/media/ruby.png", "examples/media/saucer.csv", "examples/media/saucer.gal", "examples/media/saucer.png", "examples/media/spaceship.png", "examples/media/stickfigure.bmp", "examples/media/stickfigure.png", "examples/media/video_games.png", "lib/chingu.rb", "lib/chingu/animation.rb", "lib/chingu/assets.rb", "lib/chingu/basic_game_object.rb", "lib/chingu/core_extensions.rb", "lib/chingu/fpscounter.rb", "lib/chingu/game_object.rb", "lib/chingu/game_object_list.rb", "lib/chingu/game_state.rb", "lib/chingu/game_state_manager.rb", "lib/chingu/game_states/debug.rb", "lib/chingu/game_states/fade_to.rb", "lib/chingu/game_states/pause.rb", "lib/chingu/helpers/game_object.rb", "lib/chingu/helpers/game_state.rb", "lib/chingu/helpers/gfx.rb", "lib/chingu/helpers/input_client.rb", "lib/chingu/helpers/input_dispatcher.rb", "lib/chingu/helpers/rotation_center.rb", "lib/chingu/high_score.rb", "lib/chingu/inflector.rb", "lib/chingu/input.rb", "lib/chingu/named_resource.rb", "lib/chingu/parallax.rb", "lib/chingu/particle.rb", "lib/chingu/rect.rb", "lib/chingu/require_all.rb", "lib/chingu/text.rb", "lib/chingu/traits/collision_detection.rb", "lib/chingu/traits/effect.rb", "lib/chingu/traits/retrofy.rb", "lib/chingu/traits/timer.rb", "lib/chingu/traits/velocity.rb", "lib/chingu/window.rb"]
15
+ s.files = ["History.txt", "LICENSE", "Manifest.txt", "README.rdoc", "Rakefile", "benchmarks/README.txt", "benchmarks/benchmark.rb", "benchmarks/benchmark3.rb", "benchmarks/benchmark4.rb", "benchmarks/benchmark5.rb", "benchmarks/benchmark6.rb", "benchmarks/meta_benchmark.rb", "benchmarks/meta_benchmark2.rb", "chingu.gemspec", "examples/example1.rb", "examples/example10.rb", "examples/example11.rb", "examples/example12.rb", "examples/example13.rb", "examples/example2.rb", "examples/example3.rb", "examples/example4.rb", "examples/example5.rb", "examples/example6.rb", "examples/example7.rb", "examples/example8.rb", "examples/example9.rb", "examples/game1.rb", "examples/high_score_list.yml", "examples/media/Parallax-scroll-example-layer-0.png", "examples/media/Parallax-scroll-example-layer-1.png", "examples/media/Parallax-scroll-example-layer-2.png", "examples/media/Parallax-scroll-example-layer-3.png", "examples/media/background1.png", "examples/media/bullet.png", "examples/media/bullet_hit.wav", "examples/media/city1.csv", "examples/media/city1.png", "examples/media/city2.png", "examples/media/droid.bmp", "examples/media/enemy_bullet.png", "examples/media/explosion.wav", "examples/media/fire_bullet.png", "examples/media/fireball.png", "examples/media/laser.wav", "examples/media/particle.png", "examples/media/plane.csv", "examples/media/plane.png", "examples/media/ruby.png", "examples/media/saucer.csv", "examples/media/saucer.gal", "examples/media/saucer.png", "examples/media/spaceship.png", "examples/media/stickfigure.bmp", "examples/media/stickfigure.png", "examples/media/video_games.png", "lib/chingu.rb", "lib/chingu/animation.rb", "lib/chingu/assets.rb", "lib/chingu/basic_game_object.rb", "lib/chingu/core_extensions.rb", "lib/chingu/fpscounter.rb", "lib/chingu/game_object.rb", "lib/chingu/game_object_list.rb", "lib/chingu/game_state.rb", "lib/chingu/game_state_manager.rb", "lib/chingu/game_states/debug.rb", "lib/chingu/game_states/fade_to.rb", "lib/chingu/game_states/pause.rb", "lib/chingu/helpers/game_object.rb", "lib/chingu/helpers/game_state.rb", "lib/chingu/helpers/gfx.rb", "lib/chingu/helpers/input_client.rb", "lib/chingu/helpers/input_dispatcher.rb", "lib/chingu/helpers/rotation_center.rb", "lib/chingu/high_score_list.rb", "lib/chingu/inflector.rb", "lib/chingu/input.rb", "lib/chingu/named_resource.rb", "lib/chingu/parallax.rb", "lib/chingu/particle.rb", "lib/chingu/rect.rb", "lib/chingu/require_all.rb", "lib/chingu/text.rb", "lib/chingu/traits/collision_detection.rb", "lib/chingu/traits/effect.rb", "lib/chingu/traits/retrofy.rb", "lib/chingu/traits/timer.rb", "lib/chingu/traits/velocity.rb", "lib/chingu/window.rb"]
16
16
  s.homepage = %q{http://github.com/ippa/chingu/tree/master}
17
17
  s.rdoc_options = ["--main", "README.rdoc"]
18
18
  s.require_paths = ["lib"]
@@ -0,0 +1,88 @@
1
+ require 'rubygems'
2
+ require File.join(File.dirname($0), "..", "lib", "chingu")
3
+ include Gosu
4
+ include Chingu
5
+
6
+ #
7
+ # Demonstrating Chingus HighScoreList-class
8
+ # I couldn't keep myself from spicying it up some though :P
9
+ #
10
+ class Game < Chingu::Window
11
+ def initialize
12
+ super(640,400)
13
+ self.input = {:esc => :exit}
14
+ self.caption = "Example of Chingus HighScore class"
15
+
16
+ PulsatingText.create("HIGH SCORES", :x => $window.width/2, :y => 50, :size => 70)
17
+
18
+ #
19
+ # Load a list from disk, defaults to "high_score_list.yml"
20
+ # Argument :size forces list to this size
21
+ #
22
+ @high_score_list = HighScoreList.load(:size => 10)
23
+
24
+ #
25
+ # Add some new high scores to the list. :name and :score are required but you can put whatever.
26
+ # They will mix with the old scores, automatic default sorting on :score
27
+ #
28
+ 10.times { @high_score_list.add(:name => "NEW", :score => rand(10000)) }
29
+
30
+ #
31
+ # Iterate through all high scores and create the visual represenation of it
32
+ #
33
+ @high_score_list.each_with_index do |high_score, index|
34
+ y = index * 25 + 100
35
+ Text.create(high_score[:name], :x => 200, :y => y, :size => 20)
36
+ Text.create(high_score[:score], :x => 400, :y => y, :size => 20)
37
+ end
38
+
39
+ 5.times do
40
+ score = rand(20000)
41
+ puts "position for #{score}: #{@high_score_list.position_by_score(score)}"
42
+ end
43
+
44
+ # @high_score_list.save # Uncomment to save list to disk
45
+ end
46
+
47
+ def update
48
+ super
49
+ self.caption = "FPS #{$window.fps} - game objects: #{game_objects.size}"
50
+ end
51
+ end
52
+
53
+ #
54
+ # colorful pulsating text...
55
+ #
56
+ class PulsatingText < Text
57
+ has_trait :timer, :effect
58
+ @@red = Color.new(0xFFFF0000)
59
+ @@green = Color.new(0xFF00FF00)
60
+ @@blue = Color.new(0xFF0000FF)
61
+
62
+ def initialize(text, options = {})
63
+ super(text, options)
64
+
65
+ options = text if text.is_a? Hash
66
+ @pulse = options[:pulse] || false
67
+ self.rotation_center(:center_center)
68
+ every(20) { create_pulse } if @pulse == false
69
+ end
70
+
71
+ def create_pulse
72
+ pulse = PulsatingText.create(@text, :x => @x, :y => @y, :height => @height, :pulse => true, :image => @image, :zorder => @zorder+1)
73
+ colors = [@@red, @@green, @@blue]
74
+ pulse.color = colors[rand(colors.size)].dup
75
+ pulse.mode = :additive
76
+ pulse.alpha -= 150
77
+ pulse.scale_rate = 0.002
78
+ pulse.fade_rate = -3 + rand(2)
79
+ pulse.rotation_rate = rand(2)==0 ? 0.05 : -0.05
80
+ end
81
+
82
+ def update
83
+ destroy if self.alpha == 0
84
+ end
85
+
86
+ end
87
+
88
+ Game.new.show
@@ -0,0 +1,21 @@
1
+ ---
2
+ - :name: ABC
3
+ :score: 9260
4
+ - :name: ABC
5
+ :score: 9112
6
+ - :name: ABC
7
+ :score: 8660
8
+ - :name: ABC
9
+ :score: 8030
10
+ - :name: ABC
11
+ :score: 7802
12
+ - :name: ABC
13
+ :score: 6976
14
+ - :name: ABC
15
+ :score: 6718
16
+ - :name: ABC
17
+ :score: 6325
18
+ - :name: ABC
19
+ :score: 5632
20
+ - :name: ABC
21
+ :score: 4199
data/lib/chingu.rb CHANGED
@@ -26,8 +26,7 @@ require 'rubygems' unless RUBY_VERSION =~ /1\.9/
26
26
  require 'gosu'
27
27
  require File.join(CHINGU_ROOT,"chingu","require_all") # Thanks to http://github.com/tarcieri/require_all !
28
28
  require_all "#{CHINGU_ROOT}/chingu"
29
- #autoload :OpenStruct, "ostruct"
30
29
 
31
30
  module Chingu
32
- VERSION = "0.5.8.1"
31
+ VERSION = "0.5.8.2"
33
32
  end
@@ -10,7 +10,7 @@ module Chingu
10
10
  # Is autodetection of width / height possible?
11
11
  #
12
12
  class Animation
13
- attr_accessor :frames, :delay
13
+ attr_accessor :frames, :delay, :step
14
14
 
15
15
  #
16
16
  # Create a new Animation.
@@ -22,9 +22,10 @@ module Chingu
22
22
  # - height: width of each frame in the tileanimation
23
23
  # - size: [x,y] specify width/height with 1 argument (an array)
24
24
  # - delay: milliseconds between each frame
25
+ # - step: [steps] move animation forward [steps] frames each time we call #next
25
26
  #
26
27
  def initialize(options)
27
- options = {:loop => true, :bounce => false, :width => 32, :height => 32, :index => 0, :delay => 100}.merge(options)
28
+ options = {:step => 1, :loop => true, :bounce => false, :width => 32, :height => 32, :index => 0, :delay => 100}.merge(options)
28
29
 
29
30
  @loop = options[:loop]
30
31
  @bounce = options[:bounce]
@@ -33,6 +34,7 @@ module Chingu
33
34
  @width = options[:width]
34
35
  @index = options[:index]
35
36
  @delay = options[:delay]
37
+ @step = options[:step] || 1
36
38
  @dt = 0
37
39
 
38
40
  if options[:size]
@@ -44,7 +46,6 @@ module Chingu
44
46
 
45
47
  @frame_actions = []
46
48
  @frames = Gosu::Image.load_tiles($window, @file, @width, @height, true)
47
- @step = 1
48
49
  end
49
50
 
50
51
  #
data/lib/chingu/assets.rb CHANGED
@@ -9,7 +9,7 @@ module Chingu
9
9
  end
10
10
 
11
11
  def image_path(file)
12
- File.join(ROOT, "gfx", file)
12
+ File.join(ROOT, "images", file)
13
13
  end
14
14
 
15
15
  class Asset
@@ -21,6 +21,9 @@ module Chingu
21
21
  end
22
22
  end
23
23
 
24
+ #
25
+ # Extend GOSU's core classes with NamedResource
26
+ #
24
27
  module Gosu
25
28
  class Image
26
29
  include Chingu::NamedResource
@@ -45,20 +48,5 @@ module Gosu
45
48
  (path = find_file(name)) ? Gosu::Sample.new($window, path) : nil
46
49
  end
47
50
  end
48
- Sound = Sample
49
-
50
- class Tile
51
- include Chingu::NamedResource
52
-
53
- def self.autoload(name)
54
- (path = find_file(name)) ? Gosu::Image.load_tiles($window, path, 32, 32, true) : nil
55
- end
56
- end
57
-
58
- class CutTiles
59
- def self.[](name, width, height)
60
- @@tiles = Hash.new unless defined?(@@tiles)
61
- @@tiles[name] ||= Gosu::Image.load_tiles($window, name, width, height, true)
62
- end
63
- end
51
+ Sound = Sample # Gosu uses Sample, but Sound makes sense too.
64
52
  end
@@ -62,9 +62,9 @@ module Chingu
62
62
  # Use create() instead of new() if you want to keep track of your objects through
63
63
  # Chingus "game_objects" which is available in all game states and the main window.
64
64
  #
65
- def self.create(options = {})
66
- instance = self.new(options)
67
-
65
+ #def self.create(options = {})
66
+ def self.create(*options)
67
+ instance = self.new(*options)
68
68
 
69
69
  #
70
70
  # Add to parents list of game objects
@@ -0,0 +1,117 @@
1
+ #--
2
+ #
3
+ # Chingu -- OpenGL accelerated 2D game framework for Ruby
4
+ # Copyright (C) 2009 ippa / ippa@rubylicio.us
5
+ #
6
+ # This library is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU Lesser General Public
8
+ # License as published by the Free Software Foundation; either
9
+ # version 2.1 of the License, or (at your option) any later version.
10
+ #
11
+ # This library is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this library; if not, write to the Free Software
18
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
+ #
20
+ #++
21
+
22
+ module Chingu
23
+ #
24
+ # Highscore-class
25
+ #
26
+ # - Keeps a local YAML file with highscores, default highscores.yml in root game dir.
27
+ # - Add, delete, clear highscores
28
+ # - Iterate through highscores with simple Highscore#each
29
+ #
30
+ class HighScoreList
31
+ attr_reader :file
32
+
33
+ #
34
+ # Create a new high score list with 0 entries
35
+ #
36
+ def initialize(options = {})
37
+ require 'yaml'
38
+ @file = options[:file] || "high_score_list.yml"
39
+ @size = options[:size] || 100
40
+ @sort_on = options[:sort_on] || :score
41
+ @high_scores = Array.new
42
+ end
43
+
44
+ #
45
+ # Create a new high score list and try to load content from :file-parameter
46
+ # If no :file is given, HighScoreList tries to load from file "high_score_list.yml"
47
+ #
48
+ def self.load(options = {})
49
+ high_score_list = HighScoreList.new(options)
50
+ high_score_list.load
51
+ return high_score_list
52
+ end
53
+
54
+ #
55
+ # Add a new high score to list.
56
+ # 'data' is a hash of key/value-pairs that needs to contain at least the keys :name and :score
57
+ #
58
+ def add(data)
59
+ raise "No :name value in high score!" if data[:name].nil?
60
+ raise "No :score value in high score!" if data[:score].nil?
61
+
62
+ @high_scores.push(data)
63
+ @high_scores.sort! { |a, b| b[@sort_on] <=> a[@sort_on] }
64
+ @high_scores = @high_scores[0..@size]
65
+ end
66
+ alias << add
67
+
68
+ #
69
+ # Returns the position 'score' would get in among the high scores:
70
+ # @high_score_list.position_by_score(999999999) # most likely returns 1 for the number one spot
71
+ # @high_score_list.position_by_score(1) # most likely returns nil since no placement is found (didn't make it to the high scores)
72
+ #
73
+ def position_by_score(score)
74
+ position = 1
75
+ @high_scores.each do |high_score|
76
+ return position if score > high_score[:score]
77
+ position += 1
78
+ end
79
+ return nil
80
+ end
81
+
82
+ #
83
+ # Direct access to invidual high scores
84
+ #
85
+ def [](index)
86
+ @high_scores[index]
87
+ end
88
+
89
+ #
90
+ # Iterate through all high scores
91
+ #
92
+ def each
93
+ @high_scores.each { |high_score| yield high_score }
94
+ end
95
+
96
+ def each_with_index
97
+ @high_scores.each_with_index { |high_score, index| yield high_score, index }
98
+ end
99
+
100
+ #
101
+ # Load data from previously specified @file
102
+ #
103
+ def load
104
+ @high_scores = YAML.load_file(@file) if File.exists?(@file)
105
+ end
106
+
107
+ #
108
+ # Save high score data into previously specified @file
109
+ #
110
+ def save
111
+ File.open(@file, 'w') do |out|
112
+ YAML.dump(@high_scores, out)
113
+ end
114
+ end
115
+
116
+ end
117
+ end
data/lib/chingu/text.rb CHANGED
@@ -27,14 +27,14 @@ module Chingu
27
27
  # @font.draw("A Text", 200, 50, 55, 2.0)
28
28
  #
29
29
  # Chingu
30
- # @text = Chingu::Text.new(:text => "A Text", :x => 200, :y => 50, :zorder => 55, :factor_x => 2.0)
30
+ # @text = Chingu::Text.new("A Text", :x => 200, :y => 50, :zorder => 55, :factor_x => 2.0)
31
31
  # @text.draw # usually not needed as Text is a GameObject and therefore autodrawn
32
32
  #
33
33
  # @text comes with a number of changable properties, x,y,zorder,angle,factor_x,color,mode etc.
34
34
  #
35
35
  class Text < Chingu::GameObject
36
36
  attr_accessor :text
37
- attr_reader :height, :gosu_font
37
+ attr_reader :height, :gosu_font, :line_spacing, :align, :max_width
38
38
 
39
39
  @@size = nil
40
40
  @@font = nil
@@ -48,21 +48,47 @@ module Chingu
48
48
 
49
49
  #
50
50
  # Takes the standard GameObject-hash-arguments but also:
51
- # - :text - a string of text
52
- # - :font_name|:font - name of a systemfont (default: "verdana")
53
- # - :height|size - how many pixels high should the text be
51
+ # :text - a string of text
52
+ # :font_name|:font - Name of a system font, or a filename to a TTF file (must contain �/�, does not work on Linux).
53
+ # :height|:size - Height of the font in pixels.
54
+ # :line_spacing - Spacing between two lines of text in pixels.
55
+ # :max_width - Width of the bitmap that will be returned. Text will be split into multiple lines to avoid drawing over the right border. When a single word is too long, it will be truncated.
56
+ # :align - One of :left, :right, :center or :justify.
54
57
  #
55
- def initialize(options)
58
+ # if :max_width is given the text is drawn using :line_spacing, :align and :max_width
59
+ #
60
+ def initialize(text, options = {})
61
+ if text.is_a? Hash
62
+ options = text
63
+ text = nil
64
+ end
65
+
56
66
  super(options)
57
- @text = options[:text] || "-No text specified-"
67
+
68
+ @text = text || options[:text] || "-No text specified-"
58
69
  @font = options[:font] || @@font || default_font_name()
59
- @height = options[:height] || options[:size] || @@size || 15
70
+ @height = @size = options[:height] || options[:size] || @@size || 15
71
+ @line_spacing = options[:line_spacing] || 1
72
+ @align = options[:align] || :left
73
+ @max_width = options[:max_width]
74
+
75
+ self.rotation_center(:top_left)
60
76
 
61
77
  @gosu_font = Gosu::Font.new($window, @font, @height)
78
+
79
+ create_image unless @image
80
+ end
81
+
82
+ #
83
+ # Set a new text, a new image is created.
84
+ #
85
+ def text=(text)
86
+ @text = text
87
+ create_image
62
88
  end
63
89
 
64
- def draw
65
- @gosu_font.draw_rot(@text, @x.to_i, @y.to_i, @zorder, @angle, @factor_x, @factor_y, @color, @mode)
90
+ def size
91
+ @height
66
92
  end
67
93
 
68
94
  #
@@ -71,7 +97,18 @@ module Chingu
71
97
  def width
72
98
  @gosu_font.text_width(@text, @factor_x)
73
99
  end
74
-
100
+
101
+ private
102
+
103
+ #
104
+ # Create the actual image from text and parameters supplied.
105
+ #
106
+ def create_image
107
+ if @max_width
108
+ @image = Gosu::Image.from_text($window, @text, @font, @height, @line_spacing, @max_width, @align)
109
+ else
110
+ @image = Gosu::Image.from_text($window, @text, @font, @height)
111
+ end
112
+ end
75
113
  end
76
-
77
114
  end
@@ -40,30 +40,31 @@ module Chingu
40
40
  # [start_time, end_time (or nil if one-shot), &block]
41
41
  #
42
42
  @_timers = Array.new
43
+ @_repeating_timers = Array.new
43
44
  super
44
45
  end
45
46
 
46
47
  def during(time, &block)
47
- ms = milliseconds()
48
+ ms = Gosu::milliseconds()
48
49
  @_last_timer = [ms, ms + time, block]
49
50
  @_timers << @_last_timer
50
51
  self
51
52
  end
52
53
 
53
54
  def after(time, &block)
54
- ms = milliseconds()
55
+ ms = Gosu::milliseconds()
55
56
  @_last_timer = [ms + time, nil, block]
56
57
  @_timers << @_last_timer
57
58
  self
58
59
  end
59
60
 
60
61
  def between(start_time, end_time, &block)
61
- ms = milliseconds()
62
+ ms = Gosu::milliseconds()
62
63
  @_last_timer = [ms + start_time, ms + end_time, block]
63
64
  @_timers << @_last_timer
64
65
  self
65
66
  end
66
-
67
+
67
68
  def then(&block)
68
69
  # ...use one-shots start_time for our trailing "then".
69
70
  # ...use durable timers end_time for our trailing "then".
@@ -71,17 +72,29 @@ module Chingu
71
72
  @_timers << [start_time, nil, block]
72
73
  end
73
74
 
75
+ def every(delay, &block)
76
+ ms = Gosu::milliseconds()
77
+ @_repeating_timers << [ms + delay, delay, block]
78
+ end
79
+
74
80
  def update_trait
75
- ms = milliseconds()
81
+ ms = Gosu::milliseconds()
76
82
  @_timers.each do |start_time, end_time, block|
77
- if ms > start_time && (end_time == nil || ms < end_time)
78
- block.call
83
+ block.call if ms > start_time && (end_time == nil || ms < end_time)
84
+ end
85
+
86
+ index = 0
87
+ @_repeating_timers.each do |start_time, delay, block|
88
+ if ms > start_time
89
+ block.call
90
+ @_repeating_timers[index] = [ms + delay, delay, block]
79
91
  end
92
+ index += 1
80
93
  end
81
94
 
82
95
  # Remove one-shot timers (only a start_time, no end_time) and all timers which have expired
83
96
  @_timers.reject! { |start_time, end_time, block| (ms > start_time && end_time == nil) || (end_time != nil && ms > end_time) }
84
-
97
+
85
98
  super
86
99
  end
87
100
 
data/lib/chingu/window.rb CHANGED
@@ -46,11 +46,10 @@ module Chingu
46
46
  $window = super(width, height, fullscreen, update_interval)
47
47
 
48
48
  @root = File.dirname(File.expand_path($0))
49
- Chingu::Asset.autoload_dirs = [".", File.join(@root, "gfx"), File.join(@root, "media"), File.join(@root, "sfx")]
50
- Gosu::Image.autoload_dirs = [".", File.join(@root, "gfx"), File.join(@root, "media")]
51
- Gosu::Sample.autoload_dirs = [".", File.join(@root, "sound"), File.join(@root, "media")]
52
- Gosu::Tile.autoload_dirs = [".", File.join(@root, "gfx"), File.join(@root, "media")]
53
- Gosu::Song.autoload_dirs = [".", File.join(@root, "sfx"), File.join(@root, "media")]
49
+ Chingu::Asset.autoload_dirs = [".", File.join(@root, "assets"), File.join(@root, "media")]
50
+ Gosu::Image.autoload_dirs = [".", File.join(@root, "images"), File.join(@root, "gfx"), File.join(@root, "media")]
51
+ Gosu::Sample.autoload_dirs = [".", File.join(@root, "sounds"), File.join(@root, "sfx"), File.join(@root, "media")]
52
+ Gosu::Song.autoload_dirs = [".", File.join(@root, "songs"), File.join(@root, "sounds"), File.join(@root, "sfx"), File.join(@root, "media")]
54
53
 
55
54
  @game_objects = GameObjectList.new
56
55
  @input_clients = Array.new
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chingu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.8.1
4
+ version: 0.5.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ippa
@@ -30,7 +30,7 @@ cert_chain:
30
30
  hxtMlw==
31
31
  -----END CERTIFICATE-----
32
32
 
33
- date: 2009-10-19 00:00:00 +02:00
33
+ date: 2009-10-22 00:00:00 +02:00
34
34
  default_executable:
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
@@ -76,6 +76,7 @@ files:
76
76
  - examples/example10.rb
77
77
  - examples/example11.rb
78
78
  - examples/example12.rb
79
+ - examples/example13.rb
79
80
  - examples/example2.rb
80
81
  - examples/example3.rb
81
82
  - examples/example4.rb
@@ -85,6 +86,7 @@ files:
85
86
  - examples/example8.rb
86
87
  - examples/example9.rb
87
88
  - examples/game1.rb
89
+ - examples/high_score_list.yml
88
90
  - examples/media/Parallax-scroll-example-layer-0.png
89
91
  - examples/media/Parallax-scroll-example-layer-1.png
90
92
  - examples/media/Parallax-scroll-example-layer-2.png
@@ -131,7 +133,7 @@ files:
131
133
  - lib/chingu/helpers/input_client.rb
132
134
  - lib/chingu/helpers/input_dispatcher.rb
133
135
  - lib/chingu/helpers/rotation_center.rb
134
- - lib/chingu/high_score.rb
136
+ - lib/chingu/high_score_list.rb
135
137
  - lib/chingu/inflector.rb
136
138
  - lib/chingu/input.rb
137
139
  - lib/chingu/named_resource.rb
metadata.gz.sig CHANGED
Binary file
@@ -1,60 +0,0 @@
1
- #--
2
- #
3
- # Chingu -- OpenGL accelerated 2D game framework for Ruby
4
- # Copyright (C) 2009 ippa / ippa@rubylicio.us
5
- #
6
- # This library is free software; you can redistribute it and/or
7
- # modify it under the terms of the GNU Lesser General Public
8
- # License as published by the Free Software Foundation; either
9
- # version 2.1 of the License, or (at your option) any later version.
10
- #
11
- # This library is distributed in the hope that it will be useful,
12
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
- # Lesser General Public License for more details.
15
- #
16
- # You should have received a copy of the GNU Lesser General Public
17
- # License along with this library; if not, write to the Free Software
18
- # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
- #
20
- #++
21
-
22
-
23
- module Chingu
24
-
25
- #
26
- # Highscore-class
27
- #
28
- # - Keeps a local YAML file with highscores, default highscores.yml in root game dir.
29
- # - Add, delete, clear highscores
30
- # - Iterate through highscores with simple Highscore#each
31
- #
32
- class HighScore
33
- def initialize(options = {})
34
- @file = options[:file] || "high_scores.yml"
35
- @high_scores = Array.new
36
-
37
- #OpenStruct.new()
38
- end
39
-
40
- #
41
- #
42
- #
43
- def add(name, score)
44
-
45
- end
46
- alias << add
47
-
48
- def each
49
- @highscores.each { |highscore| yield highscore }
50
- end
51
-
52
- def save
53
- end
54
-
55
- def self.all
56
-
57
- end
58
- end
59
-
60
- end