ippa-chingu 0.2.0
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/History.txt +5 -0
- data/Manifest.txt +34 -0
- data/README.rdoc +329 -0
- data/Rakefile +19 -0
- data/chingu.gemspec +34 -0
- data/examples/example1.rb +30 -0
- data/examples/example2.rb +76 -0
- data/examples/example3.rb +37 -0
- data/examples/example4.rb +110 -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/spaceship.png +0 -0
- data/examples/media/stickfigure.bmp +0 -0
- data/examples/media/stickfigure.png +0 -0
- data/lib/chingu/animation.rb +109 -0
- data/lib/chingu/assets.rb +50 -0
- data/lib/chingu/chipmunk_object.rb +117 -0
- data/lib/chingu/data_structures.rb +6 -0
- data/lib/chingu/fpscounter.rb +21 -0
- data/lib/chingu/game_object.rb +101 -0
- data/lib/chingu/game_state.rb +39 -0
- data/lib/chingu/game_state_manager.rb +84 -0
- data/lib/chingu/helpers.rb +41 -0
- data/lib/chingu/input.rb +100 -0
- data/lib/chingu/named_resource.rb +254 -0
- data/lib/chingu/parallax.rb +80 -0
- data/lib/chingu/rect.rb +612 -0
- data/lib/chingu/text.rb +46 -0
- data/lib/chingu/window.rb +161 -0
- data/lib/chingu.rb +29 -0
- metadata +99 -0
@@ -0,0 +1,161 @@
|
|
1
|
+
module Chingu
|
2
|
+
class Window < Gosu::Window
|
3
|
+
include Chingu::GameStateHelpers # adds push_gamestate(), pop_gamestate() and previous_gamestate()
|
4
|
+
include Chingu::DrawHelpers # adds fill() etc..
|
5
|
+
|
6
|
+
attr_reader :root, :update_list, :draw_list, :tick, :game_state_manager
|
7
|
+
attr_accessor :key_receivers, :input
|
8
|
+
attr_reader :game_objects
|
9
|
+
|
10
|
+
#
|
11
|
+
# See http://www.libgosu.org/rdoc/classes/Gosu/Window.html
|
12
|
+
#
|
13
|
+
# On top of that we add:
|
14
|
+
# - Default widht / height, --fullscreen option from console
|
15
|
+
# - Global variable $window
|
16
|
+
# - Standard #update which updates all Chingu::GameObject's
|
17
|
+
# - Standard #draw which goes through
|
18
|
+
# - Assethandling with Image["picture.png"] and Sample["shot.wav"]
|
19
|
+
# - Default input mapping escape to close
|
20
|
+
#
|
21
|
+
def initialize(width = 640, height = 480)
|
22
|
+
full_screen = ARGV.include?("--fullscreen")
|
23
|
+
$window = super(width, height, full_screen)
|
24
|
+
|
25
|
+
@root = File.dirname(File.expand_path($0))
|
26
|
+
Gosu::Image.autoload_dirs = [".", File.join(@root, "gfx"), File.join(@root, "media")]
|
27
|
+
Gosu::Sample.autoload_dirs = [".", File.join(@root, "sound"), File.join(@root, "media")]
|
28
|
+
Gosu::Tile.autoload_dirs = [".", File.join(@root, "gfx"), File.join(@root, "media")]
|
29
|
+
|
30
|
+
@game_objects = []
|
31
|
+
@input = nil
|
32
|
+
|
33
|
+
@ticks = 0
|
34
|
+
@last_tick = Gosu::milliseconds
|
35
|
+
|
36
|
+
@fps_counter = FPSCounter.new
|
37
|
+
@game_state_manager = GameStateManager.new
|
38
|
+
|
39
|
+
@update_list = []
|
40
|
+
@draw_list = []
|
41
|
+
|
42
|
+
self.input = { :escape => close }
|
43
|
+
end
|
44
|
+
|
45
|
+
def add_game_object(game_object)
|
46
|
+
@game_objects.push(game_object) unless @game_objects.include?(game_object)
|
47
|
+
end
|
48
|
+
|
49
|
+
def update_tick
|
50
|
+
@tick = Gosu::milliseconds - @last_tick
|
51
|
+
@last_tick = Gosu::milliseconds
|
52
|
+
@tick
|
53
|
+
end
|
54
|
+
|
55
|
+
def fps
|
56
|
+
@fps_counter.fps
|
57
|
+
end
|
58
|
+
|
59
|
+
#
|
60
|
+
# By default button_up sends the keyevent to the GameStateManager
|
61
|
+
# .. Which then is responsible to send it to the right GameState(s)
|
62
|
+
#
|
63
|
+
def button_up(id)
|
64
|
+
@game_state_manager.button_up(id)
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
#
|
69
|
+
# By default button_down sends the keyevent to the GameStateManager
|
70
|
+
# .. Which then is responsible to send it to the right GameState(s)
|
71
|
+
#
|
72
|
+
def button_down(id)
|
73
|
+
@game_state_manager.button_down(id)
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
#
|
78
|
+
# Standard GOSU main class update
|
79
|
+
#
|
80
|
+
def update
|
81
|
+
@fps_counter.register_tick
|
82
|
+
update_tick
|
83
|
+
|
84
|
+
#
|
85
|
+
# Process inputs for:
|
86
|
+
# - Our main game window (self)
|
87
|
+
# - .. and all gameobjects connected to it
|
88
|
+
# - the active gamestate
|
89
|
+
# - ... and all GameObjects connected to it
|
90
|
+
#
|
91
|
+
[self, @game_state_manager.state].each do |object|
|
92
|
+
next if object.nil?
|
93
|
+
|
94
|
+
dispatch_input_for(object)
|
95
|
+
|
96
|
+
object.game_objects.each do |game_object|
|
97
|
+
dispatch_input_for(game_object)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
@game_objects.each { |object| object.update }
|
102
|
+
@game_state_manager.update
|
103
|
+
end
|
104
|
+
|
105
|
+
def draw
|
106
|
+
@game_objects.each { |object| object.draw }
|
107
|
+
@game_state_manager.draw
|
108
|
+
end
|
109
|
+
|
110
|
+
private
|
111
|
+
|
112
|
+
#
|
113
|
+
# Dispatches a input for any given object
|
114
|
+
#
|
115
|
+
def dispatch_input_for(object)
|
116
|
+
return if object.nil? || object.input.nil?
|
117
|
+
|
118
|
+
object.input.each do |symbol, action|
|
119
|
+
if button_down?(Input::SYMBOL_TO_CONSTANT[symbol])
|
120
|
+
#puts "#{object.to_s} :#{symbol.to_s} => #{action.to_s}"
|
121
|
+
#puts "[#{action.class.to_s} - #{action.class.superclass.to_s}]"
|
122
|
+
if action.is_a? Symbol
|
123
|
+
object.send(action)
|
124
|
+
elsif action.is_a? Proc
|
125
|
+
action.call
|
126
|
+
elsif action.is_a? Chingu::GameState
|
127
|
+
push_gamestate(action)
|
128
|
+
elsif action.superclass == Chingu::GameState
|
129
|
+
push_gamestate(action)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
# def button_down(id)
|
142
|
+
# key_recievers.each do |key_reciever|
|
143
|
+
# key_reciever.keymap.each do |key, action|
|
144
|
+
# key_reciever.send(:before_keymap_dispatch) if key_reciever.respond_to? (:before_keymap_dispatch)
|
145
|
+
# if Keymap::constant_to_symbol[id] == key
|
146
|
+
# puts "#{key.to_s} => #{action.to_s}"
|
147
|
+
# key_reciever.send(action)
|
148
|
+
# end
|
149
|
+
# end
|
150
|
+
# end
|
151
|
+
# end
|
152
|
+
|
153
|
+
#def button_up(id)
|
154
|
+
# key_recievers.each do |key_reciever|
|
155
|
+
# key_reciever.release_keymap.each do |key, action|
|
156
|
+
# if Keymap::Keys[id] == key
|
157
|
+
# key_reciever.send(action)
|
158
|
+
# end
|
159
|
+
# end
|
160
|
+
# end
|
161
|
+
#end
|
data/lib/chingu.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#
|
2
|
+
#
|
3
|
+
#
|
4
|
+
#
|
5
|
+
require 'rubygems'
|
6
|
+
require 'gosu'
|
7
|
+
|
8
|
+
%w{ helpers
|
9
|
+
game_state_manager
|
10
|
+
game_state
|
11
|
+
window
|
12
|
+
fpscounter
|
13
|
+
named_resource
|
14
|
+
assets
|
15
|
+
game_object
|
16
|
+
text
|
17
|
+
data_structures
|
18
|
+
rect
|
19
|
+
animation
|
20
|
+
input
|
21
|
+
parallax
|
22
|
+
}.each do |lib|
|
23
|
+
root ||= File.dirname(File.expand_path(__FILE__))
|
24
|
+
require File.join(root,"chingu",lib)
|
25
|
+
end
|
26
|
+
|
27
|
+
module Chingu
|
28
|
+
VERSION = "0.2.0"
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ippa-chingu
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ippa
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-08-10 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hoe
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.3.2
|
24
|
+
version:
|
25
|
+
description: 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.
|
26
|
+
email:
|
27
|
+
- ippa@rubylicio.us
|
28
|
+
executables: []
|
29
|
+
|
30
|
+
extensions: []
|
31
|
+
|
32
|
+
extra_rdoc_files:
|
33
|
+
- History.txt
|
34
|
+
- Manifest.txt
|
35
|
+
files:
|
36
|
+
- History.txt
|
37
|
+
- Manifest.txt
|
38
|
+
- README.rdoc
|
39
|
+
- Rakefile
|
40
|
+
- chingu.gemspec
|
41
|
+
- examples/example1.rb
|
42
|
+
- examples/example2.rb
|
43
|
+
- examples/example3.rb
|
44
|
+
- examples/example4.rb
|
45
|
+
- examples/media/Parallax-scroll-example-layer-0.png
|
46
|
+
- examples/media/Parallax-scroll-example-layer-1.png
|
47
|
+
- examples/media/Parallax-scroll-example-layer-2.png
|
48
|
+
- examples/media/Parallax-scroll-example-layer-3.png
|
49
|
+
- examples/media/background1.png
|
50
|
+
- examples/media/fire_bullet.png
|
51
|
+
- examples/media/spaceship.png
|
52
|
+
- examples/media/stickfigure.bmp
|
53
|
+
- examples/media/stickfigure.png
|
54
|
+
- lib/chingu.rb
|
55
|
+
- lib/chingu/animation.rb
|
56
|
+
- lib/chingu/assets.rb
|
57
|
+
- lib/chingu/chipmunk_object.rb
|
58
|
+
- lib/chingu/data_structures.rb
|
59
|
+
- lib/chingu/fpscounter.rb
|
60
|
+
- lib/chingu/game_object.rb
|
61
|
+
- lib/chingu/game_state.rb
|
62
|
+
- lib/chingu/game_state_manager.rb
|
63
|
+
- lib/chingu/helpers.rb
|
64
|
+
- lib/chingu/input.rb
|
65
|
+
- lib/chingu/named_resource.rb
|
66
|
+
- lib/chingu/parallax.rb
|
67
|
+
- lib/chingu/rect.rb
|
68
|
+
- lib/chingu/text.rb
|
69
|
+
- lib/chingu/window.rb
|
70
|
+
has_rdoc: true
|
71
|
+
homepage: http://github.com/ippa/chingu/tree/master
|
72
|
+
licenses:
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options:
|
75
|
+
- --main
|
76
|
+
- README.rdoc
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: "0"
|
84
|
+
version:
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: "0"
|
90
|
+
version:
|
91
|
+
requirements: []
|
92
|
+
|
93
|
+
rubyforge_project: chingu
|
94
|
+
rubygems_version: 1.3.5
|
95
|
+
signing_key:
|
96
|
+
specification_version: 2
|
97
|
+
summary: Game framework built on top of the OpenGL accelerated game lib Gosu
|
98
|
+
test_files: []
|
99
|
+
|