chingu 0.6.5 → 0.6.6
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/chingu.gemspec +5 -5
- data/examples/example15.rb +19 -7
- data/lib/chingu.rb +1 -1
- data/lib/chingu/traits/collision_detection.rb +4 -4
- data/lib/chingu/traits/timer.rb +74 -20
- data/lib/chingu/traits/velocity.rb +11 -1
- metadata +3 -3
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
Binary file
|
data/chingu.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{chingu}
|
5
|
-
s.version = "0.6.
|
5
|
+
s.version = "0.6.6"
|
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-12-
|
9
|
+
s.date = %q{2009-12-12}
|
10
10
|
s.description = %q{OpenGL accelerated 2D game framework for Ruby.
|
11
11
|
Builds on the awesome Gosu (Ruby/C++) which provides all the core functionality.
|
12
12
|
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.}
|
@@ -25,11 +25,11 @@ It adds simple yet powerful game states, prettier input handling, deployment saf
|
|
25
25
|
s.specification_version = 3
|
26
26
|
|
27
27
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
28
|
-
s.add_development_dependency(%q<hoe>, [">= 2.
|
28
|
+
s.add_development_dependency(%q<hoe>, [">= 2.4.0"])
|
29
29
|
else
|
30
|
-
s.add_dependency(%q<hoe>, [">= 2.
|
30
|
+
s.add_dependency(%q<hoe>, [">= 2.4.0"])
|
31
31
|
end
|
32
32
|
else
|
33
|
-
s.add_dependency(%q<hoe>, [">= 2.
|
33
|
+
s.add_dependency(%q<hoe>, [">= 2.4.0"])
|
34
34
|
end
|
35
35
|
end
|
data/examples/example15.rb
CHANGED
@@ -3,6 +3,9 @@ require File.join(File.dirname($0), "..", "lib", "chingu")
|
|
3
3
|
include Gosu
|
4
4
|
include Chingu
|
5
5
|
|
6
|
+
#
|
7
|
+
# Testing advanced options of timer-trait
|
8
|
+
#
|
6
9
|
class Game < Chingu::Window
|
7
10
|
def initialize
|
8
11
|
super(640,400)
|
@@ -16,10 +19,23 @@ class Stuff < GameState
|
|
16
19
|
|
17
20
|
def initialize(options = {})
|
18
21
|
super
|
19
|
-
|
22
|
+
self.input = {:t => :toggle, :"1" => :fast, :"2" => :slow}
|
20
23
|
@thing = Thing.create(:x => $window.width/2, :y => $window.height / 2 )
|
21
|
-
|
22
|
-
every(500){ @thing.visible? ? @thing.hide! : @thing.show!}
|
24
|
+
|
25
|
+
every(500, :name => :blink) { @thing.visible? ? @thing.hide! : @thing.show! }
|
26
|
+
p timer_exists?(:blink)
|
27
|
+
end
|
28
|
+
|
29
|
+
def toggle
|
30
|
+
stop_timer(:name => :blink)
|
31
|
+
end
|
32
|
+
|
33
|
+
def fast
|
34
|
+
every(200, :name => :blink) { @thing.visible? ? @thing.hide! : @thing.show! }
|
35
|
+
end
|
36
|
+
|
37
|
+
def slow
|
38
|
+
every(1000, :name => :blink) { @thing.visible? ? @thing.hide! : @thing.show! }
|
23
39
|
end
|
24
40
|
|
25
41
|
def update
|
@@ -33,10 +49,6 @@ class Thing < GameObject
|
|
33
49
|
super
|
34
50
|
@image = Image["circle.png"]
|
35
51
|
end
|
36
|
-
|
37
|
-
def update
|
38
|
-
#@y += 1
|
39
|
-
end
|
40
52
|
end
|
41
53
|
|
42
54
|
Game.new.show
|
data/lib/chingu.rb
CHANGED
@@ -111,7 +111,7 @@ module Chingu
|
|
111
111
|
# Explicit radius-collision
|
112
112
|
# Works like each_collsion but with inline-code for speedups
|
113
113
|
#
|
114
|
-
def each_bounding_circle_collision(klasses
|
114
|
+
def each_bounding_circle_collision(*klasses)
|
115
115
|
Array(klasses).each do |klass|
|
116
116
|
klass.all.each do |object|
|
117
117
|
yield(self, object) if Gosu.distance(self.x, self.y, object.x, object.y) < self.radius + object.radius
|
@@ -123,7 +123,7 @@ module Chingu
|
|
123
123
|
# Explicit bounding_box-collision
|
124
124
|
# Works like each_collision but with inline-code for speedups
|
125
125
|
#
|
126
|
-
def each_bounding_box_collision(klasses
|
126
|
+
def each_bounding_box_collision(*klasses)
|
127
127
|
Array(klasses).each do |klass|
|
128
128
|
klass.all.each do |object|
|
129
129
|
yield(self, object) if self.bounding_box.collide_rect?(object.bounding_box)
|
@@ -136,7 +136,7 @@ module Chingu
|
|
136
136
|
#
|
137
137
|
# Works like each_collision but with inline-code for speedups
|
138
138
|
#
|
139
|
-
def each_bounding_circle_collision(klasses
|
139
|
+
def each_bounding_circle_collision(*klasses)
|
140
140
|
Array(klasses).each do |klass|
|
141
141
|
object2_list = klass.all
|
142
142
|
#total_radius = object1.radius + object2.radius # possible optimization?
|
@@ -153,7 +153,7 @@ module Chingu
|
|
153
153
|
#
|
154
154
|
# Works like each_collsion but with explicit bounding_box collisions (inline-code for speedups)
|
155
155
|
#
|
156
|
-
def each_bounding_box_collision(klasses
|
156
|
+
def each_bounding_box_collision(*klasses)
|
157
157
|
Array(klasses).each do |klass|
|
158
158
|
object2_list = klass.all
|
159
159
|
self.all.each do |object1|
|
data/lib/chingu/traits/timer.rb
CHANGED
@@ -36,64 +36,118 @@ module Chingu
|
|
36
36
|
def setup_trait(options)
|
37
37
|
#
|
38
38
|
# Timers are saved as an array of arrays where each entry contains:
|
39
|
-
# [start_time, end_time (or nil if one-shot), &block]
|
39
|
+
# [name, start_time, end_time (or nil if one-shot), &block]
|
40
40
|
#
|
41
41
|
@_timers = Array.new
|
42
42
|
@_repeating_timers = Array.new
|
43
43
|
super
|
44
44
|
end
|
45
45
|
|
46
|
-
|
46
|
+
#
|
47
|
+
# Executes block each update during 'time' milliseconds
|
48
|
+
#
|
49
|
+
def during(time, options = {}, &block)
|
50
|
+
return if timer_exists?(options[:name]) && options[:replace] == false
|
51
|
+
stop_timer(options[:name])
|
52
|
+
|
47
53
|
ms = Gosu::milliseconds()
|
48
|
-
@_last_timer = [ms, ms + time, block]
|
54
|
+
@_last_timer = [options[:name], ms, ms + time, block]
|
49
55
|
@_timers << @_last_timer
|
50
56
|
self
|
51
57
|
end
|
52
58
|
|
53
|
-
|
59
|
+
#
|
60
|
+
# Executes block after 'time' milliseconds
|
61
|
+
#
|
62
|
+
def after(time, options = {}, &block)
|
63
|
+
return if timer_exists?(options[:name]) && options[:replace] == false
|
64
|
+
stop_timer(options[:name])
|
65
|
+
|
54
66
|
ms = Gosu::milliseconds()
|
55
|
-
@_last_timer = [ms + time, nil, block]
|
67
|
+
@_last_timer = [options[:name], ms + time, nil, block]
|
56
68
|
@_timers << @_last_timer
|
57
69
|
self
|
58
70
|
end
|
59
|
-
|
60
|
-
|
71
|
+
|
72
|
+
#
|
73
|
+
# Executes block each update during 'start_time' and 'end_time'
|
74
|
+
#
|
75
|
+
def between(start_time, end_time, options = {}, &block)
|
76
|
+
return if timer_exists?(options[:name]) && options[:replace] == false
|
77
|
+
stop_timer(options[:name])
|
78
|
+
|
61
79
|
ms = Gosu::milliseconds()
|
62
|
-
@_last_timer = [ms + start_time, ms + end_time, block]
|
80
|
+
@_last_timer = [options[:name], ms + start_time, ms + end_time, block]
|
63
81
|
@_timers << @_last_timer
|
64
82
|
self
|
65
83
|
end
|
66
84
|
|
85
|
+
#
|
86
|
+
# Executes block every 'delay' milliseconds
|
87
|
+
#
|
88
|
+
def every(delay, options = {}, &block)
|
89
|
+
return if timer_exists?(options[:name]) && options[:replace] == false
|
90
|
+
stop_timer(options[:name])
|
91
|
+
|
92
|
+
ms = Gosu::milliseconds()
|
93
|
+
@_repeating_timers << [options[:name], ms + delay, delay, block]
|
94
|
+
end
|
95
|
+
|
96
|
+
#
|
97
|
+
# Executes block after the last timer ends
|
98
|
+
# ...use one-shots start_time for our trailing "then".
|
99
|
+
# ...use durable timers end_time for our trailing "then".
|
100
|
+
#
|
67
101
|
def then(&block)
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
102
|
+
start_time = @_last_timer[2].nil? ? @_last_timer[1] : @_last_timer[2]
|
103
|
+
@_timers << [@_last_timer[0], start_time, nil, block]
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
#
|
108
|
+
# See if a timer with name 'name' exists
|
109
|
+
#
|
110
|
+
def timer_exists?(timer_name = nil)
|
111
|
+
return false if timer_name.nil?
|
112
|
+
@_timers.each { |name, | return true if timer_name == name }
|
113
|
+
@_repeating_timers.each { |name, | return true if timer_name == name }
|
114
|
+
return false
|
115
|
+
end
|
116
|
+
|
117
|
+
#
|
118
|
+
# Stop timer with name 'name'
|
119
|
+
#
|
120
|
+
def stop_timer(name)
|
121
|
+
@_timers.reject! { |name, start_time, end_time, block| name == name }
|
122
|
+
@_repeating_timers.reject! { |name, start_time, end_time, block| name == name }
|
72
123
|
end
|
73
124
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
125
|
+
#
|
126
|
+
# Stop all timers
|
127
|
+
#
|
128
|
+
def stop_timers
|
129
|
+
@_timers.clear
|
130
|
+
@_repeating_timers.clear
|
131
|
+
end
|
78
132
|
|
79
133
|
def update_trait
|
80
134
|
ms = Gosu::milliseconds()
|
81
135
|
|
82
|
-
@_timers.each do |start_time, end_time, block|
|
136
|
+
@_timers.each do |name, start_time, end_time, block|
|
83
137
|
block.call if ms > start_time && (end_time == nil || ms < end_time)
|
84
138
|
end
|
85
139
|
|
86
140
|
index = 0
|
87
|
-
@_repeating_timers.each do |start_time, delay, block|
|
141
|
+
@_repeating_timers.each do |name, start_time, delay, block|
|
88
142
|
if ms > start_time
|
89
143
|
block.call
|
90
|
-
@_repeating_timers[index] = [ms + delay, delay, block]
|
144
|
+
@_repeating_timers[index] = [name, ms + delay, delay, block]
|
91
145
|
end
|
92
146
|
index += 1
|
93
147
|
end
|
94
148
|
|
95
149
|
# Remove one-shot timers (only a start_time, no end_time) and all timers which have expired
|
96
|
-
@_timers.reject! { |start_time, end_time, block| (ms > start_time && end_time == nil) || (end_time != nil && ms > end_time) }
|
150
|
+
@_timers.reject! { |name, start_time, end_time, block| (ms > start_time && end_time == nil) || (end_time != nil && ms > end_time) }
|
97
151
|
|
98
152
|
super
|
99
153
|
end
|
@@ -23,9 +23,13 @@ module Chingu
|
|
23
23
|
module Traits
|
24
24
|
#
|
25
25
|
# A chingu trait providing velocity and acceleration logic.
|
26
|
+
# Adds parameters: velocity_x/y, acceleration_x/y and modifies self.x / self.y
|
27
|
+
# Also keeps previous_x and previous_y which is the x, y before modification.
|
28
|
+
# Can be useful for example collision detection
|
26
29
|
#
|
27
30
|
module Velocity
|
28
31
|
attr_accessor :velocity_x, :velocity_y, :acceleration_x, :acceleration_y, :max_velocity
|
32
|
+
attr_reader :previous_x, :previous_y
|
29
33
|
|
30
34
|
def setup_trait(options)
|
31
35
|
@velocity_options = {:debug => false}.merge(options)
|
@@ -44,13 +48,19 @@ module Chingu
|
|
44
48
|
def update_trait
|
45
49
|
@velocity_y += @acceleration_y if (@velocity_y + @acceleration_y).abs < @max_velocity
|
46
50
|
@velocity_x += @acceleration_x if (@velocity_x + @acceleration_x).abs < @max_velocity
|
51
|
+
|
52
|
+
@previous_y = @y
|
53
|
+
@previous_x = @x
|
54
|
+
|
47
55
|
self.y += @velocity_y
|
48
56
|
self.x += @velocity_x
|
49
57
|
super
|
50
58
|
end
|
51
59
|
|
52
60
|
def stop
|
53
|
-
@acceleration_y = @acceleration_x =
|
61
|
+
# @acceleration_y = @acceleration_x = 0
|
62
|
+
@velocity_x = 0
|
63
|
+
@velocity_y = 0
|
54
64
|
end
|
55
65
|
end
|
56
66
|
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.6.
|
4
|
+
version: 0.6.6
|
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-12-
|
33
|
+
date: 2009-12-12 00:00:00 +01:00
|
34
34
|
default_executable:
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
@@ -41,7 +41,7 @@ dependencies:
|
|
41
41
|
requirements:
|
42
42
|
- - ">="
|
43
43
|
- !ruby/object:Gem::Version
|
44
|
-
version: 2.
|
44
|
+
version: 2.4.0
|
45
45
|
version:
|
46
46
|
description: |-
|
47
47
|
OpenGL accelerated 2D game framework for Ruby.
|
metadata.gz.sig
CHANGED
Binary file
|