ippa-chingu 0.4.1 → 0.4.2

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.
data/chingu.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{chingu}
5
- s.version = "0.4.1"
5
+ s.version = "0.4.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"]
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.description = %q{Game framework built on top of the OpenGL accelerated game lib Gosu. It adds simple yet powerfull game states, prettier inputhandling, deploymentsafe asset-handling, a basic re-usable game object and automation of common task.}
11
11
  s.email = ["ippa@rubylicio.us"]
12
12
  s.extra_rdoc_files = ["History.txt", "Manifest.txt"]
13
- s.files = ["History.txt", "Manifest.txt", "README.rdoc", "Rakefile", "chingu.gemspec", "examples/example1.rb", "examples/example2.rb", "examples/example3.rb", "examples/example4.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/fire_bullet.png", "examples/media/spaceship.png", "examples/media/stickfigure.bmp", "examples/media/stickfigure.png", "lib/chingu.rb", "lib/chingu/animation.rb", "lib/chingu/assets.rb", "lib/chingu/chipmunk_object.rb", "lib/chingu/data_structures.rb", "lib/chingu/fpscounter.rb", "lib/chingu/game_object.rb", "lib/chingu/game_state.rb", "lib/chingu/game_state_manager.rb", "lib/chingu/helpers.rb", "lib/chingu/input.rb", "lib/chingu/named_resource.rb", "lib/chingu/parallax.rb", "lib/chingu/rect.rb", "lib/chingu/text.rb", "lib/chingu/window.rb"]
13
+ s.files = ["History.txt", "Manifest.txt", "README.rdoc", "Rakefile", "chingu.gemspec", "examples/example1.rb", "examples/example2.rb", "examples/example3.rb", "examples/example4.rb", "examples/example5.rb", "examples/example6.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/fire_bullet.png", "examples/media/ruby.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/chipmunk_object.rb", "lib/chingu/data_structures.rb", "lib/chingu/fpscounter.rb", "lib/chingu/game_object.rb", "lib/chingu/game_state.rb", "lib/chingu/game_state_manager.rb", "lib/chingu/helpers.rb", "lib/chingu/input.rb", "lib/chingu/named_resource.rb", "lib/chingu/parallax.rb", "lib/chingu/rect.rb", "lib/chingu/text.rb", "lib/chingu/window.rb"]
14
14
  s.has_rdoc = true
15
15
  s.homepage = %q{http://github.com/ippa/chingu/tree/master}
16
16
  s.rdoc_options = ["--main", "README.rdoc"]
@@ -0,0 +1,97 @@
1
+ require 'rubygems'
2
+ require File.join(File.dirname($0), "..", "lib", "chingu")
3
+ include Gosu
4
+
5
+ #
6
+ # Using Chingus game state mananger in pure Gosu.
7
+ #
8
+ class Game < Gosu::Window
9
+ attr_reader :font
10
+ def initialize
11
+ $window = super(800,600,false)
12
+
13
+ @font = Font.new($window, default_font_name(), 20)
14
+
15
+ # Create our game state manager and start out with State1
16
+ @manager = Chingu::GameStateManager.new
17
+ @manager.switch_game_state(State1)
18
+ end
19
+
20
+ def button_down(id)
21
+ @manager.push_game_state(State1) if(id==Button::Kb1)
22
+ @manager.push_game_state(State2) if(id==Button::Kb2)
23
+ @manager.push_game_state(State3) if(id==Button::Kb3)
24
+ @manager.pop_game_state if(id==Button::KbBackspace)
25
+ close if(id==Button::KbEscape)
26
+
27
+ # This makes sure button_down(id) is called on the active game state
28
+ # Enables input-handling in game states, you might wanna do the same with button_up()
29
+ @manager.button_down(id)
30
+ end
31
+
32
+ def update
33
+ # This makes sure update() is called on the active game state
34
+ @manager.update
35
+ end
36
+
37
+ def draw
38
+ @font.draw("Game State Stack. 1-3 to push a game state. Backspace to pop.", 100, 200, 0)
39
+ @manager.game_states.each_with_index do |game_state, index|
40
+ @font.draw("#{index+1}) #{game_state.to_s}", 100, 220+index*20, 0)
41
+ end
42
+
43
+ # This makes sure draw() is called on the active game state
44
+ @manager.draw
45
+ end
46
+ end
47
+
48
+ class State1 < Chingu::GameState
49
+ def setup
50
+ @spinner = ["|", "/", "-", "\\", "|", "/", "-", "\\"]
51
+ @spinner_index = 0.0
52
+ end
53
+
54
+ def update(dt)
55
+ @spinner_index += 0.1
56
+ @spinner_index = 0 if @spinner_index >= @spinner.size
57
+ end
58
+
59
+ def draw
60
+ $window.font.draw("Inside State1: #{@spinner[@spinner_index.to_i]}", 100, 100, 0)
61
+ end
62
+ end
63
+
64
+ class State2 < Chingu::GameState
65
+ def setup
66
+ @factor = 0.0
67
+ @ticks = 0.0
68
+ end
69
+
70
+ def update(dt)
71
+ @ticks += 0.01
72
+ @factor = 1.5 + Math.sin(@ticks)
73
+ end
74
+
75
+ def draw
76
+ $window.font.draw("Inside State2 - factor_y: #{@factor.to_s}", 100, 100, 0, 1.0, @factor)
77
+ end
78
+ end
79
+
80
+
81
+ class State3 < Chingu::GameState
82
+ def setup
83
+ @factor = 0.0
84
+ @ticks = 0.0
85
+ end
86
+
87
+ def update(dt)
88
+ @ticks += 0.01
89
+ @factor = 1.5 + Math.sin(@ticks)
90
+ end
91
+ def draw
92
+ $window.font.draw("Inside State3 - factor_x: #{@factor.to_s}", 100, 100, 0, @factor, 1.0)
93
+ end
94
+ end
95
+
96
+
97
+ Game.new.show
@@ -0,0 +1,70 @@
1
+ require 'rubygems'
2
+ require File.join(File.dirname($0), "..", "lib", "chingu")
3
+ include Gosu
4
+
5
+ #
6
+ # Example of using a special GameState to fade between game states
7
+ #
8
+ class Game < Chingu::Window
9
+ def initialize
10
+ super(640,800)
11
+ switch_game_state(State1)
12
+ self.input = {:space => :next_game_state, :esc => :exit}
13
+ self.caption = "Example of fading game state to switch between 2 other game states"
14
+ end
15
+
16
+ def next_game_state
17
+ push_game_state(FadeTo.new(State2.new)) if current_game_state.is_a?(State1)
18
+ push_game_state(FadeTo.new(State1.new)) if current_game_state.is_a?(State2)
19
+ end
20
+ end
21
+
22
+ class State1 < Chingu::GameState
23
+ def draw
24
+ Image["ruby.png"].draw(0,0,0)
25
+ end
26
+ end
27
+
28
+ class State2 < Chingu::GameState
29
+ def draw
30
+ Image["video_games.png"].draw(0,0,0)
31
+ end
32
+ end
33
+
34
+
35
+ class FadeTo < Chingu::GameState
36
+ def initialize(game_state)
37
+ @new_game_state = game_state
38
+ end
39
+
40
+ def setup
41
+ @color = Gosu::Color.new(0,0,0,0)
42
+ @alpha = 0.0
43
+ @fading_in = false
44
+ end
45
+
46
+ def update(dt)
47
+ @alpha += (@fading_in ? -2 : 2)
48
+ if @alpha >= 255
49
+ @fading_in = true
50
+ else
51
+ @color.alpha = @alpha.to_i
52
+ end
53
+ end
54
+
55
+ def draw
56
+ previous_game_state.draw if @fading_in == false
57
+ @new_game_state.draw if @fading_in == true
58
+
59
+ $window.draw_quad( 0,0,@color,
60
+ $window.width,0,@color,
61
+ $window.width,$window.height,@color,
62
+ 0,$window.height,@color,999)
63
+
64
+ if @fading_in == true && @alpha == 0
65
+ switch_game_state(@new_game_state)
66
+ end
67
+ end
68
+ end
69
+
70
+ Game.new.show
Binary file
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ippa-chingu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ippa
@@ -42,15 +42,19 @@ files:
42
42
  - examples/example2.rb
43
43
  - examples/example3.rb
44
44
  - examples/example4.rb
45
+ - examples/example5.rb
46
+ - examples/example6.rb
45
47
  - examples/media/Parallax-scroll-example-layer-0.png
46
48
  - examples/media/Parallax-scroll-example-layer-1.png
47
49
  - examples/media/Parallax-scroll-example-layer-2.png
48
50
  - examples/media/Parallax-scroll-example-layer-3.png
49
51
  - examples/media/background1.png
50
52
  - examples/media/fire_bullet.png
53
+ - examples/media/ruby.png
51
54
  - examples/media/spaceship.png
52
55
  - examples/media/stickfigure.bmp
53
56
  - examples/media/stickfigure.png
57
+ - examples/media/video_games.png
54
58
  - lib/chingu.rb
55
59
  - lib/chingu/animation.rb
56
60
  - lib/chingu/assets.rb