chingu 0.5.6 → 0.5.7
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.tar.gz.sig +0 -0
- data/History.txt +3 -0
- data/Manifest.txt +14 -0
- data/README.rdoc +4 -4
- data/Rakefile +16 -0
- data/chingu.gemspec +3 -3
- data/examples/example2.rb +7 -6
- data/examples/example3.rb +30 -12
- data/examples/game1.rb +304 -0
- data/examples/media/background1.png +0 -0
- data/examples/media/bullet.png +0 -0
- data/examples/media/bullet_hit.wav +0 -0
- data/examples/media/city1.csv +2 -0
- data/examples/media/city1.png +0 -0
- data/examples/media/city2.png +0 -0
- data/examples/media/enemy_bullet.png +0 -0
- data/examples/media/explosion.wav +0 -0
- data/examples/media/laser.wav +0 -0
- data/examples/media/plane.csv +2 -0
- data/examples/media/plane.png +0 -0
- data/examples/media/ruby.png +0 -0
- data/examples/media/saucer.csv +4 -0
- data/examples/media/saucer.gal +0 -0
- data/examples/media/saucer.png +0 -0
- data/examples/media/video_games.png +0 -0
- data/lib/chingu.rb +1 -1
- data/lib/chingu/basic_game_object.rb +33 -3
- data/lib/chingu/game_object.rb +2 -31
- data/lib/chingu/game_object_list.rb +3 -2
- data/lib/chingu/parallax.rb +80 -28
- data/lib/chingu/traits/retrofy.rb +8 -0
- metadata +16 -2
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
Binary file
|
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
@@ -24,15 +24,29 @@ examples/example6.rb
|
|
24
24
|
examples/example7.rb
|
25
25
|
examples/example8.rb
|
26
26
|
examples/example9.rb
|
27
|
+
examples/game1.rb
|
27
28
|
examples/media/Parallax-scroll-example-layer-0.png
|
28
29
|
examples/media/Parallax-scroll-example-layer-1.png
|
29
30
|
examples/media/Parallax-scroll-example-layer-2.png
|
30
31
|
examples/media/Parallax-scroll-example-layer-3.png
|
31
32
|
examples/media/background1.png
|
33
|
+
examples/media/bullet.png
|
34
|
+
examples/media/bullet_hit.wav
|
35
|
+
examples/media/city1.csv
|
36
|
+
examples/media/city1.png
|
37
|
+
examples/media/city2.png
|
38
|
+
examples/media/enemy_bullet.png
|
39
|
+
examples/media/explosion.wav
|
32
40
|
examples/media/fire_bullet.png
|
33
41
|
examples/media/fireball.png
|
42
|
+
examples/media/laser.wav
|
34
43
|
examples/media/particle.png
|
44
|
+
examples/media/plane.csv
|
45
|
+
examples/media/plane.png
|
35
46
|
examples/media/ruby.png
|
47
|
+
examples/media/saucer.csv
|
48
|
+
examples/media/saucer.gal
|
49
|
+
examples/media/saucer.png
|
36
50
|
examples/media/spaceship.png
|
37
51
|
examples/media/stickfigure.bmp
|
38
52
|
examples/media/stickfigure.png
|
data/README.rdoc
CHANGED
@@ -606,10 +606,10 @@ GameObject.all is naming straight from rails for example. Most stuff in GameObje
|
|
606
606
|
* Don't separate too much from Gosus core-naming
|
607
607
|
|
608
608
|
== CREDITS:
|
609
|
-
* Jacius of Rubygame (For doing cool stuff that's well documented as re-usable). So far rect.rb and named_resource.rb is
|
610
|
-
* Jduff for input / commits
|
611
|
-
* Jlnr,Philymore,Shawn24,JamesKilton for constructive feedback/discussions
|
612
|
-
*
|
609
|
+
* Jacius of Rubygame (For doing cool stuff that's well documented as re-usable). So far rect.rb and named_resource.rb is straight outta Rubygame.
|
610
|
+
* Jduff for input / commits
|
611
|
+
* Jlnr,Philymore,Shawn24,JamesKilton for constructive feedback/discussions
|
612
|
+
* Ariel Pillet for codesuggestions and cleanups
|
613
613
|
* Thanks to http://github.com/tarcieri for require_all code, good stuff
|
614
614
|
|
615
615
|
== REQUIREMENTS:
|
data/Rakefile
CHANGED
@@ -17,3 +17,19 @@ task :gemspec do
|
|
17
17
|
system "rake git:manifest"
|
18
18
|
system "rake debug_gem | grep -v \"(in \" | grep -v \"erik\" > chingu.gemspec"
|
19
19
|
end
|
20
|
+
|
21
|
+
|
22
|
+
#begin
|
23
|
+
# require 'jeweler'
|
24
|
+
# Jeweler::Tasks.new do |gemspec|
|
25
|
+
# gemspec.name = "chingu"
|
26
|
+
# gemspec.summary = "Game framework built on top of the OpenGL accelerated game lib Gosu"
|
27
|
+
# gemspec.description = "Game framework built on top of the OpenGL accelerated game lib Gosu"
|
28
|
+
# gemspec.email = "ippa@rubylicio.us"
|
29
|
+
# gemspec.homepage = "http://github.com/ippa/chingu"
|
30
|
+
# gemspec.authors = ["ippa"]
|
31
|
+
# gemspec.rubyforge_project = "chingu"
|
32
|
+
# end
|
33
|
+
#rescue LoadError
|
34
|
+
# puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
35
|
+
#end
|
data/chingu.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{chingu}
|
5
|
-
s.version = "0.5.
|
5
|
+
s.version = "0.5.7"
|
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-
|
9
|
+
s.date = %q{2009-10-14}
|
10
10
|
s.description = %q{Game framework built on top of the OpenGL accelerated game lib Gosu.
|
11
11
|
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.}
|
12
12
|
s.email = ["ippa@rubylicio.us"]
|
13
13
|
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "benchmarks/README.txt"]
|
14
|
-
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/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/fireball.png", "examples/media/particle.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/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/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"]
|
14
|
+
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/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/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
15
|
s.homepage = %q{http://github.com/ippa/chingu/tree/master}
|
16
16
|
s.rdoc_options = ["--main", "README.rdoc"]
|
17
17
|
s.require_paths = ["lib"]
|
data/examples/example2.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
require 'rubygems'
|
2
|
+
require 'devil'
|
2
3
|
require File.join(File.dirname($0), "..", "lib", "chingu")
|
3
4
|
include Gosu
|
4
5
|
|
5
6
|
#
|
6
7
|
# A little more complicated example where we do our own #update and #draw code.
|
7
|
-
# We also add another
|
8
|
+
# We also add another GameObject - a bullet fired with space.
|
8
9
|
#
|
9
10
|
# Also tests out the Debug game state.
|
10
11
|
#
|
@@ -64,8 +65,8 @@ class Play < Chingu::GameState
|
|
64
65
|
:holding_right => :move_right,
|
65
66
|
:holding_up => :move_up,
|
66
67
|
:holding_down => :move_down,
|
67
|
-
:space => :fire
|
68
|
-
|
68
|
+
:space => :fire
|
69
|
+
}
|
69
70
|
self.input = { :f1 => :debug, :escape => :exit }
|
70
71
|
end
|
71
72
|
|
@@ -75,19 +76,19 @@ class Play < Chingu::GameState
|
|
75
76
|
|
76
77
|
#
|
77
78
|
# If we want to add extra graphics drawn just define your own draw.
|
78
|
-
# Be sure to call #super for enabling Chingus autodrawing of
|
79
|
+
# Be sure to call #super for enabling Chingus autodrawing of instances of GameObject.
|
79
80
|
# Putting #super before or after the background-draw-call really doesn't matter since Gosu work with "zorder".
|
80
81
|
#
|
81
82
|
def draw
|
82
83
|
# Raw Gosu Image.draw(x,y,zorder)-call
|
83
|
-
Image["background1.png"].draw(0, 0, 0)
|
84
|
+
Image["background1.png"].draw(0, 0, 0)
|
84
85
|
super
|
85
86
|
end
|
86
87
|
|
87
88
|
#
|
88
89
|
# Gosus place for gamelogic is #update in the mainwindow
|
89
90
|
#
|
90
|
-
# A #super call here would call #update on all Chingu::
|
91
|
+
# A #super call here would call #update on all Chingu::GameObject-instances and check their inputs, and call the specified method.
|
91
92
|
#
|
92
93
|
def update
|
93
94
|
super
|
data/examples/example3.rb
CHANGED
@@ -8,33 +8,51 @@ include Gosu
|
|
8
8
|
#
|
9
9
|
class Game < Chingu::Window
|
10
10
|
def initialize
|
11
|
-
super
|
12
|
-
self.input = { :holding_left => :
|
11
|
+
super(600,200)
|
12
|
+
self.input = { :holding_left => :camera_left,
|
13
|
+
:holding_right => :camera_right,
|
14
|
+
:holding_up => :camera_up,
|
15
|
+
:holding_down => :camera_down,
|
16
|
+
:escape => :exit }
|
13
17
|
|
14
18
|
self.caption = "Chingu::Parallax example. Scroll with left/right arrows."
|
15
19
|
|
16
20
|
@parallax = Chingu::Parallax.create(:x => 0, :y => 0, :center_x => 0, :center_y => 0)
|
17
21
|
|
18
22
|
#
|
19
|
-
# If no :zorder is given to @parallax.
|
23
|
+
# If no :zorder is given to @parallax.add_layer it defaults to first added -> lowest zorder
|
20
24
|
# Everywhere the :image argument is used, theese 2 values are the Same:
|
21
25
|
# 1) Image["foo.png"] 2) "foo.png"
|
22
26
|
#
|
23
|
-
#
|
24
|
-
|
25
|
-
|
26
|
-
@parallax.
|
27
|
+
# Notice we add layers to the parallax scroller in 3 different ways.
|
28
|
+
# They all end up as ParallaxLayer-instances internally
|
29
|
+
#
|
30
|
+
@parallax.add_layer(:image => "Parallax-scroll-example-layer-0.png", :damping => 100, :center => 0)
|
31
|
+
@parallax.add_layer(:image => "Parallax-scroll-example-layer-1.png", :damping => 10, :center => 0)
|
32
|
+
@parallax << Chingu::ParallaxLayer.new(:image => "Parallax-scroll-example-layer-2.png", :damping => 5, :center => 0)
|
27
33
|
@parallax << {:image => "Parallax-scroll-example-layer-3.png", :damping => 1, :center => 0} # you can also add like this
|
28
34
|
end
|
29
35
|
|
30
|
-
def
|
31
|
-
@parallax.x
|
36
|
+
def camera_left
|
37
|
+
# This is essentially the same as @parallax.x += 2
|
38
|
+
@parallax.camera_x -= 2
|
32
39
|
end
|
33
40
|
|
34
|
-
def
|
35
|
-
@parallax.x
|
41
|
+
def camera_right
|
42
|
+
# This is essentially the same as @parallax.x -= 2
|
43
|
+
@parallax.camera_x += 2
|
36
44
|
end
|
37
|
-
|
45
|
+
|
46
|
+
def camera_up
|
47
|
+
# This is essentially the same as @parallax.y += 2
|
48
|
+
@parallax.camera_y -= 2
|
49
|
+
end
|
50
|
+
|
51
|
+
def camera_down
|
52
|
+
# This is essentially the same as @parallax.y -= 2
|
53
|
+
@parallax.camera_y += 2
|
54
|
+
end
|
55
|
+
|
38
56
|
end
|
39
57
|
|
40
58
|
Game.new.show
|
data/examples/game1.rb
ADDED
@@ -0,0 +1,304 @@
|
|
1
|
+
#
|
2
|
+
#
|
3
|
+
# A "full" simple game in Chingu, using GameState, GameObject, Paralaxx, has_traits etc
|
4
|
+
#
|
5
|
+
# TODO: clean up code as Chingu moves along :). Comments.
|
6
|
+
#
|
7
|
+
#
|
8
|
+
require 'rubygems'
|
9
|
+
require File.join(File.dirname($0), "..", "lib", "chingu")
|
10
|
+
|
11
|
+
require 'texplay' # adds Image#get_pixel
|
12
|
+
#require 'devil/gosu' # adds Gosu::Window#screenshot and better file support
|
13
|
+
require 'opengl' # adds raw gl stuff so Image#retrofy works (in some setups this seems to be 'gl')
|
14
|
+
|
15
|
+
include Gosu
|
16
|
+
include Chingu
|
17
|
+
|
18
|
+
class Game < Chingu::Window
|
19
|
+
attr_reader :factor
|
20
|
+
|
21
|
+
def initialize
|
22
|
+
super(1000,800,false)
|
23
|
+
self.input = { :escape => :exit }
|
24
|
+
@factor = 2
|
25
|
+
switch_game_state(Level)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
#
|
30
|
+
# GAME STATE: GAME OVER
|
31
|
+
#
|
32
|
+
class GameOver < Chingu::GameState
|
33
|
+
def setup
|
34
|
+
@text = Text.create(:text => "GAME OVER (ESC to quit, RETURN to try again!)", :size => 40, :x => 30, :y => 100)
|
35
|
+
self.input = { :esc => :exit, :return => :try_again}
|
36
|
+
@layover = Color.new(0x99000000)
|
37
|
+
end
|
38
|
+
|
39
|
+
def draw
|
40
|
+
super
|
41
|
+
previous_game_state.draw
|
42
|
+
fill(@layover)
|
43
|
+
end
|
44
|
+
|
45
|
+
def try_again
|
46
|
+
pop_game_state # pop back to our playing game state
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
#
|
51
|
+
# GAME STATE: GAME OVER
|
52
|
+
#
|
53
|
+
class Done < Chingu::GameState
|
54
|
+
def initialize(options)
|
55
|
+
@score = options[:score]
|
56
|
+
end
|
57
|
+
|
58
|
+
def setup
|
59
|
+
@text = Text.create(:text => "You made it! Score #{@score} (ESC to quit, RETURN to try again!)", :size => 40, :x => 30, :y => 100)
|
60
|
+
self.input = { :esc => :exit, :return => :try_again}
|
61
|
+
end
|
62
|
+
|
63
|
+
def try_again
|
64
|
+
pop_game_state # pop back to our playing game state
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
#
|
70
|
+
# GAME STATE: LEVEL
|
71
|
+
#
|
72
|
+
class Level < Chingu::GameState
|
73
|
+
def initialize(options = {})
|
74
|
+
super
|
75
|
+
|
76
|
+
@parallax = Parallax.create
|
77
|
+
ParallaxLayer.has_trait :retrofy
|
78
|
+
@parallax << ParallaxLayer.new(:image => Image["city2.png"].retrofy, :center => 0, :damping => 5, :factor => $window.factor)
|
79
|
+
@parallax << ParallaxLayer.new(:image => Image["city1.png"].retrofy, :center => 0, :damping => 1, :factor => $window.factor)
|
80
|
+
@player = Player.create(:x => 10, :y => 100)
|
81
|
+
|
82
|
+
@bg1 = Color.new(0xFFCE28FF)
|
83
|
+
@bg2 = Color.new(0xFF013E87)
|
84
|
+
end
|
85
|
+
|
86
|
+
#
|
87
|
+
# This is called each time this GameState is switched/pushed/poped to.
|
88
|
+
#
|
89
|
+
def setup
|
90
|
+
# Remove all lingering g
|
91
|
+
Enemy.destroy_all
|
92
|
+
Bullet.destroy_all
|
93
|
+
|
94
|
+
@player.score = 0
|
95
|
+
@player.x = 10
|
96
|
+
@player.y = 100
|
97
|
+
|
98
|
+
@parallax.camera_x = 0
|
99
|
+
@total_game_ticks = 100000
|
100
|
+
@timer = 100
|
101
|
+
@total_ticks = 0
|
102
|
+
end
|
103
|
+
|
104
|
+
#
|
105
|
+
# Our
|
106
|
+
#
|
107
|
+
def solid_pixel_at?(x, y)
|
108
|
+
@parallax.layers.last.get_pixel(x, y)[3] != 0
|
109
|
+
end
|
110
|
+
|
111
|
+
def update
|
112
|
+
super
|
113
|
+
|
114
|
+
# Move the level forward by increasing the parallax-scrollers camera x-coordinate
|
115
|
+
@parallax.camera_x += 1
|
116
|
+
|
117
|
+
#
|
118
|
+
Bullet.all.select { |b| solid_pixel_at?(b.x, b.y)}.each { |b| b.die }
|
119
|
+
|
120
|
+
# Collide player with terrain
|
121
|
+
push_game_state(GameOver) if solid_pixel_at?(@player.x, @player.y)
|
122
|
+
|
123
|
+
# Collide player with enemies and enemy bullets
|
124
|
+
@player.each_radius_collision(Enemy) do |player, enemy|
|
125
|
+
enemy.die
|
126
|
+
push_game_state(GameOver)
|
127
|
+
end
|
128
|
+
|
129
|
+
Bullet.each_radius_collision(Enemy) do |bullet, enemy|
|
130
|
+
bullet.die
|
131
|
+
if enemy.hit_by(bullet)
|
132
|
+
@player.score += 20
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
|
137
|
+
@timer = @timer * 0.9999
|
138
|
+
@total_ticks += 1
|
139
|
+
if @total_ticks > @timer
|
140
|
+
Enemy.create(:x => $window.width/2, :y => rand(300))
|
141
|
+
@total_ticks = 0
|
142
|
+
end
|
143
|
+
|
144
|
+
#push_game_state(Done.new(:score => @player.score)) if @game_steps == 1
|
145
|
+
|
146
|
+
$window.caption = "City Battle! Score: #{@player.score}"
|
147
|
+
end
|
148
|
+
|
149
|
+
def draw
|
150
|
+
fill_gradient(:from => @bg2, :to => @bg1)
|
151
|
+
super
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
#
|
156
|
+
# OUR PLAYER
|
157
|
+
#
|
158
|
+
class Player < GameObject
|
159
|
+
has_trait :velocity, :collision_detection, :retrofy
|
160
|
+
attr_accessor :score
|
161
|
+
|
162
|
+
def initialize(options = {})
|
163
|
+
super
|
164
|
+
@image = Image["plane.png"].retrofy
|
165
|
+
self.factor = $window.factor
|
166
|
+
|
167
|
+
self.input = {
|
168
|
+
:holding_left => :left,
|
169
|
+
:holding_right => :right,
|
170
|
+
:holding_up => :up,
|
171
|
+
:holding_down => :down,
|
172
|
+
:space => :fire }
|
173
|
+
|
174
|
+
@max_velocity = 1
|
175
|
+
@radius = 10
|
176
|
+
@score = 0
|
177
|
+
end
|
178
|
+
|
179
|
+
def up
|
180
|
+
@velocity_y += -@max_velocity
|
181
|
+
end
|
182
|
+
def down
|
183
|
+
@velocity_y += @max_velocity
|
184
|
+
end
|
185
|
+
def right
|
186
|
+
@velocity_x += @max_velocity
|
187
|
+
end
|
188
|
+
def left
|
189
|
+
@velocity_x -= @max_velocity
|
190
|
+
end
|
191
|
+
|
192
|
+
def fire
|
193
|
+
Bullet.create(:x => self.x, :y => self.y)
|
194
|
+
Sound["laser.wav"].play
|
195
|
+
end
|
196
|
+
|
197
|
+
def update
|
198
|
+
@velocity_y *= 0.6
|
199
|
+
@velocity_x *= 0.6
|
200
|
+
|
201
|
+
@x = @last_x if @x < 0 || @x > $window.width/$window.factor
|
202
|
+
@y = @last_y if @y < 0 || @y > $window.height/$window.factor
|
203
|
+
@last_x, @last_y = @x, @y
|
204
|
+
end
|
205
|
+
|
206
|
+
end
|
207
|
+
|
208
|
+
#
|
209
|
+
# OUR PLAYERS BULLETS
|
210
|
+
#
|
211
|
+
class Bullet < GameObject
|
212
|
+
has_trait :retrofy, :timer, :collision_detection
|
213
|
+
attr_reader :status
|
214
|
+
|
215
|
+
def initialize(options)
|
216
|
+
super
|
217
|
+
@image = Image["bullet.png"].retrofy
|
218
|
+
self.factor = $window.factor
|
219
|
+
@velocity_x = 10
|
220
|
+
@status = :default
|
221
|
+
@radius = 3
|
222
|
+
end
|
223
|
+
|
224
|
+
def die
|
225
|
+
return if @status == :dying
|
226
|
+
Sound["bullet_hit.wav"].play
|
227
|
+
@status = :dying
|
228
|
+
during(50) { @factor_x += 1; @factor_y += 1; @x -= 1; }.then { self.destroy }
|
229
|
+
end
|
230
|
+
|
231
|
+
def update
|
232
|
+
return if @status == :dying
|
233
|
+
@x += @velocity_x
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
#
|
238
|
+
# ENEMY BULLET
|
239
|
+
#
|
240
|
+
class EnemyBullet < Bullet
|
241
|
+
def initialize(options)
|
242
|
+
super
|
243
|
+
@image = Image["enemy_bullet.png"].retrofy
|
244
|
+
@velocity_x = -3
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
#
|
249
|
+
# OUR ENEMY SAUCER
|
250
|
+
#
|
251
|
+
class Enemy < GameObject
|
252
|
+
has_trait :collision_detection, :retrofy, :timer
|
253
|
+
|
254
|
+
def initialize(options)
|
255
|
+
super
|
256
|
+
@velocity = options[:velocity] || 2
|
257
|
+
@health = options[:health] || 100
|
258
|
+
|
259
|
+
@anim = Animation.new(:file => "media/saucer.png", :size => [32,13], :delay => 100)
|
260
|
+
@anim.retrofy
|
261
|
+
@image = @anim.first
|
262
|
+
|
263
|
+
self.factor = $window.factor
|
264
|
+
@radius = 5
|
265
|
+
@black = Color.new(0xFF000000)
|
266
|
+
@status == :default
|
267
|
+
end
|
268
|
+
|
269
|
+
def hit_by(object)
|
270
|
+
return if @status == :dying
|
271
|
+
|
272
|
+
during(20) { @mode = :additive; }.then { @mode = :default }
|
273
|
+
@health -= 20
|
274
|
+
|
275
|
+
if @health <= 0
|
276
|
+
die
|
277
|
+
return true
|
278
|
+
else
|
279
|
+
return false
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
def fire
|
284
|
+
EnemyBullet.create(:x => self.x, :y => self.y)
|
285
|
+
end
|
286
|
+
|
287
|
+
def die
|
288
|
+
return if @status == :dying
|
289
|
+
Sound["explosion.wav"].play
|
290
|
+
@status = :dying
|
291
|
+
@color = @black
|
292
|
+
@color.alpha = 50
|
293
|
+
during(200) { @factor_x += 0.5; @factor_y += 0.5; @x -= 1; @color.alpha -= 1}.then { self.destroy }
|
294
|
+
end
|
295
|
+
|
296
|
+
def update
|
297
|
+
return if @status == :dying
|
298
|
+
|
299
|
+
@image = @anim.next!
|
300
|
+
@x -= @velocity
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
Game.new.show
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/examples/media/ruby.png
CHANGED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/lib/chingu.rb
CHANGED
@@ -6,7 +6,7 @@ module Chingu
|
|
6
6
|
# It will also acts as a container for the trait-system of chingu.
|
7
7
|
#
|
8
8
|
class BasicGameObject
|
9
|
-
attr_reader :options
|
9
|
+
attr_reader :options, :paused, :visible
|
10
10
|
attr_accessor :parent
|
11
11
|
|
12
12
|
#
|
@@ -43,6 +43,12 @@ module Chingu
|
|
43
43
|
@parent = $window.game_state_manager.inside_state || $window
|
44
44
|
end
|
45
45
|
|
46
|
+
# if true, BasicGameObject#update will be called
|
47
|
+
@paused = options[:paused] || false
|
48
|
+
|
49
|
+
# if true, BasicGameObject#draw will be called
|
50
|
+
@visible = options[:visible] || true
|
51
|
+
|
46
52
|
# This will call #setup_trait on the latest trait mixed in
|
47
53
|
# which then will pass it on to the next setup_trait() with a super-call.
|
48
54
|
setup_trait(options)
|
@@ -67,7 +73,32 @@ module Chingu
|
|
67
73
|
|
68
74
|
return instance
|
69
75
|
end
|
70
|
-
|
76
|
+
|
77
|
+
#
|
78
|
+
# Disable auto-updating of traits
|
79
|
+
#
|
80
|
+
def pause!
|
81
|
+
@paused = true
|
82
|
+
end
|
83
|
+
#
|
84
|
+
# Enable auto-update of traits
|
85
|
+
#
|
86
|
+
def unpause!
|
87
|
+
@paused = false
|
88
|
+
end
|
89
|
+
#
|
90
|
+
# Disable auto-drawing of object
|
91
|
+
#
|
92
|
+
def hide!
|
93
|
+
@visible = false
|
94
|
+
end
|
95
|
+
#
|
96
|
+
# Enable auto-drawing of object
|
97
|
+
#
|
98
|
+
def show!
|
99
|
+
@visible = true
|
100
|
+
end
|
101
|
+
|
71
102
|
def setup_trait(options)
|
72
103
|
end
|
73
104
|
|
@@ -125,7 +156,6 @@ module Chingu
|
|
125
156
|
#
|
126
157
|
def destroy
|
127
158
|
@parent.remove_game_object(self) if @parent
|
128
|
-
self.freeze
|
129
159
|
end
|
130
160
|
alias :destroy! :destroy
|
131
161
|
end
|
data/lib/chingu/game_object.rb
CHANGED
@@ -28,7 +28,7 @@ module Chingu
|
|
28
28
|
#
|
29
29
|
class GameObject < Chingu::BasicGameObject
|
30
30
|
attr_accessor :image, :x, :y, :angle, :center_x, :center_y, :factor_x, :factor_y, :color, :mode, :zorder
|
31
|
-
attr_reader :
|
31
|
+
attr_reader :factor, :center
|
32
32
|
|
33
33
|
include Chingu::Helpers::InputClient # Adds input and input=
|
34
34
|
include Chingu::Helpers::RotationCenter # Adds easy and verbose modification of @center_x and @center_y
|
@@ -62,39 +62,10 @@ module Chingu
|
|
62
62
|
|
63
63
|
@mode = options[:mode] || :default # :additive is also available.
|
64
64
|
@zorder = options[:zorder] || 100
|
65
|
-
|
66
|
-
# gameloop/framework logic (TODO: use or get rid of)
|
67
|
-
@paused = options[:paused] || false
|
68
|
-
@visible = options[:visible] || true
|
69
|
-
|
65
|
+
|
70
66
|
setup_trait(options) if respond_to?(:setup_trait)
|
71
67
|
end
|
72
68
|
|
73
|
-
#
|
74
|
-
# Disable auto-updating of traits
|
75
|
-
#
|
76
|
-
def pause!
|
77
|
-
@paused = true
|
78
|
-
end
|
79
|
-
#
|
80
|
-
# Enable auto-update of traits
|
81
|
-
#
|
82
|
-
def unpause!
|
83
|
-
@paused = false
|
84
|
-
end
|
85
|
-
#
|
86
|
-
# Disable auto-drawing of object
|
87
|
-
#
|
88
|
-
def hide!
|
89
|
-
@visible = false
|
90
|
-
end
|
91
|
-
#
|
92
|
-
# Enable auto-drawing of object
|
93
|
-
#
|
94
|
-
def show!
|
95
|
-
@visible = true
|
96
|
-
end
|
97
|
-
|
98
69
|
# Quick way of setting both factor_x and factor_y
|
99
70
|
def factor=(factor)
|
100
71
|
@factor = factor
|
@@ -41,11 +41,12 @@ module Chingu
|
|
41
41
|
#@game_objects_by_class[klass] || []
|
42
42
|
end
|
43
43
|
|
44
|
-
def
|
44
|
+
def destroy_all
|
45
45
|
@game_objects.clear
|
46
46
|
#@game_objects_of_class.clear
|
47
47
|
end
|
48
|
-
alias :clear :
|
48
|
+
alias :clear :destroy_all
|
49
|
+
alias :remove_all :destroy_all
|
49
50
|
|
50
51
|
def add_game_object(object)
|
51
52
|
@game_objects.push(object)
|
data/lib/chingu/parallax.rb
CHANGED
@@ -1,42 +1,72 @@
|
|
1
1
|
#
|
2
2
|
# Class for simple parallaxscrolling
|
3
|
+
#
|
3
4
|
# See: http://en.wikipedia.org/wiki/Parallax_scrolling
|
4
5
|
#
|
5
6
|
module Chingu
|
6
7
|
class Parallax < Chingu::GameObject
|
7
|
-
attr_reader :
|
8
|
+
attr_reader :layers
|
8
9
|
|
9
10
|
#
|
10
11
|
# Options (in hash-format):
|
11
12
|
#
|
12
|
-
# repeat: [true|false] When one
|
13
|
+
# repeat: [true|false] When one layer ends within the screen, repeat/loop it
|
13
14
|
#
|
14
15
|
def initialize(options = {})
|
15
16
|
super(options)
|
16
17
|
@repeat = options[:repeat] || true
|
17
|
-
@
|
18
|
+
@layers = Array.new
|
18
19
|
end
|
19
20
|
|
20
21
|
#
|
21
|
-
# Add one
|
22
|
-
# You can also add new
|
22
|
+
# Add one layer, either an ParallaxLayer-object or a Hash of options to create one
|
23
|
+
# You can also add new layers with the shortcut "<<":
|
23
24
|
# @parallax << {:image => "landscape.png", :damping => 1}
|
24
25
|
#
|
25
|
-
def
|
26
|
-
@
|
26
|
+
def add_layer(arg)
|
27
|
+
@layers << (arg.is_a?(ParallaxLayer) ? arg : ParallaxLayer.new(arg))
|
28
|
+
end
|
29
|
+
alias << add_layer
|
30
|
+
|
31
|
+
|
32
|
+
#
|
33
|
+
# Parallax#camera_x= works in inverse to Parallax#x (moving the "camera", not the image)
|
34
|
+
#
|
35
|
+
def camera_x=(x)
|
36
|
+
@x = -x
|
37
|
+
end
|
38
|
+
|
39
|
+
#
|
40
|
+
# Parallax#camera_y= works in inverse to Parallax#y (moving the "camera", not the image)
|
41
|
+
#
|
42
|
+
def camera_y=(y)
|
43
|
+
@y = -y
|
44
|
+
end
|
45
|
+
|
46
|
+
#
|
47
|
+
# Get the x-coordinate for the camera (inverse to x)
|
48
|
+
#
|
49
|
+
def camera_x
|
50
|
+
-@x
|
51
|
+
end
|
52
|
+
|
53
|
+
#
|
54
|
+
# Get the y-coordinate for the camera (inverse to y)
|
55
|
+
#
|
56
|
+
def camera_y
|
57
|
+
-@y
|
27
58
|
end
|
28
|
-
alias << add_background
|
29
59
|
|
30
60
|
#
|
31
61
|
# TODO: make use of $window.milliseconds_since_last_update here!
|
32
62
|
#
|
33
63
|
def update
|
34
|
-
@
|
35
|
-
|
36
|
-
|
64
|
+
@layers.each do |layer|
|
65
|
+
layer.x = @x / layer.damping
|
66
|
+
layer.y = @y / layer.damping
|
37
67
|
|
38
|
-
# This is the magic that repeats the
|
39
|
-
|
68
|
+
# This is the magic that repeats the layer to the left and right
|
69
|
+
layer.x -= layer.image.width while layer.x > 0
|
40
70
|
end
|
41
71
|
end
|
42
72
|
|
@@ -44,40 +74,62 @@ module Chingu
|
|
44
74
|
# Draw
|
45
75
|
#
|
46
76
|
def draw
|
47
|
-
@
|
48
|
-
|
77
|
+
@layers.each do |layer|
|
78
|
+
layer.draw
|
49
79
|
|
50
|
-
save_x =
|
80
|
+
save_x = layer.x
|
51
81
|
|
52
|
-
## If
|
53
|
-
while (
|
54
|
-
|
55
|
-
|
82
|
+
## If layer lands inside our screen, repeat it
|
83
|
+
while (layer.x + layer.image.width) < $window.width
|
84
|
+
layer.x += layer.image.width
|
85
|
+
layer.draw
|
56
86
|
end
|
57
87
|
|
58
|
-
|
88
|
+
layer.x = save_x
|
59
89
|
end
|
60
90
|
self
|
61
|
-
end
|
91
|
+
end
|
62
92
|
end
|
63
93
|
|
64
94
|
#
|
65
|
-
#
|
95
|
+
# ParallaxLayer is mainly used by class Parallax to keep track of the different layers.
|
96
|
+
# If you @parallax << { :image => "foo.png" } a ParallaxLayer will be created automaticly from that Hash.
|
97
|
+
#
|
98
|
+
# If no zorder is provided the ParallaxLayer-class increments an internal zorder number which will
|
99
|
+
# put the last layer added on top of the rest.
|
66
100
|
#
|
67
|
-
class
|
101
|
+
class ParallaxLayer < Chingu::GameObject
|
68
102
|
@@zorder_counter = 0
|
69
103
|
attr_reader :damping
|
70
104
|
|
71
105
|
def initialize(options)
|
72
|
-
|
73
|
-
options.merge!(:
|
106
|
+
# No auto update/draw, the parentclass Parallax takes care of that!
|
107
|
+
options.merge!(:visible => false, :paused => true)
|
74
108
|
|
75
109
|
# If no zorder is given, use a global incrementing counter. First added, furthest behind when drawn.
|
76
110
|
options.merge!(:zorder => (@@zorder_counter+=1)) if options[:zorder].nil?
|
77
111
|
|
78
112
|
super(options)
|
79
|
-
|
113
|
+
|
80
114
|
@damping = options[:damping] || 10
|
81
|
-
end
|
115
|
+
end
|
116
|
+
|
117
|
+
#
|
118
|
+
# Gets pixel from layers image
|
119
|
+
# The pixel is from the window point of view, so coordinates are converted:
|
120
|
+
#
|
121
|
+
# @parallax.layers.first.get_pixel(10, 10) # the visible pixel at 10, 10
|
122
|
+
# @parallax.layers.first.image.get_pixel(10, 10) # gets pixel 10, 10 from layers image no matter where layer is positioned
|
123
|
+
#
|
124
|
+
def get_pixel(x, y)
|
125
|
+
image_x = x - @x
|
126
|
+
image_y = y - @y
|
127
|
+
|
128
|
+
# On a 100 x 100 image, get_pixel works to 99 x 99
|
129
|
+
image_x -= @image.width while image_x >= @image.width
|
130
|
+
|
131
|
+
@image.get_pixel(image_x, image_y)
|
132
|
+
end
|
133
|
+
|
82
134
|
end
|
83
135
|
end
|
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.
|
4
|
+
version: 0.5.7
|
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-
|
33
|
+
date: 2009-10-15 00:00:00 +02:00
|
34
34
|
default_executable:
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
@@ -83,15 +83,29 @@ files:
|
|
83
83
|
- examples/example7.rb
|
84
84
|
- examples/example8.rb
|
85
85
|
- examples/example9.rb
|
86
|
+
- examples/game1.rb
|
86
87
|
- examples/media/Parallax-scroll-example-layer-0.png
|
87
88
|
- examples/media/Parallax-scroll-example-layer-1.png
|
88
89
|
- examples/media/Parallax-scroll-example-layer-2.png
|
89
90
|
- examples/media/Parallax-scroll-example-layer-3.png
|
90
91
|
- examples/media/background1.png
|
92
|
+
- examples/media/bullet.png
|
93
|
+
- examples/media/bullet_hit.wav
|
94
|
+
- examples/media/city1.csv
|
95
|
+
- examples/media/city1.png
|
96
|
+
- examples/media/city2.png
|
97
|
+
- examples/media/enemy_bullet.png
|
98
|
+
- examples/media/explosion.wav
|
91
99
|
- examples/media/fire_bullet.png
|
92
100
|
- examples/media/fireball.png
|
101
|
+
- examples/media/laser.wav
|
93
102
|
- examples/media/particle.png
|
103
|
+
- examples/media/plane.csv
|
104
|
+
- examples/media/plane.png
|
94
105
|
- examples/media/ruby.png
|
106
|
+
- examples/media/saucer.csv
|
107
|
+
- examples/media/saucer.gal
|
108
|
+
- examples/media/saucer.png
|
95
109
|
- examples/media/spaceship.png
|
96
110
|
- examples/media/stickfigure.bmp
|
97
111
|
- examples/media/stickfigure.png
|
metadata.gz.sig
CHANGED
Binary file
|