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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
-
|
|
|
|
|
!
-
|
-
|
!
-
|
|
|
|
|
|
|
|
-
|
|
!
|
#module
#deffunc boxl int, int, int, int
mref x1, 0
mref y1, 1
mref x2, 2
mref y2, 3
line x1, y1, x2, y1
line x2, y1, x2, y2
line x2, y2, x1, y2
line x1, y2, x1, y1
return
#deffunc mgetcoli_bb val, val, int
mref bp1, 48 mref bp2, 49 mref fsw, 2 mref outstat, 64
outstat = 0
dim bpsw,4,2 memcpy bpsw, bp1, 16
memcpy bpsw, bp2, 16, 16
if fsw {
repeat 2
if bpsw.0.cnt>bpsw.2.cnt : bpsw.0.cnt+=bpsw.2.cnt : bpsw.2.cnt=bpsw.0.cnt-bpsw.2.cnt : bpsw.0.cnt-=bpsw.2.cnt
if bpsw.1.cnt>bpsw.3.cnt : bpsw.1.cnt+=bpsw.3.cnt : bpsw.3.cnt=bpsw.1.cnt-bpsw.3.cnt : bpsw.1.cnt-=bpsw.3.cnt
loop
}
if (bpsw.0.0>bpsw.2.1) | (bpsw.2.0<bpsw.0.1) | (bpsw.1.0>bpsw.3.1) | (bpsw.3.0<bpsw.1.1) ! 1 : outstat=1
return
#deffunc mgetcoli_bl val, int, int, int, int
mref crpos, 48 mref x1, 1 mref y1, 2
mref x2, 3
mref y2, 4
mref outstat, 64
outstat = 0
dim crpos2, 4
crpos2 = x1, y1, x2, y2
mgetcoli_bb crpos, crpos2, 1
if stat=0 : return
ht = 0
a = crpos.0 : b1 = crpos.1 : b2 = crpos.3
gosub *hantei
a = crpos.2 : b1 = crpos.1 : b2 = crpos.3
gosub *hantei
if (ht=4)|(ht=-4) {
outstat = 0 } else {
outstat = 1 }
return
*hantei
if x1!x2 {
bb = y1-y2*a + (x1*y2)-(x2*y1) / (x1-x2)
if bb>b1 : ht += -1 if bb<b1 : ht += 1 if bb>b2 : ht += -1 if bb<b2 : ht += 1 } else {
if x1>a : ht += -1 if x1<a : ht += 1 }
return
#global
title "衝突判定サンプル"
#define JIKIMV 3 dim intJikiPos, 2 dim intJikiHitA, 2 dim hanteiA, 4
intJikiPos = winx/2, winy/2
intJikiHitA = 30, 40
dim intTekiA, 4
intTekiA = 50,50, 100,100
dim lz, 4 lz = winx/2, 100, 0, winy-100
dlz = 1
*main
redraw 0
color 255,255,255 : boxf : color 0,0,0
stick key, 255
gosub *keiinput
if lz.2>=winx : dlz = -1
if lz.2<=0 : dlz = 1
lz.2+= dlz*3
fhit = 0 hanteiA = intJikiPos.0, intJikiPos.1, intJikiPos.0 + intJikiHitA.0, intJikiPos.1 + intJikiHitA.1
mgetcoli_bl hanteiA, lz.0, lz.1, lz.2, lz.3
if stat : fhit = 1
mgetcoli_bb hanteiA, intTekiA, 1
if stat : fhit = 1
ff=200,50,winx-100,30
mgetcoli_bb ff, hanteiA
if stat : fhit = 1
line lz.0, lz.1, lz.2, lz.3
pos lz.0-32, lz.1-16 : mes "レーザー"
boxl intTekiA.0, intTekiA.1, intTekiA.2, intTekiA.3 pos intTekiA.0, intTekiA.1 : mes "敵"
boxl ff.0, ff.1, ff.2, ff.3
if fhit=1 : color 255,0,0
boxl hanteiA.0, hanteiA.1, hanteiA.2, hanteiA.3
pos hanteiA.0, hanteiA.1 : mes "自機"
redraw 1
await 5
goto *main
stop
*keiinput
if key&1 : addx = -JIKIMV
if key&2 : addy = -JIKIMV
if key&4 : addx = JIKIMV
if key&8 : addy = JIKIMV
if key&128 : end
intJikiPos.0+= addx
intJikiPos.1+= addy
addx = 0 : addy = 0
return
|