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
|
-
|
|
|
|
|
|
!
-
|
|
-
|
|
!
-
|
|
|
|
!
-
|
|
|
|
!
-
|
|
!
-
|
|
!
|
#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 GHOST_SAVE_SPAN 1024 #define GHOST_FILE_NAME "Race_Ghost.sav"
*init
buffer 1, AREA_X, AREA_Y
screen 0, AREA_X, AREA_Y * 2, 0
gmode 0, AREA_X, AREA_Y
title "ゴーストの記憶・表示 - 平面レースゲームの場合"
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
exist GHOST_FILE_NAME
existGhost = strsize sdim nextGhostData, GHOST_SAVE_SPAN if existGhost >= 0 {
ghostX = carX : ghostY = carY : ghostZ = carZ ghostT = carT ghostSpeed = carSpeed ghostPage = -1 sdim ghostData, GHOST_SAVE_SPAN gosub *loadNextGhost
}
onexit goto *endFlag
*main
gosub *move gosub *draw
ghostIndex++
if ghostIndex == GHOST_SAVE_SPAN : gosub *loadNextGhost
await 16
goto *main
*move
stick key, 15
if (ghostPage * GHOST_SAVE_SPAN + ghostIndex) <= existGhost {
ghostkey = peek(ghostData, ghostIndex) } else {
existGhost = -1 }
poke nextGhostData, ghostIndex, key
gosub *moveCar gosub *moveGhost 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
*moveGhost
if existGhost < 0 : return
ghostSpeed = limitf(ghostSpeed + 0.1*((ghostKey & 2) - 1), 0.0, 3.0)
if GhostSpeed > 0.0 {
ghostT += 0.1*((ghostKey & 1) - (ghostKey >> 2 & 1))
ghostX = limitf(ghostX + ghostSpeed * cos(ghostT), 0, AREA_X)
ghostY = limitf(ghostY + ghostSpeed * sin(ghostT), 0, AREA_Y)
needToDraw = 1
}
return
*moveCam
camT = atan(camY - carY, camX - carX)
camX = carX + cos(camT) * CAM_DISTANCE
camY = carY + sin(camT) * CAM_DISTANCE
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 *drawBufGhost 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
*drawBufGhost
if existGhost < 0 : return
color 128, 128, 128
d3initlineto
d3lineto ghostX, ghostY, ghostZ
d3lineto ghostX - cos(ghostT + 0.2) * CAR_SIZE, ghostY - sin(ghostT + 0.2) * CAR_SIZE, ghostZ
d3lineto ghostX - cos(ghostT - 0.2) * CAR_SIZE, ghostY - sin(ghostT - 0.2) * CAR_SIZE, ghostZ
d3lineto ghostX, ghostY, ghostZ
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 *drawScrMapGhost
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
*drawScrMapghost
if existGhost < 0 : return
color 128, 128, 128
pos ghostX, AREA_Y - ghostY
line ghostX - cos(ghostT + 0.2) * CAR_SIZE, AREA_Y - (ghostY - sin(ghostT + 0.2) * CAR_SIZE)
line ghostX - cos(ghostT - 0.2) * CAR_SIZE, AREA_Y - (ghostY - sin(ghostT - 0.2) * CAR_SIZE)
line ghostX, AREA_Y - ghostY
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
*loadNextGhost
ghostPage++ if existGhost >= 0 {
bload GHOST_FILE_NAME, ghostData, limit(existGhost - ghostPage * GHOST_SAVE_SPAN, 0, GHOST_SAVE_SPAN), GHOST_SAVE_SPAN * ghostPage
}
if ghostPage > 0 {
bsave GHOST_FILE_NAME, nextGhostData, GHOST_SAVE_SPAN, GHOST_SAVE_SPAN * (ghostPage - 1)
}
memset nextGhostData, 0, GHOST_SAVE_SPAN
ghostIndex = 0
return
*endFlag
bsave GHOST_FILE_NAME, nextGhostData, ghostIndex, GHOST_SAVE_SPAN * (ghostPage - 1)
end
|