chingu 0.7.6.2 → 0.7.6.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{chingu}
8
- s.version = "0.7.6.2"
8
+ s.version = "0.7.6.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["ippa"]
12
- s.date = %q{2010-06-18}
12
+ s.date = %q{2010-06-19}
13
13
  s.description = %q{OpenGL accelerated 2D game framework for Ruby. Builds on Gosu (Ruby/C++) which provides all the core functionality. Chingu adds simple yet powerful game states, prettier input handling, deployment safe asset-handling, a basic re-usable game object and stackable game logic.}
14
14
  s.email = %q{ippa@rubylicio.us}
15
15
  s.extra_rdoc_files = [
@@ -47,6 +47,7 @@ Gem::Specification.new do |s|
47
47
  "examples/example20_trait_inheritence_test.rb",
48
48
  "examples/example21.yml",
49
49
  "examples/example21_sidescroller_with_edit.rb",
50
+ "examples/example22_text.rb",
50
51
  "examples/example2_gamestate_basics.rb",
51
52
  "examples/example3_parallax.rb",
52
53
  "examples/example4_gamestates.rb",
@@ -97,6 +98,7 @@ Gem::Specification.new do |s|
97
98
  "examples/media/star_25x25_explode.gal",
98
99
  "examples/media/star_25x25_explode.png",
99
100
  "examples/media/stone_wall.bmp",
101
+ "examples/media/talk_bubble.png",
100
102
  "examples/media/tube.png",
101
103
  "examples/media/video_games.png",
102
104
  "examples/media/wood.png",
@@ -164,6 +166,7 @@ Gem::Specification.new do |s|
164
166
  "examples/example1_basics.rb",
165
167
  "examples/example20_trait_inheritence_test.rb",
166
168
  "examples/example21_sidescroller_with_edit.rb",
169
+ "examples/example22_text.rb",
167
170
  "examples/example2_gamestate_basics.rb",
168
171
  "examples/example3_parallax.rb",
169
172
  "examples/example4_gamestates.rb",
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require File.join(File.dirname($0), "..", "lib", "chingu")
4
+ include Gosu
5
+ include Chingu
6
+
7
+
8
+ class Game < Chingu::Window
9
+ def initialize
10
+ super(640,480,false) # leave it blank and it will be 800,600,non fullscreen
11
+ self.input = { :escape => :exit } # exits example on Escape
12
+ self.caption = "Demonstration of Text"
13
+ push_game_state(Woff)
14
+ end
15
+ end
16
+
17
+ class Woff < GameState
18
+ def setup
19
+ self.input = { [:space, :esc] => :exit }
20
+
21
+
22
+ # Some Text with adapting :background
23
+ Text.create("tiny", :x => 200, :y => 200, :size => 20, :background => "talk_bubble.png", :color => Color::BLACK)
24
+
25
+ Text.size = 50
26
+ Text.padding = 20
27
+ Text.create("Hello", :x => 100, :y => 30, :background => "talk_bubble.png", :color => Color::BLACK)
28
+ Text.create("YES YOU! Bla bla bla bla.", :size => 40, :x => 200, :y => 300, :background => "talk_bubble.png", :color => Color::BLACK)
29
+
30
+ #
31
+ # TODO: More text examples!
32
+ #
33
+ end
34
+
35
+ def draw
36
+ fill_gradient(:from => Color::CYAN, :to => Color::BLUE)
37
+ super
38
+ end
39
+ end
40
+
41
+
42
+ Game.new.show
@@ -33,7 +33,7 @@ require_all "#{CHINGU_ROOT}/chingu/traits"
33
33
  require_all "#{CHINGU_ROOT}/chingu"
34
34
 
35
35
  module Chingu
36
- VERSION = "0.7.6.2"
36
+ VERSION = "0.7.6.3"
37
37
 
38
38
  DEBUG_COLOR = Gosu::Color.new(0xFFFF0000)
39
39
  DEBUG_ZORDER = 9999
@@ -93,7 +93,24 @@ module Chingu
93
93
  setup
94
94
 
95
95
  end
96
-
96
+
97
+ #
98
+ # Get all settings from a game object in one array.
99
+ # Complemented by the GameObject#attributes= setter.
100
+ # Makes it easy to clone a objects x,y,angle etc.
101
+ #
102
+ def attributes
103
+ [@x, @y, @angle, @center_x, @center_y, @factor_x, @factor_y, @color, @mode, @zorder]
104
+ end
105
+
106
+ #
107
+ # Set all attributes on 1 line
108
+ # Mainly used in combination with game_object1.attributes = game_object2.attributes
109
+ #
110
+ def attributes=(attributes)
111
+ self.x, self.y, self.angle, self.center_x, self.center_y, self.factor_x, self.factor_y, self.color, self.mode, self.zorder = *attributes
112
+ end
113
+
97
114
  #
98
115
  # Set an effective width for the object on screen.
99
116
  # Chingu does this by setting factor_x depending on imge.width and width given.
@@ -34,17 +34,19 @@ module Chingu
34
34
  #
35
35
  class Text < Chingu::GameObject
36
36
  attr_accessor :text
37
- attr_reader :height, :gosu_font, :line_spacing, :align, :max_width
37
+ attr_reader :height, :gosu_font, :line_spacing, :align, :max_width, :background
38
38
 
39
39
  @@size = nil
40
40
  @@font = nil
41
+ @@padding = 5
41
42
  def self.font; @@font; end
42
43
  def self.font=(value); @@font = value; end
43
-
44
44
  def self.size; @@size; end
45
45
  def self.size=(value); @@size = value; end
46
46
  def self.height; @@size; end
47
47
  def self.height=(value); @@size = value; end
48
+ def self.padding; @@padding; end
49
+ def self.padding=(value); @@padding = value; end
48
50
 
49
51
  #
50
52
  # Takes the standard GameObject-hash-arguments but also:
@@ -71,12 +73,22 @@ module Chingu
71
73
  @line_spacing = options[:line_spacing] || 1
72
74
  @align = options[:align] || :left
73
75
  @max_width = options[:max_width]
74
-
76
+ @padding = options[:padding] || @@padding
75
77
  self.rotation_center = :top_left
76
-
78
+
77
79
  @gosu_font = Gosu::Font.new($window, @font, @height)
78
-
79
80
  create_image unless @image
81
+
82
+ if options[:background]
83
+ @background = GameObject.create(:image => options[:background])
84
+ @background.attributes = self.attributes
85
+ @background.color = Color::WHITE
86
+ @background.zorder -= 1
87
+ @background.x -= @padding
88
+ @background.y -= @padding
89
+ @background.width = self.width + @padding * 2
90
+ @background.height = self.height + @padding * 2
91
+ end
80
92
  end
81
93
 
82
94
  #
@@ -98,6 +110,14 @@ module Chingu
98
110
  @gosu_font.text_width(@text, @factor_x)
99
111
  end
100
112
 
113
+ #
114
+ #
115
+ #
116
+ def draw
117
+ @background.draw if @background # draw our background, if any
118
+ super # super -> GameObject#draw which draws out text
119
+ end
120
+
101
121
  private
102
122
 
103
123
  #
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chingu
3
3
  version: !ruby/object:Gem::Version
4
- hash: 107
4
+ hash: 105
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
9
  - 6
10
- - 2
11
- version: 0.7.6.2
10
+ - 3
11
+ version: 0.7.6.3
12
12
  platform: ruby
13
13
  authors:
14
14
  - ippa
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-06-18 00:00:00 +02:00
19
+ date: 2010-06-19 00:00:00 +02:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -75,6 +75,7 @@ files:
75
75
  - examples/example20_trait_inheritence_test.rb
76
76
  - examples/example21.yml
77
77
  - examples/example21_sidescroller_with_edit.rb
78
+ - examples/example22_text.rb
78
79
  - examples/example2_gamestate_basics.rb
79
80
  - examples/example3_parallax.rb
80
81
  - examples/example4_gamestates.rb
@@ -125,6 +126,7 @@ files:
125
126
  - examples/media/star_25x25_explode.gal
126
127
  - examples/media/star_25x25_explode.png
127
128
  - examples/media/stone_wall.bmp
129
+ - examples/media/talk_bubble.png
128
130
  - examples/media/tube.png
129
131
  - examples/media/video_games.png
130
132
  - examples/media/wood.png
@@ -219,6 +221,7 @@ test_files:
219
221
  - examples/example1_basics.rb
220
222
  - examples/example20_trait_inheritence_test.rb
221
223
  - examples/example21_sidescroller_with_edit.rb
224
+ - examples/example22_text.rb
222
225
  - examples/example2_gamestate_basics.rb
223
226
  - examples/example3_parallax.rb
224
227
  - examples/example4_gamestates.rb