File: collision.rsd

package info (click to toggle)
ruby-sdl 2.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, sid, stretch
  • size: 1,544 kB
  • ctags: 1,359
  • sloc: cpp: 7,598; ansic: 4,498; ruby: 2,246; makefile: 106; sh: 102
file content (200 lines) | stat: -rw-r--r-- 3,339 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
= Collision Detection
* ((<Collision Detection outline>))
* ((<SDL::CollisionMap>))

* ((<Collision Detection Methods>))
TOC

== Collision Detection outline
Ruby/SDL has collision detection system
derived from 
((<SGE|URL:http://www.etek.chalmers.se/~e8cal1/sge/index.html>)).
This enables you to pixel-pixel checking after
creating binary image by  @[Surface#make_collision_map].

Please see sample/collision.rb too.

== SDL::CollisionMap
This class represents binary image used by collision 
detections.
You can create this instance only by 
@[Surface#make_collision_map].

METHODS(CollisionMap)

== Collision Detection Methods
%%%
NAME make_collision_map
MOD Surface
TYPE #
DEP SGE
PURPOSE Creates a new collision map
RVAL SDL::CollisionMap

PROTO
make_collision_map
makeCollisionMap

DESC
Creates a new collision map from @[Surface] object.
Use @[Surface#set_color_key] before calling this method.
Every non-transparent pixel is set to
solid in the collision map. 

Returns a new @[CollisionMap] object.

EXCEPTION *

SEEALSO
Surface#set_color_key
CollisionMap#collision_check
CollisionMap#clear
CollisionMap#set

%%
NAME collision_check
MOD CollisionMap
TYPE #
DEP SGE
PURPOSE Does pixel collision detection.
RVAL true/false

PROTO
collision_check(x1, y1, cmap, x2, y2)

DESC
Does pixel perfect collision detection with 
$[self] and $[cmap]. 
The ($[x1],$[y1]) and ($[x2],$[y2])
coords are the positions of the upper left corners of the
images. Returns true if any solid
pixels of the two images overlap or else false.

This method calls @[CollisionMap#bounding_box_check] 
internally.

SEEALSO
CollisionMap#bounding_box_check

%%
NAME bounding_box_check
MOD CollisionMap
TYPE .
DEP SGE
PURPOSE Checks if two shapes overlap.
RVAL true/false

PROTO
bounding_box_check(x1,y1,w1,h1,x2,y2,w2,h2)
boundingBoxCheck(x1,y1,w1,h1,x2,y2,w2,h2)

DESC

Checks if two rectangles 
($[x1], $[$y1], $[w1], $[h1]) and
($[x2], $[$y2], $[w2], $[h2]) overlap.

RET
Returns true if two rectangles overlap, otherwise
returns false.

SEEALSO
CollisionMap#bounding_box_check

%%
NAME bounding_box_check
MOD CollisionMap
TYPE #
DEP SGE
PURPOSE Checks if two shapes overlap.
RVAL true/false

PROTO
bounding_box_check(x1, y1, cmap, x2, y2)
boundingBoxCheck(x1, y1, cmap, x2, y2)

DESC

Checks if two rectangles 
(the bounding boxes, $[self] and $[cmap]) overlap. 
The ($[x1],$[y1]) and ($[x2],$[y2])
coords are the positions of the upper left corners of the
images.

RET
Returns true if two rectangles overlap, otherwise
returns false.

SEEALSO
CollisionMap.bounding_box_check
CollisionMap#collision_check
CollisionMap#w
CollisionMap#h

%%
NAME clear
MOD CollisionMap
TYPE #
DEP SGE
PURPOSE Clears an area in the collision map

PROTO
clear(x, y, w, h)

DESC
Clears an area in the collision map from anything solid.

SEEALSO
CollisionMap#set

%%
NAME set
MOD CollisionMap
TYPE #
DEP SGE
PURPOSE Makes an area in the collision map solid

PROTO
set(x, y, w, h)

DESC
Makes an area in the collision map solid.

SEEALSO
CollisionMap#set

%%
NAME w
MOD CollisionMap
TYPE #
DEP SGE
PURPOSE Gets width of collision map
RVAL Integer

PROTO
w

DESC
Returns width of collision map.

SEEALSO
CollisionMap#h

%%
NAME h
MOD CollisionMap
TYPE #
DEP SGE
PURPOSE Get height of collision map
RVAL Integer

PROTO
h

DESC
Returns height of collision map.


SEEALSO
CollisionMap#w