tung-tea 0.0.4 → 0.1.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/README.rdoc CHANGED
@@ -1,4 +1,4 @@
1
- = tea
1
+ = Tea
2
2
 
3
3
  <i>For simpler games from a simpler age.</i>
4
4
 
@@ -18,7 +18,15 @@ many game engines and APIs.
18
18
 
19
19
  == Installing
20
20
 
21
- TODO
21
+ First, get Ruby (http://www.ruby-lang.org) if you don't have it already. Ruby
22
+ 1.9 or later is recommended.
23
+
24
+ Tea is available as a gem on GitHub, so you can install it like so:
25
+
26
+ gem install tung-tea -s http://gems.github.com
27
+
28
+ The rubysdl gem (http://www.kmc.gr.jp/~ohai/rubysdl.en.html) will be installed
29
+ automatically as a dependency of Tea.
22
30
 
23
31
 
24
32
  == Using Tea
@@ -34,7 +42,7 @@ Below is a simple bouncing circle demo.
34
42
  Tea::Screen.set_mode 640, 480
35
43
 
36
44
  x, y = 320, 240
37
- dx, dy = rand() * 2 - 1, rand() * 2 - 1
45
+ dx, dy = rand() * 4 - 2, rand() * 4 - 2
38
46
  r = 20
39
47
 
40
48
  loop do
@@ -77,10 +85,11 @@ What isn't done yet:
77
85
  * Screen resizing
78
86
  * Handling of alpha in colours for primitives
79
87
 
80
- What's still on the drawing board:
81
88
 
82
- * Timed game loop code
83
- * Resource management
89
+ == More information
90
+
91
+ Project page:: http://github.com/tung/tea
92
+ Wiki:: http://wiki.github.com/tung/tea
84
93
 
85
94
 
86
95
  == License
@@ -94,6 +103,6 @@ FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
94
103
  details.
95
104
 
96
105
  You should have received a copy of the GNU Lesser General Public License along
97
- with Tea. If not, see <http://www.gnu.org/licenses/>.
106
+ with Tea. If not, see (http://www.gnu.org/licenses).
98
107
 
99
108
  Copyright (c) 2009 Tung Nguyen.
@@ -0,0 +1,129 @@
1
+ These key constants are returned by key events and can be passed into keyboard status checking methods. The all live in Tea::Kbd, so the 'A' key on your keyboard would be Tea::Kbd::A, for example.
2
+
3
+ The value of each constant is a Ruby symbol with the same name, which should make debugging easier.
4
+
5
+ BACKSPACE
6
+ TAB
7
+ ENTER
8
+ PAUSE
9
+ ESCAPE
10
+ SPACE
11
+ EXCLAMATION_MARK
12
+ DOUBLE_QUOTE
13
+ HASH
14
+ DOLLAR
15
+ AMPERSAND
16
+ QUOTE
17
+ OPEN_PAREN
18
+ CLOSE_PAREN
19
+ ASTERISK
20
+ PLUS
21
+ COMMA
22
+ MINUS
23
+ PERIOD
24
+ SLASH
25
+ K0
26
+ K1
27
+ K2
28
+ K3
29
+ K4
30
+ K5
31
+ K6
32
+ K7
33
+ K8
34
+ K9
35
+ COLON
36
+ SEMICOLON
37
+ LESS_THAN
38
+ EQUALS
39
+ GREATER_THAN
40
+ QUESTION_MARK
41
+ AT
42
+ OPEN_SQUARE_BRACKET
43
+ BACKSLASH
44
+ CLOSE_SQUARE_BRACKET
45
+ CARET
46
+ UNDERSCORE
47
+ BACKTICK
48
+ A
49
+ B
50
+ C
51
+ D
52
+ E
53
+ F
54
+ G
55
+ H
56
+ I
57
+ J
58
+ K
59
+ L
60
+ M
61
+ N
62
+ O
63
+ P
64
+ Q
65
+ R
66
+ S
67
+ T
68
+ U
69
+ V
70
+ W
71
+ X
72
+ Y
73
+ Z
74
+ DELETE
75
+ NP0
76
+ NP1
77
+ NP2
78
+ NP3
79
+ NP4
80
+ NP5
81
+ NP6
82
+ NP7
83
+ NP8
84
+ NP9
85
+ NP_PERIOD
86
+ NP_DIVIDE
87
+ NP_MULTIPLY
88
+ NP_MINUS
89
+ NP_PLUS
90
+ NP_ENTER
91
+ NP_EQUALS
92
+ UP
93
+ DOWN
94
+ RIGHT
95
+ LEFT
96
+ INSERT
97
+ HOME
98
+ END
99
+ PAGE_UP
100
+ PAGE_DOWN
101
+ F1
102
+ F2
103
+ F3
104
+ F4
105
+ F5
106
+ F6
107
+ F7
108
+ F8
109
+ F9
110
+ F10
111
+ F11
112
+ F12
113
+ NUM_LOCK
114
+ CAPS_LOCK
115
+ SCROLL_LOCK
116
+ R_SHIFT
117
+ L_SHIFT
118
+ R_CTRL
119
+ L_CTRL
120
+ R_ALT
121
+ L_ALT
122
+ L_SUPER
123
+ R_SUPER
124
+ ALT_GR
125
+ PRINT_SCREEN
126
+ SYS_REQ
127
+ BREAK
128
+ MENU
129
+ EURO
@@ -0,0 +1,19 @@
1
+ Key modifiers are things like Shift or Num Lock that change the meaning of some keys when they're held down or toggled on. Tea::Kbd::Down and Tea::Kbd::Up events provide modifier information.
2
+
3
+ The following constants are valid modifiers that also happen to match their keys. Like the [[Key Constants]], they also live in Tea::Kbd, so the left Shift key would be Tea::Kbd::L_SHIFT.
4
+
5
+ L_SHIFT
6
+ R_SHIFT
7
+ L_CTRL
8
+ R_CTRL
9
+ L_ALT
10
+ R_ALT
11
+ NUM_LOCK
12
+ CAPS_LOCK
13
+ ALT_GR
14
+
15
+ These extra constants can used for convenience. They also live in Tea::Kbd, but aren't physical keys.
16
+
17
+ SHIFT
18
+ CTRL
19
+ ALT
@@ -0,0 +1,204 @@
1
+ This page is manually assembled, so parts of it may become out of date. If something's missing or doesn't exist, let me know.
2
+
3
+
4
+ h1. Tea
5
+
6
+ h2. Tea.init()
7
+
8
+ Intialise Tea. This needs to be called before using any of Tea's objects or methods. May throw Tea::Error if initialisation fails.
9
+
10
+ h2. Tea::Error
11
+
12
+ This is the exception class raised when Bad Things happen in any of Tea's objects or methods.
13
+
14
+
15
+ h1. Graphics
16
+
17
+ h2. Tea::Bitmap
18
+
19
+ A Bitmap is a grid of pixels that holds graphics. It can be drawn onto and drawn with.
20
+
21
+ h3. Tea::Bitmap included mixins
22
+
23
+ Instances of Tea::Bitmap share methods from the following modules:
24
+
25
+ Tea::Blitting:
26
+ * blit(source_blittable, x, y)
27
+
28
+ Tea::PrimitiveDrawing:
29
+ * clear()
30
+ * point(x, y, color)
31
+ * rect(x, y, w, h, color)
32
+ * line(x1, y1, x2, y2, color[, {:antialias => false}])
33
+ * circle(x, y, radius, color[, {:outline => false, :antialias => false}])
34
+
35
+ Note that colours are of the form 0xRRGGBBAA.
36
+
37
+ h3. Tea::Bitmap.new(image_path)
38
+
39
+ Create a new Bitmap from an image file. May raise Tea::Error if it fails.
40
+
41
+ h3. Tea::Bitmap#w()
42
+
43
+ The width of the Bitmap in pixels.
44
+
45
+ h3. Tea::Bitmap#h()
46
+
47
+ The height of the Bitmap in pixels.
48
+
49
+ h2. Tea::Screen
50
+
51
+ Tea::Screen acts much like a Bitmap, except things drawn to it will be displayed on the screen once Tea::Screen.update() is called.
52
+
53
+ h3. Tea::Screen mixins
54
+
55
+ Since Tea::Screen is an object and not a class, its mixins add methods to Tea::Screen itself.
56
+
57
+ Tea::Blitting:
58
+ * blit(source_blittable, x, y)
59
+
60
+ Tea::PrimitiveDrawing:
61
+ * clear()
62
+ * point(x, y, color)
63
+ * rect(x, y, w, h, color)
64
+ * line(x1, y1, x2, y2, color[, {:antialias => false}])
65
+ * circle(x, y, radius, color[, {:outline => false, :antialias => false}])
66
+
67
+ Note that colours are of the form 0xRRGGBBAA.
68
+
69
+ h3. Tea::Screen.set_mode(width, height)
70
+
71
+ Create a screen window with the given dimensions. After this, you can start drawing on the screen. May raise Tea::Error if it fails.
72
+
73
+ h3. Tea::Screen.update()
74
+
75
+ Make what has been drawn on the screen visible.
76
+
77
+ h3. Tea::Screen.w()
78
+
79
+ The width of the screen in pixels.
80
+
81
+ h3. Tea::Screen.h()
82
+
83
+ The height of the screen in pixels.
84
+
85
+
86
+ h1. Input and other events
87
+
88
+ Event handling is the heart and soul of most games, so this subsystem is quite important.
89
+
90
+ h2. Tea::Event
91
+
92
+ The Event module allows access to the event queue, and the classes of events that come out.
93
+
94
+ Events rely on having a screen window, so call Tea::Screen.set_mode before using any of these.
95
+
96
+ h3. Tea::Event.get(wait=false)
97
+
98
+ Get the next event in the event queue. If wait is true and there are no events to return, this method will wait until there is one and return it. Otherwise, an empty event queue will return nil. The events that can be returned include:
99
+
100
+ * *Tea::App::Exit*
101
+ * *Tea::App::Minimized*
102
+ * *Tea::App::Restored*
103
+
104
+ * *Tea::Kbd::Lost*
105
+ - i.e. keyboard input focus lost
106
+ * *Tea::Kbd::Gained*
107
+ - i.e. keyboard input focus gained
108
+ * *Tea::Kbd::Down*
109
+ - key - keyboard key that was pressed (see [[Key Constants]])
110
+ - mods - a hash of modifiers active when key was pressed (see [[Key Modifiers]])
111
+ - char - character generated when the key is typed
112
+ * *Tea::Kbd::Up*
113
+ - key - keyboard key that was released (see [[Key Constants]])
114
+ - mods - modifiers active when the key was released (see [[Key Modifiers]])
115
+
116
+ * *Tea::Mouse::Move*
117
+ - x, y - coordinates of the mouse
118
+ - buttons - a hash of mouse buttons to true/false: Tea::Mouse::LEFT, MIDDLE and RIGHT
119
+ * *Tea::Mouse::Lost*
120
+ - i.e. mouse is no longer in the screen window
121
+ * *Tea::Mouse::Gained*
122
+ - i.e. mouse is within the screen window
123
+ * *Tea::Mouse::Down*
124
+ - x, y - coordinates of the mouse when the button was pressed
125
+ - button - one of Tea::Mouse::LEFT, MIDDLE or RIGHT
126
+ * *Tea::Mouse::Up*
127
+ - x, y - coordinates of the mouse when the button was released
128
+ - button - mouse button constant, same as for Tea::Mouse::Down#button
129
+ * *Tea::Mouse::Scroll*
130
+ - x, y - coordinates of the mouse when the scroll wheel was used
131
+ - delta - 1 for a downward scroll, -1 for an upward scroll
132
+
133
+ These returned event objects may have methods that give extra information about the event itself.
134
+
135
+ May raise Tea::Error if getting an event fails.
136
+
137
+ h2. Tea::App
138
+
139
+ As well as the app-related events that spawn from here, this module also provides some app-related status checking.
140
+
141
+ The methods below will only return different values when Tea::Event.get() is called.
142
+
143
+ h3. Tea::App.visible?
144
+
145
+ Returns true if the screen window is visible, i.e. not minimised.
146
+
147
+ h2. Tea::Kbd
148
+
149
+ As well as the keyboard-related events that spawn from here, this module also lets you check the status of keys and modifiers.
150
+
151
+ The methods below will only return different values when Tea::Event.get() is called.
152
+
153
+ h3. Tea::Kbd.in_app?()
154
+
155
+ Returns true if the keyboard focus is within the screen window. Most of the time, this means the screen window is in the foreground.
156
+
157
+ h3. Tea::Kbd.key_down?(key)
158
+
159
+ Returns true if the key given is being pressed. See [[Key Constants]].
160
+
161
+ h3. Tea::Kbd.mod_active?(mod)
162
+
163
+ Returns true if the modifier is 'active'.
164
+
165
+ For Shift, Ctrl, Alt and AltGr (not sure on the last one) this means they're being held down.
166
+
167
+ For Num Lock and Caps Lock, this means their toggle is on.
168
+
169
+ Tea::Kbd::SHIFT, CTRL and ALT can be passed in for convenience. See [[Key Modifiers]].
170
+
171
+ h2. Tea::Mouse
172
+
173
+ As well as the mouse-related events that spawn from here, this module also lets you check the state of the mouse.
174
+
175
+ The methods below will only return different values when Tea::Event.get() is called.
176
+
177
+ h3. Tea::Mouse.in_app?()
178
+
179
+ Returns true if the mouse cursor is over the screen window. If there are other windows in front of the screen window, this can still return true, depending on your environment.
180
+
181
+ h3. Tea::Mouse.x()
182
+
183
+ Get the x part of the mouse coordinates.
184
+
185
+ h3. Tea::Mouse.y()
186
+
187
+ Get the y part of the mouse coordinates.
188
+
189
+ h3. Tea::Mouse.left?()
190
+
191
+ Returns true when the left mouse button is held down.
192
+
193
+ h3. Tea::Mouse.middle?()
194
+
195
+ Returns true when the middle mouse button is held down.
196
+
197
+ h3. Tea::Mouse.right?()
198
+
199
+ Returns true when the right mouse button is held down.
200
+
201
+
202
+ h1. Sound
203
+
204
+ Nothing yet.
@@ -47,8 +47,8 @@ module Tea
47
47
  (options[:antialias] if options)
48
48
  end
49
49
 
50
- # Draw a circle centred at (x, y) with the given radius and color.
51
- # Optional hash arguments:
50
+ # Draw a circle centred at (x, y) with the given radius and color
51
+ # (0xRRGGBBAA). Optional hash arguments:
52
52
  #
53
53
  # +:outline+:: If true, do not fill the circle, just draw an outline.
54
54
  # +:antialias+:: If true, smooth the edges of the circle with
@@ -67,10 +67,20 @@ module Tea
67
67
  # Convert hex_color of the form 0xRRGGBBAA to a color value the
68
68
  # primitive_buffer understands.
69
69
  def primitive_color(hex_color)
70
+ primitive_rgba_to_color(*primitive_hex_to_rgba(hex_color))
71
+ end
72
+
73
+ # Break hex_color from the form 0xRRGGBBAA to [red, green, blue, alpha].
74
+ def primitive_hex_to_rgba(hex_color)
70
75
  red = (hex_color & 0xff000000) >> 24
71
76
  green = (hex_color & 0x00ff0000) >> 16
72
77
  blue = (hex_color & 0x0000ff00) >> 8
73
78
  alpha = (hex_color & 0x000000ff)
79
+ [red, green, blue, alpha]
80
+ end
81
+
82
+ # Generate a colour compatible with the primitive buffer.
83
+ def primitive_rgba_to_color(red, green, blue, alpha=255)
74
84
  primitive_buffer.map_rgba(red, green, blue, alpha)
75
85
  end
76
86
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tung-tea
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-25 00:00:00 -07:00
12
+ date: 2009-07-26 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -52,6 +52,9 @@ files:
52
52
  - doc/example/state_app.rb
53
53
  - doc/example/state_keyboard.rb
54
54
  - doc/example/state_mouse.rb
55
+ - doc/key_constants.textile
56
+ - doc/key_modifiers.textile
57
+ - doc/reference.textile
55
58
  - lib/tea.rb
56
59
  - lib/tea/c_bitmap.rb
57
60
  - lib/tea/c_error.rb
@@ -63,7 +66,7 @@ files:
63
66
  - lib/tea/m_primitive_drawing.rb
64
67
  - lib/tea/screen.rb
65
68
  has_rdoc: false
66
- homepage:
69
+ homepage: http://github.com/tung/tea
67
70
  post_install_message:
68
71
  rdoc_options:
69
72
  - --charset=UTF-8