chingu 0.5.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/History.txt +21 -0
- data/LICENSE +504 -0
- data/Manifest.txt +72 -0
- data/README.rdoc +588 -0
- data/Rakefile +19 -0
- data/benchmarks/README.txt +1 -0
- data/benchmarks/benchmark.rb +6 -0
- data/benchmarks/benchmark3.rb +23 -0
- data/benchmarks/benchmark4.rb +71 -0
- data/benchmarks/benchmark5.rb +91 -0
- data/benchmarks/benchmark6.rb +23 -0
- data/benchmarks/meta_benchmark.rb +67 -0
- data/benchmarks/meta_benchmark2.rb +39 -0
- data/chingu.gemspec +34 -0
- data/examples/example1.rb +37 -0
- data/examples/example10.rb +75 -0
- data/examples/example11.rb +51 -0
- data/examples/example12.rb +67 -0
- data/examples/example2.rb +115 -0
- data/examples/example3.rb +40 -0
- data/examples/example4.rb +175 -0
- data/examples/example5.rb +107 -0
- data/examples/example6.rb +57 -0
- data/examples/example7.rb +133 -0
- data/examples/example8.rb +109 -0
- data/examples/example9.rb +106 -0
- data/examples/media/Parallax-scroll-example-layer-0.png +0 -0
- data/examples/media/Parallax-scroll-example-layer-1.png +0 -0
- data/examples/media/Parallax-scroll-example-layer-2.png +0 -0
- data/examples/media/Parallax-scroll-example-layer-3.png +0 -0
- data/examples/media/background1.png +0 -0
- data/examples/media/fire_bullet.png +0 -0
- data/examples/media/fireball.png +0 -0
- data/examples/media/particle.png +0 -0
- data/examples/media/ruby.png +0 -0
- data/examples/media/spaceship.png +0 -0
- data/examples/media/stickfigure.bmp +0 -0
- data/examples/media/stickfigure.png +0 -0
- data/examples/media/video_games.png +0 -0
- data/lib/chingu.rb +32 -0
- data/lib/chingu/actor.rb +17 -0
- data/lib/chingu/animation.rb +142 -0
- data/lib/chingu/assets.rb +64 -0
- data/lib/chingu/basic_game_object.rb +132 -0
- data/lib/chingu/core_extensions.rb +53 -0
- data/lib/chingu/effects.rb +36 -0
- data/lib/chingu/fpscounter.rb +62 -0
- data/lib/chingu/game_object.rb +127 -0
- data/lib/chingu/game_object_list.rb +91 -0
- data/lib/chingu/game_state.rb +137 -0
- data/lib/chingu/game_state_manager.rb +284 -0
- data/lib/chingu/game_states/debug.rb +65 -0
- data/lib/chingu/game_states/fade_to.rb +91 -0
- data/lib/chingu/game_states/pause.rb +57 -0
- data/lib/chingu/gfx_helpers.rb +89 -0
- data/lib/chingu/helpers.rb +166 -0
- data/lib/chingu/inflector.rb +34 -0
- data/lib/chingu/input.rb +100 -0
- data/lib/chingu/named_resource.rb +254 -0
- data/lib/chingu/parallax.rb +83 -0
- data/lib/chingu/particle.rb +21 -0
- data/lib/chingu/rect.rb +612 -0
- data/lib/chingu/require_all.rb +133 -0
- data/lib/chingu/text.rb +56 -0
- data/lib/chingu/traits/collision_detection.rb +172 -0
- data/lib/chingu/traits/effect.rb +113 -0
- data/lib/chingu/traits/input.rb +38 -0
- data/lib/chingu/traits/retrofy.rb +53 -0
- data/lib/chingu/traits/rotation_center.rb +84 -0
- data/lib/chingu/traits/timer.rb +90 -0
- data/lib/chingu/traits/velocity.rb +67 -0
- data/lib/chingu/window.rb +170 -0
- metadata +162 -0
- metadata.gz.sig +1 -0
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/lib/chingu.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#--
|
2
|
+
#
|
3
|
+
# Chingu -- Game framework built on top of the opengl accelerated gamelib Gosu
|
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
|
+
CHINGU_ROOT = File.dirname(File.expand_path(__FILE__))
|
23
|
+
|
24
|
+
require 'rubygems' unless RUBY_VERSION =~ /1\.9/
|
25
|
+
require 'gosu'
|
26
|
+
require 'set'
|
27
|
+
require File.join(CHINGU_ROOT,"chingu","require_all") # Thanks to http://github.com/tarcieri/require_all !
|
28
|
+
require_all "#{CHINGU_ROOT}/chingu"
|
29
|
+
|
30
|
+
module Chingu
|
31
|
+
VERSION = "0.5.5.3"
|
32
|
+
end
|
data/lib/chingu/actor.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module Chingu
|
2
|
+
#
|
3
|
+
# A game object class with most components included, nice for quick prototypes
|
4
|
+
#
|
5
|
+
# TODO: we probably wanna expand this concept or remove Actor as a whole.
|
6
|
+
#
|
7
|
+
class Actor < Chingu::GameObject
|
8
|
+
has_traits :effect, :velocity, :input
|
9
|
+
|
10
|
+
def update
|
11
|
+
# needed for traits to work
|
12
|
+
super
|
13
|
+
|
14
|
+
# your game logic Here
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
module Chingu
|
2
|
+
#
|
3
|
+
# The Animation-class helps you load and manage a tileanimation.
|
4
|
+
# A Tileanimation is a file where all the frames are put after eachother.
|
5
|
+
#
|
6
|
+
# An easy to use program to create tileanimations is http://tilestudio.sourceforge.net/
|
7
|
+
#
|
8
|
+
class Animation
|
9
|
+
attr_accessor :frames, :delay
|
10
|
+
|
11
|
+
#
|
12
|
+
# Create a new Animation.
|
13
|
+
#
|
14
|
+
# - loop: [true|false]. After the last frame is used, start from the beginning.
|
15
|
+
# - bounce: [true|false]. After the last frame is used, play it backwards untill the first frame is used again, then start playing forwards again.
|
16
|
+
# - file: Tile-file to cut up animation frames from.
|
17
|
+
# - width: width of each frame in the tileanimation
|
18
|
+
# - height: width of each frame in the tileanimation
|
19
|
+
#
|
20
|
+
#
|
21
|
+
def initialize(options)
|
22
|
+
options = {:loop => true, :bounce => false, :width => 32, :height => 32, :index => 0, :delay => 100}.merge(options)
|
23
|
+
|
24
|
+
@loop = options[:loop]
|
25
|
+
@bounce = options[:bounce]
|
26
|
+
@file = options[:file]
|
27
|
+
@height = options[:height]
|
28
|
+
@width = options[:width]
|
29
|
+
@index = options[:index]
|
30
|
+
@delay = options[:delay]
|
31
|
+
@dt = 0
|
32
|
+
|
33
|
+
if options[:size]
|
34
|
+
@width = options[:size][0]
|
35
|
+
@height = options[:size][1]
|
36
|
+
end
|
37
|
+
|
38
|
+
@frame_actions = []
|
39
|
+
@frames = Gosu::Image.load_tiles($window, @file, @width, @height, true)
|
40
|
+
@step = 1
|
41
|
+
end
|
42
|
+
|
43
|
+
#
|
44
|
+
# Returns first frame (GOSU::Image) from animation
|
45
|
+
#
|
46
|
+
def first
|
47
|
+
@frames.first
|
48
|
+
end
|
49
|
+
|
50
|
+
#
|
51
|
+
# Returns last frame (GOSU::Image) from animation
|
52
|
+
#
|
53
|
+
def last
|
54
|
+
@frames.first
|
55
|
+
end
|
56
|
+
|
57
|
+
#
|
58
|
+
# Fetch a frame or frames:
|
59
|
+
#
|
60
|
+
# @animation[0] # returns first frame
|
61
|
+
# @animation[0..2] # returns a new Animation-instance with first, second and third frame
|
62
|
+
#
|
63
|
+
def [](index)
|
64
|
+
return @frames[index] if index.is_a?(Fixnum)
|
65
|
+
return self.new_from_frames(index) if index.is_a?(Range)
|
66
|
+
end
|
67
|
+
|
68
|
+
#
|
69
|
+
# Get the current frame (a Gosu#Image)
|
70
|
+
#
|
71
|
+
def image
|
72
|
+
@frames[@index]
|
73
|
+
end
|
74
|
+
|
75
|
+
#
|
76
|
+
# Resets the animation, re-starts it at frame 0
|
77
|
+
# returns itself.
|
78
|
+
#
|
79
|
+
def reset!
|
80
|
+
@index = 0
|
81
|
+
self
|
82
|
+
end
|
83
|
+
|
84
|
+
#
|
85
|
+
# Returns a new animation with the frames from the original animation.
|
86
|
+
# Specify which frames you want with "range", for example "0..3" for the 4 first frames.
|
87
|
+
#
|
88
|
+
def new_from_frames(range)
|
89
|
+
new_animation = self.dup
|
90
|
+
new_animation.frames = []
|
91
|
+
range.each do |nr|
|
92
|
+
new_animation.frames << self.frames[nr]
|
93
|
+
end
|
94
|
+
return new_animation
|
95
|
+
end
|
96
|
+
|
97
|
+
#
|
98
|
+
# Propelles the animation forward. Usually called in #update within the class which holds the animation.
|
99
|
+
# #next! will look at bounce and loop flags to always return a correct frame (a Gosu#Image)
|
100
|
+
#
|
101
|
+
def next!
|
102
|
+
if (@dt += $window.milliseconds_since_last_tick) > @delay
|
103
|
+
@dt = 0
|
104
|
+
@previous_index = @index
|
105
|
+
@index += @step
|
106
|
+
|
107
|
+
# Has the animation hit end or beginning... time for bounce or loop?
|
108
|
+
if (@index >= @frames.size || @index < 0)
|
109
|
+
if @bounce
|
110
|
+
@step *= -1 # invert number
|
111
|
+
@index += @step
|
112
|
+
elsif @loop
|
113
|
+
@index = 0
|
114
|
+
else
|
115
|
+
@index = @previous_index # no bounce or loop, use previous frame
|
116
|
+
end
|
117
|
+
end
|
118
|
+
@frame_actions[@index].call if @frame_actions[@index]
|
119
|
+
end
|
120
|
+
@frames[@index]
|
121
|
+
end
|
122
|
+
|
123
|
+
#
|
124
|
+
# Initialize non-blurry zoom on frames in animation
|
125
|
+
#
|
126
|
+
def retrofy
|
127
|
+
frames.each { |frame| frame.retrofy }
|
128
|
+
end
|
129
|
+
|
130
|
+
#
|
131
|
+
# Execute a certain block of code when a certain frame in the animation is active.
|
132
|
+
# This could be used for pixel perfect animation/movement.
|
133
|
+
#
|
134
|
+
def on_frame(frames, &block)
|
135
|
+
if frames.kind_of? Array
|
136
|
+
frames.each { |frame| @frame_actions[frame] = block }
|
137
|
+
else
|
138
|
+
@frame_actions[frames] = block
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
#
|
2
|
+
# Rubygames Named Resources for GOSU
|
3
|
+
# Assumes a global variable $window having the Gosu::Window instance.
|
4
|
+
# Quick 'n easy access to sprites, sounds and tiles!
|
5
|
+
#
|
6
|
+
module Chingu
|
7
|
+
def media_path(file)
|
8
|
+
File.join($window.root, "media", file)
|
9
|
+
end
|
10
|
+
|
11
|
+
def image_path(file)
|
12
|
+
File.join($window.root, "gfx", file)
|
13
|
+
end
|
14
|
+
|
15
|
+
class ImagePath
|
16
|
+
include Chingu::NamedResource
|
17
|
+
|
18
|
+
def self.autoload(name)
|
19
|
+
find_file(name)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
module Gosu
|
25
|
+
class Image
|
26
|
+
include Chingu::NamedResource
|
27
|
+
|
28
|
+
def self.autoload(name)
|
29
|
+
(path = find_file(name)) ? Gosu::Image.new($window, path, true) : nil
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class Song
|
34
|
+
include Chingu::NamedResource
|
35
|
+
|
36
|
+
def self.autoload(name)
|
37
|
+
(path = find_file(name)) ? Gosu::Song.new($window, path) : nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class Sample
|
42
|
+
include Chingu::NamedResource
|
43
|
+
|
44
|
+
def self.autoload(name)
|
45
|
+
(path = find_file(name)) ? Gosu::Sample.new($window, path) : nil
|
46
|
+
end
|
47
|
+
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
|
64
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
module Chingu
|
2
|
+
#
|
3
|
+
# BasicGameObject. Resonating with 1.9.1, this is our most basic class that all game objects ultimate should build on.
|
4
|
+
#
|
5
|
+
# All objects that inherits from this class will by default be automaticly be updated and drawn.
|
6
|
+
# It will also acts as a container for the trait-system of chingu.
|
7
|
+
#
|
8
|
+
class BasicGameObject
|
9
|
+
attr_reader :options
|
10
|
+
attr_accessor :parent
|
11
|
+
|
12
|
+
#
|
13
|
+
# adds a trait or traits to a certain game class
|
14
|
+
#
|
15
|
+
# Executes a ruby "include" the specified module
|
16
|
+
#
|
17
|
+
def self.has_trait(*traits)
|
18
|
+
has_traits(*traits)
|
19
|
+
end
|
20
|
+
|
21
|
+
#
|
22
|
+
# See #has_trait
|
23
|
+
#
|
24
|
+
def self.has_traits(*traits)
|
25
|
+
Array(traits).each do |trait|
|
26
|
+
if trait.is_a?(::Symbol) || trait.is_a?(::String)
|
27
|
+
include Chingu::Traits.const_get(Chingu::Inflector.camelize(trait))
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
#
|
33
|
+
# BasicGameObject initialize
|
34
|
+
# - call .setup_trait() on all traits that implements it
|
35
|
+
#
|
36
|
+
def initialize(options = {})
|
37
|
+
@options = options
|
38
|
+
|
39
|
+
#
|
40
|
+
# A GameObject either belong to a GameState or our mainwindow ($window)
|
41
|
+
#
|
42
|
+
if $window && $window.respond_to?(:game_state_manager)
|
43
|
+
@parent = $window.game_state_manager.inside_state || $window
|
44
|
+
end
|
45
|
+
|
46
|
+
# This will call #setup_trait on the latest trait mixed in
|
47
|
+
# which then will pass it on to the next setup_trait() with a super-call.
|
48
|
+
setup_trait(options)
|
49
|
+
end
|
50
|
+
|
51
|
+
#
|
52
|
+
# Creates a new object from class just as new() but also:
|
53
|
+
# - adds game object to current game state
|
54
|
+
# - or $window if no game state exists
|
55
|
+
#
|
56
|
+
# Use create() instead of new() if you want to keep track of your objects through
|
57
|
+
# Chingus "game_objects" which is available in all game states and the main window.
|
58
|
+
#
|
59
|
+
def self.create(options = {})
|
60
|
+
instance = self.new(options)
|
61
|
+
|
62
|
+
|
63
|
+
#
|
64
|
+
# Add to parents list of game objects
|
65
|
+
#
|
66
|
+
instance.parent.add_game_object(instance) if instance.parent
|
67
|
+
|
68
|
+
return instance
|
69
|
+
end
|
70
|
+
|
71
|
+
def setup_trait(options)
|
72
|
+
end
|
73
|
+
|
74
|
+
def update_trait
|
75
|
+
end
|
76
|
+
|
77
|
+
def draw_trait
|
78
|
+
end
|
79
|
+
|
80
|
+
def update
|
81
|
+
end
|
82
|
+
|
83
|
+
def draw
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
#
|
88
|
+
# Returns an array with all objects of current class.
|
89
|
+
# BasicGameObject#all is state aware so only objects belonging to the current state will be returned.
|
90
|
+
#
|
91
|
+
# Bullet.all.each do {} # Iterate through all bullets in current game state
|
92
|
+
#
|
93
|
+
def self.all
|
94
|
+
$window.current_parent.game_objects.of_class(self).dup
|
95
|
+
end
|
96
|
+
|
97
|
+
#
|
98
|
+
# Returns
|
99
|
+
#
|
100
|
+
def self.size
|
101
|
+
$window.current_parent.game_objects.of_class(self).size
|
102
|
+
end
|
103
|
+
|
104
|
+
#
|
105
|
+
# Destroy all instances of current class that fills a certain condition
|
106
|
+
# Enemy.destroy_if(&:dead?) # Assumes Enemy.dead? returns true/false depending on aliveness :)
|
107
|
+
#
|
108
|
+
def self.destroy_if(&block)
|
109
|
+
all.each do |object|
|
110
|
+
object.destroy if yield(object)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
#
|
115
|
+
# Destroys all intances of objects class:
|
116
|
+
# Bullet.destroy_all # Removes all Bullet objects from the game
|
117
|
+
#
|
118
|
+
def self.destroy_all
|
119
|
+
self.all.each { |object| object.destroy! }
|
120
|
+
end
|
121
|
+
|
122
|
+
#
|
123
|
+
# Removes object from the update cycle and freezes the object to prevent further modifications.
|
124
|
+
# If the object isn't being managed by Chingu (ie. you're doing manual update/draw calls) the object is only frozen, not removed from any updae cycle (because you are controlling that).
|
125
|
+
#
|
126
|
+
def destroy
|
127
|
+
@parent.remove_game_object(self) if @parent
|
128
|
+
self.freeze
|
129
|
+
end
|
130
|
+
alias :destroy! :destroy
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
#--
|
2
|
+
#
|
3
|
+
# Chingu -- Game framework built on top of the opengl accelerated gamelib Gosu
|
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
|
+
#
|
24
|
+
# Core extensions to GOSU
|
25
|
+
# Some of these require the gem 'texplay'
|
26
|
+
#
|
27
|
+
module Gosu
|
28
|
+
|
29
|
+
class Image
|
30
|
+
#
|
31
|
+
# Returns true if the pixel at x, y is 100% transperant (good for collisiondetection)
|
32
|
+
# Requires texplay
|
33
|
+
#
|
34
|
+
def transparent_pixel?(x, y)
|
35
|
+
begin
|
36
|
+
self.get_pixel(x,y)[3] == 0
|
37
|
+
rescue
|
38
|
+
puts "Error in get_pixel at x/y: #{x}/#{y}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# Retrofy should be called just after the image is loaded.
|
44
|
+
# When retrofied an image will use a non-blurry zoom.
|
45
|
+
# This could be used to make each pixel a sharp 4 pixelblock => retrofeeling.
|
46
|
+
#
|
47
|
+
def retrofy
|
48
|
+
glBindTexture(GL_TEXTURE_2D, self.gl_tex_info.tex_name)
|
49
|
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
|
50
|
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|