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
|
-
|
|
|
!
-
|
|
|
|
!
|
#include "d3m.hsp"
#const PI 3.14159
#const AREA_X 320 #const AREA_Y 320 #const GRID_DISTANCE 32 #const GRID_NUM_X 11 #const GRID_NUM_Y 11 #const CAR_SIZE 12 #const CAM_DISTANCE 15.0#const CAM_MODE_MAX 7
*init
buffer 1, AREA_X, AREA_Y
screen 0, AREA_X, AREA_Y * 2, 0
gmode 0, AREA_X, AREA_Y
title "3Dカメラワーク - 平面レースゲームの場合"
carX = 10.0 : carY = 10.0 : carZ = 0.0 carT = PI / 4 carSpeed = 0.0 camX = 0.0 : camY = 0.0 : camZ = 20.0 camT = carT needToDraw = 1
camMode = 0
*main
gosub *move gosub *draw await 16
goto *main
*move
stick key, 15
if key & 16 {
camMode = (camMode + 1) \ CAM_MODE_MAX
needToDraw = 1
}
gosub *moveCar gosub *moveCam return
*moveCar
carSpeed = limitf(carSpeed + 0.1*((key & 2) - 1), 0.0, 3.0) if carSpeed > 0.0 {
carT += 0.1*((key & 1) - (key >> 2 & 1))
carX = limitf(carX + carSpeed * cos(carT), 0, AREA_X)
carY = limitf(carY + carSpeed * sin(carT), 0, AREA_Y)
needToDraw = 1 }
return
*moveCam
switch camMode
case 1 camT = atan(camY - carY, camX - carX)
camX = carX + cos(camT) * CAM_DISTANCE
camY = carY + sin(camT) * CAM_DISTANCE
swbreak
case 2 camT = PI * 3 / 2
camX = carX + cos(camT) * CAM_DISTANCE
camY = carY + sin(camT) * CAM_DISTANCE
swbreak
case 3 camT = PI * 3 / 2
camX = carX + cos(camT) * 5
camY = carY + sin(camT) * 5
swbreak
case 4 camX = AREA_X / 2
camY = AREA_Y / 2
swbreak
case 5 camT -= 0.03
if camT < 0 : camT += PI * 2
camX = carX + cos(camT) * CAM_DISTANCE
camY = carY + sin(camT) * CAM_DISTANCE
needToDraw = 1
swbreak
case 6 camT = atan(camY - carY, camX - carX)
camX = (carX + cos(camT) * CAM_DISTANCE + camX * 3) / 4
camY = (carY + sin(camT) * CAM_DISTANCE + camY * 3) / 4
swbreak
default camT = carT + PI
camX = carX + cos(camT) * CAM_DISTANCE
camY = carY + sin(camT) * CAM_DISTANCE
swbreak
swend
gsel 1
d3setcam camX, camY, camZ, carX, carY, carZ, 2
return
*draw
if needToDraw == 0 : return
gsel 1
gosub *drawBuf
gsel 0
gosub *drawScr
if carSpeed == 0.0 : needToDraw = 0
return
*drawBuf
color : boxf
gosub *drawBufGrid gosub *drawBufCar return
*drawBufGrid
color 0, 0, 255
repeat 9, int(carY / GRID_DISTANCE) - 4
if (cnt < 0)|(GRID_NUM_X <= cnt) : continue
y = cnt * GRID_DISTANCE
repeat 9, int(carX / GRID_DISTANCE) - 4
if (cnt < 0)|(GRID_NUM_Y <= cnt) : continue
x = cnt * GRID_DISTANCE
d3line x, 0, 0, x, AREA_Y, 0
d3line 0, y, 0, AREA_X, y, 0
loop
loop
return
*drawBufCar
color 255
d3initlineto
d3lineto carX, carY, carZ
d3lineto carX - cos(carT + 0.2) * CAR_SIZE, carY - sin(carT + 0.2) * CAR_SIZE, carZ
d3lineto carX - cos(carT - 0.2) * CAR_SIZE, carY - sin(carT - 0.2) * CAR_SIZE, carZ
d3lineto carX, carY, carZ
return
*drawScr
redraw 0
gosub *drawScrMap
pos 0, 320
gcopy 1, 0, 0 redraw 1
return
*drawScrMap
color : boxf 0, 0, 320, 320
gosub *drawScrMapGrid
gosub *drawScrMapCar
gosub *drawScrMapCam
return
*drawScrMapGrid
color 0, 0, 255
repeat GRID_NUM_Y
y = cnt * GRID_DISTANCE
repeat GRID_NUM_X
x = cnt * GRID_DISTANCE
line x, 0, x, AREA_Y
line 0, y, AREA_X, y
loop
loop
return
*drawScrMapCar
color 255
pos carX, AREA_Y - carY
line carX - cos(carT + 0.2) * CAR_SIZE, AREA_Y - (carY - sin(carT + 0.2) * CAR_SIZE)
line carX - cos(carT - 0.2) * CAR_SIZE, AREA_Y - (carY - sin(carT - 0.2) * CAR_SIZE)
line carX, AREA_Y - carY
return
*drawScrMapCam
color 0, 255
circle camX - 2, - camY + 2 + AREA_Y, camX + 2, - camY - 2 + AREA_Y
return
|