chingu 0.8rc3 → 0.8

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -479,7 +479,21 @@ Chingus inputhandler will detect that Menu is a GameState-class, create a new in
479
479
  === Premade game states
480
480
  Chingu comes with some pre-made game states.
481
481
  A simple but usefull one is GameStates::Pause. Once pushed it will draw the previous game state but not update it --
482
- effectively pausing it.
482
+ effectively pausing it. Some others are:
483
+
484
+ == GameStates::EnterName
485
+ A gamestate where a gamer can select letters from a A-Z list, contructing his alias. When he's done he selects "GO!" and a
486
+ developer-specified callback will be called with the name/alias as argument.
487
+
488
+ push_game_state GameStates::EnterName.new(:callback => method(:add))
489
+
490
+ def add(name)
491
+ puts "User entered name #{name}"
492
+ end
493
+
494
+ Combine GameStates::EnterName with class OnlineHighScoreList, a free acount @ www.gamercv.com and you have a premade stack to
495
+ provide your 48h gamecompo entry with online high scores that adds an extra dimension to your game. See example16 for a full working example of this.
496
+
483
497
 
484
498
  == GameStates::Edit
485
499
  The biggest and most usable is GameStates::Edit which enables fast 'n easy level-building with game objects.
data/chingu.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{chingu}
8
- s.version = "0.8rc3"
8
+ s.version = "0.8"
9
9
 
10
- s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
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-12-12}
12
+ s.date = %q{2010-12-13}
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 = [
@@ -13,10 +13,19 @@ include Chingu
13
13
  class Game < Chingu::Window
14
14
  def initialize
15
15
  super(640,400)
16
- self.input = {:esc => :exit, :a => :add, :r => :add_random}
17
16
  self.caption = "OnlineHighScoreList example. Press 'A' to add a top-score, 'R' to add a random."
17
+ push_game_state(HighScore)
18
+ end
19
+ end
20
+
21
+ class HighScore < GameState
22
+
23
+ def setup
24
+ self.input = {:esc => :exit, :a => :enter_name, :r => :add_random}
25
+
26
+ PulsatingText.create("class OnlineHighScoreList & www.gamvercv.com", :x => $window.width/2, :y => 50, :size => 30)
27
+ Text.create("Syncs from/to http://www.gamercv.com/games/1-test", :x => $window.width/2, :y => 80, :size => 24, :rotation_center => :center)
18
28
 
19
- @title = PulsatingText.create("class OnlineHighScoreList & www.gamvercv.com", :x => $window.width/2, :y => 50, :size => 30)
20
29
 
21
30
  #
22
31
  # Load a remote high score list
@@ -24,10 +33,16 @@ class Game < Chingu::Window
24
33
  @high_score_list = OnlineHighScoreList.load(:game_id => 1, :login => "chingu", :password => "chingu", :limit => 10)
25
34
 
26
35
  create_text
27
- end
36
+ end
28
37
 
29
- def add
30
- data = {:name => "NEW", :score => (@high_score_list[0][:score].to_i + 10), :text => "Hello from Chingus example16.rb"}
38
+ def enter_name
39
+ push_game_state GameStates::EnterName.new(:callback => method(:add) )
40
+ end
41
+
42
+ def add(name = nil)
43
+ return unless name
44
+ return unless name.size > 0
45
+ data = {:name => name, :score => (@high_score_list[0][:score].to_i + 10), :text => "Hello from Chingus example16.rb"}
31
46
  position = @high_score_list.add(data)
32
47
  puts "Got position: #{position.to_s}"
33
48
  create_text
@@ -51,7 +66,7 @@ class Game < Chingu::Window
51
66
  Text.create(high_score[:name], :x => 200, :y => y, :size => 20)
52
67
  Text.create(high_score[:score], :x => 400, :y => y, :size => 20)
53
68
  end
54
- end
69
+ end
55
70
  end
56
71
 
57
72
  #
data/lib/chingu.rb CHANGED
@@ -37,7 +37,7 @@ require_all "#{CHINGU_ROOT}/chingu/traits"
37
37
  require_all "#{CHINGU_ROOT}/chingu"
38
38
 
39
39
  module Chingu
40
- VERSION = "0.8rc3"
40
+ VERSION = "0.8"
41
41
 
42
42
  DEBUG_COLOR = Gosu::Color.new(0xFFFF0000)
43
43
  DEBUG_ZORDER = 9999
@@ -31,30 +31,39 @@ module Chingu
31
31
  def initialize(options = {})
32
32
  super
33
33
 
34
- Text.create("Please enter your name:", :x => 0, :y => 0, :size => 40)
35
-
34
+ Text.create("<u>Please enter your name</u>", :rotation_center => :top_center, :x => $window.width/2, :y => 10, :size => 40)
35
+
36
+ on_input([:holding_up, :holding_w, :holding_gamepad_up], :up)
37
+ on_input([:holding_down, :holding_s, :holding_gamepad_down], :down)
36
38
  on_input([:holding_left, :holding_a, :holding_gamepad_left], :left)
37
39
  on_input([:holding_right, :holding_d, :holding_gamepad_right], :right)
38
40
  on_input([:space, :x, :enter, :gamepad_button_1, :return], :action)
41
+ on_input(:esc, :pop_game_state)
39
42
 
40
43
  @callback = options[:callback]
44
+ @columns = options[:columns] || 10
41
45
 
42
46
  @string = []
43
47
  @texts = []
44
- @start_y = 200
45
- @start_x = 0
46
- @index = 0
47
- #@letters = %w[ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ! " # % & ( ) [ ] = * _ < GO! ]
48
- @letters = %w[ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ! _ < GO! ]
49
- x = @start_x
48
+ @index = 1
49
+ @letter_size = 30
50
+ @letters = %w[ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ! " # % & ( ) [ ] / \\ - = * SPACE DEL ENTER ]
51
+
52
+ @y = 140
53
+ @x = ($window.width - 350)/2
50
54
 
51
- @letters.each do |letter|
52
- @texts << Text.create(letter, :x => x, :y => @start_y, :rotation_center => :bottom_left, :size => 25)
53
- x += 25
55
+ @letters.each_with_index do |letter, index|
56
+ @texts << Text.create(letter, :x => @x, :y => @y, :size => @letter_size)
57
+ @x += @texts.last.width + 20
58
+
59
+ if (index+1) % @columns == 0
60
+ @y += @letter_size
61
+ @x = @texts.first.x
62
+ end
54
63
  end
55
64
 
56
65
  @selected_color = Color::RED
57
- @signature = Text.create("", :x => $window.width/2, :y => $window.height/2, :size => 80, :align => :center)
66
+ @name = Text.create("", :rotaion_center => :top_center, :x => $window.width/2, :y => 60, :size => 80)
58
67
  end
59
68
 
60
69
  # Move cursor 1 step to the left
@@ -62,34 +71,40 @@ module Chingu
62
71
 
63
72
  # Move cursor 1 step to the right
64
73
  def right; move_cursor(1); end
74
+
75
+ # Move cursor 1 step to the left
76
+ def up; move_cursor(-@columns); end
65
77
 
78
+ # Move cursor 1 step to the right
79
+ def down; move_cursor(@columns); end
80
+
66
81
  # Move cursor any given value (positive or negative). Used by left() and right()
67
82
  def move_cursor(amount = 1)
68
83
  @index += amount
69
- @index = 0 if @index >= @letters.size
84
+ @index = 0 if @index >= @letters.size
85
+ @index = @letters.size-1 if @index < 0
86
+
87
+ @texts.each { |text| text.color = Color::WHITE }
88
+ @texts[@index].color = Color::RED
89
+
70
90
  sleep(0.1)
71
91
  end
72
92
 
73
93
  def action
74
94
  case @letters[@index]
75
- when "<" then @string.pop
76
- when "_" then @string << " "
77
- when "GO!" then go
78
- else @string << @letters[@index]
95
+ when "DEL" then @string.pop
96
+ when "SPACE" then @string << " "
97
+ when "ENTER" then go
98
+ else @string << @letters[@index]
79
99
  end
80
-
81
- @signature.text = @string.join
82
- @signature.x = $window.width/2 - @signature.width/2
83
- end
84
-
85
- def draw
86
- @rect = Rect.new(@start_x + (25 * @index), @start_y+25, @texts[@index].width, 10)
87
- fill_rect(@rect, @selected_color, 0)
88
- super
100
+
101
+ @name.text = @string.join
102
+ @name.x = $window.width/2 - @name.width/2
89
103
  end
90
-
104
+
91
105
  def go
92
- pop_game_state(:name => @string.join)
106
+ @callback.call(@name.text)
107
+ pop_game_state
93
108
  end
94
109
 
95
110
  end
data/lib/chingu/text.rb CHANGED
@@ -67,16 +67,17 @@ module Chingu
67
67
 
68
68
  # We remove the :size param so it doesn't get to GameObject where it means something else
69
69
  @size = options.delete(:size) || options.delete(:height) || @@size || 15
70
-
70
+
71
+ options = {:rotation_center => :top_left}.merge(options)
72
+
71
73
  super(options)
72
-
74
+
73
75
  @text = text || options[:text] || "-No text specified-"
74
76
  @font = options[:font] || @@font || Gosu::default_font_name()
75
77
  @line_spacing = options[:line_spacing] || 1
76
78
  @align = options[:align] || :left
77
79
  @max_width = options[:max_width]
78
80
  @padding = options[:padding] || @@padding
79
- self.rotation_center = :top_left
80
81
 
81
82
  @gosu_font = Gosu::Font[@font, @size]
82
83
  create_image unless @image
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chingu
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: true
4
+ prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 8rc3
8
- version: 0.8rc3
7
+ - 8
8
+ version: "0.8"
9
9
  platform: ruby
10
10
  authors:
11
11
  - ippa
@@ -13,7 +13,7 @@ autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
15
 
16
- date: 2010-12-12 00:00:00 +01:00
16
+ date: 2010-12-13 00:00:00 +01:00
17
17
  default_executable:
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
@@ -289,13 +289,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
289
289
  required_rubygems_version: !ruby/object:Gem::Requirement
290
290
  none: false
291
291
  requirements:
292
- - - ">"
292
+ - - ">="
293
293
  - !ruby/object:Gem::Version
294
294
  segments:
295
- - 1
296
- - 3
297
- - 1
298
- version: 1.3.1
295
+ - 0
296
+ version: "0"
299
297
  requirements: []
300
298
 
301
299
  rubyforge_project: chingu