gosu_wrapper 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/version.rb +1 -1
- data/readme.md +126 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 917ff2ab23c3b32591b9ca6e6cb81b60e88aaf13
|
4
|
+
data.tar.gz: 96a2c3dd86049eef3b8b00c2d620e9d435154d75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64d1346282045251db6f4de0300f6701087643d85e9a9bf875c415b77c77f34960b8b75f61c3cd8f4040bf08ce3054781b8d6ac38a1eced95657b4c3de26d835
|
7
|
+
data.tar.gz: d67cc8edbee1b432e7a61682f85dec118fc20193919a6f9cdf55cb9503ceb3b471f1fea5f6f9f1cad08d74bc4ba87beeb53caa97d48a9e094f7ff390dcd80c92
|
data/lib/version.rb
CHANGED
data/readme.md
CHANGED
@@ -0,0 +1,126 @@
|
|
1
|
+
### Installing
|
2
|
+
|
3
|
+
_gosu and activesupport will be loaded as dependencies_
|
4
|
+
|
5
|
+
`gem install gosu_wrapper`
|
6
|
+
|
7
|
+
or in a gemfile: `gem 'gosu_wrapper'`
|
8
|
+
|
9
|
+
### Usage
|
10
|
+
|
11
|
+
One public class is exposed, `GosuWrapper`. It's essentially a wrapper
|
12
|
+
over an anonymous `Gosu::Window` class that gets functionality added through
|
13
|
+
metaprogramming.
|
14
|
+
|
15
|
+
In lieue of a "getting started" snippet, I'm going to delegate that to the
|
16
|
+
[gosu_wrapper_snake_example](http://github.com/maxpleaner/gosu_wrapper_snake_example)
|
17
|
+
codebase and run through the API step-by-step here.
|
18
|
+
|
19
|
+
---
|
20
|
+
|
21
|
+
**`#initialize(width:, height:, attributes:)`**
|
22
|
+
|
23
|
+
- This defines `#window` which is an instance of `Gosu::Window`.
|
24
|
+
- width & height are num pixels (of the total window).
|
25
|
+
- attributes is an array of symbols.
|
26
|
+
It must at least include `:window_height` and `:window_width`.
|
27
|
+
All of the keys in your app's state hash should be given here.
|
28
|
+
Each of them get attr_accessors defined on `#window` and shorthand
|
29
|
+
accessors using `method_missing` (see next section).
|
30
|
+
|
31
|
+
---
|
32
|
+
|
33
|
+
**There are four instance methods added using `method_missing`**
|
34
|
+
|
35
|
+
1. `#get_<attr>`
|
36
|
+
- delegates the getter to `window`
|
37
|
+
2. `#set_<attr>(val)`
|
38
|
+
- delegates the setter to `window`
|
39
|
+
3. `#change_<attr>(sym, arg)`
|
40
|
+
- a shorthand for some update operations
|
41
|
+
on non-mutable objects. For example `change_score(:+, 1)`
|
42
|
+
4. `#get_or_set_<attr>(&blk)`
|
43
|
+
- returns the val if it's truthy, and otherwise sets the val equal
|
44
|
+
to the block result (returning it as well).
|
45
|
+
|
46
|
+
---
|
47
|
+
|
48
|
+
**`#define_method_on_window(name, &blk)`**
|
49
|
+
|
50
|
+
- this should be a private method, but is used by a number of others so
|
51
|
+
it's worth explaing.
|
52
|
+
- It defines the method named `name` on `window` with `blk` as its body.
|
53
|
+
- Arguments are determined by the block
|
54
|
+
- The block is always invoked with the `GosuWrapper` instance as
|
55
|
+
the value of `self`
|
56
|
+
|
57
|
+
---
|
58
|
+
|
59
|
+
**`#scope(*args, **keywords, &blk)`**
|
60
|
+
|
61
|
+
- another method that should be private; this is what handles
|
62
|
+
calling a proc with the `GosuWrapper` instance as the value of `self`.
|
63
|
+
|
64
|
+
---
|
65
|
+
|
66
|
+
**`#config(&blk)`**
|
67
|
+
|
68
|
+
- mostly the same thing as `#scope` but is meant to be used publically.
|
69
|
+
- the only functional difference is this always returns `self`
|
70
|
+
(the `GosuWrapper` instance) whereas `#scope` returns the result of the
|
71
|
+
block.
|
72
|
+
- Like `#scope`, this is a classic DSL-style method which exists for the
|
73
|
+
sole purpose of saving keystrokes (using `instance_exec`)
|
74
|
+
|
75
|
+
---
|
76
|
+
|
77
|
+
**`#add_hook(name, &blk)`**
|
78
|
+
|
79
|
+
- a "hook" conceptually is a method internally defined by `Gosu::Window`
|
80
|
+
that we're tapping into by overriding. Hooking into events `update`,
|
81
|
+
`button_down`, and `draw` are how the app works at a basic level.
|
82
|
+
- the `button_down` proc is passed an `id` which can be checked against
|
83
|
+
the values in `#buttons` to determine which key was pressed.
|
84
|
+
- `update` and `draw` are run every tick. Conceptually, `update`
|
85
|
+
is used to change the state and `draw` to represent it.
|
86
|
+
|
87
|
+
---
|
88
|
+
|
89
|
+
**`#add_helper(name, &blk)`**
|
90
|
+
|
91
|
+
- functionally speaking this is the exact same thing as `add_hook` -
|
92
|
+
it defines a method on `Gosu::Window`.
|
93
|
+
- It exists to distinguish between built-in hooks like `update` from
|
94
|
+
custom methods.
|
95
|
+
- These can be called with `#invoke` or its alias `#call_helper`.
|
96
|
+
|
97
|
+
---
|
98
|
+
|
99
|
+
**`#show`**
|
100
|
+
|
101
|
+
- Starts the game. Needs to be called only once.
|
102
|
+
|
103
|
+
---
|
104
|
+
|
105
|
+
**`#draw_rect(start_x:, start_y:, end_x:, end_y:, color)`**
|
106
|
+
|
107
|
+
- Can be called from `draw` only. Fills the rectangle with `color`
|
108
|
+
|
109
|
+
---
|
110
|
+
|
111
|
+
**`#colors`**
|
112
|
+
|
113
|
+
- a hash of name => color object pairs
|
114
|
+
|
115
|
+
---
|
116
|
+
|
117
|
+
**`#buttons`**
|
118
|
+
|
119
|
+
- a hash of name => button id pairs
|
120
|
+
|
121
|
+
---
|
122
|
+
|
123
|
+
**`#invoke/#call_helper/#dispatch/#call_hook`**
|
124
|
+
|
125
|
+
- all aliases for the same simple thing: calling a function on
|
126
|
+
`window` (the `Gosu::Window instance`).
|